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
Constant Summary collapse
- REDUNDANT_DISABLE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'Lint/RedundantCopDisableDirective'
- COP_NAME_PATTERN =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'([A-Z]\w+/)*(?:[A-Z]\w+)'
- COP_NAMES_PATTERN =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
"(?:#{COP_NAME_PATTERN} , )*#{COP_NAME_PATTERN}"
- COPS_PATTERN =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
"(all|#{COP_NAMES_PATTERN})"
- COMMENT_DIRECTIVE_REGEXP =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Regexp.new( "# rubocop : ((?:disable|enable|todo))\\b #{COPS_PATTERN}" .gsub(' ', '\s*') )
Instance Attribute Summary collapse
-
#processed_source ⇒ Object
readonly
Returns the value of attribute processed_source.
Instance Method Summary collapse
- #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.
27 28 29 |
# File 'lib/rubocop/comment_config.rb', line 27 def initialize(processed_source) @processed_source = processed_source end |
Instance Attribute Details
#processed_source ⇒ Object (readonly)
Returns the value of attribute processed_source.
25 26 27 |
# File 'lib/rubocop/comment_config.rb', line 25 def processed_source @processed_source end |
Instance Method Details
#cop_disabled_line_ranges ⇒ Object
39 40 41 |
# File 'lib/rubocop/comment_config.rb', line 39 def cop_disabled_line_ranges @cop_disabled_line_ranges ||= analyze end |
#cop_enabled_at_line?(cop, line_number) ⇒ Boolean
31 32 33 34 35 36 37 |
# File 'lib/rubocop/comment_config.rb', line 31 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 |