Class: RuboCop::CommentConfig

Inherits:
Object
  • Object
show all
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.

Constant Summary collapse

COMMENT_DIRECTIVE_REGEXP =
Regexp.new(
  '\A# rubocop : ((?:dis|en)able)\b ((?:[\w/]+,? )+)'.gsub(' ', '\s*')
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(processed_source) ⇒ CommentConfig

Returns a new instance of CommentConfig.


13
14
15
# File 'lib/rubocop/comment_config.rb', line 13

def initialize(processed_source)
  @processed_source = processed_source
end

Instance Attribute Details

#processed_sourceObject (readonly)

Returns the value of attribute processed_source


11
12
13
# File 'lib/rubocop/comment_config.rb', line 11

def processed_source
  @processed_source
end

Instance Method Details

#cop_disabled_line_rangesObject


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

Returns:

  • (Boolean)

17
18
19
20
21
# File 'lib/rubocop/comment_config.rb', line 17

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]
  disabled_line_ranges.none? { |range| range.include?(line_number) }
end