Class: RuboCop::Cop::Offense

Inherits:
Object
  • Object
show all
Includes:
Dry::Core::Constants
Defined in:
lib/rfix/extension/offense.rb

Constant Summary collapse

STAR =

concerning :Features do

Rainbow("").yellow
CROSS =
Rainbow("").red
CHECK =
Rainbow("").green
CIRCLE =
Rainbow("").blue

Instance Method Summary collapse

Instance Method Details

#clickable_path(root_path) ⇒ Object



45
46
47
# File 'lib/rfix/extension/offense.rb', line 45

def clickable_path(root_path)
  Rainbow("#{relative_path(root_path)}:#{where}").italic
end

#clickable_plain_severityObject



59
60
61
# File 'lib/rfix/extension/offense.rb', line 59

def clickable_plain_severity
  TTY::Link.link_to(cop_name, href)
end

#clickable_severityObject



63
64
65
# File 'lib/rfix/extension/offense.rb', line 63

def clickable_severity
  clickable_plain_severity && Rainbow(clickable_plain_severity).italic
end

#codeObject



35
36
37
# File 'lib/rfix/extension/offense.rb', line 35

def code
  message.split(": ", 2).first
end

#escape(str) ⇒ Object



76
77
78
# File 'lib/rfix/extension/offense.rb', line 76

def escape(str)
  Shellwords.escape(str)
end

#hrefObject



49
50
51
52
53
54
55
56
57
# File 'lib/rfix/extension/offense.rb', line 49

def href
  cop_name.split("/", 2).then do |department, cop|
    return nil if [cop, department].any?(&:nil?)

    { type: department.parameterize, cop: cop.parameterize }
  end.then do |options|
    "https://docs.rubocop.org/rubocop/cops_%<type>s.html#%<type>s%<cop>s" % options
  end
end

#iconObject



67
68
69
70
71
72
73
74
# File 'lib/rfix/extension/offense.rb', line 67

def icon
  {
    uncorrected: CIRCLE,
    unsupported: CROSS,
    correctable: STAR,
    corrected: CHECK
  }.fetch(status)
end

#infoObject



27
28
29
# File 'lib/rfix/extension/offense.rb', line 27

def info
  message.split(": ", 2).last.delete("\n")
end

#msgObject



31
32
33
# File 'lib/rfix/extension/offense.rb', line 31

def msg
  Rainbow(info).italic
end

#relative_path(root_path) ⇒ Object



39
40
41
42
43
# File 'lib/rfix/extension/offense.rb', line 39

def relative_path(root_path)
  return EMPTY_STRING unless location.respond_to?(:source_buffer)

  Pathname(location.source_buffer.name).relative_path_from(root_path)
end

#whereObject



23
24
25
# File 'lib/rfix/extension/offense.rb', line 23

def where
  "#{line}:#{real_column}"
end