rubocop 0.21.0 → 0.22.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rubocop might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/{rubocop-todo.yml → .rubocop_todo.yml} +5 -5
- data/CHANGELOG.md +41 -0
- data/README.md +21 -11
- data/config/default.yml +33 -10
- data/config/disabled.yml +0 -4
- data/config/enabled.yml +27 -1
- data/lib/rubocop.rb +17 -1
- data/lib/rubocop/config.rb +32 -27
- data/lib/rubocop/config_loader.rb +21 -8
- data/lib/rubocop/cop/cop.rb +8 -8
- data/lib/rubocop/cop/lint/block_alignment.rb +22 -22
- data/lib/rubocop/cop/lint/condition_position.rb +3 -5
- data/lib/rubocop/cop/lint/debugger.rb +4 -5
- data/lib/rubocop/cop/lint/end_alignment.rb +11 -10
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +10 -11
- data/lib/rubocop/cop/lint/require_parentheses.rb +7 -7
- data/lib/rubocop/cop/lint/rescue_exception.rb +3 -3
- data/lib/rubocop/cop/lint/string_conversion_in_interpolation.rb +6 -7
- data/lib/rubocop/cop/lint/unreachable_code.rb +2 -3
- data/lib/rubocop/cop/lint/unused_block_argument.rb +2 -15
- data/lib/rubocop/cop/lint/unused_method_argument.rb +2 -14
- data/lib/rubocop/cop/lint/useless_comparison.rb +4 -5
- data/lib/rubocop/cop/lint/void.rb +6 -8
- data/lib/rubocop/cop/mixin/autocorrect_alignment.rb +4 -2
- data/lib/rubocop/cop/mixin/autocorrect_unless_changing_ast.rb +1 -3
- data/lib/rubocop/cop/mixin/code_length.rb +5 -5
- data/lib/rubocop/cop/mixin/negative_conditional.rb +6 -6
- data/lib/rubocop/cop/mixin/percent_literal.rb +2 -3
- data/lib/rubocop/cop/mixin/space_after_punctuation.rb +5 -5
- data/lib/rubocop/cop/mixin/space_inside.rb +10 -11
- data/lib/rubocop/cop/mixin/unused_argument.rb +35 -0
- data/lib/rubocop/cop/offense.rb +1 -1
- data/lib/rubocop/cop/rails/action_filter.rb +6 -8
- data/lib/rubocop/cop/rails/default_scope.rb +2 -4
- data/lib/rubocop/cop/rails/delegate.rb +2 -0
- data/lib/rubocop/cop/rails/has_and_belongs_to_many.rb +2 -3
- data/lib/rubocop/cop/rails/output.rb +2 -3
- data/lib/rubocop/cop/rails/read_write_attribute.rb +3 -4
- data/lib/rubocop/cop/rails/validation.rb +2 -3
- data/lib/rubocop/cop/style/alias.rb +3 -3
- data/lib/rubocop/cop/style/align_hash.rb +4 -4
- data/lib/rubocop/cop/style/align_parameters.rb +13 -1
- data/lib/rubocop/cop/style/and_or.rb +2 -5
- data/lib/rubocop/cop/style/array_join.rb +3 -4
- data/lib/rubocop/cop/style/ascii_identifiers.rb +2 -3
- data/lib/rubocop/cop/style/block_comments.rb +2 -3
- data/lib/rubocop/cop/style/block_nesting.rb +2 -3
- data/lib/rubocop/cop/style/blocks.rb +9 -9
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +5 -5
- data/lib/rubocop/cop/style/class_and_module_children.rb +1 -1
- data/lib/rubocop/cop/style/class_methods.rb +3 -5
- data/lib/rubocop/cop/style/collection_methods.rb +8 -11
- data/lib/rubocop/cop/style/comment_annotation.rb +9 -9
- data/lib/rubocop/cop/style/comment_indentation.rb +66 -0
- data/lib/rubocop/cop/style/constant_name.rb +3 -3
- data/lib/rubocop/cop/style/cyclomatic_complexity.rb +5 -5
- data/lib/rubocop/cop/style/deprecated_hash_methods.rb +6 -6
- data/lib/rubocop/cop/style/each_with_object.rb +38 -0
- data/lib/rubocop/cop/style/empty_lines.rb +8 -8
- data/lib/rubocop/cop/style/empty_lines_around_body.rb +7 -7
- data/lib/rubocop/cop/style/encoding.rb +6 -7
- data/lib/rubocop/cop/style/end_of_line.rb +10 -10
- data/lib/rubocop/cop/style/file_name.rb +11 -7
- data/lib/rubocop/cop/style/guard_clause.rb +32 -22
- data/lib/rubocop/cop/style/indentation_width.rb +25 -26
- data/lib/rubocop/cop/style/lambda.rb +8 -9
- data/lib/rubocop/cop/style/leading_comment_space.rb +4 -5
- data/lib/rubocop/cop/style/line_end_concatenation.rb +29 -6
- data/lib/rubocop/cop/style/line_length.rb +9 -9
- data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +7 -6
- data/lib/rubocop/cop/style/module_function.rb +3 -4
- data/lib/rubocop/cop/style/multiline_if_then.rb +3 -3
- data/lib/rubocop/cop/style/negated_if.rb +2 -0
- data/lib/rubocop/cop/style/next.rb +80 -0
- data/lib/rubocop/cop/style/nil_comparison.rb +2 -3
- data/lib/rubocop/cop/style/non_nil_check.rb +15 -3
- data/lib/rubocop/cop/style/not.rb +4 -4
- data/lib/rubocop/cop/style/numeric_literals.rb +7 -8
- data/lib/rubocop/cop/style/op_method.rb +3 -5
- data/lib/rubocop/cop/style/parameter_lists.rb +4 -4
- data/lib/rubocop/cop/style/parentheses_around_condition.rb +5 -6
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +5 -5
- data/lib/rubocop/cop/style/predicate_name.rb +2 -4
- data/lib/rubocop/cop/style/redundant_self.rb +11 -12
- data/lib/rubocop/cop/style/self_assignment.rb +8 -13
- data/lib/rubocop/cop/style/semicolon.rb +16 -19
- data/lib/rubocop/cop/style/signal_exception.rb +10 -11
- data/lib/rubocop/cop/style/single_line_block_params.rb +2 -3
- data/lib/rubocop/cop/style/single_line_methods.rb +3 -4
- data/lib/rubocop/cop/style/space_after_colon.rb +9 -9
- data/lib/rubocop/cop/style/space_after_control_keyword.rb +3 -3
- data/lib/rubocop/cop/style/space_after_method_name.rb +3 -3
- data/lib/rubocop/cop/style/space_after_not.rb +3 -4
- data/lib/rubocop/cop/style/space_around_operators.rb +5 -4
- data/lib/rubocop/cop/style/space_before_comment.rb +29 -0
- data/lib/rubocop/cop/style/space_before_modifier_keyword.rb +6 -7
- data/lib/rubocop/cop/style/symbol_array.rb +2 -3
- data/lib/rubocop/cop/style/tab.rb +8 -8
- data/lib/rubocop/cop/style/trailing_blank_lines.rb +10 -10
- data/lib/rubocop/cop/style/trailing_whitespace.rb +6 -7
- data/lib/rubocop/cop/style/trivial_accessors.rb +3 -4
- data/lib/rubocop/cop/style/unless_else.rb +2 -3
- data/lib/rubocop/cop/style/unneeded_capital_w.rb +3 -3
- data/lib/rubocop/cop/style/unneeded_percent_x.rb +26 -0
- data/lib/rubocop/cop/style/when_then.rb +3 -3
- data/lib/rubocop/cop/style/while_until_do.rb +3 -6
- data/lib/rubocop/cop/style/word_array.rb +8 -7
- data/lib/rubocop/cop/team.rb +9 -11
- data/lib/rubocop/cop/util.rb +2 -3
- data/lib/rubocop/cop/variable_force.rb +2 -3
- data/lib/rubocop/cop/variable_force/variable_table.rb +1 -2
- data/lib/rubocop/file_inspector.rb +5 -0
- data/lib/rubocop/formatter/clang_style_formatter.rb +3 -4
- data/lib/rubocop/formatter/disabled_config_formatter.rb +6 -6
- data/lib/rubocop/options.rb +14 -11
- data/lib/rubocop/target_finder.rb +12 -1
- data/lib/rubocop/version.rb +1 -1
- data/relnotes/v0.21.0.md +11 -0
- data/relnotes/v0.22.0.md +77 -0
- data/spec/rubocop/cli_spec.rb +86 -40
- data/spec/rubocop/comment_config_spec.rb +1 -1
- data/spec/rubocop/config_loader_spec.rb +3 -3
- data/spec/rubocop/config_spec.rb +14 -3
- data/spec/rubocop/cop/force_spec.rb +1 -1
- data/spec/rubocop/cop/lint/unused_block_argument_spec.rb +164 -99
- data/spec/rubocop/cop/lint/unused_method_argument_spec.rb +195 -85
- data/spec/rubocop/cop/lint/void_spec.rb +8 -0
- data/spec/rubocop/cop/rails/delegate_spec.rb +17 -0
- data/spec/rubocop/cop/rails/output_spec.rb +3 -3
- data/spec/rubocop/cop/severity_spec.rb +5 -5
- data/spec/rubocop/cop/style/align_parameters_spec.rb +108 -0
- data/spec/rubocop/cop/style/block_nesting_spec.rb +3 -3
- data/spec/rubocop/cop/style/class_and_module_children_spec.rb +12 -10
- data/spec/rubocop/cop/style/comment_indentation_spec.rb +174 -0
- data/spec/rubocop/cop/style/each_with_object_spec.rb +44 -0
- data/spec/rubocop/cop/style/end_of_line_spec.rb +3 -5
- data/spec/rubocop/cop/style/guard_clause_spec.rb +135 -57
- data/spec/rubocop/cop/style/if_unless_modifier_spec.rb +7 -7
- data/spec/rubocop/cop/style/line_end_concatenation_spec.rb +75 -1
- data/spec/rubocop/cop/style/line_length_spec.rb +7 -7
- data/spec/rubocop/cop/style/negated_if_spec.rb +5 -1
- data/spec/rubocop/cop/style/next_spec.rb +210 -0
- data/spec/rubocop/cop/style/non_nil_check_spec.rb +44 -13
- data/spec/rubocop/cop/style/self_assignment_spec.rb +1 -1
- data/spec/rubocop/cop/style/space_around_operators_spec.rb +1 -0
- data/spec/rubocop/cop/style/space_before_comment_spec.rb +34 -0
- data/spec/rubocop/cop/style/unneeded_percent_x_spec.rb +34 -0
- data/spec/rubocop/cop/style/while_until_modifier_spec.rb +2 -2
- data/spec/rubocop/cop/util_spec.rb +2 -2
- data/spec/rubocop/cop/variable_force_spec.rb +1 -1
- data/spec/rubocop/formatter/disabled_config_formatter_spec.rb +4 -4
- data/spec/rubocop/formatter/disabled_lines_formatter_spec.rb +2 -2
- data/spec/rubocop/formatter/offense_count_formatter_spec.rb +2 -2
- data/spec/rubocop/options_spec.rb +3 -0
- data/spec/support/shared_context.rb +1 -3
- data/spec/support/statement_modifier_helper.rb +2 -2
- metadata +20 -3
@@ -5,136 +5,246 @@ require 'spec_helper'
|
|
5
5
|
describe Rubocop::Cop::Lint::UnusedMethodArgument do
|
6
6
|
subject(:cop) { described_class.new }
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
context 'inspection' do
|
9
|
+
before do
|
10
|
+
inspect_source(cop, source)
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'when a method takes multiple arguments' do
|
14
|
+
context 'and an argument is unused' do
|
15
|
+
let(:source) { <<-END }
|
16
|
+
def some_method(foo, bar)
|
17
|
+
puts bar
|
18
|
+
end
|
19
|
+
END
|
20
|
+
|
21
|
+
it 'registers an offense' do
|
22
|
+
expect(cop.offenses.size).to eq(1)
|
23
|
+
expect(cop.offenses.first.message).to eq(
|
24
|
+
'Unused method argument - `foo`. ' \
|
25
|
+
"If it's necessary, use `_` or `_foo` " \
|
26
|
+
"as an argument name to indicate that it won't be used."
|
27
|
+
)
|
28
|
+
expect(cop.offenses.first.severity.name).to eq(:warning)
|
29
|
+
expect(cop.offenses.first.line).to eq(1)
|
30
|
+
expect(cop.highlights).to eq(['foo'])
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'and all the arguments are unused' do
|
35
|
+
let(:source) { <<-END }
|
36
|
+
def some_method(foo, bar)
|
37
|
+
end
|
38
|
+
END
|
39
|
+
|
40
|
+
it 'registers offenses and suggests the use of `*`' do
|
41
|
+
expect(cop.offenses.size).to eq(2)
|
42
|
+
expect(cop.offenses.first.message).to eq(
|
43
|
+
'Unused method argument - `foo`. ' \
|
44
|
+
"If it's necessary, use `_` or `_foo` " \
|
45
|
+
"as an argument name to indicate that it won't be used. " \
|
46
|
+
'You can also write as `some_method(*)` if you want the method ' \
|
47
|
+
"to accept any arguments but don't care about them.")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
11
51
|
|
12
|
-
|
13
|
-
context 'and an argument is unused' do
|
52
|
+
context 'when a singleton method argument is unused' do
|
14
53
|
let(:source) { <<-END }
|
15
|
-
def some_method(foo
|
16
|
-
puts bar
|
54
|
+
def self.some_method(foo)
|
17
55
|
end
|
18
56
|
END
|
19
57
|
|
20
58
|
it 'registers an offense' do
|
21
59
|
expect(cop.offenses.size).to eq(1)
|
22
|
-
expect(cop.offenses.first.message).to eq(
|
23
|
-
'Unused method argument - `foo`. ' \
|
24
|
-
"If it's necessary, use `_` or `_foo` " \
|
25
|
-
"as an argument name to indicate that it won't be used."
|
26
|
-
)
|
27
|
-
expect(cop.offenses.first.severity.name).to eq(:warning)
|
28
60
|
expect(cop.offenses.first.line).to eq(1)
|
29
61
|
expect(cop.highlights).to eq(['foo'])
|
30
62
|
end
|
31
63
|
end
|
32
64
|
|
33
|
-
context '
|
65
|
+
context 'when an underscore-prefixed method argument is unused' do
|
34
66
|
let(:source) { <<-END }
|
35
|
-
def some_method(
|
67
|
+
def some_method(_foo)
|
36
68
|
end
|
37
69
|
END
|
38
70
|
|
39
|
-
it '
|
40
|
-
expect(cop.offenses
|
41
|
-
expect(cop.offenses.first.message).to eq(
|
42
|
-
'Unused method argument - `foo`. ' \
|
43
|
-
"If it's necessary, use `_` or `_foo` " \
|
44
|
-
"as an argument name to indicate that it won't be used. " \
|
45
|
-
'You can also write as `some_method(*)` if you want the method ' \
|
46
|
-
"to accept any arguments but don't care about them.")
|
71
|
+
it 'accepts' do
|
72
|
+
expect(cop.offenses).to be_empty
|
47
73
|
end
|
48
74
|
end
|
49
|
-
end
|
50
75
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
76
|
+
context 'when a method argument is used' do
|
77
|
+
let(:source) { <<-END }
|
78
|
+
def some_method(foo)
|
79
|
+
puts foo
|
80
|
+
end
|
81
|
+
END
|
56
82
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
expect(cop.highlights).to eq(['foo'])
|
83
|
+
it 'accepts' do
|
84
|
+
expect(cop.offenses).to be_empty
|
85
|
+
end
|
61
86
|
end
|
62
|
-
end
|
63
87
|
|
64
|
-
|
65
|
-
|
66
|
-
|
88
|
+
context 'when a variable is unused' do
|
89
|
+
let(:source) { <<-END }
|
90
|
+
def some_method
|
91
|
+
foo = 1
|
92
|
+
end
|
93
|
+
END
|
94
|
+
|
95
|
+
it 'does not care' do
|
96
|
+
expect(cop.offenses).to be_empty
|
67
97
|
end
|
68
|
-
|
98
|
+
end
|
99
|
+
|
100
|
+
context 'when a block argument is unused' do
|
101
|
+
let(:source) { <<-END }
|
102
|
+
1.times do |foo|
|
103
|
+
end
|
104
|
+
END
|
69
105
|
|
70
|
-
|
71
|
-
|
106
|
+
it 'does not care' do
|
107
|
+
expect(cop.offenses).to be_empty
|
108
|
+
end
|
72
109
|
end
|
73
|
-
end
|
74
110
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
111
|
+
context 'in a method calling `super` without arguments' do
|
112
|
+
context 'when a method argument is not used explicitly' do
|
113
|
+
let(:source) { <<-END }
|
114
|
+
def some_method(foo)
|
115
|
+
super
|
116
|
+
end
|
117
|
+
END
|
118
|
+
|
119
|
+
it 'accepts since the arguments are guaranteed to be the same as ' \
|
120
|
+
"superclass' ones and the user has no control on them" do
|
121
|
+
expect(cop.offenses).to be_empty
|
122
|
+
end
|
79
123
|
end
|
80
|
-
|
124
|
+
end
|
81
125
|
|
82
|
-
|
83
|
-
|
126
|
+
context 'in a method calling `super` with arguments' do
|
127
|
+
context 'when a method argument is unused' do
|
128
|
+
let(:source) { <<-END }
|
129
|
+
def some_method(foo)
|
130
|
+
super(:something)
|
131
|
+
end
|
132
|
+
END
|
133
|
+
|
134
|
+
it 'registers an offense' do
|
135
|
+
expect(cop.offenses.size).to eq(1)
|
136
|
+
expect(cop.offenses.first.line).to eq(1)
|
137
|
+
expect(cop.highlights).to eq(['foo'])
|
138
|
+
end
|
139
|
+
end
|
84
140
|
end
|
85
141
|
end
|
86
142
|
|
87
|
-
context '
|
88
|
-
|
89
|
-
|
90
|
-
|
143
|
+
context 'auto-correct' do
|
144
|
+
it 'fixes single' do
|
145
|
+
expect(autocorrect_source(cop, <<-SOURCE
|
146
|
+
def some_method(foo)
|
147
|
+
super(:something)
|
148
|
+
end
|
149
|
+
SOURCE
|
150
|
+
)).to eq(<<-CORRECTED_SOURCE
|
151
|
+
def some_method(_foo)
|
152
|
+
super(:something)
|
91
153
|
end
|
92
|
-
|
154
|
+
CORRECTED_SOURCE
|
155
|
+
)
|
156
|
+
end
|
93
157
|
|
94
|
-
it '
|
95
|
-
expect(cop
|
158
|
+
it 'fixes multiple' do
|
159
|
+
expect(autocorrect_source(cop, <<-SOURCE
|
160
|
+
def some_method(foo, bar)
|
161
|
+
super(:something)
|
162
|
+
end
|
163
|
+
SOURCE
|
164
|
+
)).to eq(<<-CORRECTED_SOURCE
|
165
|
+
def some_method(_foo, _bar)
|
166
|
+
super(:something)
|
167
|
+
end
|
168
|
+
CORRECTED_SOURCE
|
169
|
+
)
|
96
170
|
end
|
97
|
-
end
|
98
171
|
|
99
|
-
|
100
|
-
|
101
|
-
|
172
|
+
it 'preserves whitespace' do
|
173
|
+
expect(autocorrect_source(cop, <<-SOURCE
|
174
|
+
def some_method(foo,
|
175
|
+
bar)
|
176
|
+
super(:something)
|
102
177
|
end
|
103
|
-
|
178
|
+
SOURCE
|
179
|
+
)).to eq(<<-CORRECTED_SOURCE
|
180
|
+
def some_method(_foo,
|
181
|
+
_bar)
|
182
|
+
super(:something)
|
183
|
+
end
|
184
|
+
CORRECTED_SOURCE
|
185
|
+
)
|
186
|
+
end
|
104
187
|
|
105
|
-
it '
|
106
|
-
expect(cop
|
188
|
+
it 'preserves splat' do
|
189
|
+
expect(autocorrect_source(cop, <<-SOURCE
|
190
|
+
def some_method(foo, *bars, baz)
|
191
|
+
stuff(foo, baz)
|
192
|
+
end
|
193
|
+
SOURCE
|
194
|
+
)).to eq(<<-CORRECTED_SOURCE
|
195
|
+
def some_method(foo, *_bars, baz)
|
196
|
+
stuff(foo, baz)
|
197
|
+
end
|
198
|
+
CORRECTED_SOURCE
|
199
|
+
)
|
107
200
|
end
|
108
|
-
end
|
109
201
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
202
|
+
it 'preserves default' do
|
203
|
+
expect(autocorrect_source(cop, <<-SOURCE
|
204
|
+
def some_method(foo, bar = baz)
|
205
|
+
stuff(foo)
|
206
|
+
end
|
207
|
+
SOURCE
|
208
|
+
)).to eq(<<-CORRECTED_SOURCE
|
209
|
+
def some_method(foo, _bar = baz)
|
210
|
+
stuff(foo)
|
211
|
+
end
|
212
|
+
CORRECTED_SOURCE
|
213
|
+
)
|
214
|
+
end
|
117
215
|
|
118
|
-
|
119
|
-
|
120
|
-
|
216
|
+
it 'preserves block reference' do
|
217
|
+
expect(autocorrect_source(cop, <<-SOURCE
|
218
|
+
def some_method(foo, &baz)
|
219
|
+
stuff(foo)
|
220
|
+
end
|
221
|
+
SOURCE
|
222
|
+
)).to eq(<<-CORRECTED_SOURCE
|
223
|
+
def some_method(foo, &_baz)
|
224
|
+
stuff(foo)
|
121
225
|
end
|
226
|
+
CORRECTED_SOURCE
|
227
|
+
)
|
122
228
|
end
|
123
|
-
end
|
124
229
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
END
|
230
|
+
it 'ignores used' do
|
231
|
+
original_source = <<-SOURCE
|
232
|
+
def some_method(foo, bar)
|
233
|
+
other_method(foo, bar)
|
234
|
+
end
|
235
|
+
SOURCE
|
132
236
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
237
|
+
expect(autocorrect_source(cop, original_source)).to eq(original_source)
|
238
|
+
end
|
239
|
+
|
240
|
+
it 'ignores implicit super' do
|
241
|
+
original_source = <<-SOURCE
|
242
|
+
def some_method(foo, bar)
|
243
|
+
super
|
137
244
|
end
|
245
|
+
SOURCE
|
246
|
+
|
247
|
+
expect(autocorrect_source(cop, original_source)).to eq(original_source)
|
138
248
|
end
|
139
249
|
end
|
140
250
|
end
|
@@ -120,6 +120,23 @@ describe Rubocop::Cop::Rails::Delegate do
|
|
120
120
|
expect(cop.offenses).to be_empty
|
121
121
|
end
|
122
122
|
|
123
|
+
it 'ignores delegation with assignment' do
|
124
|
+
inspect_source(cop,
|
125
|
+
['def new',
|
126
|
+
' @bar = Foo.new',
|
127
|
+
'end'])
|
128
|
+
expect(cop.offenses).to be_empty
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'ignores delegation to constant' do
|
132
|
+
inspect_source(cop,
|
133
|
+
['FOO = []',
|
134
|
+
'def size',
|
135
|
+
' FOO.size',
|
136
|
+
'end'])
|
137
|
+
expect(cop.offenses).to be_empty
|
138
|
+
end
|
139
|
+
|
123
140
|
describe '#autocorrect' do
|
124
141
|
context 'trivial delegation' do
|
125
142
|
let(:source) do
|
@@ -5,7 +5,7 @@ require 'spec_helper'
|
|
5
5
|
describe Rubocop::Cop::Rails::Output do
|
6
6
|
subject(:cop) { described_class.new }
|
7
7
|
|
8
|
-
it '
|
8
|
+
it 'records an offense for puts statements' do
|
9
9
|
source = ['p "edmond dantes"',
|
10
10
|
'puts "sinbad"',
|
11
11
|
'print "abbe busoni"',
|
@@ -14,7 +14,7 @@ describe Rubocop::Cop::Rails::Output do
|
|
14
14
|
expect(cop.offenses.size).to eq(4)
|
15
15
|
end
|
16
16
|
|
17
|
-
it '
|
17
|
+
it 'does not record an offense for methods' do
|
18
18
|
source = ['obj.print',
|
19
19
|
'something.p',
|
20
20
|
'nothing.pp']
|
@@ -22,7 +22,7 @@ describe Rubocop::Cop::Rails::Output do
|
|
22
22
|
expect(cop.offenses).to be_empty
|
23
23
|
end
|
24
24
|
|
25
|
-
it '
|
25
|
+
it 'does not record an offense for comments' do
|
26
26
|
source = ['# print "test"',
|
27
27
|
'# p']
|
28
28
|
inspect_source(cop, source)
|
@@ -73,23 +73,23 @@ describe Rubocop::Cop::Severity do
|
|
73
73
|
|
74
74
|
describe 'constructs from code' do
|
75
75
|
describe 'R' do
|
76
|
-
it { expect(
|
76
|
+
it { expect(described_class.new('R')).to eq(refactor) }
|
77
77
|
end
|
78
78
|
|
79
79
|
describe 'C' do
|
80
|
-
it { expect(
|
80
|
+
it { expect(described_class.new('C')).to eq(convention) }
|
81
81
|
end
|
82
82
|
|
83
83
|
describe 'W' do
|
84
|
-
it { expect(
|
84
|
+
it { expect(described_class.new('W')).to eq(warning) }
|
85
85
|
end
|
86
86
|
|
87
87
|
describe 'E' do
|
88
|
-
it { expect(
|
88
|
+
it { expect(described_class.new('E')).to eq(error) }
|
89
89
|
end
|
90
90
|
|
91
91
|
describe 'F' do
|
92
|
-
it { expect(
|
92
|
+
it { expect(described_class.new('F')).to eq(fatal) }
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
@@ -183,6 +183,25 @@ describe Rubocop::Cop::Style::AlignParameters, :config do
|
|
183
183
|
expect(cop.offenses).to be_empty
|
184
184
|
end
|
185
185
|
|
186
|
+
context 'assigned methods' do
|
187
|
+
it 'accepts the first parameter being on a new row' do
|
188
|
+
inspect_source(cop, [' assigned_value = match(',
|
189
|
+
' a,',
|
190
|
+
' b,',
|
191
|
+
' c',
|
192
|
+
' )'])
|
193
|
+
expect(cop.offenses).to be_empty
|
194
|
+
end
|
195
|
+
|
196
|
+
it 'accepts the first parameter being on method row' do
|
197
|
+
inspect_source(cop, [' assigned_value = match(a,',
|
198
|
+
' b,',
|
199
|
+
' c',
|
200
|
+
' )'])
|
201
|
+
expect(cop.offenses).to be_empty
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
186
205
|
it 'auto-corrects alignment' do
|
187
206
|
new_source = autocorrect_source(cop, ['func(a,',
|
188
207
|
' b,',
|
@@ -291,5 +310,94 @@ describe Rubocop::Cop::Style::AlignParameters, :config do
|
|
291
310
|
expect(autocorrect_source(cop, original_source))
|
292
311
|
.to eq(correct_source.join("\n"))
|
293
312
|
end
|
313
|
+
|
314
|
+
context 'multi-line method calls' do
|
315
|
+
it 'can handle existing indentation from multi-line method calls' do
|
316
|
+
inspect_source(cop, [' something',
|
317
|
+
' .method_name(',
|
318
|
+
' a,',
|
319
|
+
' b,',
|
320
|
+
' c',
|
321
|
+
' )'])
|
322
|
+
expect(cop.offenses).to be_empty
|
323
|
+
end
|
324
|
+
|
325
|
+
it 'registers offences for double indentation from relevant method' do
|
326
|
+
inspect_source(cop, [' something',
|
327
|
+
' .method_name(',
|
328
|
+
' a,',
|
329
|
+
' b,',
|
330
|
+
' c',
|
331
|
+
' )'])
|
332
|
+
expect(cop.offenses.size).to eq(3)
|
333
|
+
end
|
334
|
+
|
335
|
+
it 'does not err on method call without a method name' do
|
336
|
+
inspect_source(cop, [' something',
|
337
|
+
' .(',
|
338
|
+
' a,',
|
339
|
+
' b,',
|
340
|
+
' c',
|
341
|
+
' )'])
|
342
|
+
expect(cop.offenses).to be_empty
|
343
|
+
end
|
344
|
+
|
345
|
+
it 'autocorrects relative to position of relevant method call' do
|
346
|
+
original_source = [
|
347
|
+
' something',
|
348
|
+
' .method_name(',
|
349
|
+
' a,',
|
350
|
+
' b,',
|
351
|
+
' c',
|
352
|
+
' )'
|
353
|
+
]
|
354
|
+
correct_source = [
|
355
|
+
' something',
|
356
|
+
' .method_name(',
|
357
|
+
' a,',
|
358
|
+
' b,',
|
359
|
+
' c',
|
360
|
+
' )'
|
361
|
+
]
|
362
|
+
expect(autocorrect_source(cop, original_source))
|
363
|
+
.to eq(correct_source.join("\n"))
|
364
|
+
end
|
365
|
+
end
|
366
|
+
|
367
|
+
context 'assigned methods' do
|
368
|
+
it 'accepts the first parameter being on a new row' do
|
369
|
+
inspect_source(cop, [' assigned_value = match(',
|
370
|
+
' a,',
|
371
|
+
' b,',
|
372
|
+
' c',
|
373
|
+
' )'])
|
374
|
+
expect(cop.offenses).to be_empty
|
375
|
+
end
|
376
|
+
|
377
|
+
it 'accepts the first parameter being on method row' do
|
378
|
+
inspect_source(cop, [' assigned_value = match(a,',
|
379
|
+
' b,',
|
380
|
+
' c',
|
381
|
+
' )'])
|
382
|
+
expect(cop.offenses).to be_empty
|
383
|
+
end
|
384
|
+
|
385
|
+
it 'autocorrects even when first argument is in wrong position' do
|
386
|
+
original_source = [' assigned_value = match(',
|
387
|
+
' a,',
|
388
|
+
' b,',
|
389
|
+
' c',
|
390
|
+
' )']
|
391
|
+
|
392
|
+
correct_source = [' assigned_value = match(',
|
393
|
+
' a,',
|
394
|
+
' b,',
|
395
|
+
' c',
|
396
|
+
' )']
|
397
|
+
|
398
|
+
expect(autocorrect_source(cop, original_source))
|
399
|
+
.to eq(correct_source.join("\n"))
|
400
|
+
end
|
401
|
+
end
|
294
402
|
end
|
295
403
|
end
|