Class: RubocopChallenger::Rubocop::Rule
- Inherits:
-
Object
- Object
- RubocopChallenger::Rubocop::Rule
- Includes:
- Comparable
- Defined in:
- lib/rubocop_challenger/rubocop/rule.rb
Overview
Parse rubocop rule which loaded from Rubocop::TodoReader class
Instance Attribute Summary collapse
-
#contents ⇒ Object
readonly
Returns the value of attribute contents.
-
#offense_count ⇒ Object
readonly
Returns the value of attribute offense_count.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#==(other) ⇒ Boolean
Compare to other rule.
- #autocorrectable? ⇒ Boolean
-
#initialize(contents) ⇒ Rule
constructor
A new instance of Rule.
- #rubydoc_url ⇒ Object
Constructor Details
#initialize(contents) ⇒ Rule
Returns a new instance of Rule.
11 12 13 14 15 |
# File 'lib/rubocop_challenger/rubocop/rule.rb', line 11 def initialize(contents) @contents = contents.dup @title = extract_title @offense_count = extract_offense_count end |
Instance Attribute Details
#contents ⇒ Object (readonly)
Returns the value of attribute contents.
9 10 11 |
# File 'lib/rubocop_challenger/rubocop/rule.rb', line 9 def contents @contents end |
#offense_count ⇒ Object (readonly)
Returns the value of attribute offense_count.
9 10 11 |
# File 'lib/rubocop_challenger/rubocop/rule.rb', line 9 def offense_count @offense_count end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
9 10 11 |
# File 'lib/rubocop_challenger/rubocop/rule.rb', line 9 def title @title end |
Instance Method Details
#<=>(other) ⇒ Object
25 26 27 |
# File 'lib/rubocop_challenger/rubocop/rule.rb', line 25 def <=>(other) offense_count <=> other.offense_count end |
#==(other) ⇒ Boolean
Compare to other rule
21 22 23 |
# File 'lib/rubocop_challenger/rubocop/rule.rb', line 21 def ==(other) title == other.title end |
#autocorrectable? ⇒ Boolean
29 30 31 32 33 |
# File 'lib/rubocop_challenger/rubocop/rule.rb', line 29 def autocorrectable? contents.match?('# This cop supports (un)?safe autocorrection') || # for rubocop >= v1.30.0 contents.match?(/# This cop supports (un)?safe auto-correction/) || # for rubocop >= v1.26.0 contents.include?('# Cop supports --auto-correct') # for rubocop < v1.26.0 end |
#rubydoc_url ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/rubocop_challenger/rubocop/rule.rb', line 35 def rubydoc_url if title.start_with?('RSpec') "https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/#{title}" else "https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/#{title}" end end |