rubocop 0.7.2 → 0.8.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/.travis.yml +7 -1
- data/CHANGELOG.md +19 -0
- data/README.md +4 -8
- data/bin/rubocop +2 -2
- data/config/default.yml +8 -0
- data/config/enabled.yml +21 -24
- data/lib/rubocop.rb +9 -7
- data/lib/rubocop/cli.rb +73 -52
- data/lib/rubocop/config.rb +8 -5
- data/lib/rubocop/cop/access_control.rb +41 -0
- data/lib/rubocop/cop/alias.rb +7 -5
- data/lib/rubocop/cop/align_parameters.rb +20 -96
- data/lib/rubocop/cop/and_or.rb +26 -0
- data/lib/rubocop/cop/ascii_comments.rb +3 -8
- data/lib/rubocop/cop/ascii_identifiers.rb +6 -5
- data/lib/rubocop/cop/avoid_class_vars.rb +5 -10
- data/lib/rubocop/cop/avoid_for.rb +7 -5
- data/lib/rubocop/cop/avoid_global_vars.rb +19 -7
- data/lib/rubocop/cop/avoid_perl_backrefs.rb +7 -10
- data/lib/rubocop/cop/avoid_perlisms.rb +11 -10
- data/lib/rubocop/cop/block_comments.rb +4 -6
- data/lib/rubocop/cop/blocks.rb +11 -47
- data/lib/rubocop/cop/case_indentation.rb +9 -31
- data/lib/rubocop/cop/class_and_module_camel_case.rb +20 -11
- data/lib/rubocop/cop/class_methods.rb +5 -10
- data/lib/rubocop/cop/collection_methods.rb +16 -16
- data/lib/rubocop/cop/colon_method_call.rb +8 -32
- data/lib/rubocop/cop/constant_name.rb +24 -0
- data/lib/rubocop/cop/cop.rb +20 -78
- data/lib/rubocop/cop/def_parentheses.rb +43 -35
- data/lib/rubocop/cop/empty_line_between_defs.rb +11 -15
- data/lib/rubocop/cop/empty_lines.rb +20 -9
- data/lib/rubocop/cop/empty_literal.rb +47 -0
- data/lib/rubocop/cop/encoding.rb +3 -3
- data/lib/rubocop/cop/end_of_line.rb +3 -3
- data/lib/rubocop/cop/ensure_return.rb +6 -23
- data/lib/rubocop/cop/eval.rb +7 -10
- data/lib/rubocop/cop/favor_join.rb +9 -24
- data/lib/rubocop/cop/favor_modifier.rb +38 -48
- data/lib/rubocop/cop/favor_percent_r.rb +7 -7
- data/lib/rubocop/cop/favor_sprintf.rb +8 -24
- data/lib/rubocop/cop/favor_unless_over_negated_if.rb +19 -17
- data/lib/rubocop/cop/handle_exceptions.rb +7 -11
- data/lib/rubocop/cop/hash_syntax.rb +29 -14
- data/lib/rubocop/cop/if_then_else.rb +32 -29
- data/lib/rubocop/cop/leading_comment_space.rb +5 -8
- data/lib/rubocop/cop/line_continuation.rb +4 -7
- data/lib/rubocop/cop/line_length.rb +3 -3
- data/lib/rubocop/cop/loop.rb +33 -0
- data/lib/rubocop/cop/method_and_variable_snake_case.rb +42 -19
- data/lib/rubocop/cop/method_length.rb +34 -37
- data/lib/rubocop/cop/new_lambda_literal.rb +8 -6
- data/lib/rubocop/cop/not.rb +10 -4
- data/lib/rubocop/cop/numeric_literals.rb +9 -7
- data/lib/rubocop/cop/offence.rb +1 -1
- data/lib/rubocop/cop/op_method.rb +12 -22
- data/lib/rubocop/cop/parameter_lists.rb +12 -6
- data/lib/rubocop/cop/parentheses_around_condition.rb +11 -11
- data/lib/rubocop/cop/percent_r.rb +7 -7
- data/lib/rubocop/cop/reduce_arguments.rb +13 -51
- data/lib/rubocop/cop/rescue_exception.rb +13 -29
- data/lib/rubocop/cop/rescue_modifier.rb +5 -8
- data/lib/rubocop/cop/semicolon.rb +15 -74
- data/lib/rubocop/cop/single_line_methods.rb +28 -44
- data/lib/rubocop/cop/space_after_comma_etc.rb +29 -9
- data/lib/rubocop/cop/space_after_control_keyword.rb +16 -15
- data/lib/rubocop/cop/string_literals.rb +9 -35
- data/lib/rubocop/cop/surrounding_space.rb +213 -112
- data/lib/rubocop/cop/symbol_array.rb +9 -7
- data/lib/rubocop/cop/symbol_name.rb +23 -0
- data/lib/rubocop/cop/syntax.rb +14 -7
- data/lib/rubocop/cop/tab.rb +3 -3
- data/lib/rubocop/cop/ternary_operator.rb +26 -24
- data/lib/rubocop/cop/trailing_whitespace.rb +3 -5
- data/lib/rubocop/cop/trivial_accessors.rb +18 -95
- data/lib/rubocop/cop/unless_else.rb +11 -7
- data/lib/rubocop/cop/util.rb +26 -0
- data/lib/rubocop/cop/variable_interpolation.rb +18 -10
- data/lib/rubocop/cop/when_then.rb +6 -17
- data/lib/rubocop/cop/word_array.rb +18 -19
- data/lib/rubocop/version.rb +1 -1
- data/rubocop.gemspec +1 -0
- data/spec/project_spec.rb +1 -1
- data/spec/rubocop/cli_spec.rb +16 -9
- data/spec/rubocop/config_spec.rb +13 -3
- data/spec/rubocop/cops/access_control_spec.rb +129 -0
- data/spec/rubocop/cops/alias_spec.rb +2 -6
- data/spec/rubocop/cops/align_parameters_spec.rb +58 -71
- data/spec/rubocop/cops/and_or_spec.rb +37 -0
- data/spec/rubocop/cops/ascii_comments_spec.rb +3 -4
- data/spec/rubocop/cops/ascii_identifiers_spec.rb +3 -4
- data/spec/rubocop/cops/avoid_class_vars_spec.rb +7 -2
- data/spec/rubocop/cops/avoid_for_spec.rb +1 -4
- data/spec/rubocop/cops/{avoid_global_vars.rb → avoid_global_vars_spec.rb} +4 -4
- data/spec/rubocop/cops/avoid_perl_backrefs_spec.rb +1 -1
- data/spec/rubocop/cops/avoid_perlisms_spec.rb +5 -5
- data/spec/rubocop/cops/block_comments_spec.rb +0 -4
- data/spec/rubocop/cops/blocks_spec.rb +33 -0
- data/spec/rubocop/cops/case_indentation_spec.rb +5 -5
- data/spec/rubocop/cops/class_and_module_camel_case_spec.rb +15 -5
- data/spec/rubocop/cops/class_methods_spec.rb +4 -4
- data/spec/rubocop/cops/collection_methods_spec.rb +9 -4
- data/spec/rubocop/cops/colon_method_call_spec.rb +11 -5
- data/spec/rubocop/cops/constant_name_spec.rb +42 -0
- data/spec/rubocop/cops/def_with_parentheses_spec.rb +13 -8
- data/spec/rubocop/cops/def_without_parentheses_spec.rb +11 -5
- data/spec/rubocop/cops/empty_line_between_defs_spec.rb +38 -38
- data/spec/rubocop/cops/empty_lines_spec.rb +15 -3
- data/spec/rubocop/cops/empty_literal_spec.rb +90 -0
- data/spec/rubocop/cops/encoding_spec.rb +9 -9
- data/spec/rubocop/cops/end_of_line_spec.rb +2 -2
- data/spec/rubocop/cops/ensure_return_spec.rb +1 -3
- data/spec/rubocop/cops/eval_spec.rb +8 -5
- data/spec/rubocop/cops/favor_join_spec.rb +1 -5
- data/spec/rubocop/cops/favor_modifier_spec.rb +16 -14
- data/spec/rubocop/cops/{favor_percent_r.rb → favor_percent_r_spec.rb} +6 -6
- data/spec/rubocop/cops/favor_sprintf_spec.rb +3 -9
- data/spec/rubocop/cops/favor_unless_over_negated_if_spec.rb +4 -4
- data/spec/rubocop/cops/favor_until_over_negated_while_spec.rb +3 -3
- data/spec/rubocop/cops/handle_exceptions_spec.rb +1 -3
- data/spec/rubocop/cops/hash_syntax_spec.rb +11 -6
- data/spec/rubocop/cops/if_with_semicolon_spec.rb +7 -1
- data/spec/rubocop/cops/leading_comment_space_spec.rb +0 -7
- data/spec/rubocop/cops/line_continuation_spec.rb +2 -2
- data/spec/rubocop/cops/line_length_spec.rb +2 -2
- data/spec/rubocop/cops/loop_spec.rb +31 -0
- data/spec/rubocop/cops/method_and_variable_snake_case_spec.rb +38 -12
- data/spec/rubocop/cops/method_length_spec.rb +85 -85
- data/spec/rubocop/cops/multiline_if_then_spec.rb +15 -15
- data/spec/rubocop/cops/new_lambda_literal_spec.rb +3 -3
- data/spec/rubocop/cops/not_spec.rb +1 -4
- data/spec/rubocop/cops/numeric_literals_spec.rb +13 -13
- data/spec/rubocop/cops/one_line_conditional_spec.rb +1 -1
- data/spec/rubocop/cops/op_method_spec.rb +2 -9
- data/spec/rubocop/cops/parameter_lists_spec.rb +7 -7
- data/spec/rubocop/cops/parentheses_around_condition_spec.rb +41 -44
- data/spec/rubocop/cops/percent_r_spec.rb +6 -6
- data/spec/rubocop/cops/reduce_arguments_spec.rb +4 -4
- data/spec/rubocop/cops/rescue_exception_spec.rb +48 -8
- data/spec/rubocop/cops/rescue_modifier_spec.rb +2 -5
- data/spec/rubocop/cops/semicolon_spec.rb +2 -30
- data/spec/rubocop/cops/single_line_methods_spec.rb +13 -13
- data/spec/rubocop/cops/space_after_colon_spec.rb +3 -3
- data/spec/rubocop/cops/space_after_comma_spec.rb +14 -2
- data/spec/rubocop/cops/space_after_control_keyword_spec.rb +42 -3
- data/spec/rubocop/cops/space_after_semicolon_spec.rb +2 -2
- data/spec/rubocop/cops/space_around_braces_spec.rb +18 -3
- data/spec/rubocop/cops/space_around_equals_in_default_parameter_spec.rb +4 -4
- data/spec/rubocop/cops/space_around_operators_spec.rb +82 -27
- data/spec/rubocop/cops/space_inside_brackets_spec.rb +13 -7
- data/spec/rubocop/cops/space_inside_hash_literal_braces_spec.rb +14 -9
- data/spec/rubocop/cops/space_inside_parens_spec.rb +7 -3
- data/spec/rubocop/cops/string_literals_spec.rb +17 -5
- data/spec/rubocop/cops/symbol_array_spec.rb +18 -2
- data/spec/rubocop/cops/symbol_name_spec.rb +119 -0
- data/spec/rubocop/cops/syntax_spec.rb +25 -18
- data/spec/rubocop/cops/tab_spec.rb +2 -2
- data/spec/rubocop/cops/ternary_operator_spec.rb +13 -17
- data/spec/rubocop/cops/trailing_whitespace_spec.rb +3 -3
- data/spec/rubocop/cops/trivial_accessors_spec.rb +17 -20
- data/spec/rubocop/cops/unless_else_spec.rb +8 -8
- data/spec/rubocop/cops/variable_interpolation_spec.rb +0 -5
- data/spec/rubocop/cops/when_then_spec.rb +14 -21
- data/spec/rubocop/cops/word_array_spec.rb +12 -4
- data/spec/spec_helper.rb +12 -4
- metadata +40 -31
- data/.document +0 -5
- data/lib/rubocop/cop/ampersands_pipes_vs_and_or.rb +0 -25
- data/lib/rubocop/cop/array_literal.rb +0 -61
- data/lib/rubocop/cop/brace_after_percent.rb +0 -32
- data/lib/rubocop/cop/grammar.rb +0 -138
- data/lib/rubocop/cop/hash_literal.rb +0 -61
- data/lib/rubocop/cop/percent_literals.rb +0 -25
- data/lib/rubocop/cop/symbol_snake_case.rb +0 -47
- data/spec/rubocop/cops/ampersands_pipes_vs_and_or_spec.rb +0 -57
- data/spec/rubocop/cops/array_literal_spec.rb +0 -46
- data/spec/rubocop/cops/brace_after_percent_spec.rb +0 -33
- data/spec/rubocop/cops/grammar_spec.rb +0 -81
- data/spec/rubocop/cops/hash_literal_spec.rb +0 -46
- data/spec/rubocop/cops/multiline_blocks_spec.rb +0 -24
- data/spec/rubocop/cops/percent_literals_spec.rb +0 -47
- data/spec/rubocop/cops/single_line_blocks_spec.rb +0 -22
- data/spec/rubocop/cops/symbol_snake_case_spec.rb +0 -93
data/lib/rubocop/version.rb
CHANGED
data/rubocop.gemspec
CHANGED
@@ -28,6 +28,7 @@ Gem::Specification.new do |s|
|
|
28
28
|
s.summary = 'Automatic Ruby code style checking tool.'
|
29
29
|
|
30
30
|
s.add_runtime_dependency('rainbow', '>= 1.1.4')
|
31
|
+
s.add_runtime_dependency('parser', '~> 2.0.0.beta2')
|
31
32
|
s.add_development_dependency('rake', '~> 10.0')
|
32
33
|
s.add_development_dependency('rspec', '~> 2.13')
|
33
34
|
s.add_development_dependency('yard', '~> 0.8')
|
data/spec/project_spec.rb
CHANGED
data/spec/rubocop/cli_spec.rb
CHANGED
@@ -176,17 +176,22 @@ module Rubocop
|
|
176
176
|
end
|
177
177
|
|
178
178
|
it 'runs just one cop if --only is passed' do
|
179
|
-
create_file('example.rb', [
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
179
|
+
create_file('example.rb', ['if x== 0 ',
|
180
|
+
"\ty",
|
181
|
+
'end'])
|
182
|
+
# IfUnlessModifier depends on the configuration of LineLength.
|
183
|
+
# That configuration might have been set by other spec examples
|
184
|
+
# so we reset it to emulate a start from scratch.
|
185
|
+
Cop::LineLength.config = nil
|
186
|
+
|
187
|
+
expect(cli.run(['--only', 'IfUnlessModifier', 'example.rb'])).to eq(1)
|
184
188
|
expect($stdout.string)
|
185
189
|
.to eq(['== example.rb ==',
|
186
|
-
'C: 1:
|
187
|
-
'
|
190
|
+
'C: 1: Favor modifier if/unless usage when you have a ' +
|
191
|
+
'single-line body. Another good alternative is the usage of ' +
|
192
|
+
'control flow &&/||.',
|
188
193
|
'',
|
189
|
-
'1 file inspected,
|
194
|
+
'1 file inspected, 1 offence detected',
|
190
195
|
''].join("\n"))
|
191
196
|
end
|
192
197
|
|
@@ -400,6 +405,7 @@ module Rubocop
|
|
400
405
|
end
|
401
406
|
|
402
407
|
it 'registers an offence for a syntax error' do
|
408
|
+
pending
|
403
409
|
create_file('example.rb', [
|
404
410
|
'# encoding: utf-8',
|
405
411
|
'class Test',
|
@@ -416,9 +422,10 @@ module Rubocop
|
|
416
422
|
end
|
417
423
|
|
418
424
|
it 'can process a file with an invalid UTF-8 byte sequence' do
|
425
|
+
pending
|
419
426
|
create_file('example.rb', [
|
420
427
|
'# encoding: utf-8',
|
421
|
-
"#
|
428
|
+
"# #{'f9'.hex.chr}#{'29'.hex.chr}"
|
422
429
|
])
|
423
430
|
expect(cli.run(['--emacs', 'example.rb'])).to eq(0)
|
424
431
|
end
|
data/spec/rubocop/config_spec.rb
CHANGED
@@ -208,7 +208,7 @@ describe Rubocop::Config do
|
|
208
208
|
end
|
209
209
|
end
|
210
210
|
|
211
|
-
describe '#validate
|
211
|
+
describe '#validate', :isolated_environment do
|
212
212
|
# TODO: Because Config.load_file now outputs the validation warning,
|
213
213
|
# it is inserting text into the rspec test output here.
|
214
214
|
# The next 2 lines should be removed eventually.
|
@@ -232,7 +232,7 @@ describe Rubocop::Config do
|
|
232
232
|
|
233
233
|
it 'raises validation error' do
|
234
234
|
expect do
|
235
|
-
configuration.validate
|
235
|
+
configuration.validate
|
236
236
|
end.to raise_error(Rubocop::Config::ValidationError) do |error|
|
237
237
|
expect(error.message).to start_with('unrecognized cop LyneLenth')
|
238
238
|
end
|
@@ -250,7 +250,7 @@ describe Rubocop::Config do
|
|
250
250
|
|
251
251
|
it 'raises validation error' do
|
252
252
|
expect do
|
253
|
-
configuration.validate
|
253
|
+
configuration.validate
|
254
254
|
end.to raise_error(Rubocop::Config::ValidationError) do |error|
|
255
255
|
expect(error.message).to
|
256
256
|
start_with('unrecognized parameter LineLength:Min')
|
@@ -396,4 +396,14 @@ describe Rubocop::Config do
|
|
396
396
|
end
|
397
397
|
end
|
398
398
|
end
|
399
|
+
|
400
|
+
describe 'configuration for SymbolName' do
|
401
|
+
describe 'AllowCamelCase' do
|
402
|
+
it 'is enabled by default' do
|
403
|
+
default_config = Rubocop::Config.default_configuration
|
404
|
+
symbol_name_config = default_config.for_cop('SymbolName')
|
405
|
+
expect(symbol_name_config['AllowCamelCase']).to be_true
|
406
|
+
end
|
407
|
+
end
|
408
|
+
end
|
399
409
|
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
module Rubocop
|
6
|
+
module Cop
|
7
|
+
describe AccessControl do
|
8
|
+
let(:a) { AccessControl.new }
|
9
|
+
|
10
|
+
it 'registers an offence for misaligned private' do
|
11
|
+
inspect_source(a,
|
12
|
+
['class Test',
|
13
|
+
'',
|
14
|
+
'private',
|
15
|
+
'',
|
16
|
+
' def test; end',
|
17
|
+
'end'])
|
18
|
+
expect(a.offences.size).to eq(1)
|
19
|
+
expect(a.offences.map(&:message))
|
20
|
+
.to eq([AccessControl::INDENT_MSG])
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'registers an offence for misaligned private in module' do
|
24
|
+
inspect_source(a,
|
25
|
+
['module Test',
|
26
|
+
'',
|
27
|
+
'private',
|
28
|
+
'',
|
29
|
+
' def test; end',
|
30
|
+
'end'])
|
31
|
+
expect(a.offences.size).to eq(1)
|
32
|
+
expect(a.offences.map(&:message))
|
33
|
+
.to eq([AccessControl::INDENT_MSG])
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'registers an offence for misaligned private in singleton class' do
|
37
|
+
inspect_source(a,
|
38
|
+
['class << self',
|
39
|
+
'',
|
40
|
+
'private',
|
41
|
+
'',
|
42
|
+
' def test; end',
|
43
|
+
'end'])
|
44
|
+
expect(a.offences.size).to eq(1)
|
45
|
+
expect(a.offences.map(&:message))
|
46
|
+
.to eq([AccessControl::INDENT_MSG])
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'registers an offence for misaligned protected' do
|
50
|
+
inspect_source(a,
|
51
|
+
['class Test',
|
52
|
+
'',
|
53
|
+
'protected',
|
54
|
+
'',
|
55
|
+
' def test; end',
|
56
|
+
'end'])
|
57
|
+
expect(a.offences.size).to eq(1)
|
58
|
+
expect(a.offences.map(&:message))
|
59
|
+
.to eq([AccessControl::INDENT_MSG])
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'accepts properly indented private' do
|
63
|
+
inspect_source(a,
|
64
|
+
['class Test',
|
65
|
+
'',
|
66
|
+
' private',
|
67
|
+
'',
|
68
|
+
' def test; end',
|
69
|
+
'end'])
|
70
|
+
expect(a.offences).to be_empty
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'accepts properly indented protected' do
|
74
|
+
inspect_source(a,
|
75
|
+
['class Test',
|
76
|
+
'',
|
77
|
+
' protected',
|
78
|
+
'',
|
79
|
+
' def test; end',
|
80
|
+
'end'])
|
81
|
+
expect(a.offences).to be_empty
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'handles properly nested classes' do
|
85
|
+
inspect_source(a,
|
86
|
+
['class Test',
|
87
|
+
'',
|
88
|
+
' class Nested',
|
89
|
+
'',
|
90
|
+
' private',
|
91
|
+
'',
|
92
|
+
' def a; end',
|
93
|
+
' end',
|
94
|
+
'',
|
95
|
+
' protected',
|
96
|
+
'',
|
97
|
+
' def test; end',
|
98
|
+
'end'])
|
99
|
+
expect(a.offences.size).to eq(1)
|
100
|
+
expect(a.offences.map(&:message))
|
101
|
+
.to eq([AccessControl::INDENT_MSG])
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'requires blank line before private/protected' do
|
105
|
+
inspect_source(a,
|
106
|
+
['class Test',
|
107
|
+
' protected',
|
108
|
+
'',
|
109
|
+
' def test; end',
|
110
|
+
'end'])
|
111
|
+
expect(a.offences.size).to eq(1)
|
112
|
+
expect(a.offences.map(&:message))
|
113
|
+
.to eq([AccessControl::BLANK_MSG])
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'requires blank line after private/protected' do
|
117
|
+
inspect_source(a,
|
118
|
+
['class Test',
|
119
|
+
'',
|
120
|
+
' protected',
|
121
|
+
' def test; end',
|
122
|
+
'end'])
|
123
|
+
expect(a.offences.size).to eq(1)
|
124
|
+
expect(a.offences.map(&:message))
|
125
|
+
.to eq([AccessControl::BLANK_MSG])
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
@@ -9,32 +9,28 @@ module Rubocop
|
|
9
9
|
|
10
10
|
it 'registers an offence for alias with symbol args' do
|
11
11
|
inspect_source(a,
|
12
|
-
'file.rb',
|
13
12
|
['alias :ala :bala'])
|
14
13
|
expect(a.offences.size).to eq(1)
|
15
14
|
expect(a.offences.map(&:message))
|
16
|
-
.to eq([Alias::
|
15
|
+
.to eq([Alias::MSG])
|
17
16
|
end
|
18
17
|
|
19
18
|
it 'registers an offence for alias with bareword args' do
|
20
19
|
inspect_source(a,
|
21
|
-
'file.rb',
|
22
20
|
['alias ala bala'])
|
23
21
|
expect(a.offences.size).to eq(1)
|
24
22
|
expect(a.offences.map(&:message))
|
25
|
-
.to eq([Alias::
|
23
|
+
.to eq([Alias::MSG])
|
26
24
|
end
|
27
25
|
|
28
26
|
it 'does not register an offence for alias_method' do
|
29
27
|
inspect_source(a,
|
30
|
-
'file.rb',
|
31
28
|
['alias_method :ala, :bala'])
|
32
29
|
expect(a.offences).to be_empty
|
33
30
|
end
|
34
31
|
|
35
32
|
it 'does not register an offence for :alias' do
|
36
33
|
inspect_source(a,
|
37
|
-
'file.rb',
|
38
34
|
['[:alias, :ala, :bala]'])
|
39
35
|
expect(a.offences).to be_empty
|
40
36
|
end
|
@@ -8,43 +8,45 @@ module Rubocop
|
|
8
8
|
let(:align) { AlignParameters.new }
|
9
9
|
|
10
10
|
it 'registers an offence for parameters with single indent' do
|
11
|
-
inspect_source(align,
|
12
|
-
|
13
|
-
expect(align.offences.
|
14
|
-
['Align the parameters of a method call if they span more than ' +
|
15
|
-
'one line.'])
|
11
|
+
inspect_source(align, ['function(a,',
|
12
|
+
' if b then c else d end)'])
|
13
|
+
expect(align.offences.size).to eq(1)
|
16
14
|
end
|
17
15
|
|
18
16
|
it 'registers an offence for parameters with double indent' do
|
19
|
-
inspect_source(align,
|
20
|
-
|
21
|
-
expect(align.offences.
|
22
|
-
|
23
|
-
|
17
|
+
inspect_source(align, ['function(a,',
|
18
|
+
' if b then c else d end)'])
|
19
|
+
expect(align.offences.size).to eq(1)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'accepts multiline []= method call' do
|
23
|
+
inspect_source(align, ['Test.config["something"] =',
|
24
|
+
' true'])
|
25
|
+
expect(align.offences).to be_empty
|
24
26
|
end
|
25
27
|
|
26
28
|
it 'accepts correctly aligned parameters' do
|
27
|
-
inspect_source(align,
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
expect(align.offences
|
29
|
+
inspect_source(align, ['function(a,',
|
30
|
+
' 0, 1,',
|
31
|
+
' (x + y),',
|
32
|
+
' if b then c else d end)'])
|
33
|
+
expect(align.offences).to be_empty
|
32
34
|
end
|
33
35
|
|
34
36
|
it 'accepts calls that only span one line' do
|
35
|
-
inspect_source(align,
|
36
|
-
expect(align.offences
|
37
|
+
inspect_source(align, ['find(path, s, @special[sexp[0]])'])
|
38
|
+
expect(align.offences).to be_empty
|
37
39
|
end
|
38
40
|
|
39
41
|
it "doesn't get confused by a symbol argument" do
|
40
|
-
inspect_source(align,
|
42
|
+
inspect_source(align,
|
41
43
|
['add_offence(:convention, index,',
|
42
|
-
'
|
43
|
-
expect(align.offences
|
44
|
+
' MSG % kind)'])
|
45
|
+
expect(align.offences).to be_empty
|
44
46
|
end
|
45
47
|
|
46
48
|
it "doesn't get confused by splat operator" do
|
47
|
-
inspect_source(align,
|
49
|
+
inspect_source(align,
|
48
50
|
['func1(*a,',
|
49
51
|
' *b,',
|
50
52
|
' c)',
|
@@ -59,7 +61,7 @@ module Rubocop
|
|
59
61
|
end
|
60
62
|
|
61
63
|
it "doesn't get confused by extra comma at the end" do
|
62
|
-
inspect_source(align,
|
64
|
+
inspect_source(align,
|
63
65
|
['func1(a,',
|
64
66
|
' b,)'])
|
65
67
|
expect(align.offences.map(&:to_s)).to eq(
|
@@ -68,52 +70,52 @@ module Rubocop
|
|
68
70
|
end
|
69
71
|
|
70
72
|
it 'can handle a correctly aligned string literal as first argument' do
|
71
|
-
inspect_source(align,
|
73
|
+
inspect_source(align,
|
72
74
|
['add_offence(:convention, x,',
|
73
75
|
' a)'])
|
74
|
-
expect(align.offences
|
76
|
+
expect(align.offences).to be_empty
|
75
77
|
end
|
76
78
|
|
77
79
|
it 'can handle a string literal as other argument' do
|
78
|
-
inspect_source(align,
|
80
|
+
inspect_source(align,
|
79
81
|
['add_offence(:convention,',
|
80
82
|
' "", a)'])
|
81
|
-
expect(align.offences
|
83
|
+
expect(align.offences).to be_empty
|
82
84
|
end
|
83
85
|
|
84
86
|
it "doesn't get confused by a line break inside a parameter" do
|
85
|
-
inspect_source(align,
|
87
|
+
inspect_source(align,
|
86
88
|
['read(path, { headers: true,',
|
87
89
|
' converters: :numeric })'])
|
88
|
-
expect(align.offences
|
90
|
+
expect(align.offences).to be_empty
|
89
91
|
end
|
90
92
|
|
91
93
|
it "doesn't get confused by symbols with embedded expressions" do
|
92
|
-
inspect_source(align,
|
94
|
+
inspect_source(align,
|
93
95
|
['send(:"#{name}_comments_path")'])
|
94
|
-
expect(align.offences
|
96
|
+
expect(align.offences).to be_empty
|
95
97
|
end
|
96
98
|
|
97
99
|
it "doesn't get confused by regexen with embedded expressions" do
|
98
|
-
inspect_source(align,
|
100
|
+
inspect_source(align,
|
99
101
|
['a(/#{name}/)'])
|
100
|
-
expect(align.offences
|
102
|
+
expect(align.offences).to be_empty
|
101
103
|
end
|
102
104
|
|
103
105
|
it 'accepts braceless hashes' do
|
104
|
-
inspect_source(align,
|
106
|
+
inspect_source(align,
|
105
107
|
['run(collection, :entry_name => label,',
|
106
108
|
' :paginator => paginator)'])
|
107
|
-
expect(align.offences
|
109
|
+
expect(align.offences).to be_empty
|
108
110
|
end
|
109
111
|
|
110
112
|
it 'accepts the first parameter being on a new row' do
|
111
|
-
inspect_source(align,
|
113
|
+
inspect_source(align,
|
112
114
|
[' match(',
|
113
115
|
' a,',
|
114
116
|
' b',
|
115
117
|
' )'])
|
116
|
-
expect(align.offences
|
118
|
+
expect(align.offences).to be_empty
|
117
119
|
end
|
118
120
|
|
119
121
|
it 'can handle heredoc strings' do
|
@@ -123,31 +125,31 @@ module Rubocop
|
|
123
125
|
' return value',
|
124
126
|
' end',
|
125
127
|
' EOS']
|
126
|
-
inspect_source(align,
|
127
|
-
expect(align.offences
|
128
|
+
inspect_source(align, src)
|
129
|
+
expect(align.offences).to be_empty
|
128
130
|
end
|
129
131
|
|
130
132
|
it 'can handle a method call within a method call' do
|
131
|
-
inspect_source(align,
|
133
|
+
inspect_source(align,
|
132
134
|
['a(a1,',
|
133
135
|
' b(b1,',
|
134
136
|
' b2),',
|
135
137
|
' a2)'])
|
136
|
-
expect(align.offences
|
138
|
+
expect(align.offences).to be_empty
|
137
139
|
end
|
138
140
|
|
139
141
|
it 'can handle a call embedded in a string' do
|
140
|
-
inspect_source(align,
|
142
|
+
inspect_source(align,
|
141
143
|
['model("#{index(name)}", child)'])
|
142
|
-
expect(align.offences
|
144
|
+
expect(align.offences).to be_empty
|
143
145
|
end
|
144
146
|
|
145
147
|
it 'can handle do-end' do
|
146
|
-
inspect_source(align,
|
148
|
+
inspect_source(align,
|
147
149
|
[' run(lambda do |e|',
|
148
150
|
" w = e['warden']",
|
149
151
|
' end)'])
|
150
|
-
expect(align.offences
|
152
|
+
expect(align.offences).to be_empty
|
151
153
|
end
|
152
154
|
|
153
155
|
it 'can handle a call with a block inside another call' do
|
@@ -155,55 +157,40 @@ module Rubocop
|
|
155
157
|
' exec_query("info(\'#{row[\'name\']}\')").map { |col|',
|
156
158
|
" col['name']",
|
157
159
|
' })']
|
158
|
-
inspect_source(align,
|
159
|
-
expect(align.offences
|
160
|
+
inspect_source(align, src)
|
161
|
+
expect(align.offences).to be_empty
|
160
162
|
end
|
161
163
|
|
162
164
|
it 'can handle a ternary condition with a block reference' do
|
163
165
|
src = ['cond ? a : func(&b)']
|
164
|
-
inspect_source(align,
|
165
|
-
expect(align.offences
|
166
|
+
inspect_source(align, src)
|
167
|
+
expect(align.offences).to be_empty
|
166
168
|
end
|
167
169
|
|
168
170
|
it 'can handle parentheses used with no parameters' do
|
169
171
|
src = ['func()']
|
170
|
-
inspect_source(align,
|
171
|
-
expect(align.offences
|
172
|
-
end
|
173
|
-
|
174
|
-
it 'can handle a multiline hash as first parameter' do
|
175
|
-
src = ['assert_equal({',
|
176
|
-
' :space_before => "",',
|
177
|
-
'}, state)']
|
178
|
-
inspect_source(align, '', src)
|
179
|
-
expect(align.offences.map(&:message)).to be_empty
|
172
|
+
inspect_source(align, src)
|
173
|
+
expect(align.offences).to be_empty
|
180
174
|
end
|
181
175
|
|
182
176
|
it 'can handle a multiline hash as second parameter' do
|
183
177
|
src = ['tag(:input, {',
|
184
178
|
' :value => value',
|
185
179
|
'})']
|
186
|
-
inspect_source(align,
|
187
|
-
expect(align.offences
|
180
|
+
inspect_source(align, src)
|
181
|
+
expect(align.offences).to be_empty
|
188
182
|
end
|
189
183
|
|
190
184
|
it 'can handle method calls without parentheses' do
|
191
185
|
src = ['a(b c, d)']
|
192
|
-
inspect_source(align,
|
193
|
-
expect(align.offences
|
186
|
+
inspect_source(align, src)
|
187
|
+
expect(align.offences).to be_empty
|
194
188
|
end
|
195
189
|
|
196
190
|
it 'can handle other method calls without parentheses' do
|
197
191
|
src = ['chars(Unicode.apply_mapping @wrapped_string, :uppercase)']
|
198
|
-
inspect_source(align,
|
199
|
-
expect(align.offences
|
200
|
-
end
|
201
|
-
|
202
|
-
it "doesn't check alignment if tabs are used to indent" do
|
203
|
-
src = ['a(b,',
|
204
|
-
"\tc)"]
|
205
|
-
inspect_source(align, '', src)
|
206
|
-
expect(align.offences.map(&:message)).to be_empty
|
192
|
+
inspect_source(align, src)
|
193
|
+
expect(align.offences).to be_empty
|
207
194
|
end
|
208
195
|
end
|
209
196
|
end
|