rubocop 0.14.1 → 0.15.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 +5 -3
- data/CHANGELOG.md +245 -198
- data/README.md +7 -0
- data/Rakefile +5 -1
- data/config/default.yml +27 -4
- data/config/enabled.yml +18 -4
- data/lib/rubocop.rb +13 -1
- data/lib/rubocop/cli.rb +83 -23
- data/lib/rubocop/config.rb +1 -1
- data/lib/rubocop/cop/cop.rb +31 -6
- data/lib/rubocop/cop/lint/block_alignment.rb +11 -8
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +21 -14
- data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -1
- data/lib/rubocop/cop/rails/output.rb +35 -0
- data/lib/rubocop/cop/style/{access_control.rb → access_modifier_indentation.rb} +18 -15
- data/lib/rubocop/cop/style/alias.rb +14 -2
- data/lib/rubocop/cop/style/align_hash.rb +174 -109
- data/lib/rubocop/cop/style/autocorrect_alignment.rb +38 -18
- data/lib/rubocop/cop/style/blocks.rb +4 -6
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +3 -3
- data/lib/rubocop/cop/style/cyclomatic_complexity.rb +46 -0
- data/lib/rubocop/cop/style/empty_lines_around_access_modifier.rb +48 -0
- data/lib/rubocop/cop/style/empty_lines_around_body.rb +62 -0
- data/lib/rubocop/cop/style/end_of_line.rb +6 -2
- data/lib/rubocop/cop/style/favor_modifier.rb +11 -1
- data/lib/rubocop/cop/style/final_newline.rb +10 -4
- data/lib/rubocop/cop/style/hash_syntax.rb +32 -21
- data/lib/rubocop/cop/style/leading_comment_space.rb +9 -0
- data/lib/rubocop/cop/style/method_call_parentheses.rb +11 -1
- data/lib/rubocop/cop/style/numeric_literals.rb +11 -15
- data/lib/rubocop/cop/style/redundant_return.rb +7 -4
- data/lib/rubocop/cop/style/redundant_self.rb +3 -3
- data/lib/rubocop/cop/style/signal_exception.rb +4 -2
- data/lib/rubocop/cop/style/space_after_comma_etc.rb +7 -1
- data/lib/rubocop/cop/style/space_after_control_keyword.rb +6 -0
- data/lib/rubocop/cop/style/space_after_method_name.rb +7 -1
- data/lib/rubocop/cop/style/space_after_not.rb +6 -2
- data/lib/rubocop/cop/style/space_around_block_braces.rb +149 -0
- data/lib/rubocop/cop/style/space_around_equals_in_parameter_default.rb +33 -0
- data/lib/rubocop/cop/style/space_around_operators.rb +169 -0
- data/lib/rubocop/cop/style/space_before_modifier_keyword.rb +6 -0
- data/lib/rubocop/cop/style/space_inside.rb +35 -0
- data/lib/rubocop/cop/style/space_inside_brackets.rb +18 -0
- data/lib/rubocop/cop/style/space_inside_hash_literal_braces.rb +99 -0
- data/lib/rubocop/cop/style/space_inside_parens.rb +18 -0
- data/lib/rubocop/cop/style/special_global_vars.rb +52 -25
- data/lib/rubocop/cop/style/string_literals.rb +1 -1
- data/lib/rubocop/cop/style/surrounding_space.rb +1 -344
- data/lib/rubocop/cop/style/trailing_blank_lines.rb +17 -5
- data/lib/rubocop/cop/style/trailing_whitespace.rb +9 -5
- data/lib/rubocop/cop/style/trivial_accessors.rb +1 -2
- data/lib/rubocop/cop/style/word_array.rb +16 -1
- data/lib/rubocop/cop/team.rb +5 -5
- data/lib/rubocop/cop/util.rb +1 -0
- data/lib/rubocop/formatter/offence_count_formatter.rb +0 -1
- data/lib/rubocop/options.rb +76 -111
- data/lib/rubocop/rake_task.rb +4 -2
- data/lib/rubocop/target_finder.rb +3 -3
- data/lib/rubocop/version.rb +1 -1
- data/spec/rubocop/cli_spec.rb +123 -13
- data/spec/rubocop/config_spec.rb +2 -2
- data/spec/rubocop/cop/lint/rescue_exception_spec.rb +10 -0
- data/spec/rubocop/cop/lint/useless_setter_call_spec.rb +13 -0
- data/spec/rubocop/cop/offence_spec.rb +2 -0
- data/spec/rubocop/cop/rails/output_spec.rb +40 -0
- data/spec/rubocop/cop/style/access_modifier_indentation_spec.rb +243 -0
- data/spec/rubocop/cop/style/alias_spec.rb +8 -0
- data/spec/rubocop/cop/style/align_array_spec.rb +12 -0
- data/spec/rubocop/cop/style/align_hash_spec.rb +15 -0
- data/spec/rubocop/cop/style/braces_around_hash_parameters_spec.rb +7 -4
- data/spec/rubocop/cop/style/cyclomatic_complexity_spec.rb +203 -0
- data/spec/rubocop/cop/style/empty_lines_around_access_modifier_spec.rb +56 -0
- data/spec/rubocop/cop/style/empty_lines_around_body_spec.rb +87 -0
- data/spec/rubocop/cop/style/end_of_line_spec.rb +17 -8
- data/spec/rubocop/cop/style/favor_modifier_spec.rb +34 -0
- data/spec/rubocop/cop/style/final_newline_spec.rb +5 -0
- data/spec/rubocop/cop/style/hash_syntax_spec.rb +22 -2
- data/spec/rubocop/cop/style/leading_comment_space_spec.rb +5 -0
- data/spec/rubocop/cop/style/method_call_parentheses_spec.rb +39 -4
- data/spec/rubocop/cop/style/numeric_literals_spec.rb +5 -0
- data/spec/rubocop/cop/style/signal_exception_spec.rb +11 -0
- data/spec/rubocop/cop/style/space_after_colon_spec.rb +7 -0
- data/spec/rubocop/cop/style/space_after_comma_spec.rb +5 -0
- data/spec/rubocop/cop/style/space_after_control_keyword_spec.rb +29 -8
- data/spec/rubocop/cop/style/space_after_method_name_spec.rb +15 -0
- data/spec/rubocop/cop/style/space_after_semicolon_spec.rb +5 -0
- data/spec/rubocop/cop/style/space_around_block_braces_spec.rb +68 -0
- data/spec/rubocop/cop/style/space_around_equals_in_default_parameter_spec.rb +5 -0
- data/spec/rubocop/cop/style/space_around_operators_spec.rb +43 -0
- data/spec/rubocop/cop/style/space_before_modifier_keyword_spec.rb +23 -0
- data/spec/rubocop/cop/style/space_inside_brackets_spec.rb +7 -0
- data/spec/rubocop/cop/style/space_inside_hash_literal_braces_spec.rb +65 -23
- data/spec/rubocop/cop/style/space_inside_parens_spec.rb +7 -0
- data/spec/rubocop/cop/style/special_global_vars_spec.rb +12 -2
- data/spec/rubocop/cop/style/string_literals_spec.rb +6 -0
- data/spec/rubocop/cop/style/symbol_array_spec.rb +5 -7
- data/spec/rubocop/cop/style/trailing_blank_lines_spec.rb +26 -1
- data/spec/rubocop/cop/style/trailing_whitespace_spec.rb +7 -0
- data/spec/rubocop/cop/style/trivial_accessors_spec.rb +8 -0
- data/spec/rubocop/cop/style/word_array_spec.rb +33 -2
- data/spec/rubocop/cop/team_spec.rb +4 -4
- data/spec/rubocop/formatter/json_formatter_spec.rb +1 -1
- data/spec/rubocop/options_spec.rb +5 -96
- data/spec/rubocop/processed_source_spec.rb +3 -3
- data/spec/spec_helper.rb +28 -23
- data/spec/support/mri_syntax_checker.rb +20 -16
- metadata +24 -5
- data/spec/rubocop/cop/style/access_control_spec.rb +0 -164
@@ -52,4 +52,19 @@ describe Rubocop::Cop::Style::SpaceAfterMethodName do
|
|
52
52
|
'end'])
|
53
53
|
expect(cop.offences).to be_empty
|
54
54
|
end
|
55
|
+
|
56
|
+
it 'auto-corrects unwanted space' do
|
57
|
+
new_source = autocorrect_source(cop, ['def func (x)',
|
58
|
+
' a',
|
59
|
+
'end',
|
60
|
+
'def self.func (x)',
|
61
|
+
' a',
|
62
|
+
'end'])
|
63
|
+
expect(new_source).to eq(['def func(x)',
|
64
|
+
' a',
|
65
|
+
'end',
|
66
|
+
'def self.func(x)',
|
67
|
+
' a',
|
68
|
+
'end'].join("\n"))
|
69
|
+
end
|
55
70
|
end
|
@@ -15,4 +15,9 @@ describe Rubocop::Cop::Style::SpaceAfterSemicolon do
|
|
15
15
|
inspect_source(cop, ['x = 1;'])
|
16
16
|
expect(cop.messages).to be_empty
|
17
17
|
end
|
18
|
+
|
19
|
+
it 'auto-corrects missing space' do
|
20
|
+
new_source = autocorrect_source(cop, 'x = 1;y = 2')
|
21
|
+
expect(new_source).to eq('x = 1; y = 2')
|
22
|
+
end
|
18
23
|
end
|
@@ -11,6 +11,44 @@ describe Rubocop::Cop::Style::SpaceAroundBlockBraces, :config do
|
|
11
11
|
}
|
12
12
|
end
|
13
13
|
|
14
|
+
context 'with space inside empty braces not allowed' do
|
15
|
+
let(:cop_config) { { 'EnforcedStyleForEmptyBraces' => 'no_space' } }
|
16
|
+
|
17
|
+
it 'accepts empty braces with no space inside' do
|
18
|
+
inspect_source(cop, ['each {}'])
|
19
|
+
expect(cop.messages).to be_empty
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'registers an offence for empty braces with space inside' do
|
23
|
+
inspect_source(cop, ['each { }'])
|
24
|
+
expect(cop.messages).to eq(['Space inside empty braces detected.'])
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'auto-corrects unwanted space' do
|
28
|
+
new_source = autocorrect_source(cop, 'each { }')
|
29
|
+
expect(new_source).to eq('each {}')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'with space inside empty braces allowed' do
|
34
|
+
let(:cop_config) { { 'EnforcedStyleForEmptyBraces' => 'space' } }
|
35
|
+
|
36
|
+
it 'accepts empty braces with space inside' do
|
37
|
+
inspect_source(cop, ['each { }'])
|
38
|
+
expect(cop.messages).to be_empty
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'registers an offence for empty braces with no space inside' do
|
42
|
+
inspect_source(cop, ['each {}'])
|
43
|
+
expect(cop.messages).to eq(['Space missing inside empty braces.'])
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'auto-corrects missing space' do
|
47
|
+
new_source = autocorrect_source(cop, 'each {}')
|
48
|
+
expect(new_source).to eq('each { }')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
14
52
|
it 'accepts braces surrounded by spaces' do
|
15
53
|
inspect_source(cop, ['each { puts }'])
|
16
54
|
expect(cop.messages).to be_empty
|
@@ -35,6 +73,11 @@ describe Rubocop::Cop::Style::SpaceAroundBlockBraces, :config do
|
|
35
73
|
expect(cop.highlights).to eq(['}'])
|
36
74
|
end
|
37
75
|
|
76
|
+
it 'auto-corrects missing space' do
|
77
|
+
new_source = autocorrect_source(cop, 'each { puts}')
|
78
|
+
expect(new_source).to eq('each { puts }')
|
79
|
+
end
|
80
|
+
|
38
81
|
context 'with passed in parameters' do
|
39
82
|
it 'accepts left brace with inner space' do
|
40
83
|
inspect_source(cop, ['each { |x| puts }'])
|
@@ -48,6 +91,11 @@ describe Rubocop::Cop::Style::SpaceAroundBlockBraces, :config do
|
|
48
91
|
expect(cop.highlights).to eq(['{'])
|
49
92
|
end
|
50
93
|
|
94
|
+
it 'auto-corrects missing space' do
|
95
|
+
new_source = autocorrect_source(cop, 'each{|x| puts }')
|
96
|
+
expect(new_source).to eq('each { |x| puts }')
|
97
|
+
end
|
98
|
+
|
51
99
|
context 'and space before block parameters not allowed' do
|
52
100
|
let(:cop_config) do
|
53
101
|
{
|
@@ -62,6 +110,11 @@ describe Rubocop::Cop::Style::SpaceAroundBlockBraces, :config do
|
|
62
110
|
expect(cop.highlights).to eq([' '])
|
63
111
|
end
|
64
112
|
|
113
|
+
it 'auto-corrects unwanted space' do
|
114
|
+
new_source = autocorrect_source(cop, 'each { |x| puts }')
|
115
|
+
expect(new_source).to eq('each {|x| puts }')
|
116
|
+
end
|
117
|
+
|
65
118
|
it 'accepts left brace without inner space' do
|
66
119
|
inspect_source(cop, ['each {|x| puts }'])
|
67
120
|
expect(cop.messages).to be_empty
|
@@ -102,6 +155,11 @@ describe Rubocop::Cop::Style::SpaceAroundBlockBraces, :config do
|
|
102
155
|
expect(cop.highlights).to eq(['{'])
|
103
156
|
end
|
104
157
|
|
158
|
+
it 'auto-corrects missing space' do
|
159
|
+
new_source = autocorrect_source(cop, 'each{ puts }')
|
160
|
+
expect(new_source).to eq('each {puts}')
|
161
|
+
end
|
162
|
+
|
105
163
|
context 'with passed in parameters' do
|
106
164
|
context 'and space before block parameters allowed' do
|
107
165
|
it 'accepts left brace with inner space' do
|
@@ -115,6 +173,11 @@ describe Rubocop::Cop::Style::SpaceAroundBlockBraces, :config do
|
|
115
173
|
expect(cop.messages).to eq(['Space between { and | missing.'])
|
116
174
|
expect(cop.highlights).to eq(['{'])
|
117
175
|
end
|
176
|
+
|
177
|
+
it 'auto-corrects missing space' do
|
178
|
+
new_source = autocorrect_source(cop, 'each {|x| puts}')
|
179
|
+
expect(new_source).to eq('each { |x| puts}')
|
180
|
+
end
|
118
181
|
end
|
119
182
|
|
120
183
|
context 'and space before block parameters not allowed' do
|
@@ -130,6 +193,11 @@ describe Rubocop::Cop::Style::SpaceAroundBlockBraces, :config do
|
|
130
193
|
expect(cop.messages).to eq(['Space between { and | detected.'])
|
131
194
|
expect(cop.highlights).to eq([' '])
|
132
195
|
end
|
196
|
+
|
197
|
+
it 'auto-corrects unwanted space' do
|
198
|
+
new_source = autocorrect_source(cop, 'each { |x| puts}')
|
199
|
+
expect(new_source).to eq('each {|x| puts}')
|
200
|
+
end
|
133
201
|
end
|
134
202
|
end
|
135
203
|
end
|
@@ -25,4 +25,9 @@ describe Rubocop::Cop::Style::SpaceAroundEqualsInParameterDefault do
|
|
25
25
|
inspect_source(cop, ['def f(x, y = 0, z = {})', 'end'])
|
26
26
|
expect(cop.messages).to be_empty
|
27
27
|
end
|
28
|
+
|
29
|
+
it 'auto-corrects missing space' do
|
30
|
+
new_source = autocorrect_source(cop, ['def f(x, y=0, z=1)', 'end'])
|
31
|
+
expect(new_source).to eq(['def f(x, y = 0, z = 1)', 'end'].join("\n"))
|
32
|
+
end
|
28
33
|
end
|
@@ -11,6 +11,11 @@ describe Rubocop::Cop::Style::SpaceAroundOperators do
|
|
11
11
|
["Surrounding space missing for operator '='."] * 3)
|
12
12
|
end
|
13
13
|
|
14
|
+
it 'auto-corrects assignment without space on both sides' do
|
15
|
+
new_source = autocorrect_source(cop, ['x=0', 'y= 0', 'z =0'])
|
16
|
+
expect(new_source).to eq(['x = 0', 'y = 0', 'z = 0'].join("\n"))
|
17
|
+
end
|
18
|
+
|
14
19
|
it 'registers an offence for ternary operator without space' do
|
15
20
|
inspect_source(cop, ['x == 0?1:2'])
|
16
21
|
expect(cop.messages).to eq(
|
@@ -18,6 +23,11 @@ describe Rubocop::Cop::Style::SpaceAroundOperators do
|
|
18
23
|
"Surrounding space missing for operator ':'."])
|
19
24
|
end
|
20
25
|
|
26
|
+
it 'auto-corrects a ternary operator without space' do
|
27
|
+
new_source = autocorrect_source(cop, 'x == 0?1:2')
|
28
|
+
expect(new_source).to eq('x == 0 ? 1 : 2')
|
29
|
+
end
|
30
|
+
|
21
31
|
it 'registers an offence in presence of modifier if statement' do
|
22
32
|
check_modifier('if')
|
23
33
|
end
|
@@ -41,6 +51,10 @@ describe Rubocop::Cop::Style::SpaceAroundOperators do
|
|
41
51
|
expect(cop.offences.map(&:line)).to eq([1, 2])
|
42
52
|
expect(cop.messages).to eq(
|
43
53
|
["Surrounding space missing for operator '='."] * 2)
|
54
|
+
|
55
|
+
new_source = autocorrect_source(cop, src)
|
56
|
+
expect(new_source)
|
57
|
+
.to eq(src.map { |line| line.sub(/=/, ' = ') }.join("\n"))
|
44
58
|
end
|
45
59
|
|
46
60
|
it 'registers an offence for binary operators that could be unary' do
|
@@ -51,12 +65,27 @@ describe Rubocop::Cop::Style::SpaceAroundOperators do
|
|
51
65
|
"Surrounding space missing for operator '+'."])
|
52
66
|
end
|
53
67
|
|
68
|
+
it 'auto-corrects missing space in binary operators that could be unary' do
|
69
|
+
new_source = autocorrect_source(cop, ['a-3', 'x&0xff', 'z+0'])
|
70
|
+
expect(new_source).to eq(['a - 3', 'x & 0xff', 'z + 0'].join("\n"))
|
71
|
+
end
|
72
|
+
|
54
73
|
it 'registers an offence for arguments to a method' do
|
55
74
|
inspect_source(cop, ['puts 1+2'])
|
56
75
|
expect(cop.messages).to eq(
|
57
76
|
["Surrounding space missing for operator '+'."])
|
58
77
|
end
|
59
78
|
|
79
|
+
it 'auto-corrects missing space in arguments to a method' do
|
80
|
+
new_source = autocorrect_source(cop, 'puts 1+2')
|
81
|
+
expect(new_source).to eq('puts 1 + 2')
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'accepts operator surrounded by tabs' do
|
85
|
+
inspect_source(cop, ["a\t+\tb"])
|
86
|
+
expect(cop.messages).to be_empty
|
87
|
+
end
|
88
|
+
|
60
89
|
it 'accepts operator symbols' do
|
61
90
|
inspect_source(cop, ['func(:-)'])
|
62
91
|
expect(cop.messages).to be_empty
|
@@ -156,6 +185,13 @@ describe Rubocop::Cop::Style::SpaceAroundOperators do
|
|
156
185
|
"Surrounding space missing for operator '&&'."])
|
157
186
|
end
|
158
187
|
|
188
|
+
it 'auto-corrects missing space' do
|
189
|
+
new_source = autocorrect_source(cop, ['x+= a+b-c*d/e%f^g|h&i||j',
|
190
|
+
'y -=k&&l'])
|
191
|
+
expect(new_source).to eq(['x += a + b - c * d / e % f ^ g | h & i || j',
|
192
|
+
'y -= k && l'].join("\n"))
|
193
|
+
end
|
194
|
+
|
159
195
|
it 'accepts operators with spaces' do
|
160
196
|
inspect_source(cop,
|
161
197
|
['x += a + b - c * d / e % f ^ g | h & i || j',
|
@@ -181,6 +217,13 @@ describe Rubocop::Cop::Style::SpaceAroundOperators do
|
|
181
217
|
['Space around operator ** detected.'])
|
182
218
|
end
|
183
219
|
|
220
|
+
it 'auto-corrects unwanted space around **' do
|
221
|
+
new_source = autocorrect_source(cop, ['x = a * b ** 2',
|
222
|
+
'y = a * b** 2'])
|
223
|
+
expect(new_source).to eq(['x = a * b**2',
|
224
|
+
'y = a * b**2'].join("\n"))
|
225
|
+
end
|
226
|
+
|
184
227
|
it 'accepts exponent operator without spaces' do
|
185
228
|
inspect_source(cop, ['x = a * b**2'])
|
186
229
|
expect(cop.offences).to be_empty
|
@@ -44,4 +44,27 @@ describe Rubocop::Cop::Style::SpaceBeforeModifierKeyword do
|
|
44
44
|
inspect_source(cop, 'a ? b : c')
|
45
45
|
expect(cop.offences).to be_empty
|
46
46
|
end
|
47
|
+
|
48
|
+
it 'auto-corrects missing space' do
|
49
|
+
new_source = autocorrect_source(cop, ['(a = 3)if a == 2',
|
50
|
+
'a = "test"if a == 2',
|
51
|
+
'a = 42unless a == 2',
|
52
|
+
'a = [1,2,3]unless a == 2',
|
53
|
+
'a = {:a => "b"}if a == 2',
|
54
|
+
'(a = 3)while b',
|
55
|
+
'a = "test"until b',
|
56
|
+
'a = 42while b',
|
57
|
+
'a = [1,2,3]until b',
|
58
|
+
'a = {:a => "b"}while b'])
|
59
|
+
expect(new_source).to eq(['(a = 3) if a == 2',
|
60
|
+
'a = "test" if a == 2',
|
61
|
+
'a = 42 unless a == 2',
|
62
|
+
'a = [1,2,3] unless a == 2',
|
63
|
+
'a = {:a => "b"} if a == 2',
|
64
|
+
'(a = 3) while b',
|
65
|
+
'a = "test" until b',
|
66
|
+
'a = 42 while b',
|
67
|
+
'a = [1,2,3] until b',
|
68
|
+
'a = {:a => "b"} while b'].join("\n"))
|
69
|
+
end
|
47
70
|
end
|
@@ -42,4 +42,11 @@ describe Rubocop::Cop::Style::SpaceInsideBrackets do
|
|
42
42
|
expect(cop.messages).to eq(
|
43
43
|
['Space inside square brackets detected.'])
|
44
44
|
end
|
45
|
+
|
46
|
+
it 'auto-corrects unwanted space' do
|
47
|
+
new_source = autocorrect_source(cop, ['a = [1, 2 ]',
|
48
|
+
'b = [ 1, 2]'])
|
49
|
+
expect(new_source).to eq(['a = [1, 2]',
|
50
|
+
'b = [1, 2]'].join("\n"))
|
51
|
+
end
|
45
52
|
end
|
@@ -4,26 +4,83 @@ require 'spec_helper'
|
|
4
4
|
|
5
5
|
describe Rubocop::Cop::Style::SpaceInsideHashLiteralBraces, :config do
|
6
6
|
subject(:cop) { described_class.new(config) }
|
7
|
-
let(:cop_config) { { '
|
7
|
+
let(:cop_config) { { 'EnforcedStyle' => 'space' } }
|
8
|
+
|
9
|
+
context 'with space inside empty braces not allowed' do
|
10
|
+
let(:cop_config) { { 'EnforcedStyleForEmptyBraces' => 'no_space' } }
|
11
|
+
|
12
|
+
it 'accepts empty braces with no space inside' do
|
13
|
+
inspect_source(cop, ['h = {}'])
|
14
|
+
expect(cop.messages).to be_empty
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'registers an offence for empty braces with space inside' do
|
18
|
+
inspect_source(cop, ['h = { }'])
|
19
|
+
expect(cop.messages)
|
20
|
+
.to eq(['Space inside empty hash literal braces detected.'])
|
21
|
+
expect(cop.highlights).to eq([' '])
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'auto-corrects unwanted space' do
|
25
|
+
new_source = autocorrect_source(cop, 'h = { }')
|
26
|
+
expect(new_source).to eq('h = {}')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'with space inside empty braces allowed' do
|
31
|
+
let(:cop_config) { { 'EnforcedStyleForEmptyBraces' => 'space' } }
|
32
|
+
|
33
|
+
it 'accepts empty braces with space inside' do
|
34
|
+
inspect_source(cop, ['h = { }'])
|
35
|
+
expect(cop.messages).to be_empty
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'registers an offence for empty braces with no space inside' do
|
39
|
+
inspect_source(cop, ['h = {}'])
|
40
|
+
expect(cop.messages)
|
41
|
+
.to eq(['Space inside empty hash literal braces missing.'])
|
42
|
+
expect(cop.highlights).to eq(['{'])
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'auto-corrects missing space' do
|
46
|
+
new_source = autocorrect_source(cop, 'h = {}')
|
47
|
+
expect(new_source).to eq('h = { }')
|
48
|
+
end
|
49
|
+
end
|
8
50
|
|
9
51
|
it 'registers an offence for hashes with no spaces if so configured' do
|
10
52
|
inspect_source(cop,
|
11
53
|
['h = {a: 1, b: 2}',
|
12
54
|
'h = {a => 1 }'])
|
13
|
-
expect(cop.messages).to eq(
|
14
|
-
|
55
|
+
expect(cop.messages).to eq(['Space inside { missing.',
|
56
|
+
'Space inside } missing.',
|
57
|
+
'Space inside { missing.'])
|
15
58
|
expect(cop.highlights).to eq(['{', '}', '{'])
|
16
59
|
end
|
17
60
|
|
18
|
-
|
19
|
-
|
61
|
+
it 'auto-corrects missing space' do
|
62
|
+
new_source = autocorrect_source(cop, ['h = {a: 1, b: 2}',
|
63
|
+
'h = {a => 1 }'])
|
64
|
+
expect(new_source).to eq(['h = { a: 1, b: 2 }',
|
65
|
+
'h = { a => 1 }'].join("\n"))
|
66
|
+
end
|
67
|
+
|
68
|
+
context 'when EnforcedStyle is no_space' do
|
69
|
+
let(:cop_config) { { 'EnforcedStyle' => 'no_space' } }
|
20
70
|
|
21
71
|
it 'registers an offence for hashes with spaces' do
|
22
72
|
inspect_source(cop,
|
23
73
|
['h = { a: 1, b: 2 }'])
|
24
|
-
expect(cop.messages).to eq(
|
25
|
-
|
26
|
-
expect(cop.highlights).to eq(['
|
74
|
+
expect(cop.messages).to eq(['Space inside { detected.',
|
75
|
+
'Space inside } detected.'])
|
76
|
+
expect(cop.highlights).to eq([' ', ' '])
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'auto-corrects unwanted space' do
|
80
|
+
new_source = autocorrect_source(cop, ['h = { a: 1, b: 2 }',
|
81
|
+
'h = {a => 1 }'])
|
82
|
+
expect(new_source).to eq(['h = {a: 1, b: 2}',
|
83
|
+
'h = {a => 1}'].join("\n"))
|
27
84
|
end
|
28
85
|
|
29
86
|
it 'accepts hashes with no spaces' do
|
@@ -41,11 +98,6 @@ describe Rubocop::Cop::Style::SpaceInsideHashLiteralBraces, :config do
|
|
41
98
|
'}'])
|
42
99
|
expect(cop.offences).to be_empty
|
43
100
|
end
|
44
|
-
|
45
|
-
it 'accepts empty hashes without spaces' do
|
46
|
-
inspect_source(cop, ['h = {}'])
|
47
|
-
expect(cop.offences).to be_empty
|
48
|
-
end
|
49
101
|
end
|
50
102
|
|
51
103
|
it 'accepts hashes with spaces by default' do
|
@@ -55,16 +107,6 @@ describe Rubocop::Cop::Style::SpaceInsideHashLiteralBraces, :config do
|
|
55
107
|
expect(cop.offences).to be_empty
|
56
108
|
end
|
57
109
|
|
58
|
-
it 'accepts empty hashes without spaces by default' do
|
59
|
-
inspect_source(cop, ['h = {}'])
|
60
|
-
expect(cop.offences).to be_empty
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'accepts empty hashes without spaces even if configured true' do
|
64
|
-
inspect_source(cop, ['h = {}'])
|
65
|
-
expect(cop.offences).to be_empty
|
66
|
-
end
|
67
|
-
|
68
110
|
it 'accepts hash literals with no braces' do
|
69
111
|
inspect_source(cop, ['x(a: b.c)'])
|
70
112
|
expect(cop.offences).to be_empty
|
@@ -24,4 +24,11 @@ describe Rubocop::Cop::Style::SpaceInsideParens do
|
|
24
24
|
inspect_source(cop, ['split("\n")'])
|
25
25
|
expect(cop.messages).to be_empty
|
26
26
|
end
|
27
|
+
|
28
|
+
it 'auto-corrects unwanted space' do
|
29
|
+
new_source = autocorrect_source(cop, ['f( 3)',
|
30
|
+
'g(3 )'])
|
31
|
+
expect(new_source).to eq(['f(3)',
|
32
|
+
'g(3)'].join("\n"))
|
33
|
+
end
|
27
34
|
end
|
@@ -30,8 +30,13 @@ describe Rubocop::Cop::Style::SpecialGlobalVars do
|
|
30
30
|
inspect_source(cop, ['puts $$'])
|
31
31
|
expect(cop.offences.size).to eq(1)
|
32
32
|
expect(cop.messages)
|
33
|
-
.to eq(['Prefer $
|
34
|
-
|
33
|
+
.to eq(['Prefer $PROCESS_ID or $PID from the English library over $$.'])
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'is clear about variables from the English library vs those not' do
|
37
|
+
inspect_source(cop, ['puts $*'])
|
38
|
+
expect(cop.messages)
|
39
|
+
.to eq(['Prefer $ARGV from the English library, or ARGV over $*.'])
|
35
40
|
end
|
36
41
|
|
37
42
|
it 'does not register an offence for backrefs like $1' do
|
@@ -43,4 +48,9 @@ describe Rubocop::Cop::Style::SpecialGlobalVars do
|
|
43
48
|
new_source = autocorrect_source(cop, '$:')
|
44
49
|
expect(new_source).to eq('$LOAD_PATH')
|
45
50
|
end
|
51
|
+
|
52
|
+
it 'auto-corrects $/ to $INPUT_RECORD_SEPARATOR' do
|
53
|
+
new_source = autocorrect_source(cop, '$/')
|
54
|
+
expect(new_source).to eq('$INPUT_RECORD_SEPARATOR')
|
55
|
+
end
|
46
56
|
end
|
@@ -84,6 +84,12 @@ describe Rubocop::Cop::Style::StringLiterals, :config do
|
|
84
84
|
expect(cop.offences).to be_empty
|
85
85
|
end
|
86
86
|
|
87
|
+
it 'can handle character literals' do
|
88
|
+
src = 'a = ?/'
|
89
|
+
inspect_source(cop, src)
|
90
|
+
expect(cop.offences).to be_empty
|
91
|
+
end
|
92
|
+
|
87
93
|
it 'auto-corrects " with \'' do
|
88
94
|
new_source = autocorrect_source(cop, 's = "abc"')
|
89
95
|
expect(new_source).to eq("s = 'abc'")
|