Class: RuboCop::CommentConfig
- Inherits:
-
Object
- Object
- RuboCop::CommentConfig
show all
- Extended by:
- SimpleForwardable
- 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
Instance Method Summary
collapse
Constructor Details
#initialize(processed_source) ⇒ CommentConfig
Returns a new instance of CommentConfig.
34
35
36
37
|
# File 'lib/rubocop/comment_config.rb', line 34
def initialize(processed_source)
@processed_source = processed_source
@no_directives = !processed_source.raw_source.include?('rubocop')
end
|
Instance Attribute Details
#processed_source ⇒ Object
Returns the value of attribute processed_source.
30
31
32
|
# File 'lib/rubocop/comment_config.rb', line 30
def processed_source
@processed_source
end
|
Instance Method Details
63
64
65
|
# File 'lib/rubocop/comment_config.rb', line 63
def (line_number)
.none?(line_number)
end
|
#cop_disabled_line_ranges ⇒ Object
51
52
53
|
# File 'lib/rubocop/comment_config.rb', line 51
def cop_disabled_line_ranges
@cop_disabled_line_ranges ||= analyze
end
|
#cop_enabled_at_line?(cop, line_number) ⇒ Boolean
39
40
41
42
43
44
45
|
# File 'lib/rubocop/comment_config.rb', line 39
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
|
#cop_opted_in?(cop) ⇒ Boolean
47
48
49
|
# File 'lib/rubocop/comment_config.rb', line 47
def cop_opted_in?(cop)
opt_in_cops.include?(cop.cop_name)
end
|
55
56
57
58
59
60
61
|
# File 'lib/rubocop/comment_config.rb', line 55
def
disable_count = Hash.new(0)
registry.disabled(config).each do |cop|
disable_count[cop.cop_name] += 1
end
(extras: Hash.new { |h, k| h[k] = [] }, names: disable_count)
end
|