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.

Files changed (184) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +7 -1
  3. data/CHANGELOG.md +19 -0
  4. data/README.md +4 -8
  5. data/bin/rubocop +2 -2
  6. data/config/default.yml +8 -0
  7. data/config/enabled.yml +21 -24
  8. data/lib/rubocop.rb +9 -7
  9. data/lib/rubocop/cli.rb +73 -52
  10. data/lib/rubocop/config.rb +8 -5
  11. data/lib/rubocop/cop/access_control.rb +41 -0
  12. data/lib/rubocop/cop/alias.rb +7 -5
  13. data/lib/rubocop/cop/align_parameters.rb +20 -96
  14. data/lib/rubocop/cop/and_or.rb +26 -0
  15. data/lib/rubocop/cop/ascii_comments.rb +3 -8
  16. data/lib/rubocop/cop/ascii_identifiers.rb +6 -5
  17. data/lib/rubocop/cop/avoid_class_vars.rb +5 -10
  18. data/lib/rubocop/cop/avoid_for.rb +7 -5
  19. data/lib/rubocop/cop/avoid_global_vars.rb +19 -7
  20. data/lib/rubocop/cop/avoid_perl_backrefs.rb +7 -10
  21. data/lib/rubocop/cop/avoid_perlisms.rb +11 -10
  22. data/lib/rubocop/cop/block_comments.rb +4 -6
  23. data/lib/rubocop/cop/blocks.rb +11 -47
  24. data/lib/rubocop/cop/case_indentation.rb +9 -31
  25. data/lib/rubocop/cop/class_and_module_camel_case.rb +20 -11
  26. data/lib/rubocop/cop/class_methods.rb +5 -10
  27. data/lib/rubocop/cop/collection_methods.rb +16 -16
  28. data/lib/rubocop/cop/colon_method_call.rb +8 -32
  29. data/lib/rubocop/cop/constant_name.rb +24 -0
  30. data/lib/rubocop/cop/cop.rb +20 -78
  31. data/lib/rubocop/cop/def_parentheses.rb +43 -35
  32. data/lib/rubocop/cop/empty_line_between_defs.rb +11 -15
  33. data/lib/rubocop/cop/empty_lines.rb +20 -9
  34. data/lib/rubocop/cop/empty_literal.rb +47 -0
  35. data/lib/rubocop/cop/encoding.rb +3 -3
  36. data/lib/rubocop/cop/end_of_line.rb +3 -3
  37. data/lib/rubocop/cop/ensure_return.rb +6 -23
  38. data/lib/rubocop/cop/eval.rb +7 -10
  39. data/lib/rubocop/cop/favor_join.rb +9 -24
  40. data/lib/rubocop/cop/favor_modifier.rb +38 -48
  41. data/lib/rubocop/cop/favor_percent_r.rb +7 -7
  42. data/lib/rubocop/cop/favor_sprintf.rb +8 -24
  43. data/lib/rubocop/cop/favor_unless_over_negated_if.rb +19 -17
  44. data/lib/rubocop/cop/handle_exceptions.rb +7 -11
  45. data/lib/rubocop/cop/hash_syntax.rb +29 -14
  46. data/lib/rubocop/cop/if_then_else.rb +32 -29
  47. data/lib/rubocop/cop/leading_comment_space.rb +5 -8
  48. data/lib/rubocop/cop/line_continuation.rb +4 -7
  49. data/lib/rubocop/cop/line_length.rb +3 -3
  50. data/lib/rubocop/cop/loop.rb +33 -0
  51. data/lib/rubocop/cop/method_and_variable_snake_case.rb +42 -19
  52. data/lib/rubocop/cop/method_length.rb +34 -37
  53. data/lib/rubocop/cop/new_lambda_literal.rb +8 -6
  54. data/lib/rubocop/cop/not.rb +10 -4
  55. data/lib/rubocop/cop/numeric_literals.rb +9 -7
  56. data/lib/rubocop/cop/offence.rb +1 -1
  57. data/lib/rubocop/cop/op_method.rb +12 -22
  58. data/lib/rubocop/cop/parameter_lists.rb +12 -6
  59. data/lib/rubocop/cop/parentheses_around_condition.rb +11 -11
  60. data/lib/rubocop/cop/percent_r.rb +7 -7
  61. data/lib/rubocop/cop/reduce_arguments.rb +13 -51
  62. data/lib/rubocop/cop/rescue_exception.rb +13 -29
  63. data/lib/rubocop/cop/rescue_modifier.rb +5 -8
  64. data/lib/rubocop/cop/semicolon.rb +15 -74
  65. data/lib/rubocop/cop/single_line_methods.rb +28 -44
  66. data/lib/rubocop/cop/space_after_comma_etc.rb +29 -9
  67. data/lib/rubocop/cop/space_after_control_keyword.rb +16 -15
  68. data/lib/rubocop/cop/string_literals.rb +9 -35
  69. data/lib/rubocop/cop/surrounding_space.rb +213 -112
  70. data/lib/rubocop/cop/symbol_array.rb +9 -7
  71. data/lib/rubocop/cop/symbol_name.rb +23 -0
  72. data/lib/rubocop/cop/syntax.rb +14 -7
  73. data/lib/rubocop/cop/tab.rb +3 -3
  74. data/lib/rubocop/cop/ternary_operator.rb +26 -24
  75. data/lib/rubocop/cop/trailing_whitespace.rb +3 -5
  76. data/lib/rubocop/cop/trivial_accessors.rb +18 -95
  77. data/lib/rubocop/cop/unless_else.rb +11 -7
  78. data/lib/rubocop/cop/util.rb +26 -0
  79. data/lib/rubocop/cop/variable_interpolation.rb +18 -10
  80. data/lib/rubocop/cop/when_then.rb +6 -17
  81. data/lib/rubocop/cop/word_array.rb +18 -19
  82. data/lib/rubocop/version.rb +1 -1
  83. data/rubocop.gemspec +1 -0
  84. data/spec/project_spec.rb +1 -1
  85. data/spec/rubocop/cli_spec.rb +16 -9
  86. data/spec/rubocop/config_spec.rb +13 -3
  87. data/spec/rubocop/cops/access_control_spec.rb +129 -0
  88. data/spec/rubocop/cops/alias_spec.rb +2 -6
  89. data/spec/rubocop/cops/align_parameters_spec.rb +58 -71
  90. data/spec/rubocop/cops/and_or_spec.rb +37 -0
  91. data/spec/rubocop/cops/ascii_comments_spec.rb +3 -4
  92. data/spec/rubocop/cops/ascii_identifiers_spec.rb +3 -4
  93. data/spec/rubocop/cops/avoid_class_vars_spec.rb +7 -2
  94. data/spec/rubocop/cops/avoid_for_spec.rb +1 -4
  95. data/spec/rubocop/cops/{avoid_global_vars.rb → avoid_global_vars_spec.rb} +4 -4
  96. data/spec/rubocop/cops/avoid_perl_backrefs_spec.rb +1 -1
  97. data/spec/rubocop/cops/avoid_perlisms_spec.rb +5 -5
  98. data/spec/rubocop/cops/block_comments_spec.rb +0 -4
  99. data/spec/rubocop/cops/blocks_spec.rb +33 -0
  100. data/spec/rubocop/cops/case_indentation_spec.rb +5 -5
  101. data/spec/rubocop/cops/class_and_module_camel_case_spec.rb +15 -5
  102. data/spec/rubocop/cops/class_methods_spec.rb +4 -4
  103. data/spec/rubocop/cops/collection_methods_spec.rb +9 -4
  104. data/spec/rubocop/cops/colon_method_call_spec.rb +11 -5
  105. data/spec/rubocop/cops/constant_name_spec.rb +42 -0
  106. data/spec/rubocop/cops/def_with_parentheses_spec.rb +13 -8
  107. data/spec/rubocop/cops/def_without_parentheses_spec.rb +11 -5
  108. data/spec/rubocop/cops/empty_line_between_defs_spec.rb +38 -38
  109. data/spec/rubocop/cops/empty_lines_spec.rb +15 -3
  110. data/spec/rubocop/cops/empty_literal_spec.rb +90 -0
  111. data/spec/rubocop/cops/encoding_spec.rb +9 -9
  112. data/spec/rubocop/cops/end_of_line_spec.rb +2 -2
  113. data/spec/rubocop/cops/ensure_return_spec.rb +1 -3
  114. data/spec/rubocop/cops/eval_spec.rb +8 -5
  115. data/spec/rubocop/cops/favor_join_spec.rb +1 -5
  116. data/spec/rubocop/cops/favor_modifier_spec.rb +16 -14
  117. data/spec/rubocop/cops/{favor_percent_r.rb → favor_percent_r_spec.rb} +6 -6
  118. data/spec/rubocop/cops/favor_sprintf_spec.rb +3 -9
  119. data/spec/rubocop/cops/favor_unless_over_negated_if_spec.rb +4 -4
  120. data/spec/rubocop/cops/favor_until_over_negated_while_spec.rb +3 -3
  121. data/spec/rubocop/cops/handle_exceptions_spec.rb +1 -3
  122. data/spec/rubocop/cops/hash_syntax_spec.rb +11 -6
  123. data/spec/rubocop/cops/if_with_semicolon_spec.rb +7 -1
  124. data/spec/rubocop/cops/leading_comment_space_spec.rb +0 -7
  125. data/spec/rubocop/cops/line_continuation_spec.rb +2 -2
  126. data/spec/rubocop/cops/line_length_spec.rb +2 -2
  127. data/spec/rubocop/cops/loop_spec.rb +31 -0
  128. data/spec/rubocop/cops/method_and_variable_snake_case_spec.rb +38 -12
  129. data/spec/rubocop/cops/method_length_spec.rb +85 -85
  130. data/spec/rubocop/cops/multiline_if_then_spec.rb +15 -15
  131. data/spec/rubocop/cops/new_lambda_literal_spec.rb +3 -3
  132. data/spec/rubocop/cops/not_spec.rb +1 -4
  133. data/spec/rubocop/cops/numeric_literals_spec.rb +13 -13
  134. data/spec/rubocop/cops/one_line_conditional_spec.rb +1 -1
  135. data/spec/rubocop/cops/op_method_spec.rb +2 -9
  136. data/spec/rubocop/cops/parameter_lists_spec.rb +7 -7
  137. data/spec/rubocop/cops/parentheses_around_condition_spec.rb +41 -44
  138. data/spec/rubocop/cops/percent_r_spec.rb +6 -6
  139. data/spec/rubocop/cops/reduce_arguments_spec.rb +4 -4
  140. data/spec/rubocop/cops/rescue_exception_spec.rb +48 -8
  141. data/spec/rubocop/cops/rescue_modifier_spec.rb +2 -5
  142. data/spec/rubocop/cops/semicolon_spec.rb +2 -30
  143. data/spec/rubocop/cops/single_line_methods_spec.rb +13 -13
  144. data/spec/rubocop/cops/space_after_colon_spec.rb +3 -3
  145. data/spec/rubocop/cops/space_after_comma_spec.rb +14 -2
  146. data/spec/rubocop/cops/space_after_control_keyword_spec.rb +42 -3
  147. data/spec/rubocop/cops/space_after_semicolon_spec.rb +2 -2
  148. data/spec/rubocop/cops/space_around_braces_spec.rb +18 -3
  149. data/spec/rubocop/cops/space_around_equals_in_default_parameter_spec.rb +4 -4
  150. data/spec/rubocop/cops/space_around_operators_spec.rb +82 -27
  151. data/spec/rubocop/cops/space_inside_brackets_spec.rb +13 -7
  152. data/spec/rubocop/cops/space_inside_hash_literal_braces_spec.rb +14 -9
  153. data/spec/rubocop/cops/space_inside_parens_spec.rb +7 -3
  154. data/spec/rubocop/cops/string_literals_spec.rb +17 -5
  155. data/spec/rubocop/cops/symbol_array_spec.rb +18 -2
  156. data/spec/rubocop/cops/symbol_name_spec.rb +119 -0
  157. data/spec/rubocop/cops/syntax_spec.rb +25 -18
  158. data/spec/rubocop/cops/tab_spec.rb +2 -2
  159. data/spec/rubocop/cops/ternary_operator_spec.rb +13 -17
  160. data/spec/rubocop/cops/trailing_whitespace_spec.rb +3 -3
  161. data/spec/rubocop/cops/trivial_accessors_spec.rb +17 -20
  162. data/spec/rubocop/cops/unless_else_spec.rb +8 -8
  163. data/spec/rubocop/cops/variable_interpolation_spec.rb +0 -5
  164. data/spec/rubocop/cops/when_then_spec.rb +14 -21
  165. data/spec/rubocop/cops/word_array_spec.rb +12 -4
  166. data/spec/spec_helper.rb +12 -4
  167. metadata +40 -31
  168. data/.document +0 -5
  169. data/lib/rubocop/cop/ampersands_pipes_vs_and_or.rb +0 -25
  170. data/lib/rubocop/cop/array_literal.rb +0 -61
  171. data/lib/rubocop/cop/brace_after_percent.rb +0 -32
  172. data/lib/rubocop/cop/grammar.rb +0 -138
  173. data/lib/rubocop/cop/hash_literal.rb +0 -61
  174. data/lib/rubocop/cop/percent_literals.rb +0 -25
  175. data/lib/rubocop/cop/symbol_snake_case.rb +0 -47
  176. data/spec/rubocop/cops/ampersands_pipes_vs_and_or_spec.rb +0 -57
  177. data/spec/rubocop/cops/array_literal_spec.rb +0 -46
  178. data/spec/rubocop/cops/brace_after_percent_spec.rb +0 -33
  179. data/spec/rubocop/cops/grammar_spec.rb +0 -81
  180. data/spec/rubocop/cops/hash_literal_spec.rb +0 -46
  181. data/spec/rubocop/cops/multiline_blocks_spec.rb +0 -24
  182. data/spec/rubocop/cops/percent_literals_spec.rb +0 -47
  183. data/spec/rubocop/cops/single_line_blocks_spec.rb +0 -22
  184. data/spec/rubocop/cops/symbol_snake_case_spec.rb +0 -93
@@ -9,17 +9,17 @@ module Rubocop
9
9
 
10
10
  it 'registers an offence for a line ending with space' do
11
11
  source = ['x = 0 ']
12
- tws.inspect('file.rb', source, nil, nil)
12
+ tws.inspect(source, nil, nil, nil)
13
13
  expect(tws.offences.size).to eq(1)
14
14
  end
15
15
 
16
16
  it 'registers an offence for a line ending with tab' do
17
- tws.inspect('file.rb', ["x = 0\t"], nil, nil)
17
+ tws.inspect(["x = 0\t"], nil, nil, nil)
18
18
  expect(tws.offences.size).to eq(1)
19
19
  end
20
20
 
21
21
  it 'accepts a line without trailing whitespace' do
22
- tws.inspect('file.rb', ["x = 0\n"], nil, nil)
22
+ tws.inspect(["x = 0\n"], nil, nil, nil)
23
23
  expect(tws.offences).to be_empty
24
24
  end
25
25
  end
@@ -12,7 +12,7 @@ module Rubocop
12
12
  end
13
13
 
14
14
  it 'finds trivial reader' do
15
- inspect_source(trivial_accessors_finder, '',
15
+ inspect_source(trivial_accessors_finder,
16
16
  ['def foo',
17
17
  ' @foo',
18
18
  'end',
@@ -26,7 +26,7 @@ module Rubocop
26
26
  end
27
27
 
28
28
  it 'finds trivial reader in a class' do
29
- inspect_source(trivial_accessors_finder, '',
29
+ inspect_source(trivial_accessors_finder,
30
30
  ['class TrivialFoo',
31
31
  ' def foo',
32
32
  ' @foo',
@@ -41,7 +41,7 @@ module Rubocop
41
41
  end
42
42
 
43
43
  it 'finds trivial reader in a nested class' do
44
- inspect_source(trivial_accessors_finder, '',
44
+ inspect_source(trivial_accessors_finder,
45
45
  ['class TrivialFoo',
46
46
  ' class Nested',
47
47
  ' def foo',
@@ -55,7 +55,7 @@ module Rubocop
55
55
  end
56
56
 
57
57
  it 'finds trivial readers in a little less trivial class' do
58
- inspect_source(trivial_accessors_finder, '',
58
+ inspect_source(trivial_accessors_finder,
59
59
  ['class TrivialFoo',
60
60
  ' def foo',
61
61
  ' @foo',
@@ -115,7 +115,7 @@ module Rubocop
115
115
  end
116
116
 
117
117
  it 'finds trivial reader with braces' do
118
- inspect_source(trivial_accessors_finder, '',
118
+ inspect_source(trivial_accessors_finder,
119
119
  ['class Test',
120
120
  ' # trivial reader with braces',
121
121
  ' def name()',
@@ -128,7 +128,7 @@ module Rubocop
128
128
  end
129
129
 
130
130
  it 'finds trivial writer without braces' do
131
- inspect_source(trivial_accessors_finder, '',
131
+ inspect_source(trivial_accessors_finder,
132
132
  ['class Test',
133
133
  ' # trivial writer without braces',
134
134
  ' def name= name',
@@ -141,7 +141,7 @@ module Rubocop
141
141
  end
142
142
 
143
143
  it 'does not find trivial writer with function calls' do
144
- inspect_source(trivial_accessors_finder, '',
144
+ inspect_source(trivial_accessors_finder,
145
145
  ['class TrivialTest',
146
146
  ' def test=(val)',
147
147
  ' @test = val',
@@ -153,7 +153,7 @@ module Rubocop
153
153
  end
154
154
 
155
155
  it 'finds trivials with less peculiar methods' do
156
- inspect_source(trivial_accessors_finder, '',
156
+ inspect_source(trivial_accessors_finder,
157
157
  ['class NilStats',
158
158
  'def most_traded_pair',
159
159
  'end',
@@ -167,9 +167,6 @@ module Rubocop
167
167
  'def gain_at(date)',
168
168
  ' 1',
169
169
  'end',
170
- 'def gain= value',
171
- ' @value = 0.1',
172
- 'end',
173
170
  'def gain_percentage',
174
171
  ' 0',
175
172
  'end',
@@ -195,7 +192,7 @@ module Rubocop
195
192
  end
196
193
 
197
194
  it 'finds oneliner trivials' do
198
- inspect_source(trivial_accessors_finder, '',
195
+ inspect_source(trivial_accessors_finder,
199
196
  ['class Oneliner',
200
197
  ' def foo; @foo; end',
201
198
  ' def foo= foo; @foo = foo; end',
@@ -206,7 +203,7 @@ module Rubocop
206
203
  end
207
204
 
208
205
  it 'does not find a trivial reader' do
209
- inspect_source(trivial_accessors_finder, '',
206
+ inspect_source(trivial_accessors_finder,
210
207
  ['def bar',
211
208
  ' @bar + foo',
212
209
  'end'])
@@ -214,7 +211,7 @@ module Rubocop
214
211
  end
215
212
 
216
213
  it 'finds trivial writer' do
217
- inspect_source(trivial_accessors_finder, '',
214
+ inspect_source(trivial_accessors_finder,
218
215
  ['def foo=(val)',
219
216
  ' @foo = val',
220
217
  'end'])
@@ -224,7 +221,7 @@ module Rubocop
224
221
  end
225
222
 
226
223
  it 'finds trivial writer in a class' do
227
- inspect_source(trivial_accessors_finder, '',
224
+ inspect_source(trivial_accessors_finder,
228
225
  ['class TrivialFoo',
229
226
  ' def foo=(val)',
230
227
  ' @foo = val',
@@ -250,7 +247,7 @@ module Rubocop
250
247
  end
251
248
 
252
249
  it 'finds trivial accessors in a little less trivial class' do
253
- inspect_source(trivial_accessors_finder, '',
250
+ inspect_source(trivial_accessors_finder,
254
251
  ['class TrivialFoo',
255
252
  ' def foo',
256
253
  ' @foo',
@@ -271,7 +268,7 @@ module Rubocop
271
268
  end
272
269
 
273
270
  it 'does not find a trivial writer' do
274
- inspect_source(trivial_accessors_finder, '',
271
+ inspect_source(trivial_accessors_finder,
275
272
  ['def bar=(value)',
276
273
  ' @bar = value + 42',
277
274
  'end'])
@@ -279,7 +276,7 @@ module Rubocop
279
276
  end
280
277
 
281
278
  it 'finds trivial writers in a little less trivial class' do
282
- inspect_source(trivial_accessors_finder, '',
279
+ inspect_source(trivial_accessors_finder,
283
280
  ['class TrivialFoo',
284
281
  ' def foo_bar=(foo, bar)',
285
282
  ' @foo_bar = foo + bar',
@@ -297,7 +294,7 @@ module Rubocop
297
294
  end
298
295
 
299
296
  it 'does not find trivial accessors with method calls' do
300
- inspect_source(trivial_accessors_finder, '',
297
+ inspect_source(trivial_accessors_finder,
301
298
  ['class TrivialFoo',
302
299
  ' def foo_bar(foo)',
303
300
  ' foo_bar = foo + 42',
@@ -315,7 +312,7 @@ module Rubocop
315
312
  end
316
313
 
317
314
  it 'does not find trivial writer with exceptions' do
318
- inspect_source(trivial_accessors_finder, '',
315
+ inspect_source(trivial_accessors_finder,
319
316
  [' def expiration_formatted=(value)',
320
317
  ' begin',
321
318
  ' @expiration = foo_stuff',
@@ -8,20 +8,20 @@ module Rubocop
8
8
  let(:ue) { UnlessElse.new }
9
9
 
10
10
  it 'registers an offence for an unless with else' do
11
- inspect_source(ue, 'file.rb', ['unless x',
12
- ' a = 1',
13
- 'else',
14
- ' a = 0',
15
- 'end'])
11
+ inspect_source(ue, ['unless x',
12
+ ' a = 1',
13
+ 'else',
14
+ ' a = 0',
15
+ 'end'])
16
16
  expect(ue.offences.map(&:message)).to eq(
17
17
  ['Never use unless with else. Rewrite these with the ' +
18
18
  'positive case first.'])
19
19
  end
20
20
 
21
21
  it 'accepts an unless without else' do
22
- inspect_source(ue, 'file.rb', ['unless x',
23
- ' a = 1',
24
- 'end'])
22
+ inspect_source(ue, ['unless x',
23
+ ' a = 1',
24
+ 'end'])
25
25
  expect(ue.offences.map(&:message)).to be_empty
26
26
  end
27
27
  end
@@ -9,7 +9,6 @@ module Rubocop
9
9
 
10
10
  it 'registers an offence for interpolated global variables' do
11
11
  inspect_source(vi,
12
- 'file.rb',
13
12
  ['puts "this is a #$test"'])
14
13
  expect(vi.offences.size).to eq(1)
15
14
  expect(vi.offences.map(&:message))
@@ -18,7 +17,6 @@ module Rubocop
18
17
 
19
18
  it 'registers an offence for interpolated regexp back references' do
20
19
  inspect_source(vi,
21
- 'file.rb',
22
20
  ['puts "this is a #$1"'])
23
21
  expect(vi.offences.size).to eq(1)
24
22
  expect(vi.offences.map(&:message))
@@ -27,7 +25,6 @@ module Rubocop
27
25
 
28
26
  it 'registers an offence for interpolated instance variables' do
29
27
  inspect_source(vi,
30
- 'file.rb',
31
28
  ['puts "this is a #@test"'])
32
29
  expect(vi.offences.size).to eq(1)
33
30
  expect(vi.offences.map(&:message))
@@ -36,7 +33,6 @@ module Rubocop
36
33
 
37
34
  it 'registers an offence for interpolated class variables' do
38
35
  inspect_source(vi,
39
- 'file.rb',
40
36
  ['puts "this is a #@@t"'])
41
37
  expect(vi.offences.size).to eq(1)
42
38
  expect(vi.offences.map(&:message))
@@ -45,7 +41,6 @@ module Rubocop
45
41
 
46
42
  it 'does not register an offence for variables in expressions' do
47
43
  inspect_source(vi,
48
- 'file.rb',
49
44
  ['puts "this is a #{@test} #{@@t} #{$t} #{$1}"'])
50
45
  expect(vi.offences).to be_empty
51
46
  end
@@ -8,36 +8,29 @@ module Rubocop
8
8
  let(:wt) { WhenThen.new }
9
9
 
10
10
  it 'registers an offence for when x;' do
11
- inspect_source(wt, 'file.rb', ['case a',
12
- 'when b; c',
13
- 'end'])
11
+ inspect_source(wt, ['case a',
12
+ 'when b; c',
13
+ 'end'])
14
14
  expect(wt.offences.map(&:message)).to eq(
15
15
  ['Never use "when x;". Use "when x then" instead.'])
16
16
  end
17
17
 
18
- it 'misses semicolon but does not crash when there are no tokens' do
19
- inspect_source(wt, 'file.rb', ['case a',
20
- 'when []; {}',
21
- 'end'])
22
- expect(wt.offences.map(&:message)).to eq([])
23
- end
24
-
25
18
  it 'accepts when x then' do
26
- inspect_source(wt, 'file.rb', ['case a',
27
- 'when b then c',
28
- 'end'])
19
+ inspect_source(wt, ['case a',
20
+ 'when b then c',
21
+ 'end'])
29
22
  expect(wt.offences.map(&:message)).to be_empty
30
23
  end
31
24
 
32
25
  it 'accepts ; separating statements in the body of when' do
33
- inspect_source(wt, 'file.rb', ['case a',
34
- 'when b then c; d',
35
- 'end',
36
- '',
37
- 'case e',
38
- 'when f',
39
- ' g; h',
40
- 'end'])
26
+ inspect_source(wt, ['case a',
27
+ 'when b then c; d',
28
+ 'end',
29
+ '',
30
+ 'case e',
31
+ 'when f',
32
+ ' g; h',
33
+ 'end'])
41
34
  expect(wt.offences.map(&:message)).to be_empty
42
35
  end
43
36
  end
@@ -9,28 +9,36 @@ module Rubocop
9
9
 
10
10
  it 'registers an offence for arrays of single quoted strings' do
11
11
  inspect_source(wa,
12
- 'file.rb',
13
12
  ["['one', 'two', 'three']"])
14
13
  expect(wa.offences.size).to eq(1)
15
14
  end
16
15
 
17
16
  it 'registers an offence for arrays of double quoted strings' do
18
17
  inspect_source(wa,
19
- 'file.rb',
20
18
  ['["one", "two", "three"]'])
21
19
  expect(wa.offences.size).to eq(1)
22
20
  end
23
21
 
24
22
  it 'does not register an offence for array of non-words' do
25
23
  inspect_source(wa,
26
- 'file.rb',
27
24
  ['["one space", "two", "three"]'])
28
25
  expect(wa.offences).to be_empty
29
26
  end
30
27
 
28
+ it 'does not register an offence for array starting with %w' do
29
+ inspect_source(wa,
30
+ ['%w(one two three)'])
31
+ expect(wa.offences).to be_empty
32
+ end
33
+
34
+ it 'does not register an offence for array with one element' do
35
+ inspect_source(wa,
36
+ ['["three"]'])
37
+ expect(wa.offences).to be_empty
38
+ end
39
+
31
40
  it 'does not register an offence for array with empty strings' do
32
41
  inspect_source(wa,
33
- 'file.rb',
34
42
  ['["", "two", "three"]'])
35
43
  expect(wa.offences).to be_empty
36
44
  end
@@ -49,6 +49,7 @@ end
49
49
 
50
50
  RSpec.configure do |config|
51
51
  config.filter_run_excluding ruby: ->(v) { !RUBY_VERSION.start_with?(v.to_s) }
52
+ config.filter_run_excluding broken: true
52
53
  config.treat_symbols_as_metadata_keys_with_true_values = true
53
54
 
54
55
  config.expect_with :rspec do |c|
@@ -62,8 +63,15 @@ end
62
63
  # in ./support/ and its subdirectories.
63
64
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
64
65
 
65
- def inspect_source(cop, file, source)
66
- tokens, sexp, correlations = Rubocop::CLI.rip_source(source)
67
- cop.correlations = correlations
68
- cop.inspect(file, source, tokens, sexp)
66
+ def inspect_source(cop, source)
67
+ ast, comments, tokens, _ = Rubocop::CLI.parse('(string)') do |source_buffer|
68
+ source_buffer.source = source.join($RS)
69
+ end
70
+ cop.inspect(source, tokens, ast, comments)
71
+ end
72
+
73
+ class Rubocop::Cop::Cop
74
+ def messages
75
+ offences.map(&:message)
76
+ end
69
77
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bozhidar Batsov
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.1.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: parser
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 2.0.0.beta2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 2.0.0.beta2
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -105,7 +119,6 @@ extra_rdoc_files:
105
119
  - LICENSE.txt
106
120
  - README.md
107
121
  files:
108
- - .document
109
122
  - .gitignore
110
123
  - .rspec
111
124
  - .rubocop.yml
@@ -124,10 +137,10 @@ files:
124
137
  - lib/rubocop/cli.rb
125
138
  - lib/rubocop/config.rb
126
139
  - lib/rubocop/config_store.rb
140
+ - lib/rubocop/cop/access_control.rb
127
141
  - lib/rubocop/cop/alias.rb
128
142
  - lib/rubocop/cop/align_parameters.rb
129
- - lib/rubocop/cop/ampersands_pipes_vs_and_or.rb
130
- - lib/rubocop/cop/array_literal.rb
143
+ - lib/rubocop/cop/and_or.rb
131
144
  - lib/rubocop/cop/ascii_comments.rb
132
145
  - lib/rubocop/cop/ascii_identifiers.rb
133
146
  - lib/rubocop/cop/avoid_class_vars.rb
@@ -137,16 +150,17 @@ files:
137
150
  - lib/rubocop/cop/avoid_perlisms.rb
138
151
  - lib/rubocop/cop/block_comments.rb
139
152
  - lib/rubocop/cop/blocks.rb
140
- - lib/rubocop/cop/brace_after_percent.rb
141
153
  - lib/rubocop/cop/case_indentation.rb
142
154
  - lib/rubocop/cop/class_and_module_camel_case.rb
143
155
  - lib/rubocop/cop/class_methods.rb
144
156
  - lib/rubocop/cop/collection_methods.rb
145
157
  - lib/rubocop/cop/colon_method_call.rb
158
+ - lib/rubocop/cop/constant_name.rb
146
159
  - lib/rubocop/cop/cop.rb
147
160
  - lib/rubocop/cop/def_parentheses.rb
148
161
  - lib/rubocop/cop/empty_line_between_defs.rb
149
162
  - lib/rubocop/cop/empty_lines.rb
163
+ - lib/rubocop/cop/empty_literal.rb
150
164
  - lib/rubocop/cop/encoding.rb
151
165
  - lib/rubocop/cop/end_of_line.rb
152
166
  - lib/rubocop/cop/ensure_return.rb
@@ -156,14 +170,13 @@ files:
156
170
  - lib/rubocop/cop/favor_percent_r.rb
157
171
  - lib/rubocop/cop/favor_sprintf.rb
158
172
  - lib/rubocop/cop/favor_unless_over_negated_if.rb
159
- - lib/rubocop/cop/grammar.rb
160
173
  - lib/rubocop/cop/handle_exceptions.rb
161
- - lib/rubocop/cop/hash_literal.rb
162
174
  - lib/rubocop/cop/hash_syntax.rb
163
175
  - lib/rubocop/cop/if_then_else.rb
164
176
  - lib/rubocop/cop/leading_comment_space.rb
165
177
  - lib/rubocop/cop/line_continuation.rb
166
178
  - lib/rubocop/cop/line_length.rb
179
+ - lib/rubocop/cop/loop.rb
167
180
  - lib/rubocop/cop/method_and_variable_snake_case.rb
168
181
  - lib/rubocop/cop/method_length.rb
169
182
  - lib/rubocop/cop/new_lambda_literal.rb
@@ -173,7 +186,6 @@ files:
173
186
  - lib/rubocop/cop/op_method.rb
174
187
  - lib/rubocop/cop/parameter_lists.rb
175
188
  - lib/rubocop/cop/parentheses_around_condition.rb
176
- - lib/rubocop/cop/percent_literals.rb
177
189
  - lib/rubocop/cop/percent_r.rb
178
190
  - lib/rubocop/cop/reduce_arguments.rb
179
191
  - lib/rubocop/cop/rescue_exception.rb
@@ -185,13 +197,14 @@ files:
185
197
  - lib/rubocop/cop/string_literals.rb
186
198
  - lib/rubocop/cop/surrounding_space.rb
187
199
  - lib/rubocop/cop/symbol_array.rb
188
- - lib/rubocop/cop/symbol_snake_case.rb
200
+ - lib/rubocop/cop/symbol_name.rb
189
201
  - lib/rubocop/cop/syntax.rb
190
202
  - lib/rubocop/cop/tab.rb
191
203
  - lib/rubocop/cop/ternary_operator.rb
192
204
  - lib/rubocop/cop/trailing_whitespace.rb
193
205
  - lib/rubocop/cop/trivial_accessors.rb
194
206
  - lib/rubocop/cop/unless_else.rb
207
+ - lib/rubocop/cop/util.rb
195
208
  - lib/rubocop/cop/variable_interpolation.rb
196
209
  - lib/rubocop/cop/when_then.rb
197
210
  - lib/rubocop/cop/word_array.rb
@@ -204,50 +217,50 @@ files:
204
217
  - spec/rubocop/cli_spec.rb
205
218
  - spec/rubocop/config_spec.rb
206
219
  - spec/rubocop/config_store_spec.rb
220
+ - spec/rubocop/cops/access_control_spec.rb
207
221
  - spec/rubocop/cops/alias_spec.rb
208
222
  - spec/rubocop/cops/align_parameters_spec.rb
209
- - spec/rubocop/cops/ampersands_pipes_vs_and_or_spec.rb
210
- - spec/rubocop/cops/array_literal_spec.rb
223
+ - spec/rubocop/cops/and_or_spec.rb
211
224
  - spec/rubocop/cops/ascii_comments_spec.rb
212
225
  - spec/rubocop/cops/ascii_identifiers_spec.rb
213
226
  - spec/rubocop/cops/avoid_class_vars_spec.rb
214
227
  - spec/rubocop/cops/avoid_for_spec.rb
215
- - spec/rubocop/cops/avoid_global_vars.rb
228
+ - spec/rubocop/cops/avoid_global_vars_spec.rb
216
229
  - spec/rubocop/cops/avoid_perl_backrefs_spec.rb
217
230
  - spec/rubocop/cops/avoid_perlisms_spec.rb
218
231
  - spec/rubocop/cops/block_comments_spec.rb
219
- - spec/rubocop/cops/brace_after_percent_spec.rb
232
+ - spec/rubocop/cops/blocks_spec.rb
220
233
  - spec/rubocop/cops/case_indentation_spec.rb
221
234
  - spec/rubocop/cops/class_and_module_camel_case_spec.rb
222
235
  - spec/rubocop/cops/class_methods_spec.rb
223
236
  - spec/rubocop/cops/collection_methods_spec.rb
224
237
  - spec/rubocop/cops/colon_method_call_spec.rb
238
+ - spec/rubocop/cops/constant_name_spec.rb
225
239
  - spec/rubocop/cops/cop_spec.rb
226
240
  - spec/rubocop/cops/def_with_parentheses_spec.rb
227
241
  - spec/rubocop/cops/def_without_parentheses_spec.rb
228
242
  - spec/rubocop/cops/empty_line_between_defs_spec.rb
229
243
  - spec/rubocop/cops/empty_lines_spec.rb
244
+ - spec/rubocop/cops/empty_literal_spec.rb
230
245
  - spec/rubocop/cops/encoding_spec.rb
231
246
  - spec/rubocop/cops/end_of_line_spec.rb
232
247
  - spec/rubocop/cops/ensure_return_spec.rb
233
248
  - spec/rubocop/cops/eval_spec.rb
234
249
  - spec/rubocop/cops/favor_join_spec.rb
235
250
  - spec/rubocop/cops/favor_modifier_spec.rb
236
- - spec/rubocop/cops/favor_percent_r.rb
251
+ - spec/rubocop/cops/favor_percent_r_spec.rb
237
252
  - spec/rubocop/cops/favor_sprintf_spec.rb
238
253
  - spec/rubocop/cops/favor_unless_over_negated_if_spec.rb
239
254
  - spec/rubocop/cops/favor_until_over_negated_while_spec.rb
240
- - spec/rubocop/cops/grammar_spec.rb
241
255
  - spec/rubocop/cops/handle_exceptions_spec.rb
242
- - spec/rubocop/cops/hash_literal_spec.rb
243
256
  - spec/rubocop/cops/hash_syntax_spec.rb
244
257
  - spec/rubocop/cops/if_with_semicolon_spec.rb
245
258
  - spec/rubocop/cops/leading_comment_space_spec.rb
246
259
  - spec/rubocop/cops/line_continuation_spec.rb
247
260
  - spec/rubocop/cops/line_length_spec.rb
261
+ - spec/rubocop/cops/loop_spec.rb
248
262
  - spec/rubocop/cops/method_and_variable_snake_case_spec.rb
249
263
  - spec/rubocop/cops/method_length_spec.rb
250
- - spec/rubocop/cops/multiline_blocks_spec.rb
251
264
  - spec/rubocop/cops/multiline_if_then_spec.rb
252
265
  - spec/rubocop/cops/new_lambda_literal_spec.rb
253
266
  - spec/rubocop/cops/not_spec.rb
@@ -257,13 +270,11 @@ files:
257
270
  - spec/rubocop/cops/op_method_spec.rb
258
271
  - spec/rubocop/cops/parameter_lists_spec.rb
259
272
  - spec/rubocop/cops/parentheses_around_condition_spec.rb
260
- - spec/rubocop/cops/percent_literals_spec.rb
261
273
  - spec/rubocop/cops/percent_r_spec.rb
262
274
  - spec/rubocop/cops/reduce_arguments_spec.rb
263
275
  - spec/rubocop/cops/rescue_exception_spec.rb
264
276
  - spec/rubocop/cops/rescue_modifier_spec.rb
265
277
  - spec/rubocop/cops/semicolon_spec.rb
266
- - spec/rubocop/cops/single_line_blocks_spec.rb
267
278
  - spec/rubocop/cops/single_line_methods_spec.rb
268
279
  - spec/rubocop/cops/space_after_colon_spec.rb
269
280
  - spec/rubocop/cops/space_after_comma_spec.rb
@@ -277,7 +288,7 @@ files:
277
288
  - spec/rubocop/cops/space_inside_parens_spec.rb
278
289
  - spec/rubocop/cops/string_literals_spec.rb
279
290
  - spec/rubocop/cops/symbol_array_spec.rb
280
- - spec/rubocop/cops/symbol_snake_case_spec.rb
291
+ - spec/rubocop/cops/symbol_name_spec.rb
281
292
  - spec/rubocop/cops/syntax_spec.rb
282
293
  - spec/rubocop/cops/tab_spec.rb
283
294
  - spec/rubocop/cops/ternary_operator_spec.rb
@@ -321,50 +332,50 @@ test_files:
321
332
  - spec/rubocop/cli_spec.rb
322
333
  - spec/rubocop/config_spec.rb
323
334
  - spec/rubocop/config_store_spec.rb
335
+ - spec/rubocop/cops/access_control_spec.rb
324
336
  - spec/rubocop/cops/alias_spec.rb
325
337
  - spec/rubocop/cops/align_parameters_spec.rb
326
- - spec/rubocop/cops/ampersands_pipes_vs_and_or_spec.rb
327
- - spec/rubocop/cops/array_literal_spec.rb
338
+ - spec/rubocop/cops/and_or_spec.rb
328
339
  - spec/rubocop/cops/ascii_comments_spec.rb
329
340
  - spec/rubocop/cops/ascii_identifiers_spec.rb
330
341
  - spec/rubocop/cops/avoid_class_vars_spec.rb
331
342
  - spec/rubocop/cops/avoid_for_spec.rb
332
- - spec/rubocop/cops/avoid_global_vars.rb
343
+ - spec/rubocop/cops/avoid_global_vars_spec.rb
333
344
  - spec/rubocop/cops/avoid_perl_backrefs_spec.rb
334
345
  - spec/rubocop/cops/avoid_perlisms_spec.rb
335
346
  - spec/rubocop/cops/block_comments_spec.rb
336
- - spec/rubocop/cops/brace_after_percent_spec.rb
347
+ - spec/rubocop/cops/blocks_spec.rb
337
348
  - spec/rubocop/cops/case_indentation_spec.rb
338
349
  - spec/rubocop/cops/class_and_module_camel_case_spec.rb
339
350
  - spec/rubocop/cops/class_methods_spec.rb
340
351
  - spec/rubocop/cops/collection_methods_spec.rb
341
352
  - spec/rubocop/cops/colon_method_call_spec.rb
353
+ - spec/rubocop/cops/constant_name_spec.rb
342
354
  - spec/rubocop/cops/cop_spec.rb
343
355
  - spec/rubocop/cops/def_with_parentheses_spec.rb
344
356
  - spec/rubocop/cops/def_without_parentheses_spec.rb
345
357
  - spec/rubocop/cops/empty_line_between_defs_spec.rb
346
358
  - spec/rubocop/cops/empty_lines_spec.rb
359
+ - spec/rubocop/cops/empty_literal_spec.rb
347
360
  - spec/rubocop/cops/encoding_spec.rb
348
361
  - spec/rubocop/cops/end_of_line_spec.rb
349
362
  - spec/rubocop/cops/ensure_return_spec.rb
350
363
  - spec/rubocop/cops/eval_spec.rb
351
364
  - spec/rubocop/cops/favor_join_spec.rb
352
365
  - spec/rubocop/cops/favor_modifier_spec.rb
353
- - spec/rubocop/cops/favor_percent_r.rb
366
+ - spec/rubocop/cops/favor_percent_r_spec.rb
354
367
  - spec/rubocop/cops/favor_sprintf_spec.rb
355
368
  - spec/rubocop/cops/favor_unless_over_negated_if_spec.rb
356
369
  - spec/rubocop/cops/favor_until_over_negated_while_spec.rb
357
- - spec/rubocop/cops/grammar_spec.rb
358
370
  - spec/rubocop/cops/handle_exceptions_spec.rb
359
- - spec/rubocop/cops/hash_literal_spec.rb
360
371
  - spec/rubocop/cops/hash_syntax_spec.rb
361
372
  - spec/rubocop/cops/if_with_semicolon_spec.rb
362
373
  - spec/rubocop/cops/leading_comment_space_spec.rb
363
374
  - spec/rubocop/cops/line_continuation_spec.rb
364
375
  - spec/rubocop/cops/line_length_spec.rb
376
+ - spec/rubocop/cops/loop_spec.rb
365
377
  - spec/rubocop/cops/method_and_variable_snake_case_spec.rb
366
378
  - spec/rubocop/cops/method_length_spec.rb
367
- - spec/rubocop/cops/multiline_blocks_spec.rb
368
379
  - spec/rubocop/cops/multiline_if_then_spec.rb
369
380
  - spec/rubocop/cops/new_lambda_literal_spec.rb
370
381
  - spec/rubocop/cops/not_spec.rb
@@ -374,13 +385,11 @@ test_files:
374
385
  - spec/rubocop/cops/op_method_spec.rb
375
386
  - spec/rubocop/cops/parameter_lists_spec.rb
376
387
  - spec/rubocop/cops/parentheses_around_condition_spec.rb
377
- - spec/rubocop/cops/percent_literals_spec.rb
378
388
  - spec/rubocop/cops/percent_r_spec.rb
379
389
  - spec/rubocop/cops/reduce_arguments_spec.rb
380
390
  - spec/rubocop/cops/rescue_exception_spec.rb
381
391
  - spec/rubocop/cops/rescue_modifier_spec.rb
382
392
  - spec/rubocop/cops/semicolon_spec.rb
383
- - spec/rubocop/cops/single_line_blocks_spec.rb
384
393
  - spec/rubocop/cops/single_line_methods_spec.rb
385
394
  - spec/rubocop/cops/space_after_colon_spec.rb
386
395
  - spec/rubocop/cops/space_after_comma_spec.rb
@@ -394,7 +403,7 @@ test_files:
394
403
  - spec/rubocop/cops/space_inside_parens_spec.rb
395
404
  - spec/rubocop/cops/string_literals_spec.rb
396
405
  - spec/rubocop/cops/symbol_array_spec.rb
397
- - spec/rubocop/cops/symbol_snake_case_spec.rb
406
+ - spec/rubocop/cops/symbol_name_spec.rb
398
407
  - spec/rubocop/cops/syntax_spec.rb
399
408
  - spec/rubocop/cops/tab_spec.rb
400
409
  - spec/rubocop/cops/ternary_operator_spec.rb