rubocop 1.14.0 → 1.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -1
- data/config/default.yml +120 -34
- data/lib/rubocop.rb +8 -0
- data/lib/rubocop/cli/command/suggest_extensions.rb +3 -3
- data/lib/rubocop/config_loader.rb +1 -1
- data/lib/rubocop/config_validator.rb +5 -5
- data/lib/rubocop/cop/base.rb +2 -2
- data/lib/rubocop/cop/bundler/duplicated_gem.rb +1 -1
- data/lib/rubocop/cop/bundler/gem_version.rb +38 -4
- data/lib/rubocop/cop/corrector.rb +4 -4
- data/lib/rubocop/cop/generator.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/example_description.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +1 -1
- data/lib/rubocop/cop/layout/argument_alignment.rb +30 -12
- data/lib/rubocop/cop/layout/array_alignment.rb +2 -2
- data/lib/rubocop/cop/layout/block_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/case_indentation.rb +57 -9
- data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +7 -1
- data/lib/rubocop/cop/layout/comment_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/dot_position.rb +7 -1
- data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +13 -15
- data/lib/rubocop/cop/layout/first_array_element_indentation.rb +2 -2
- data/lib/rubocop/cop/layout/first_hash_element_indentation.rb +14 -2
- data/lib/rubocop/cop/layout/first_parameter_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/hash_alignment.rb +40 -14
- data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +1 -1
- data/lib/rubocop/cop/layout/indentation_width.rb +13 -2
- data/lib/rubocop/cop/layout/line_end_string_concatenation_indentation.rb +122 -0
- data/lib/rubocop/cop/layout/multiline_array_brace_layout.rb +6 -6
- data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +2 -2
- data/lib/rubocop/cop/layout/multiline_hash_brace_layout.rb +6 -6
- data/lib/rubocop/cop/layout/multiline_method_call_brace_layout.rb +6 -6
- data/lib/rubocop/cop/layout/multiline_method_definition_brace_layout.rb +6 -6
- data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +3 -3
- data/lib/rubocop/cop/layout/parameter_alignment.rb +2 -2
- data/lib/rubocop/cop/layout/redundant_line_break.rb +11 -9
- data/lib/rubocop/cop/layout/space_around_keyword.rb +28 -0
- data/lib/rubocop/cop/layout/space_around_operators.rb +7 -1
- data/lib/rubocop/cop/lint/deprecated_class_methods.rb +4 -0
- data/lib/rubocop/cop/lint/empty_block.rb +18 -2
- data/lib/rubocop/cop/lint/empty_in_pattern.rb +62 -0
- data/lib/rubocop/cop/lint/literal_as_condition.rb +13 -1
- data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +32 -17
- data/lib/rubocop/cop/lint/nested_percent_literal.rb +1 -1
- data/lib/rubocop/cop/lint/percent_string_array.rb +1 -1
- data/lib/rubocop/cop/lint/percent_symbol_array.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +105 -74
- data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +5 -0
- data/lib/rubocop/cop/lint/symbol_conversion.rb +3 -13
- data/lib/rubocop/cop/lint/unused_block_argument.rb +1 -1
- data/lib/rubocop/cop/lint/useless_assignment.rb +1 -1
- data/lib/rubocop/cop/lint/void.rb +1 -1
- data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +1 -1
- data/lib/rubocop/cop/migration/department_name.rb +3 -1
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +28 -3
- data/lib/rubocop/cop/mixin/frozen_string_literal.rb +6 -0
- data/lib/rubocop/cop/mixin/hash_alignment_styles.rb +14 -3
- data/lib/rubocop/cop/mixin/string_literals_help.rb +2 -4
- data/lib/rubocop/cop/mixin/symbol_help.rb +13 -0
- data/lib/rubocop/cop/naming/inclusive_language.rb +249 -0
- data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +2 -2
- data/lib/rubocop/cop/style/class_and_module_children.rb +28 -2
- data/lib/rubocop/cop/style/empty_literal.rb +8 -1
- data/lib/rubocop/cop/style/hash_each_methods.rb +18 -1
- data/lib/rubocop/cop/style/identical_conditional_branches.rb +58 -8
- data/lib/rubocop/cop/style/in_pattern_then.rb +56 -0
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +2 -1
- data/lib/rubocop/cop/style/multiline_in_pattern_then.rb +62 -0
- data/lib/rubocop/cop/style/multiline_when_then.rb +2 -11
- data/lib/rubocop/cop/style/multiple_comparison.rb +1 -1
- data/lib/rubocop/cop/style/nil_lambda.rb +29 -12
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +1 -1
- data/lib/rubocop/cop/style/quoted_symbols.rb +110 -0
- data/lib/rubocop/cop/style/raise_args.rb +2 -0
- data/lib/rubocop/cop/style/redundant_begin.rb +1 -1
- data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +1 -1
- data/lib/rubocop/cop/style/redundant_self.rb +24 -2
- data/lib/rubocop/cop/style/regexp_literal.rb +10 -1
- data/lib/rubocop/cop/style/special_global_vars.rb +3 -3
- data/lib/rubocop/cop/style/string_concatenation.rb +32 -5
- data/lib/rubocop/cop/style/string_literals.rb +3 -2
- data/lib/rubocop/cop/style/string_literals_in_interpolation.rb +1 -0
- data/lib/rubocop/cop/style/swap_values.rb +1 -1
- data/lib/rubocop/cop/style/top_level_method_definition.rb +83 -0
- data/lib/rubocop/cop/style/trivial_accessors.rb +65 -0
- data/lib/rubocop/cop/style/unpack_first.rb +1 -1
- data/lib/rubocop/cop/style/when_then.rb +6 -2
- data/lib/rubocop/cop/variable_force/variable_table.rb +1 -1
- data/lib/rubocop/directive_comment.rb +58 -6
- data/lib/rubocop/formatter/junit_formatter.rb +21 -6
- data/lib/rubocop/options.rb +18 -24
- data/lib/rubocop/rake_task.rb +1 -1
- data/lib/rubocop/remote_config.rb +10 -2
- data/lib/rubocop/rspec/cop_helper.rb +1 -1
- data/lib/rubocop/rspec/expect_offense.rb +1 -1
- data/lib/rubocop/version.rb +1 -1
- metadata +13 -5
@@ -64,10 +64,10 @@ module RuboCop
|
|
64
64
|
extend AutoCorrector
|
65
65
|
|
66
66
|
NEW_LINE_OFFENSE = 'Right hand side of multi-line assignment is on ' \
|
67
|
-
|
67
|
+
'the same line as the assignment operator `=`.'
|
68
68
|
|
69
69
|
SAME_LINE_OFFENSE = 'Right hand side of multi-line assignment is not ' \
|
70
|
-
|
70
|
+
'on the same line as the assignment operator `=`.'
|
71
71
|
|
72
72
|
def check_assignment(node, rhs)
|
73
73
|
return if node.send_type? && node.loc.operator&.source != '='
|
@@ -93,18 +93,18 @@ module RuboCop
|
|
93
93
|
extend AutoCorrector
|
94
94
|
|
95
95
|
SAME_LINE_MESSAGE = 'Closing hash brace must be on the same line as ' \
|
96
|
-
|
97
|
-
|
96
|
+
'the last hash element when opening brace is on the same line as ' \
|
97
|
+
'the first hash element.'
|
98
98
|
|
99
99
|
NEW_LINE_MESSAGE = 'Closing hash brace must be on the line after ' \
|
100
|
-
|
101
|
-
|
100
|
+
'the last hash element when opening brace is on a separate line ' \
|
101
|
+
'from the first hash element.'
|
102
102
|
|
103
103
|
ALWAYS_NEW_LINE_MESSAGE = 'Closing hash brace must be on the line ' \
|
104
|
-
|
104
|
+
'after the last hash element.'
|
105
105
|
|
106
106
|
ALWAYS_SAME_LINE_MESSAGE = 'Closing hash brace must be on the same ' \
|
107
|
-
|
107
|
+
'line as the last hash element.'
|
108
108
|
|
109
109
|
def on_hash(node)
|
110
110
|
check_brace_layout(node)
|
@@ -93,18 +93,18 @@ module RuboCop
|
|
93
93
|
extend AutoCorrector
|
94
94
|
|
95
95
|
SAME_LINE_MESSAGE = 'Closing method call brace must be on the ' \
|
96
|
-
|
97
|
-
|
96
|
+
'same line as the last argument when opening brace is on the same ' \
|
97
|
+
'line as the first argument.'
|
98
98
|
|
99
99
|
NEW_LINE_MESSAGE = 'Closing method call brace must be on the ' \
|
100
|
-
|
101
|
-
|
100
|
+
'line after the last argument when opening brace is on a separate ' \
|
101
|
+
'line from the first argument.'
|
102
102
|
|
103
103
|
ALWAYS_NEW_LINE_MESSAGE = 'Closing method call brace must be on ' \
|
104
|
-
|
104
|
+
'the line after the last argument.'
|
105
105
|
|
106
106
|
ALWAYS_SAME_LINE_MESSAGE = 'Closing method call brace must be on ' \
|
107
|
-
|
107
|
+
'the same line as the last argument.'
|
108
108
|
|
109
109
|
def on_send(node)
|
110
110
|
check_brace_layout(node)
|
@@ -105,18 +105,18 @@ module RuboCop
|
|
105
105
|
extend AutoCorrector
|
106
106
|
|
107
107
|
SAME_LINE_MESSAGE = 'Closing method definition brace must be on the ' \
|
108
|
-
|
109
|
-
|
108
|
+
'same line as the last parameter when opening brace is on the same ' \
|
109
|
+
'line as the first parameter.'
|
110
110
|
|
111
111
|
NEW_LINE_MESSAGE = 'Closing method definition brace must be on the ' \
|
112
|
-
|
113
|
-
|
112
|
+
'line after the last parameter when opening brace is on a separate ' \
|
113
|
+
'line from the first parameter.'
|
114
114
|
|
115
115
|
ALWAYS_NEW_LINE_MESSAGE = 'Closing method definition brace must be ' \
|
116
|
-
|
116
|
+
'on the line after the last parameter.'
|
117
117
|
|
118
118
|
ALWAYS_SAME_LINE_MESSAGE = 'Closing method definition brace must be ' \
|
119
|
-
|
119
|
+
'on the same line as the last parameter.'
|
120
120
|
|
121
121
|
def on_def(node)
|
122
122
|
check_brace_layout(node.arguments)
|
@@ -59,9 +59,9 @@ module RuboCop
|
|
59
59
|
return unless style == :aligned && cop_config['IndentationWidth']
|
60
60
|
|
61
61
|
raise ValidationError, 'The `Layout/MultilineOperationIndentation`' \
|
62
|
-
|
63
|
-
|
64
|
-
|
62
|
+
' cop only accepts an `IndentationWidth` ' \
|
63
|
+
'configuration parameter when ' \
|
64
|
+
'`EnforcedStyle` is `indented`.'
|
65
65
|
end
|
66
66
|
|
67
67
|
private
|
@@ -73,10 +73,10 @@ module RuboCop
|
|
73
73
|
extend AutoCorrector
|
74
74
|
|
75
75
|
ALIGN_PARAMS_MSG = 'Align the parameters of a method definition if ' \
|
76
|
-
|
76
|
+
'they span more than one line.'
|
77
77
|
|
78
78
|
FIXED_INDENT_MSG = 'Use one level of indentation for parameters ' \
|
79
|
-
|
79
|
+
'following the first line of a multi-line method definition.'
|
80
80
|
|
81
81
|
def on_def(node)
|
82
82
|
return if node.arguments.size < 2
|
@@ -42,8 +42,9 @@ module RuboCop
|
|
42
42
|
# # good
|
43
43
|
# foo(a) { |x| puts x }
|
44
44
|
#
|
45
|
-
class RedundantLineBreak <
|
45
|
+
class RedundantLineBreak < Base
|
46
46
|
include CheckAssignment
|
47
|
+
extend AutoCorrector
|
47
48
|
|
48
49
|
MSG = 'Redundant line break detected.'
|
49
50
|
|
@@ -55,23 +56,24 @@ module RuboCop
|
|
55
56
|
|
56
57
|
return unless offense?(node) && !part_of_ignored_node?(node)
|
57
58
|
|
58
|
-
|
59
|
-
ignore_node(node)
|
59
|
+
register_offense(node)
|
60
60
|
end
|
61
61
|
|
62
|
+
private
|
63
|
+
|
62
64
|
def check_assignment(node, _rhs)
|
63
65
|
return unless offense?(node)
|
64
66
|
|
65
|
-
|
66
|
-
ignore_node(node)
|
67
|
+
register_offense(node)
|
67
68
|
end
|
68
69
|
|
69
|
-
def
|
70
|
-
|
70
|
+
def register_offense(node)
|
71
|
+
add_offense(node) do |corrector|
|
72
|
+
corrector.replace(node.source_range, to_single_line(node.source).strip)
|
73
|
+
end
|
74
|
+
ignore_node(node)
|
71
75
|
end
|
72
76
|
|
73
|
-
private
|
74
|
-
|
75
77
|
def offense?(node)
|
76
78
|
return false if configured_to_not_be_inspected?(node)
|
77
79
|
|
@@ -53,6 +53,10 @@ module RuboCop
|
|
53
53
|
check(node, %i[keyword else].freeze)
|
54
54
|
end
|
55
55
|
|
56
|
+
def on_case_match(node)
|
57
|
+
check(node, %i[keyword else].freeze)
|
58
|
+
end
|
59
|
+
|
56
60
|
def on_ensure(node)
|
57
61
|
check(node, [:keyword].freeze)
|
58
62
|
end
|
@@ -65,10 +69,30 @@ module RuboCop
|
|
65
69
|
check(node, %i[keyword else begin end].freeze, 'then')
|
66
70
|
end
|
67
71
|
|
72
|
+
def on_if_guard(node)
|
73
|
+
check(node, [:keyword].freeze)
|
74
|
+
end
|
75
|
+
|
76
|
+
def on_in_pattern(node)
|
77
|
+
check(node, [:keyword].freeze)
|
78
|
+
end
|
79
|
+
|
68
80
|
def on_kwbegin(node)
|
69
81
|
check(node, %i[begin end].freeze, nil)
|
70
82
|
end
|
71
83
|
|
84
|
+
# Handle one-line pattern matching syntax (`in`) with `Parser::Ruby27`.
|
85
|
+
def on_match_pattern(node)
|
86
|
+
return if target_ruby_version >= 3.0
|
87
|
+
|
88
|
+
check(node, [:operator].freeze)
|
89
|
+
end
|
90
|
+
|
91
|
+
# Handle one-line pattern matching syntax (`in`) with `Parser::Ruby30`.
|
92
|
+
def on_match_pattern_p(node)
|
93
|
+
check(node, [:operator].freeze)
|
94
|
+
end
|
95
|
+
|
72
96
|
def on_next(node)
|
73
97
|
check(node, [:keyword].freeze)
|
74
98
|
end
|
@@ -109,6 +133,10 @@ module RuboCop
|
|
109
133
|
check(node, [:keyword].freeze)
|
110
134
|
end
|
111
135
|
|
136
|
+
def on_unless_guard(node)
|
137
|
+
check(node, [:keyword].freeze)
|
138
|
+
end
|
139
|
+
|
112
140
|
def on_until(node)
|
113
141
|
check(node, %i[begin end keyword].freeze)
|
114
142
|
end
|
@@ -120,6 +120,12 @@ module RuboCop
|
|
120
120
|
check_operator(:special_asgn, node.loc.operator, right.source_range)
|
121
121
|
end
|
122
122
|
|
123
|
+
def on_match_pattern(node)
|
124
|
+
return if target_ruby_version < 3.0
|
125
|
+
|
126
|
+
check_operator(:match_pattern, node.loc.operator, node.source_range)
|
127
|
+
end
|
128
|
+
|
123
129
|
alias on_or on_binary
|
124
130
|
alias on_and on_binary
|
125
131
|
alias on_lvasgn on_assignment
|
@@ -192,7 +198,7 @@ module RuboCop
|
|
192
198
|
elsif excess_leading_space?(type, operator, with_space) ||
|
193
199
|
excess_trailing_space?(right_operand, with_space)
|
194
200
|
"Operator `#{operator.source}` should be surrounded " \
|
195
|
-
|
201
|
+
'by a single space.'
|
196
202
|
end
|
197
203
|
end
|
198
204
|
|
@@ -12,6 +12,8 @@ module RuboCop
|
|
12
12
|
# File.exists?(some_path)
|
13
13
|
# Dir.exists?(some_path)
|
14
14
|
# iterator?
|
15
|
+
# Socket.gethostbyname(host)
|
16
|
+
# Socket.gethostbyaddr(host)
|
15
17
|
#
|
16
18
|
# @example
|
17
19
|
#
|
@@ -20,6 +22,8 @@ module RuboCop
|
|
20
22
|
# File.exist?(some_path)
|
21
23
|
# Dir.exist?(some_path)
|
22
24
|
# block_given?
|
25
|
+
# Addrinfo.getaddrinfo(nodename, service)
|
26
|
+
# Addrinfo.tcp(host, port).getnameinfo
|
23
27
|
class DeprecatedClassMethods < Base
|
24
28
|
extend AutoCorrector
|
25
29
|
|
@@ -7,7 +7,11 @@ module RuboCop
|
|
7
7
|
# Such empty blocks are typically an oversight or we should provide a comment
|
8
8
|
# be clearer what we're aiming for.
|
9
9
|
#
|
10
|
-
# Empty lambdas are ignored by default.
|
10
|
+
# Empty lambdas and procs are ignored by default.
|
11
|
+
#
|
12
|
+
# NOTE: For backwards compatibility, the configuration that allows/disallows
|
13
|
+
# empty lambdas and procs is called `AllowEmptyLambdas`, even though it also
|
14
|
+
# applies to procs.
|
11
15
|
#
|
12
16
|
# @example
|
13
17
|
# # bad
|
@@ -40,6 +44,10 @@ module RuboCop
|
|
40
44
|
# end
|
41
45
|
# (callable || placeholder).call
|
42
46
|
#
|
47
|
+
# proc { }
|
48
|
+
#
|
49
|
+
# Proc.new { }
|
50
|
+
#
|
43
51
|
# @example AllowEmptyLambdas: false
|
44
52
|
# # bad
|
45
53
|
# allow(subject).to receive(:callable).and_return(-> {})
|
@@ -48,12 +56,16 @@ module RuboCop
|
|
48
56
|
# end
|
49
57
|
# (callable || placeholder).call
|
50
58
|
#
|
59
|
+
# proc { }
|
60
|
+
#
|
61
|
+
# Proc.new { }
|
62
|
+
#
|
51
63
|
class EmptyBlock < Base
|
52
64
|
MSG = 'Empty block detected.'
|
53
65
|
|
54
66
|
def on_block(node)
|
55
67
|
return if node.body
|
56
|
-
return if allow_empty_lambdas? && node
|
68
|
+
return if allow_empty_lambdas? && lambda_or_proc?(node)
|
57
69
|
return if cop_config['AllowComments'] && allow_comment?(node)
|
58
70
|
|
59
71
|
add_offense(node)
|
@@ -76,6 +88,10 @@ module RuboCop
|
|
76
88
|
regexp_pattern = "# rubocop : (disable|todo) ([^,],)* (all|#{cop_name})"
|
77
89
|
Regexp.new(regexp_pattern.gsub(' ', '\s*')).match?(comment)
|
78
90
|
end
|
91
|
+
|
92
|
+
def lambda_or_proc?(node)
|
93
|
+
node.lambda? || node.proc?
|
94
|
+
end
|
79
95
|
end
|
80
96
|
end
|
81
97
|
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Lint
|
6
|
+
# This cop checks for the presence of `in` pattern branches without a body.
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
#
|
10
|
+
# # bad
|
11
|
+
# case condition
|
12
|
+
# in [a]
|
13
|
+
# do_something
|
14
|
+
# in [a, b]
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# # good
|
18
|
+
# case condition
|
19
|
+
# in [a]
|
20
|
+
# do_something
|
21
|
+
# in [a, b]
|
22
|
+
# nil
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# @example AllowComments: true (default)
|
26
|
+
#
|
27
|
+
# # good
|
28
|
+
# case condition
|
29
|
+
# in [a]
|
30
|
+
# do_something
|
31
|
+
# in [a, b]
|
32
|
+
# # noop
|
33
|
+
# end
|
34
|
+
#
|
35
|
+
# @example AllowComments: false
|
36
|
+
#
|
37
|
+
# # bad
|
38
|
+
# case condition
|
39
|
+
# in [a]
|
40
|
+
# do_something
|
41
|
+
# in [a, b]
|
42
|
+
# # noop
|
43
|
+
# end
|
44
|
+
#
|
45
|
+
class EmptyInPattern < Base
|
46
|
+
extend TargetRubyVersion
|
47
|
+
|
48
|
+
MSG = 'Avoid `in` branches without a body.'
|
49
|
+
|
50
|
+
minimum_target_ruby_version 2.7
|
51
|
+
|
52
|
+
def on_case_match(node)
|
53
|
+
node.in_pattern_branches.each do |branch|
|
54
|
+
next if branch.body || cop_config['AllowComments'] && comment_lines?(node)
|
55
|
+
|
56
|
+
add_offense(branch)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -5,7 +5,7 @@ module RuboCop
|
|
5
5
|
module Lint
|
6
6
|
# This cop checks for literals used as the conditions or as
|
7
7
|
# operands in and/or expressions serving as the conditions of
|
8
|
-
# if/while/until.
|
8
|
+
# if/while/until/case-when/case-in.
|
9
9
|
#
|
10
10
|
# @example
|
11
11
|
#
|
@@ -67,6 +67,18 @@ module RuboCop
|
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
+
def on_case_match(case_match_node)
|
71
|
+
if case_match_node.condition
|
72
|
+
check_case(case_match_node)
|
73
|
+
else
|
74
|
+
case_match_node.each_in_pattern do |in_pattern_node|
|
75
|
+
next unless in_pattern_node.condition.literal?
|
76
|
+
|
77
|
+
add_offense(in_pattern_node)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
70
82
|
def on_send(node)
|
71
83
|
return unless node.negation_method?
|
72
84
|
|
@@ -45,37 +45,52 @@ module RuboCop
|
|
45
45
|
class MissingCopEnableDirective < Base
|
46
46
|
include RangeHelp
|
47
47
|
|
48
|
-
MSG = 'Re-enable %<cop>s
|
49
|
-
MSG_BOUND = 'Re-enable %<cop>s
|
48
|
+
MSG = 'Re-enable %<cop>s %<type>s with `# rubocop:enable` after disabling it.'
|
49
|
+
MSG_BOUND = 'Re-enable %<cop>s %<type>s within %<max_range>s lines after disabling it.'
|
50
50
|
|
51
|
-
# rubocop:disable Metrics/AbcSize
|
52
51
|
def on_new_investigation
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
# the case when max_range is Float::INFINITY
|
58
|
-
next if line_range.max - line_range.min < max_range + 2
|
52
|
+
each_missing_enable do |cop, line_range|
|
53
|
+
# This has to remain a strict inequality to handle
|
54
|
+
# the case when max_range is Float::INFINITY
|
55
|
+
next if line_range.max - line_range.min < max_range + 2
|
59
56
|
|
60
|
-
|
57
|
+
range = source_range(processed_source.buffer, line_range.min, (0..0))
|
58
|
+
comment = processed_source.comment_at_line(line_range.begin)
|
61
59
|
|
62
|
-
|
63
|
-
end
|
60
|
+
add_offense(range, message: message(cop, comment))
|
64
61
|
end
|
65
62
|
end
|
66
|
-
# rubocop:enable Metrics/AbcSize
|
67
63
|
|
68
64
|
private
|
69
65
|
|
70
|
-
def
|
66
|
+
def each_missing_enable
|
67
|
+
processed_source.disabled_line_ranges.each do |cop, line_ranges|
|
68
|
+
line_ranges.each { |line_range| yield cop, line_range }
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def max_range
|
73
|
+
@max_range ||= cop_config['MaximumRangeSize']
|
74
|
+
end
|
75
|
+
|
76
|
+
def message(cop, comment, type = 'cop')
|
77
|
+
if department_enabled?(cop, comment)
|
78
|
+
type = 'department'
|
79
|
+
cop = cop.split('/').first
|
80
|
+
end
|
81
|
+
|
71
82
|
if max_range == Float::INFINITY
|
72
|
-
format(MSG, cop: cop)
|
83
|
+
format(MSG, cop: cop, type: type)
|
73
84
|
else
|
74
|
-
format(MSG_BOUND, cop: cop, max_range: max_range)
|
85
|
+
format(MSG_BOUND, cop: cop, type: type, max_range: max_range)
|
75
86
|
end
|
76
87
|
end
|
88
|
+
|
89
|
+
def department_enabled?(cop, comment)
|
90
|
+
DirectiveComment.new(comment).in_directive_department?(cop)
|
91
|
+
end
|
77
92
|
end
|
78
93
|
end
|
79
94
|
end
|
80
95
|
end
|
81
|
-
# rubocop:enable Lint/RedundantCopDisableDirective
|
96
|
+
# rubocop:enable Lint/RedundantCopDisableDirective
|