rubocop 0.4.0 → 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 +7 -0
- data/.gitignore +50 -0
- data/.rubocop.yml +5 -127
- data/.travis.yml +7 -1
- data/CHANGELOG.md +157 -0
- data/CONTRIBUTING.md +13 -6
- data/Gemfile +3 -8
- data/README.md +160 -9
- data/Rakefile +3 -17
- data/bin/rubocop +16 -10
- data/config/default.yml +46 -0
- data/config/disabled.yml +5 -0
- data/config/enabled.yml +322 -0
- data/lib/rubocop/cli.rb +248 -93
- data/lib/rubocop/config.rb +205 -0
- data/lib/rubocop/config_store.rb +37 -0
- data/lib/rubocop/cop/access_control.rb +41 -0
- data/lib/rubocop/cop/alias.rb +17 -0
- data/lib/rubocop/cop/align_parameters.rb +20 -95
- data/lib/rubocop/cop/and_or.rb +26 -0
- data/lib/rubocop/cop/ascii_comments.rb +13 -0
- data/lib/rubocop/cop/ascii_identifiers.rb +19 -0
- data/lib/rubocop/cop/avoid_class_vars.rb +15 -0
- data/lib/rubocop/cop/avoid_for.rb +17 -0
- data/lib/rubocop/cop/avoid_global_vars.rb +61 -0
- data/lib/rubocop/cop/avoid_perl_backrefs.rb +17 -0
- data/lib/rubocop/cop/avoid_perlisms.rb +47 -0
- data/lib/rubocop/cop/block_comments.rb +15 -0
- data/lib/rubocop/cop/blocks.rb +11 -47
- data/lib/rubocop/cop/case_indentation.rb +22 -0
- data/lib/rubocop/cop/class_and_module_camel_case.rb +20 -11
- data/lib/rubocop/cop/class_methods.rb +15 -0
- data/lib/rubocop/cop/collection_methods.rb +16 -16
- data/lib/rubocop/cop/colon_method_call.rb +20 -0
- data/lib/rubocop/cop/constant_name.rb +24 -0
- data/lib/rubocop/cop/cop.rb +34 -47
- data/lib/rubocop/cop/def_parentheses.rb +43 -35
- data/lib/rubocop/cop/empty_line_between_defs.rb +22 -0
- data/lib/rubocop/cop/empty_lines.rb +21 -13
- 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 +19 -0
- data/lib/rubocop/cop/eval.rb +19 -0
- data/lib/rubocop/cop/favor_join.rb +22 -0
- data/lib/rubocop/cop/favor_modifier.rb +38 -48
- data/lib/rubocop/cop/favor_percent_r.rb +19 -0
- data/lib/rubocop/cop/favor_sprintf.rb +21 -0
- data/lib/rubocop/cop/favor_unless_over_negated_if.rb +19 -17
- data/lib/rubocop/cop/handle_exceptions.rb +17 -0
- 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 +17 -0
- data/lib/rubocop/cop/line_continuation.rb +15 -0
- data/lib/rubocop/cop/line_length.rb +4 -4
- data/lib/rubocop/cop/loop.rb +33 -0
- data/lib/rubocop/cop/method_and_variable_snake_case.rb +41 -17
- data/lib/rubocop/cop/method_length.rb +52 -0
- data/lib/rubocop/cop/new_lambda_literal.rb +8 -6
- data/lib/rubocop/cop/not.rb +21 -0
- data/lib/rubocop/cop/numeric_literals.rb +9 -7
- data/lib/rubocop/cop/offence.rb +12 -1
- data/lib/rubocop/cop/op_method.rb +26 -0
- 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 +19 -0
- data/lib/rubocop/cop/reduce_arguments.rb +29 -0
- data/lib/rubocop/cop/rescue_exception.rb +26 -0
- data/lib/rubocop/cop/rescue_modifier.rb +17 -0
- data/lib/rubocop/cop/semicolon.rb +31 -0
- data/lib/rubocop/cop/single_line_methods.rb +44 -0
- data/lib/rubocop/cop/space_after_comma_etc.rb +30 -10
- data/lib/rubocop/cop/space_after_control_keyword.rb +29 -0
- data/lib/rubocop/cop/string_literals.rb +9 -23
- data/lib/rubocop/cop/surrounding_space.rb +223 -83
- data/lib/rubocop/cop/symbol_array.rb +31 -0
- data/lib/rubocop/cop/symbol_name.rb +23 -0
- data/lib/rubocop/cop/syntax.rb +35 -5
- 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 +26 -0
- data/lib/rubocop/cop/unless_else.rb +11 -7
- data/lib/rubocop/cop/util.rb +26 -0
- data/lib/rubocop/cop/variable_interpolation.rb +29 -0
- data/lib/rubocop/cop/when_then.rb +6 -14
- data/lib/rubocop/cop/word_array.rb +37 -0
- data/lib/rubocop/report/emacs_style.rb +2 -2
- data/lib/rubocop/report/plain_text.rb +1 -1
- data/lib/rubocop/version.rb +3 -1
- data/lib/rubocop.rb +48 -8
- data/rubocop.gemspec +32 -151
- data/spec/project_spec.rb +27 -0
- data/spec/rubocop/cli_spec.rb +573 -200
- data/spec/rubocop/config_spec.rb +409 -0
- data/spec/rubocop/config_store_spec.rb +66 -0
- data/spec/rubocop/cops/access_control_spec.rb +129 -0
- data/spec/rubocop/cops/alias_spec.rb +39 -0
- data/spec/rubocop/cops/align_parameters_spec.rb +66 -70
- data/spec/rubocop/cops/and_or_spec.rb +37 -0
- data/spec/rubocop/cops/ascii_comments_spec.rb +26 -0
- data/spec/rubocop/cops/ascii_identifiers_spec.rb +26 -0
- data/spec/rubocop/cops/avoid_class_vars_spec.rb +25 -0
- data/spec/rubocop/cops/avoid_for_spec.rb +35 -0
- data/spec/rubocop/cops/avoid_global_vars_spec.rb +32 -0
- data/spec/rubocop/cops/avoid_perl_backrefs_spec.rb +18 -0
- data/spec/rubocop/cops/avoid_perlisms_spec.rb +44 -0
- data/spec/rubocop/cops/block_comments_spec.rb +25 -0
- data/spec/rubocop/cops/blocks_spec.rb +33 -0
- data/spec/rubocop/cops/{indentation_spec.rb → case_indentation_spec.rb} +7 -7
- data/spec/rubocop/cops/class_and_module_camel_case_spec.rb +15 -5
- data/spec/rubocop/cops/class_methods_spec.rb +49 -0
- data/spec/rubocop/cops/collection_methods_spec.rb +9 -4
- data/spec/rubocop/cops/colon_method_call_spec.rb +53 -0
- 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 +83 -0
- data/spec/rubocop/cops/empty_lines_spec.rb +14 -59
- data/spec/rubocop/cops/empty_literal_spec.rb +90 -0
- data/spec/rubocop/cops/encoding_spec.rb +11 -11
- data/spec/rubocop/cops/end_of_line_spec.rb +2 -2
- data/spec/rubocop/cops/ensure_return_spec.rb +35 -0
- data/spec/rubocop/cops/eval_spec.rb +39 -0
- data/spec/rubocop/cops/favor_join_spec.rb +35 -0
- data/spec/rubocop/cops/favor_modifier_spec.rb +16 -14
- data/spec/rubocop/cops/favor_percent_r_spec.rb +29 -0
- data/spec/rubocop/cops/favor_sprintf_spec.rb +51 -0
- 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 +34 -0
- 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 +54 -0
- data/spec/rubocop/cops/line_continuation_spec.rb +24 -0
- data/spec/rubocop/cops/line_length_spec.rb +3 -2
- data/spec/rubocop/cops/loop_spec.rb +31 -0
- data/spec/rubocop/cops/method_and_variable_snake_case_spec.rb +55 -9
- data/spec/rubocop/cops/method_length_spec.rb +147 -0
- data/spec/rubocop/cops/multiline_if_then_spec.rb +15 -15
- data/spec/rubocop/cops/new_lambda_literal_spec.rb +5 -6
- data/spec/rubocop/cops/not_spec.rb +31 -0
- data/spec/rubocop/cops/numeric_literals_spec.rb +13 -13
- data/spec/rubocop/cops/offence_spec.rb +13 -0
- data/spec/rubocop/cops/one_line_conditional_spec.rb +1 -1
- data/spec/rubocop/cops/op_method_spec.rb +78 -0
- 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 +29 -0
- data/spec/rubocop/cops/reduce_arguments_spec.rb +57 -0
- data/spec/rubocop/cops/rescue_exception_spec.rb +125 -0
- data/spec/rubocop/cops/rescue_modifier_spec.rb +37 -0
- data/spec/rubocop/cops/semicolon_spec.rb +88 -0
- data/spec/rubocop/cops/single_line_methods_spec.rb +50 -0
- 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 +67 -0
- data/spec/rubocop/cops/space_after_semicolon_spec.rb +6 -1
- data/spec/rubocop/cops/space_around_braces_spec.rb +18 -3
- data/spec/rubocop/cops/space_around_equals_in_default_parameter_spec.rb +12 -2
- data/spec/rubocop/cops/space_around_operators_spec.rb +88 -26
- data/spec/rubocop/cops/space_inside_brackets_spec.rb +13 -7
- data/spec/rubocop/cops/space_inside_hash_literal_braces_spec.rb +79 -0
- data/spec/rubocop/cops/space_inside_parens_spec.rb +7 -3
- data/spec/rubocop/cops/string_literals_spec.rb +21 -6
- data/spec/rubocop/cops/symbol_array_spec.rb +41 -0
- data/spec/rubocop/cops/symbol_name_spec.rb +119 -0
- data/spec/rubocop/cops/syntax_spec.rb +28 -5
- 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 +329 -0
- data/spec/rubocop/cops/unless_else_spec.rb +8 -8
- data/spec/rubocop/cops/variable_interpolation_spec.rb +49 -0
- data/spec/rubocop/cops/when_then_spec.rb +14 -14
- data/spec/rubocop/cops/word_array_spec.rb +47 -0
- data/spec/spec_helper.rb +30 -9
- data/spec/support/file_helper.rb +21 -0
- data/spec/support/isolated_environment.rb +27 -0
- metadata +235 -76
- data/.document +0 -5
- data/Gemfile.lock +0 -41
- data/VERSION +0 -1
- data/lib/rubocop/cop/ampersands_pipes_vs_and_or.rb +0 -25
- data/lib/rubocop/cop/grammar.rb +0 -135
- data/lib/rubocop/cop/indentation.rb +0 -44
- data/spec/rubocop/cops/ampersands_pipes_vs_and_or_spec.rb +0 -57
- data/spec/rubocop/cops/grammar_spec.rb +0 -71
- data/spec/rubocop/cops/multiline_blocks_spec.rb +0 -24
- data/spec/rubocop/cops/single_line_blocks_spec.rb +0 -22
@@ -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)',
|
@@ -58,53 +60,62 @@ module Rubocop
|
|
58
60
|
'more than one line.'])
|
59
61
|
end
|
60
62
|
|
63
|
+
it "doesn't get confused by extra comma at the end" do
|
64
|
+
inspect_source(align,
|
65
|
+
['func1(a,',
|
66
|
+
' b,)'])
|
67
|
+
expect(align.offences.map(&:to_s)).to eq(
|
68
|
+
['C: 2: Align the parameters of a method call if they span ' +
|
69
|
+
'more than one line.'])
|
70
|
+
end
|
71
|
+
|
61
72
|
it 'can handle a correctly aligned string literal as first argument' do
|
62
|
-
inspect_source(align,
|
73
|
+
inspect_source(align,
|
63
74
|
['add_offence(:convention, x,',
|
64
75
|
' a)'])
|
65
|
-
expect(align.offences
|
76
|
+
expect(align.offences).to be_empty
|
66
77
|
end
|
67
78
|
|
68
79
|
it 'can handle a string literal as other argument' do
|
69
|
-
inspect_source(align,
|
80
|
+
inspect_source(align,
|
70
81
|
['add_offence(:convention,',
|
71
82
|
' "", a)'])
|
72
|
-
expect(align.offences
|
83
|
+
expect(align.offences).to be_empty
|
73
84
|
end
|
74
85
|
|
75
86
|
it "doesn't get confused by a line break inside a parameter" do
|
76
|
-
inspect_source(align,
|
87
|
+
inspect_source(align,
|
77
88
|
['read(path, { headers: true,',
|
78
89
|
' converters: :numeric })'])
|
79
|
-
expect(align.offences
|
90
|
+
expect(align.offences).to be_empty
|
80
91
|
end
|
81
92
|
|
82
93
|
it "doesn't get confused by symbols with embedded expressions" do
|
83
|
-
inspect_source(align,
|
94
|
+
inspect_source(align,
|
84
95
|
['send(:"#{name}_comments_path")'])
|
85
|
-
expect(align.offences
|
96
|
+
expect(align.offences).to be_empty
|
86
97
|
end
|
87
98
|
|
88
99
|
it "doesn't get confused by regexen with embedded expressions" do
|
89
|
-
inspect_source(align,
|
100
|
+
inspect_source(align,
|
90
101
|
['a(/#{name}/)'])
|
91
|
-
expect(align.offences
|
102
|
+
expect(align.offences).to be_empty
|
92
103
|
end
|
93
104
|
|
94
105
|
it 'accepts braceless hashes' do
|
95
|
-
inspect_source(align,
|
106
|
+
inspect_source(align,
|
96
107
|
['run(collection, :entry_name => label,',
|
97
108
|
' :paginator => paginator)'])
|
98
|
-
expect(align.offences
|
109
|
+
expect(align.offences).to be_empty
|
99
110
|
end
|
100
111
|
|
101
112
|
it 'accepts the first parameter being on a new row' do
|
102
|
-
inspect_source(align,
|
113
|
+
inspect_source(align,
|
103
114
|
[' match(',
|
104
115
|
' a,',
|
105
116
|
' b',
|
106
117
|
' )'])
|
107
|
-
expect(align.offences
|
118
|
+
expect(align.offences).to be_empty
|
108
119
|
end
|
109
120
|
|
110
121
|
it 'can handle heredoc strings' do
|
@@ -114,31 +125,31 @@ module Rubocop
|
|
114
125
|
' return value',
|
115
126
|
' end',
|
116
127
|
' EOS']
|
117
|
-
inspect_source(align,
|
118
|
-
expect(align.offences
|
128
|
+
inspect_source(align, src)
|
129
|
+
expect(align.offences).to be_empty
|
119
130
|
end
|
120
131
|
|
121
132
|
it 'can handle a method call within a method call' do
|
122
|
-
inspect_source(align,
|
133
|
+
inspect_source(align,
|
123
134
|
['a(a1,',
|
124
135
|
' b(b1,',
|
125
136
|
' b2),',
|
126
137
|
' a2)'])
|
127
|
-
expect(align.offences
|
138
|
+
expect(align.offences).to be_empty
|
128
139
|
end
|
129
140
|
|
130
141
|
it 'can handle a call embedded in a string' do
|
131
|
-
inspect_source(align,
|
142
|
+
inspect_source(align,
|
132
143
|
['model("#{index(name)}", child)'])
|
133
|
-
expect(align.offences
|
144
|
+
expect(align.offences).to be_empty
|
134
145
|
end
|
135
146
|
|
136
147
|
it 'can handle do-end' do
|
137
|
-
inspect_source(align,
|
148
|
+
inspect_source(align,
|
138
149
|
[' run(lambda do |e|',
|
139
150
|
" w = e['warden']",
|
140
151
|
' end)'])
|
141
|
-
expect(align.offences
|
152
|
+
expect(align.offences).to be_empty
|
142
153
|
end
|
143
154
|
|
144
155
|
it 'can handle a call with a block inside another call' do
|
@@ -146,55 +157,40 @@ module Rubocop
|
|
146
157
|
' exec_query("info(\'#{row[\'name\']}\')").map { |col|',
|
147
158
|
" col['name']",
|
148
159
|
' })']
|
149
|
-
inspect_source(align,
|
150
|
-
expect(align.offences
|
160
|
+
inspect_source(align, src)
|
161
|
+
expect(align.offences).to be_empty
|
151
162
|
end
|
152
163
|
|
153
164
|
it 'can handle a ternary condition with a block reference' do
|
154
165
|
src = ['cond ? a : func(&b)']
|
155
|
-
inspect_source(align,
|
156
|
-
expect(align.offences
|
166
|
+
inspect_source(align, src)
|
167
|
+
expect(align.offences).to be_empty
|
157
168
|
end
|
158
169
|
|
159
170
|
it 'can handle parentheses used with no parameters' do
|
160
171
|
src = ['func()']
|
161
|
-
inspect_source(align,
|
162
|
-
expect(align.offences
|
163
|
-
end
|
164
|
-
|
165
|
-
it 'can handle a multiline hash as first parameter' do
|
166
|
-
src = ['assert_equal({',
|
167
|
-
' :space_before => "",',
|
168
|
-
'}, state)']
|
169
|
-
inspect_source(align, '', src)
|
170
|
-
expect(align.offences.map(&:message)).to be_empty
|
172
|
+
inspect_source(align, src)
|
173
|
+
expect(align.offences).to be_empty
|
171
174
|
end
|
172
175
|
|
173
176
|
it 'can handle a multiline hash as second parameter' do
|
174
177
|
src = ['tag(:input, {',
|
175
178
|
' :value => value',
|
176
179
|
'})']
|
177
|
-
inspect_source(align,
|
178
|
-
expect(align.offences
|
180
|
+
inspect_source(align, src)
|
181
|
+
expect(align.offences).to be_empty
|
179
182
|
end
|
180
183
|
|
181
184
|
it 'can handle method calls without parentheses' do
|
182
185
|
src = ['a(b c, d)']
|
183
|
-
inspect_source(align,
|
184
|
-
expect(align.offences
|
186
|
+
inspect_source(align, src)
|
187
|
+
expect(align.offences).to be_empty
|
185
188
|
end
|
186
189
|
|
187
190
|
it 'can handle other method calls without parentheses' do
|
188
191
|
src = ['chars(Unicode.apply_mapping @wrapped_string, :uppercase)']
|
189
|
-
inspect_source(align,
|
190
|
-
expect(align.offences
|
191
|
-
end
|
192
|
-
|
193
|
-
it "doesn't check alignment if tabs are used to indent" do
|
194
|
-
src = ['a(b,',
|
195
|
-
"\tc)"]
|
196
|
-
inspect_source(align, '', src)
|
197
|
-
expect(align.offences.map(&:message)).to be_empty
|
192
|
+
inspect_source(align, src)
|
193
|
+
expect(align.offences).to be_empty
|
198
194
|
end
|
199
195
|
end
|
200
196
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
module Rubocop
|
6
|
+
module Cop
|
7
|
+
describe AndOr do
|
8
|
+
let(:amp) { AndOr.new }
|
9
|
+
|
10
|
+
it 'registers an offence for OR' do
|
11
|
+
inspect_source(amp,
|
12
|
+
['test if a or b'])
|
13
|
+
expect(amp.offences.size).to eq(1)
|
14
|
+
expect(amp.messages).to eq(['Use || instead of or.'])
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'registers an offence for AND' do
|
18
|
+
inspect_source(amp,
|
19
|
+
['test if a and b'])
|
20
|
+
expect(amp.offences.size).to eq(1)
|
21
|
+
expect(amp.messages).to eq(['Use && instead of and.'])
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'accepts ||' do
|
25
|
+
inspect_source(amp,
|
26
|
+
['test if a || b'])
|
27
|
+
expect(amp.offences).to be_empty
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'accepts &&' do
|
31
|
+
inspect_source(amp,
|
32
|
+
['test if a && b'])
|
33
|
+
expect(amp.offences).to be_empty
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
module Rubocop
|
6
|
+
module Cop
|
7
|
+
describe AsciiComments do
|
8
|
+
let(:ascii) { AsciiComments.new }
|
9
|
+
|
10
|
+
it 'registers an offence for a comment with non-ascii chars' do
|
11
|
+
inspect_source(ascii,
|
12
|
+
['# encoding: utf-8',
|
13
|
+
'# 这是什么?'])
|
14
|
+
expect(ascii.offences.size).to eq(1)
|
15
|
+
expect(ascii.offences.map(&:message))
|
16
|
+
.to eq([AsciiComments::MSG])
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'accepts comments with only ascii chars' do
|
20
|
+
inspect_source(ascii,
|
21
|
+
['# AZaz1@$%~,;*_`|'])
|
22
|
+
expect(ascii.offences).to be_empty
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
module Rubocop
|
6
|
+
module Cop
|
7
|
+
describe AsciiIdentifiers do
|
8
|
+
let(:ascii) { AsciiIdentifiers.new }
|
9
|
+
|
10
|
+
it 'registers an offence for a variable name with non-ascii chars' do
|
11
|
+
inspect_source(ascii,
|
12
|
+
['# encoding: utf-8',
|
13
|
+
'älg = 1'])
|
14
|
+
expect(ascii.offences.size).to eq(1)
|
15
|
+
expect(ascii.offences.map(&:message))
|
16
|
+
.to eq([AsciiIdentifiers::MSG])
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'accepts identifiers with only ascii chars' do
|
20
|
+
inspect_source(ascii,
|
21
|
+
['x.empty?'])
|
22
|
+
expect(ascii.offences).to be_empty
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
module Rubocop
|
6
|
+
module Cop
|
7
|
+
describe AvoidClassVars do
|
8
|
+
let(:acv) { AvoidClassVars.new }
|
9
|
+
|
10
|
+
it 'registers an offence for class variable declaration' do
|
11
|
+
inspect_source(acv,
|
12
|
+
['class TestClass; @@test = 10; end'])
|
13
|
+
expect(acv.offences.size).to eq(1)
|
14
|
+
expect(acv.offences.map(&:message))
|
15
|
+
.to eq(['Replace class var @@test with a class instance var.'])
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'does not register an offence for class variable usage' do
|
19
|
+
inspect_source(acv,
|
20
|
+
['@@test.test(20)'])
|
21
|
+
expect(acv.offences).to be_empty
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
module Rubocop
|
6
|
+
module Cop
|
7
|
+
describe AvoidFor do
|
8
|
+
let(:af) { AvoidFor.new }
|
9
|
+
|
10
|
+
it 'registers an offence for for' do
|
11
|
+
inspect_source(af,
|
12
|
+
['def func',
|
13
|
+
' for n in [1, 2, 3] do',
|
14
|
+
' puts n',
|
15
|
+
' end',
|
16
|
+
'end'])
|
17
|
+
expect(af.offences.size).to eq(1)
|
18
|
+
expect(af.offences.map(&:message))
|
19
|
+
.to eq([AvoidFor::MSG])
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'does not register an offence for :for' do
|
23
|
+
inspect_source(af,
|
24
|
+
['[:for, :ala, :bala]'])
|
25
|
+
expect(af.offences).to be_empty
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'does not register an offence for def for' do
|
29
|
+
inspect_source(af,
|
30
|
+
['def for; end'])
|
31
|
+
expect(af.offences).to be_empty
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
module Rubocop
|
6
|
+
module Cop
|
7
|
+
describe AvoidGlobalVars do
|
8
|
+
let(:ap) { AvoidGlobalVars.new }
|
9
|
+
|
10
|
+
it 'registers an offence for $custom' do
|
11
|
+
inspect_source(ap, ['puts $custom'])
|
12
|
+
expect(ap.offences.size).to eq(1)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'does not register an offence for $"' do
|
16
|
+
inspect_source(ap, ['puts $"'])
|
17
|
+
|
18
|
+
expect(ap.offences).to be_empty
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'does not register an offence for $ORS' do
|
22
|
+
inspect_source(ap, ['puts $0'])
|
23
|
+
expect(ap.offences).to be_empty
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'does not register an offence for backrefs like $1' do
|
27
|
+
inspect_source(ap, ['puts $1'])
|
28
|
+
expect(ap.offences).to be_empty
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
module Rubocop
|
6
|
+
module Cop
|
7
|
+
describe AvoidPerlBackrefs do
|
8
|
+
let(:ap) { AvoidPerlBackrefs.new }
|
9
|
+
|
10
|
+
it 'registers an offence for $1' do
|
11
|
+
inspect_source(ap, ['puts $1'])
|
12
|
+
expect(ap.offences.size).to eq(1)
|
13
|
+
expect(ap.offences.map(&:message))
|
14
|
+
.to eq(['Prefer the use of MatchData over $1.'])
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
module Rubocop
|
6
|
+
module Cop
|
7
|
+
describe AvoidPerlisms do
|
8
|
+
let(:ap) { AvoidPerlisms.new }
|
9
|
+
|
10
|
+
it 'registers an offence for $:' do
|
11
|
+
inspect_source(ap, ['puts $:'])
|
12
|
+
expect(ap.offences.size).to eq(1)
|
13
|
+
expect(ap.offences.map(&:message))
|
14
|
+
.to eq(['Prefer $LOAD_PATH over $:.'])
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'registers an offence for $"' do
|
18
|
+
inspect_source(ap, ['puts $"'])
|
19
|
+
expect(ap.offences.size).to eq(1)
|
20
|
+
expect(ap.offences.map(&:message))
|
21
|
+
.to eq(['Prefer $LOADED_FEATURES over $".'])
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'registers an offence for $0' do
|
25
|
+
inspect_source(ap, ['puts $0'])
|
26
|
+
expect(ap.offences.size).to eq(1)
|
27
|
+
expect(ap.offences.map(&:message))
|
28
|
+
.to eq(['Prefer $PROGRAM_NAME over $0.'])
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'registers an offence for $$' do
|
32
|
+
inspect_source(ap, ['puts $$'])
|
33
|
+
expect(ap.offences.size).to eq(1)
|
34
|
+
expect(ap.offences.map(&:message))
|
35
|
+
.to eq(['Prefer $PID or $PROCESS_ID from English library over $$.'])
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'does not register an offence for backrefs like $1' do
|
39
|
+
inspect_source(ap, ['puts $1'])
|
40
|
+
expect(ap.offences).to be_empty
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
module Rubocop
|
6
|
+
module Cop
|
7
|
+
describe BlockComments do
|
8
|
+
let(:block) { BlockComments.new }
|
9
|
+
|
10
|
+
it 'registers an offence for block comments' do
|
11
|
+
inspect_source(block,
|
12
|
+
['=begin',
|
13
|
+
'comment',
|
14
|
+
'=end'])
|
15
|
+
expect(block.offences.size).to eq(1)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'accepts regular comments' do
|
19
|
+
inspect_source(block,
|
20
|
+
['# comment'])
|
21
|
+
expect(block.offences).to be_empty
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
module Rubocop
|
6
|
+
module Cop
|
7
|
+
describe Blocks do
|
8
|
+
let(:blocks) { Blocks.new }
|
9
|
+
|
10
|
+
it 'registers an offence for a multiline block with braces' do
|
11
|
+
inspect_source(blocks, ['each { |x|',
|
12
|
+
'}'])
|
13
|
+
expect(blocks.messages).to eq([Blocks::MULTI_LINE_MSG])
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'accepts a multiline block with do-end' do
|
17
|
+
inspect_source(blocks, ['each do |x|',
|
18
|
+
'end'])
|
19
|
+
expect(blocks.offences.map(&:message)).to be_empty
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'registers an offence for a single line block with do-end' do
|
23
|
+
inspect_source(blocks, ['each do |x| end'])
|
24
|
+
expect(blocks.messages).to eq([Blocks::SINGLE_LINE_MSG])
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'accepts a single line block with braces' do
|
28
|
+
inspect_source(blocks, ['each { |x| }'])
|
29
|
+
expect(blocks.offences.map(&:message)).to be_empty
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -4,8 +4,8 @@ require 'spec_helper'
|
|
4
4
|
|
5
5
|
module Rubocop
|
6
6
|
module Cop
|
7
|
-
describe
|
8
|
-
let(:ind) {
|
7
|
+
describe CaseIndentation do
|
8
|
+
let(:ind) { CaseIndentation.new }
|
9
9
|
|
10
10
|
it "registers an offence for a when clause that's deeper than case" do
|
11
11
|
source = ['case a',
|
@@ -14,7 +14,7 @@ module Rubocop
|
|
14
14
|
' when 1 then return',
|
15
15
|
' end',
|
16
16
|
'end']
|
17
|
-
inspect_source(ind,
|
17
|
+
inspect_source(ind, source)
|
18
18
|
expect(ind.offences.map(&:message)).to eq(
|
19
19
|
['Indent when as deep as case.'] * 2)
|
20
20
|
end
|
@@ -32,7 +32,7 @@ module Rubocop
|
|
32
32
|
'when 2 then encoding',
|
33
33
|
'end',
|
34
34
|
'']
|
35
|
-
inspect_source(ind,
|
35
|
+
inspect_source(ind, source)
|
36
36
|
expect(ind.offences).to be_empty
|
37
37
|
end
|
38
38
|
|
@@ -42,7 +42,7 @@ module Rubocop
|
|
42
42
|
'when 0',
|
43
43
|
'end',
|
44
44
|
'']
|
45
|
-
inspect_source(ind,
|
45
|
+
inspect_source(ind, source)
|
46
46
|
expect(ind.offences.map(&:message)).to be_empty
|
47
47
|
end
|
48
48
|
|
@@ -55,7 +55,7 @@ module Rubocop
|
|
55
55
|
' MethodCallNode',
|
56
56
|
'end',
|
57
57
|
'']
|
58
|
-
inspect_source(ind,
|
58
|
+
inspect_source(ind, source)
|
59
59
|
expect(ind.offences.map(&:message)).to be_empty
|
60
60
|
end
|
61
61
|
|
@@ -78,7 +78,7 @@ module Rubocop
|
|
78
78
|
'when Array',
|
79
79
|
'end',
|
80
80
|
'']
|
81
|
-
inspect_source(ind,
|
81
|
+
inspect_source(ind, source)
|
82
82
|
expect(ind.offences.map(&:message)).to be_empty
|
83
83
|
end
|
84
84
|
end
|
@@ -8,26 +8,36 @@ module Rubocop
|
|
8
8
|
let(:camel_case) { ClassAndModuleCamelCase.new }
|
9
9
|
|
10
10
|
it 'registers an offence for underscore in class and module name' do
|
11
|
-
inspect_source(camel_case,
|
11
|
+
inspect_source(camel_case,
|
12
12
|
['class My_Class',
|
13
13
|
'end',
|
14
14
|
'',
|
15
15
|
'module My_Module',
|
16
16
|
'end',
|
17
17
|
])
|
18
|
-
expect(camel_case.offences.
|
19
|
-
|
18
|
+
expect(camel_case.offences.size).to eq(2)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'is not fooled by qualified names' do
|
22
|
+
inspect_source(camel_case,
|
23
|
+
['class Top::My_Class',
|
24
|
+
'end',
|
25
|
+
'',
|
26
|
+
'module My_Module::Ala',
|
27
|
+
'end',
|
28
|
+
])
|
29
|
+
expect(camel_case.offences.size).to eq(2)
|
20
30
|
end
|
21
31
|
|
22
32
|
it 'accepts CamelCase names' do
|
23
|
-
inspect_source(camel_case,
|
33
|
+
inspect_source(camel_case,
|
24
34
|
['class MyClass',
|
25
35
|
'end',
|
26
36
|
'',
|
27
37
|
'module Mine',
|
28
38
|
'end',
|
29
39
|
])
|
30
|
-
expect(camel_case.offences
|
40
|
+
expect(camel_case.offences).to be_empty
|
31
41
|
end
|
32
42
|
end
|
33
43
|
end
|