Class: RuboCop::CommentConfig
- Inherits:
-
Object
- Object
- RuboCop::CommentConfig
- Extended by:
- Forwardable
- 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: ConfigDisabledCopDirectiveComment, CopAnalysis
Constant Summary collapse
- CONFIG_DISABLED_LINE_RANGE_MIN =
-Float::INFINITY
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.
32 33 34 35 |
# File 'lib/rubocop/comment_config.rb', line 32 def initialize(processed_source) @processed_source = processed_source @no_directives = !processed_source.raw_source.include?('rubocop') end |
Instance Attribute Details
#processed_source ⇒ Object (readonly)
Returns the value of attribute processed_source.
28 29 30 |
# File 'lib/rubocop/comment_config.rb', line 28 def processed_source @processed_source end |
Instance Method Details
#comment_only_line?(line_number) ⇒ Boolean
57 58 59 |
# File 'lib/rubocop/comment_config.rb', line 57 def comment_only_line?(line_number) non_comment_token_line_numbers.none?(line_number) end |
#cop_disabled_line_ranges ⇒ Object
45 46 47 |
# File 'lib/rubocop/comment_config.rb', line 45 def cop_disabled_line_ranges @cop_disabled_line_ranges ||= analyze end |
#cop_enabled_at_line?(cop, line_number) ⇒ Boolean
37 38 39 40 41 42 43 |
# File 'lib/rubocop/comment_config.rb', line 37 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
49 50 51 52 53 54 55 |
# File 'lib/rubocop/comment_config.rb', line 49 def extra_enabled_comments disable_count = Hash.new(0) registry.disabled(config).each do |cop| disable_count[cop.cop_name] += 1 end extra_enabled_comments_with_names(extras: Hash.new { |h, k| h[k] = [] }, names: disable_count) end |