rubocop 0.75.0 → 0.76.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/config/default.yml +53 -54
- data/lib/rubocop.rb +10 -9
- data/lib/rubocop/ast/builder.rb +1 -0
- data/lib/rubocop/ast/node.rb +4 -0
- data/lib/rubocop/ast/node/return_node.rb +24 -0
- data/lib/rubocop/cli.rb +7 -4
- data/lib/rubocop/comment_config.rb +2 -2
- data/lib/rubocop/config.rb +7 -0
- data/lib/rubocop/config_loader.rb +1 -1
- data/lib/rubocop/config_loader_resolver.rb +2 -1
- data/lib/rubocop/config_obsoletion.rb +9 -0
- data/lib/rubocop/config_validator.rb +24 -15
- data/lib/rubocop/cop/commissioner.rb +15 -7
- data/lib/rubocop/cop/cop.rb +10 -6
- data/lib/rubocop/cop/corrector.rb +8 -7
- data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +1 -1
- data/lib/rubocop/cop/generator/configuration_injector.rb +1 -1
- data/lib/rubocop/cop/layout/align_hash.rb +6 -2
- data/lib/rubocop/cop/layout/comment_indentation.rb +10 -13
- data/lib/rubocop/cop/layout/empty_comment.rb +7 -16
- data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +22 -7
- data/lib/rubocop/cop/layout/empty_line_after_magic_comment.rb +2 -2
- data/lib/rubocop/cop/layout/empty_lines_around_class_body.rb +2 -2
- data/lib/rubocop/cop/layout/end_of_line.rb +8 -3
- data/lib/rubocop/cop/layout/indent_assignment.rb +2 -1
- data/lib/rubocop/cop/layout/indent_first_argument.rb +9 -7
- data/lib/rubocop/cop/layout/indent_first_hash_element.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +1 -1
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +2 -0
- data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +9 -7
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +7 -4
- data/lib/rubocop/cop/layout/space_inside_parens.rb +6 -6
- data/lib/rubocop/cop/layout/trailing_whitespace.rb +18 -2
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +9 -8
- data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +2 -2
- data/lib/rubocop/cop/lint/{unneeded_cop_disable_directive.rb → redundant_cop_disable_directive.rb} +23 -23
- data/lib/rubocop/cop/lint/{unneeded_cop_enable_directive.rb → redundant_cop_enable_directive.rb} +6 -8
- data/lib/rubocop/cop/lint/{unneeded_require_statement.rb → redundant_require_statement.rb} +1 -1
- data/lib/rubocop/cop/lint/{unneeded_splat_expansion.rb → redundant_splat_expansion.rb} +5 -5
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +5 -6
- data/lib/rubocop/cop/lint/unused_block_argument.rb +22 -6
- data/lib/rubocop/cop/lint/unused_method_argument.rb +23 -5
- data/lib/rubocop/cop/lint/void.rb +7 -26
- data/lib/rubocop/cop/metrics/abc_size.rb +1 -1
- data/lib/rubocop/cop/metrics/line_length.rb +1 -4
- data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +23 -6
- data/lib/rubocop/cop/mixin/method_complexity.rb +2 -1
- data/lib/rubocop/cop/mixin/statement_modifier.rb +5 -2
- data/lib/rubocop/cop/mixin/trailing_comma.rb +8 -6
- data/lib/rubocop/cop/naming/file_name.rb +12 -5
- data/lib/rubocop/cop/registry.rb +1 -1
- data/lib/rubocop/cop/style/attr.rb +2 -2
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +6 -6
- data/lib/rubocop/cop/style/comment_annotation.rb +5 -5
- data/lib/rubocop/cop/style/copyright.rb +11 -7
- data/lib/rubocop/cop/style/documentation_method.rb +44 -0
- data/lib/rubocop/cop/style/double_cop_disable_directive.rb +2 -2
- data/lib/rubocop/cop/style/empty_case_condition.rb +2 -2
- data/lib/rubocop/cop/style/empty_literal.rb +2 -2
- data/lib/rubocop/cop/style/empty_method.rb +5 -5
- data/lib/rubocop/cop/style/expand_path_arguments.rb +1 -1
- data/lib/rubocop/cop/style/format_string.rb +10 -7
- data/lib/rubocop/cop/style/format_string_token.rb +15 -34
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +10 -0
- data/lib/rubocop/cop/style/hash_syntax.rb +2 -2
- data/lib/rubocop/cop/style/if_unless_modifier.rb +9 -2
- data/lib/rubocop/cop/style/infinite_loop.rb +4 -3
- data/lib/rubocop/cop/style/inverse_methods.rb +19 -13
- data/lib/rubocop/cop/style/line_end_concatenation.rb +14 -10
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +20 -20
- data/lib/rubocop/cop/style/method_def_parentheses.rb +17 -9
- data/lib/rubocop/cop/style/multiline_when_then.rb +1 -1
- data/lib/rubocop/cop/style/nested_modifier.rb +4 -2
- data/lib/rubocop/cop/style/non_nil_check.rb +21 -9
- data/lib/rubocop/cop/style/{unneeded_capital_w.rb → redundant_capital_w.rb} +1 -1
- data/lib/rubocop/cop/style/{unneeded_condition.rb → redundant_condition.rb} +3 -3
- data/lib/rubocop/cop/style/{unneeded_interpolation.rb → redundant_interpolation.rb} +1 -1
- data/lib/rubocop/cop/style/{unneeded_percent_q.rb → redundant_percent_q.rb} +1 -1
- data/lib/rubocop/cop/style/redundant_return.rb +37 -21
- data/lib/rubocop/cop/style/{unneeded_sort.rb → redundant_sort.rb} +4 -4
- data/lib/rubocop/cop/style/safe_navigation.rb +19 -8
- data/lib/rubocop/cop/style/semicolon.rb +13 -2
- data/lib/rubocop/cop/style/special_global_vars.rb +5 -7
- data/lib/rubocop/cop/util.rb +1 -1
- data/lib/rubocop/cop/utils/format_string.rb +10 -18
- data/lib/rubocop/cop/variable_force.rb +7 -5
- data/lib/rubocop/formatter/clang_style_formatter.rb +8 -3
- data/lib/rubocop/formatter/emacs_style_formatter.rb +22 -12
- data/lib/rubocop/formatter/file_list_formatter.rb +1 -1
- data/lib/rubocop/formatter/formatter_set.rb +16 -16
- data/lib/rubocop/formatter/pacman_formatter.rb +3 -3
- data/lib/rubocop/formatter/simple_text_formatter.rb +7 -3
- data/lib/rubocop/formatter/tap_formatter.rb +8 -3
- data/lib/rubocop/node_pattern.rb +3 -1
- data/lib/rubocop/options.rb +16 -22
- data/lib/rubocop/result_cache.rb +1 -1
- data/lib/rubocop/runner.rb +32 -27
- data/lib/rubocop/target_finder.rb +12 -6
- data/lib/rubocop/version.rb +1 -1
- metadata +12 -11
@@ -72,7 +72,7 @@ module RuboCop
|
|
72
72
|
# If the second token is a comment, that means that a line break
|
73
73
|
# follows, and that the rules for space inside don't apply.
|
74
74
|
next if token2.comment?
|
75
|
-
next unless token2
|
75
|
+
next unless same_line?(token1, token2) && token1.space_after?
|
76
76
|
|
77
77
|
yield range_between(token1.end_pos, token2.begin_pos)
|
78
78
|
end
|
@@ -82,17 +82,18 @@ module RuboCop
|
|
82
82
|
tokens.each_cons(2) do |token1, token2|
|
83
83
|
next if can_be_ignored?(token1, token2)
|
84
84
|
|
85
|
-
next unless token2.line == token1.line && !token1.space_after?
|
86
|
-
|
87
85
|
if token1.left_parens?
|
88
86
|
yield range_between(token2.begin_pos, token2.begin_pos + 1)
|
89
|
-
|
90
87
|
elsif token2.right_parens?
|
91
88
|
yield range_between(token2.begin_pos, token2.end_pos)
|
92
89
|
end
|
93
90
|
end
|
94
91
|
end
|
95
92
|
|
93
|
+
def same_line?(token1, token2)
|
94
|
+
token1.line == token2.line
|
95
|
+
end
|
96
|
+
|
96
97
|
def parens?(token1, token2)
|
97
98
|
token1.left_parens? || token2.right_parens?
|
98
99
|
end
|
@@ -104,8 +105,7 @@ module RuboCop
|
|
104
105
|
# follows, and that the rules for space inside don't apply.
|
105
106
|
return true if token2.comment?
|
106
107
|
|
107
|
-
|
108
|
-
return true if token1.left_parens? && token2.right_parens?
|
108
|
+
return true unless same_line?(token1, token2) && !token1.space_after?
|
109
109
|
end
|
110
110
|
end
|
111
111
|
end
|
@@ -14,6 +14,20 @@ module RuboCop
|
|
14
14
|
# # good
|
15
15
|
# x = 0
|
16
16
|
#
|
17
|
+
# @example AllowInHeredoc: false (default)
|
18
|
+
# # The line in this example contains spaces after the 0.
|
19
|
+
# # bad
|
20
|
+
# code = <<~RUBY
|
21
|
+
# x = 0
|
22
|
+
# RUBY
|
23
|
+
#
|
24
|
+
# @example AllowInHeredoc: true
|
25
|
+
# # The line in this example contains spaces after the 0.
|
26
|
+
# # good
|
27
|
+
# code = <<~RUBY
|
28
|
+
# x = 0
|
29
|
+
# RUBY
|
30
|
+
#
|
17
31
|
class TrailingWhitespace < Cop
|
18
32
|
include RangeHelp
|
19
33
|
|
@@ -22,11 +36,13 @@ module RuboCop
|
|
22
36
|
def investigate(processed_source)
|
23
37
|
heredoc_ranges = extract_heredoc_ranges(processed_source.ast)
|
24
38
|
processed_source.lines.each_with_index do |line, index|
|
39
|
+
lineno = index + 1
|
40
|
+
|
25
41
|
next unless line.end_with?(' ', "\t")
|
26
|
-
next if skip_heredoc? && inside_heredoc?(heredoc_ranges,
|
42
|
+
next if skip_heredoc? && inside_heredoc?(heredoc_ranges, lineno)
|
27
43
|
|
28
44
|
range = source_range(processed_source.buffer,
|
29
|
-
|
45
|
+
lineno,
|
30
46
|
(line.rstrip.length)...(line.length))
|
31
47
|
|
32
48
|
add_offense(range, location: range)
|
@@ -86,13 +86,13 @@ module RuboCop
|
|
86
86
|
erb_new_with_non_keyword_arguments(node) do |arguments|
|
87
87
|
return if correct_arguments?(arguments)
|
88
88
|
|
89
|
-
1.
|
90
|
-
next if !
|
89
|
+
arguments[1..3].each_with_index do |argument, i|
|
90
|
+
next if !argument || argument.hash_type?
|
91
91
|
|
92
|
-
message = format(MESSAGES[i
|
92
|
+
message = format(MESSAGES[i], arg_value: argument.source)
|
93
93
|
|
94
94
|
add_offense(
|
95
|
-
node, location:
|
95
|
+
node, location: argument.source_range, message: message
|
96
96
|
)
|
97
97
|
end
|
98
98
|
end
|
@@ -138,14 +138,15 @@ module RuboCop
|
|
138
138
|
end
|
139
139
|
|
140
140
|
def override_by_legacy_args(kwargs, node)
|
141
|
+
arguments = node.arguments
|
141
142
|
overridden_kwargs = kwargs.dup
|
142
143
|
|
143
|
-
if
|
144
|
-
overridden_kwargs[0] = "trim_mode: #{
|
144
|
+
if arguments[2]
|
145
|
+
overridden_kwargs[0] = "trim_mode: #{arguments[2].source}"
|
145
146
|
end
|
146
147
|
|
147
|
-
if
|
148
|
-
overridden_kwargs[1] = "eoutvar: #{
|
148
|
+
if arguments[3] && !arguments[3].hash_type?
|
149
|
+
overridden_kwargs[1] = "eoutvar: #{arguments[3].source}"
|
149
150
|
end
|
150
151
|
|
151
152
|
overridden_kwargs
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# rubocop:disable Lint/
|
3
|
+
# rubocop:disable Lint/RedundantCopDisableDirective
|
4
4
|
module RuboCop
|
5
5
|
module Cop
|
6
6
|
module Lint
|
@@ -81,4 +81,4 @@ module RuboCop
|
|
81
81
|
end
|
82
82
|
end
|
83
83
|
end
|
84
|
-
# rubocop:enable Lint/
|
84
|
+
# rubocop:enable Lint/RedundantCopDisableDirective, Layout/SpaceAroundOperators
|
data/lib/rubocop/cop/lint/{unneeded_cop_disable_directive.rb → redundant_cop_disable_directive.rb}
RENAMED
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# The Lint/
|
4
|
-
# to be able to provide a (bad) example of
|
5
|
-
# rubocop:disable Lint/
|
3
|
+
# The Lint/RedundantCopDisableDirective cop needs to be disabled so as
|
4
|
+
# to be able to provide a (bad) example of a redundant disable.
|
5
|
+
# rubocop:disable Lint/RedundantCopDisableDirective
|
6
6
|
module RuboCop
|
7
7
|
module Cop
|
8
8
|
module Lint
|
@@ -25,21 +25,21 @@ module RuboCop
|
|
25
25
|
#
|
26
26
|
# # good
|
27
27
|
# x += 1
|
28
|
-
class
|
28
|
+
class RedundantCopDisableDirective < Cop
|
29
29
|
include NameSimilarity
|
30
30
|
include RangeHelp
|
31
31
|
|
32
|
-
COP_NAME = 'Lint/
|
32
|
+
COP_NAME = 'Lint/RedundantCopDisableDirective'
|
33
33
|
|
34
34
|
def check(offenses, cop_disabled_line_ranges, comments)
|
35
|
-
|
35
|
+
redundant_cops = Hash.new { |h, k| h[k] = Set.new }
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
each_redundant_disable(cop_disabled_line_ranges,
|
38
|
+
offenses, comments) do |comment, redundant_cop|
|
39
|
+
redundant_cops[comment].add(redundant_cop)
|
40
40
|
end
|
41
41
|
|
42
|
-
add_offenses(
|
42
|
+
add_offenses(redundant_cops)
|
43
43
|
end
|
44
44
|
|
45
45
|
def autocorrect(args)
|
@@ -89,8 +89,8 @@ module RuboCop
|
|
89
89
|
newlines: false)
|
90
90
|
end
|
91
91
|
|
92
|
-
def
|
93
|
-
|
92
|
+
def each_redundant_disable(cop_disabled_line_ranges, offenses, comments,
|
93
|
+
&block)
|
94
94
|
disabled_ranges = cop_disabled_line_ranges[COP_NAME] || [0..0]
|
95
95
|
|
96
96
|
cop_disabled_line_ranges.each do |cop, line_ranges|
|
@@ -110,9 +110,9 @@ module RuboCop
|
|
110
110
|
comment = comments.find { |c| c.loc.line == line_range.begin }
|
111
111
|
next if ignore_offense?(disabled_ranges, line_range)
|
112
112
|
|
113
|
-
|
114
|
-
|
115
|
-
yield comment,
|
113
|
+
redundant_cop = find_redundant(comment, offenses, cop, line_range,
|
114
|
+
line_ranges[ix + 1])
|
115
|
+
yield comment, redundant_cop if redundant_cop
|
116
116
|
end
|
117
117
|
end
|
118
118
|
|
@@ -123,24 +123,24 @@ module RuboCop
|
|
123
123
|
|
124
124
|
# If a cop is disabled in a range that begins on the same line as
|
125
125
|
# the end of the previous range, it means that the cop was
|
126
|
-
# already disabled by an earlier comment. So it's
|
126
|
+
# already disabled by an earlier comment. So it's redundant
|
127
127
|
# whether there are offenses or not.
|
128
|
-
|
128
|
+
redundant_comment = comments.find do |c|
|
129
129
|
c.loc.line == range.begin &&
|
130
130
|
# Comments disabling all cops don't count since it's reasonable
|
131
131
|
# to disable a few select cops first and then all cops further
|
132
132
|
# down in the code.
|
133
133
|
!all_disabled?(c)
|
134
134
|
end
|
135
|
-
yield
|
135
|
+
yield redundant_comment if redundant_comment
|
136
136
|
end
|
137
137
|
end
|
138
138
|
|
139
|
-
def
|
139
|
+
def find_redundant(comment, offenses, cop, line_range, next_line_range)
|
140
140
|
if all_disabled?(comment)
|
141
141
|
# If there's a disable all comment followed by a comment
|
142
142
|
# specifically disabling `cop`, we don't report the `all`
|
143
|
-
# comment. If the disable all comment is truly
|
143
|
+
# comment. If the disable all comment is truly redundant, we will
|
144
144
|
# detect that when examining the comments of another cop, and we
|
145
145
|
# get the full line range for the disable all.
|
146
146
|
if (next_line_range.nil? ||
|
@@ -170,8 +170,8 @@ module RuboCop
|
|
170
170
|
cops_string.split(/,\s*/).size
|
171
171
|
end
|
172
172
|
|
173
|
-
def add_offenses(
|
174
|
-
|
173
|
+
def add_offenses(redundant_cops)
|
174
|
+
redundant_cops.each do |comment, cops|
|
175
175
|
if all_disabled?(comment) ||
|
176
176
|
directive_count(comment) == cops.size
|
177
177
|
add_offense_for_entire_comment(comment, cops)
|
@@ -260,4 +260,4 @@ module RuboCop
|
|
260
260
|
end
|
261
261
|
end
|
262
262
|
end
|
263
|
-
# rubocop:enable Lint/
|
263
|
+
# rubocop:enable Lint/RedundantCopDisableDirective
|
data/lib/rubocop/cop/lint/{unneeded_cop_enable_directive.rb → redundant_cop_enable_directive.rb}
RENAMED
@@ -1,9 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# The Lint/
|
3
|
+
# The Lint/RedundantCopEnableDirective cop needs to be disabled so as
|
4
4
|
# to be able to provide a (bad) example of an unneeded enable.
|
5
5
|
|
6
|
-
# rubocop:disable Lint/
|
6
|
+
# rubocop:disable Lint/RedundantCopEnableDirective
|
7
7
|
module RuboCop
|
8
8
|
module Cop
|
9
9
|
module Lint
|
@@ -32,7 +32,7 @@ module RuboCop
|
|
32
32
|
# baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrrrrr
|
33
33
|
# # rubocop:enable all
|
34
34
|
# baz
|
35
|
-
class
|
35
|
+
class RedundantCopEnableDirective < Cop
|
36
36
|
include RangeHelp
|
37
37
|
include SurroundingSpace
|
38
38
|
|
@@ -94,16 +94,14 @@ module RuboCop
|
|
94
94
|
|
95
95
|
def range_to_remove(begin_pos, end_pos, comma_pos, comment)
|
96
96
|
start = comment_start(comment)
|
97
|
-
buffer = processed_source.buffer
|
98
|
-
range_class = Parser::Source::Range
|
99
97
|
|
100
98
|
case comma_pos
|
101
99
|
when :before
|
102
|
-
|
100
|
+
range_between(start + begin_pos - 1, start + end_pos)
|
103
101
|
when :after
|
104
|
-
|
102
|
+
range_between(start + begin_pos, start + end_pos + 1)
|
105
103
|
else
|
106
|
-
|
104
|
+
range_between(start, comment.loc.expression.end_pos)
|
107
105
|
end
|
108
106
|
end
|
109
107
|
|
@@ -49,7 +49,7 @@ module RuboCop
|
|
49
49
|
# else
|
50
50
|
# baz
|
51
51
|
# end
|
52
|
-
class
|
52
|
+
class RedundantSplatExpansion < Cop
|
53
53
|
MSG = 'Replace splat expansion with comma separated values.'
|
54
54
|
ARRAY_PARAM_MSG = 'Pass array contents as separate arguments.'
|
55
55
|
PERCENT_W = '%w'
|
@@ -70,7 +70,7 @@ module RuboCop
|
|
70
70
|
PATTERN
|
71
71
|
|
72
72
|
def on_splat(node)
|
73
|
-
|
73
|
+
redundant_splat_expansion(node) do
|
74
74
|
if array_splat?(node) &&
|
75
75
|
(method_argument?(node) || part_of_an_array?(node))
|
76
76
|
add_offense(node, message: ARRAY_PARAM_MSG)
|
@@ -90,7 +90,7 @@ module RuboCop
|
|
90
90
|
|
91
91
|
private
|
92
92
|
|
93
|
-
def
|
93
|
+
def redundant_splat_expansion(node)
|
94
94
|
literal_expansion(node) do |expanded_item|
|
95
95
|
if expanded_item.send_type?
|
96
96
|
return if array_new_inside_array_literal?(expanded_item)
|
@@ -119,7 +119,7 @@ module RuboCop
|
|
119
119
|
[node.parent.loc.expression, variable.source]
|
120
120
|
elsif !variable.array_type?
|
121
121
|
[loc.expression, "[#{variable.source}]"]
|
122
|
-
elsif
|
122
|
+
elsif redundant_brackets?(node)
|
123
123
|
[loc.expression, remove_brackets(variable)]
|
124
124
|
else
|
125
125
|
[loc.operator, '']
|
@@ -141,7 +141,7 @@ module RuboCop
|
|
141
141
|
parent.array_type? && parent.loc.begin && parent.loc.end
|
142
142
|
end
|
143
143
|
|
144
|
-
def
|
144
|
+
def redundant_brackets?(node)
|
145
145
|
parent = node.parent
|
146
146
|
grandparent = node.parent.parent
|
147
147
|
|
@@ -42,9 +42,9 @@ module RuboCop
|
|
42
42
|
|
43
43
|
method_chain = method_chain(node)
|
44
44
|
location =
|
45
|
-
Parser::Source::Range.new(node.
|
46
|
-
safe_nav.
|
47
|
-
method_chain.
|
45
|
+
Parser::Source::Range.new(node.source_range.source_buffer,
|
46
|
+
safe_nav.source_range.end_pos,
|
47
|
+
method_chain.source_range.end_pos)
|
48
48
|
add_offense(node, location: location)
|
49
49
|
end
|
50
50
|
end
|
@@ -54,9 +54,8 @@ module RuboCop
|
|
54
54
|
def method_chain(node)
|
55
55
|
chain = node
|
56
56
|
while chain.send_type?
|
57
|
-
chain = chain.parent if chain.parent
|
58
|
-
|
59
|
-
break
|
57
|
+
chain = chain.parent if chain.parent&.call_type?
|
58
|
+
break # FIXME: Unconditional break. Why while "loop" then?
|
60
59
|
end
|
61
60
|
chain
|
62
61
|
end
|
@@ -6,9 +6,7 @@ module RuboCop
|
|
6
6
|
# This cop checks for unused block arguments.
|
7
7
|
#
|
8
8
|
# @example
|
9
|
-
#
|
10
9
|
# # bad
|
11
|
-
#
|
12
10
|
# do_something do |used, unused|
|
13
11
|
# puts used
|
14
12
|
# end
|
@@ -21,10 +19,7 @@ module RuboCop
|
|
21
19
|
# puts :baz
|
22
20
|
# end
|
23
21
|
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
# #good
|
27
|
-
#
|
22
|
+
# # good
|
28
23
|
# do_something do |used, _unused|
|
29
24
|
# puts used
|
30
25
|
# end
|
@@ -36,6 +31,27 @@ module RuboCop
|
|
36
31
|
# define_method(:foo) do |_bar|
|
37
32
|
# puts :baz
|
38
33
|
# end
|
34
|
+
#
|
35
|
+
# @example IgnoreEmptyBlocks: true (default)
|
36
|
+
# # good
|
37
|
+
# do_something { |unused| }
|
38
|
+
#
|
39
|
+
# @example IgnoreEmptyBlocks: false
|
40
|
+
# # bad
|
41
|
+
# do_something { |unused| }
|
42
|
+
#
|
43
|
+
# @example AllowUnusedKeywordArguments: false (default)
|
44
|
+
# # bad
|
45
|
+
# do_something do |unused: 42|
|
46
|
+
# foo
|
47
|
+
# end
|
48
|
+
#
|
49
|
+
# @example AllowUnusedKeywordArguments: true
|
50
|
+
# # good
|
51
|
+
# do_something do |unused: 42|
|
52
|
+
# foo
|
53
|
+
# end
|
54
|
+
#
|
39
55
|
class UnusedBlockArgument < Cop
|
40
56
|
include UnusedArgument
|
41
57
|
|
@@ -6,20 +6,38 @@ module RuboCop
|
|
6
6
|
# This cop checks for unused method arguments.
|
7
7
|
#
|
8
8
|
# @example
|
9
|
-
#
|
10
9
|
# # bad
|
11
|
-
#
|
12
10
|
# def some_method(used, unused, _unused_but_allowed)
|
13
11
|
# puts used
|
14
12
|
# end
|
15
13
|
#
|
16
|
-
# @example
|
17
|
-
#
|
18
14
|
# # good
|
19
|
-
#
|
20
15
|
# def some_method(used, _unused, _unused_but_allowed)
|
21
16
|
# puts used
|
22
17
|
# end
|
18
|
+
#
|
19
|
+
# @example AllowUnusedKeywordArguments: false (default)
|
20
|
+
# # bad
|
21
|
+
# def do_something(used, unused: 42)
|
22
|
+
# used
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# @example AllowUnusedKeywordArguments: true
|
26
|
+
# # good
|
27
|
+
# def do_something(used, unused: 42)
|
28
|
+
# used
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# @example IgnoreEmptyMethods: true (default)
|
32
|
+
# # good
|
33
|
+
# def do_something(unused)
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
# @example IgnoreEmptyMethods: false
|
37
|
+
# # bad
|
38
|
+
# def do_something(unused)
|
39
|
+
# end
|
40
|
+
#
|
23
41
|
class UnusedMethodArgument < Cop
|
24
42
|
include UnusedArgument
|
25
43
|
|