Class: RuboCop::Cop::Offense
- Inherits:
-
Object
- Object
- RuboCop::Cop::Offense
- 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
- #clickable_path(root_path) ⇒ Object
- #clickable_plain_severity ⇒ Object
- #clickable_severity ⇒ Object
- #code ⇒ Object
- #escape(str) ⇒ Object
- #href ⇒ Object
- #icon ⇒ Object
- #info ⇒ Object
- #msg ⇒ Object
- #relative_path(root_path) ⇒ Object
- #where ⇒ Object
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_severity ⇒ Object
59 60 61 |
# File 'lib/rfix/extension/offense.rb', line 59 def clickable_plain_severity TTY::Link.link_to(cop_name, href) end |
#clickable_severity ⇒ Object
63 64 65 |
# File 'lib/rfix/extension/offense.rb', line 63 def clickable_severity clickable_plain_severity && Rainbow(clickable_plain_severity).italic end |
#code ⇒ Object
35 36 37 |
# File 'lib/rfix/extension/offense.rb', line 35 def code .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 |
#href ⇒ Object
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 || "https://docs.rubocop.org/rubocop/cops_%<type>s.html#%<type>s%<cop>s" % end end |
#icon ⇒ Object
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 |
#info ⇒ Object
27 28 29 |
# File 'lib/rfix/extension/offense.rb', line 27 def info .split(": ", 2).last.delete("\n") end |
#msg ⇒ Object
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 |
#where ⇒ Object
23 24 25 |
# File 'lib/rfix/extension/offense.rb', line 23 def where "#{line}:#{real_column}" end |