Class: Pronto::RubyCritic::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/pronto/rubycritic/formatter.rb

Overview

Chooses output markup based on CI environment. GitHub renders rich markdown (headings, tables, <details>) in PR review comments; GitLab does not render <details> reliably in MR / commit comments so plain markdown is used there.

Constant Summary collapse

GITHUB =
:github
GITLAB =
:gitlab
PLAIN =
:plain
SEVERITY_EMOJI =
{
  info: '💡',
  warning: '⚠️',
  error: '🔴',
  fatal: '🚨'
}.freeze
BRAND_NAME =
'pronto-rubycritic'
BRAND_URL =
'https://github.com/Rishabhs343/custom-pronto-gem'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(style: PLAIN, severity: :warning) ⇒ Formatter

Returns a new instance of Formatter.



32
33
34
35
# File 'lib/pronto/rubycritic/formatter.rb', line 32

def initialize(style: PLAIN, severity: :warning)
  @style    = style
  @severity = severity
end

Instance Attribute Details

#severityObject (readonly)

Returns the value of attribute severity.



37
38
39
# File 'lib/pronto/rubycritic/formatter.rb', line 37

def severity
  @severity
end

#styleObject (readonly)

Returns the value of attribute style.



37
38
39
# File 'lib/pronto/rubycritic/formatter.rb', line 37

def style
  @style
end

Class Method Details

.detect(env: ENV, severity: :warning) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/pronto/rubycritic/formatter.rb', line 24

def self.detect(env: ENV, severity: :warning)
  style = if env['GITHUB_ACTIONS'] then GITHUB
          elsif env['GITLAB_CI']   then GITLAB
          else PLAIN
          end
  new(style: style, severity: severity)
end

Instance Method Details

#call(mod, smell) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/pronto/rubycritic/formatter.rb', line 39

def call(mod, smell)
  case @style
  when GITHUB then format_github(mod, smell)
  when GITLAB then format_gitlab(mod, smell)
  else             format_plain(mod, smell)
  end
end