Class: RuboCop::CommentConfig
- Inherits:
-
Object
- Object
- RuboCop::CommentConfig
- Defined in:
- lib/rubocop/comment_config.rb
Overview
This class parses the special ‘rubocop:disable` comments in a source and provides a way to check if each cop is enabled at arbitrary line.
Defined Under Namespace
Classes: CopAnalysis
Instance Attribute Summary collapse
-
#processed_source ⇒ Object
readonly
Returns the value of attribute processed_source.
Instance Method Summary collapse
- #comment_only_line?(line_number) ⇒ Boolean
- #cop_disabled_line_ranges ⇒ Object
- #cop_enabled_at_line?(cop, line_number) ⇒ Boolean
- #extra_enabled_comments ⇒ Object
-
#initialize(processed_source) ⇒ CommentConfig
constructor
A new instance of CommentConfig.
Constructor Details
#initialize(processed_source) ⇒ CommentConfig
Returns a new instance of CommentConfig.
11 12 13 |
# File 'lib/rubocop/comment_config.rb', line 11 def initialize(processed_source) @processed_source = processed_source end |
Instance Attribute Details
#processed_source ⇒ Object (readonly)
Returns the value of attribute processed_source.
9 10 11 |
# File 'lib/rubocop/comment_config.rb', line 9 def processed_source @processed_source end |
Instance Method Details
#comment_only_line?(line_number) ⇒ Boolean
31 32 33 |
# File 'lib/rubocop/comment_config.rb', line 31 def comment_only_line?(line_number) non_comment_token_line_numbers.none?(line_number) end |
#cop_disabled_line_ranges ⇒ Object
23 24 25 |
# File 'lib/rubocop/comment_config.rb', line 23 def cop_disabled_line_ranges @cop_disabled_line_ranges ||= analyze end |
#cop_enabled_at_line?(cop, line_number) ⇒ Boolean
15 16 17 18 19 20 21 |
# File 'lib/rubocop/comment_config.rb', line 15 def cop_enabled_at_line?(cop, line_number) cop = cop.cop_name if cop.respond_to?(:cop_name) disabled_line_ranges = cop_disabled_line_ranges[cop] return true unless disabled_line_ranges disabled_line_ranges.none? { |range| range.include?(line_number) } end |
#extra_enabled_comments ⇒ Object
27 28 29 |
# File 'lib/rubocop/comment_config.rb', line 27 def extra_enabled_comments extra_enabled_comments_with_names(extras: Hash.new { |h, k| h[k] = [] }, names: Hash.new(0)) end |