rubocop 0.16.0 → 0.17.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 (189) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +3 -1
  4. data/CHANGELOG.md +44 -0
  5. data/CONTRIBUTING.md +40 -8
  6. data/Gemfile +6 -0
  7. data/README.md +65 -20
  8. data/Rakefile +0 -1
  9. data/config/default.yml +15 -3
  10. data/config/enabled.yml +143 -109
  11. data/lib/rubocop.rb +45 -26
  12. data/lib/rubocop/cli.rb +26 -27
  13. data/lib/rubocop/config.rb +0 -1
  14. data/lib/rubocop/config_loader.rb +16 -23
  15. data/lib/rubocop/cop/commissioner.rb +2 -7
  16. data/lib/rubocop/cop/cop.rb +24 -51
  17. data/lib/rubocop/cop/ignored_node.rb +31 -0
  18. data/lib/rubocop/cop/lint/ambiguous_operator.rb +50 -0
  19. data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +36 -0
  20. data/lib/rubocop/cop/lint/assignment_in_condition.rb +3 -11
  21. data/lib/rubocop/cop/lint/block_alignment.rb +6 -20
  22. data/lib/rubocop/cop/lint/condition_position.rb +52 -0
  23. data/lib/rubocop/cop/lint/else_layout.rb +57 -0
  24. data/lib/rubocop/cop/lint/end_alignment.rb +33 -8
  25. data/lib/rubocop/cop/lint/invalid_character_literal.rb +37 -0
  26. data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +2 -4
  27. data/lib/rubocop/cop/lint/syntax.rb +6 -12
  28. data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +25 -0
  29. data/lib/rubocop/cop/mixin/array_syntax.rb +20 -0
  30. data/lib/rubocop/cop/mixin/autocorrect_alignment.rb +76 -0
  31. data/lib/rubocop/cop/mixin/check_assignment.rb +26 -0
  32. data/lib/rubocop/cop/{check_methods.rb → mixin/check_methods.rb} +0 -0
  33. data/lib/rubocop/cop/mixin/code_length.rb +33 -0
  34. data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +53 -0
  35. data/lib/rubocop/cop/mixin/configurable_max.rb +19 -0
  36. data/lib/rubocop/cop/mixin/configurable_naming.rb +45 -0
  37. data/lib/rubocop/cop/{style → mixin}/if_node.rb +0 -0
  38. data/lib/rubocop/cop/mixin/if_then_else.rb +23 -0
  39. data/lib/rubocop/cop/mixin/negative_conditional.rb +24 -0
  40. data/lib/rubocop/cop/mixin/parser_diagnostic.rb +34 -0
  41. data/lib/rubocop/cop/mixin/safe_assignment.rb +19 -0
  42. data/lib/rubocop/cop/mixin/space_after_punctuation.rb +32 -0
  43. data/lib/rubocop/cop/mixin/space_inside.rb +31 -0
  44. data/lib/rubocop/cop/mixin/statement_modifier.rb +59 -0
  45. data/lib/rubocop/cop/mixin/string_help.rb +32 -0
  46. data/lib/rubocop/cop/mixin/surrounding_space.rb +42 -0
  47. data/lib/rubocop/cop/rails/default_scope.rb +3 -1
  48. data/lib/rubocop/cop/style/accessor_method_name.rb +4 -12
  49. data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +16 -1
  50. data/lib/rubocop/cop/style/case_indentation.rb +33 -16
  51. data/lib/rubocop/cop/style/character_literal.rb +10 -0
  52. data/lib/rubocop/cop/style/dot_position.rb +23 -6
  53. data/lib/rubocop/cop/style/empty_lines_around_body.rb +5 -5
  54. data/lib/rubocop/cop/style/favor_unless_over_negated_if.rb +1 -32
  55. data/lib/rubocop/cop/style/favor_until_over_negated_while.rb +20 -0
  56. data/lib/rubocop/cop/style/hash_syntax.rb +5 -1
  57. data/lib/rubocop/cop/style/if_unless_modifier.rb +34 -0
  58. data/lib/rubocop/cop/style/if_with_semicolon.rb +1 -1
  59. data/lib/rubocop/cop/style/indentation_consistency.rb +51 -0
  60. data/lib/rubocop/cop/style/indentation_width.rb +0 -26
  61. data/lib/rubocop/cop/style/lambda_call.rb +12 -5
  62. data/lib/rubocop/cop/style/method_def_parentheses.rb +29 -11
  63. data/lib/rubocop/cop/style/multiline_if_then.rb +4 -9
  64. data/lib/rubocop/cop/style/multiline_ternary_operator.rb +22 -0
  65. data/lib/rubocop/cop/style/{ternary_operator.rb → nested_ternary_operator.rb} +0 -15
  66. data/lib/rubocop/cop/style/numeric_literals.rb +30 -2
  67. data/lib/rubocop/cop/style/one_line_conditional.rb +2 -1
  68. data/lib/rubocop/cop/style/parameter_lists.rb +7 -3
  69. data/lib/rubocop/cop/style/parentheses_around_condition.rb +9 -11
  70. data/lib/rubocop/cop/style/predicate_name.rb +4 -12
  71. data/lib/rubocop/cop/style/raise_args.rb +19 -11
  72. data/lib/rubocop/cop/style/regexp_literal.rb +19 -6
  73. data/lib/rubocop/cop/style/space_after_colon.rb +36 -0
  74. data/lib/rubocop/cop/style/space_after_comma.rb +16 -0
  75. data/lib/rubocop/cop/style/space_after_semicolon.rb +16 -0
  76. data/lib/rubocop/cop/style/space_around_block_braces.rb +38 -38
  77. data/lib/rubocop/cop/style/space_around_operators.rb +1 -2
  78. data/lib/rubocop/cop/style/space_inside_hash_literal_braces.rb +6 -2
  79. data/lib/rubocop/cop/style/string_literals.rb +5 -5
  80. data/lib/rubocop/cop/style/trailing_comma.rb +94 -0
  81. data/lib/rubocop/cop/style/unless_else.rb +2 -2
  82. data/lib/rubocop/cop/style/while_until_modifier.rb +32 -0
  83. data/lib/rubocop/cop/style/word_array.rb +9 -1
  84. data/lib/rubocop/cop/util.rb +14 -0
  85. data/lib/rubocop/cop/variable_inspector.rb +11 -6
  86. data/lib/rubocop/cop/variable_inspector/scope.rb +4 -3
  87. data/lib/rubocop/file_inspector.rb +22 -6
  88. data/lib/rubocop/formatter/clang_style_formatter.rb +1 -1
  89. data/lib/rubocop/formatter/colorizable.rb +37 -0
  90. data/lib/rubocop/formatter/disabled_config_formatter.rb +27 -6
  91. data/lib/rubocop/formatter/progress_formatter.rb +1 -1
  92. data/lib/rubocop/formatter/simple_text_formatter.rb +9 -5
  93. data/lib/rubocop/options.rb +19 -4
  94. data/lib/rubocop/target_finder.rb +4 -0
  95. data/lib/rubocop/version.rb +1 -1
  96. data/rubocop-todo.yml +10 -2
  97. data/rubocop.gemspec +3 -2
  98. data/spec/project_spec.rb +12 -7
  99. data/spec/rubocop/cli_spec.rb +262 -99
  100. data/spec/rubocop/config_loader_spec.rb +5 -5
  101. data/spec/rubocop/config_spec.rb +3 -3
  102. data/spec/rubocop/config_store_spec.rb +12 -11
  103. data/spec/rubocop/cop/commissioner_spec.rb +21 -5
  104. data/spec/rubocop/cop/cop_spec.rb +1 -1
  105. data/spec/rubocop/cop/lint/ambiguous_operator_spec.rb +113 -0
  106. data/spec/rubocop/cop/lint/ambiguous_regexp_literal_spec.rb +35 -0
  107. data/spec/rubocop/cop/lint/block_alignment_spec.rb +2 -2
  108. data/spec/rubocop/cop/lint/condition_position_spec.rb +49 -0
  109. data/spec/rubocop/cop/lint/else_layout_spec.rb +65 -0
  110. data/spec/rubocop/cop/lint/end_alignment_spec.rb +41 -1
  111. data/spec/rubocop/cop/lint/invalid_character_literal_spec.rb +33 -0
  112. data/spec/rubocop/cop/lint/parentheses_as_grouped_expression_spec.rb +3 -3
  113. data/spec/rubocop/cop/lint/shadowing_outer_local_variable_spec.rb +12 -12
  114. data/spec/rubocop/cop/lint/syntax_spec.rb +2 -2
  115. data/spec/rubocop/cop/lint/useless_assignment_spec.rb +72 -54
  116. data/spec/rubocop/cop/lint/useless_else_without_rescue_spec.rb +48 -0
  117. data/spec/rubocop/cop/offence_spec.rb +1 -1
  118. data/spec/rubocop/cop/rails/default_scope_spec.rb +6 -0
  119. data/spec/rubocop/cop/rails/output_spec.rb +2 -1
  120. data/spec/rubocop/cop/style/align_hash_spec.rb +9 -9
  121. data/spec/rubocop/cop/style/align_parameters_spec.rb +1 -1
  122. data/spec/rubocop/cop/style/braces_around_hash_parameters_spec.rb +5 -0
  123. data/spec/rubocop/cop/style/case_indentation_spec.rb +53 -2
  124. data/spec/rubocop/cop/style/class_and_module_camel_case_spec.rb +3 -3
  125. data/spec/rubocop/cop/style/documentation_spec.rb +0 -1
  126. data/spec/rubocop/cop/style/dot_position_spec.rb +18 -3
  127. data/spec/rubocop/cop/style/empty_line_between_defs_spec.rb +4 -4
  128. data/spec/rubocop/cop/style/empty_lines_around_body_spec.rb +13 -0
  129. data/spec/rubocop/cop/style/favor_unless_over_negated_if_spec.rb +1 -1
  130. data/spec/rubocop/cop/style/favor_until_over_negated_while_spec.rb +1 -1
  131. data/spec/rubocop/cop/style/hash_syntax_spec.rb +5 -0
  132. data/spec/rubocop/cop/style/{favor_modifier_spec.rb → if_unless_modifier_spec.rb} +4 -111
  133. data/spec/rubocop/cop/style/indentation_consistency_spec.rb +490 -0
  134. data/spec/rubocop/cop/style/indentation_width_spec.rb +19 -91
  135. data/spec/rubocop/cop/style/lambda_call_spec.rb +18 -0
  136. data/spec/rubocop/cop/style/method_called_on_do_end_block_spec.rb +2 -2
  137. data/spec/rubocop/cop/style/method_def_parentheses_spec.rb +35 -1
  138. data/spec/rubocop/cop/style/method_length_spec.rb +1 -0
  139. data/spec/rubocop/cop/style/method_name_spec.rb +27 -5
  140. data/spec/rubocop/cop/style/multiline_block_chain_spec.rb +4 -4
  141. data/spec/rubocop/cop/style/multiline_if_then_spec.rb +2 -2
  142. data/spec/rubocop/cop/style/multiline_ternary_operator_spec.rb +18 -0
  143. data/spec/rubocop/cop/style/{ternary_operator_spec.rb → nested_ternary_operator_spec.rb} +0 -15
  144. data/spec/rubocop/cop/style/numeric_literals_spec.rb +18 -1
  145. data/spec/rubocop/cop/style/one_line_conditional_spec.rb +2 -1
  146. data/spec/rubocop/cop/style/parameter_lists_spec.rb +1 -0
  147. data/spec/rubocop/cop/style/parentheses_around_condition_spec.rb +13 -4
  148. data/spec/rubocop/cop/style/raise_args_spec.rb +22 -0
  149. data/spec/rubocop/cop/style/redundant_self_spec.rb +4 -4
  150. data/spec/rubocop/cop/style/regexp_literal_spec.rb +4 -0
  151. data/spec/rubocop/cop/style/space_after_colon_spec.rb +12 -4
  152. data/spec/rubocop/cop/style/space_after_method_name_spec.rb +2 -2
  153. data/spec/rubocop/cop/style/space_around_block_braces_spec.rb +30 -1
  154. data/spec/rubocop/cop/style/{space_around_equals_in_default_parameter_spec.rb → space_around_equals_in_parameter_default_spec.rb} +0 -0
  155. data/spec/rubocop/cop/style/space_around_operators_spec.rb +2 -1
  156. data/spec/rubocop/cop/style/space_inside_hash_literal_braces_spec.rb +20 -3
  157. data/spec/rubocop/cop/style/string_literals_spec.rb +33 -0
  158. data/spec/rubocop/cop/style/trailing_comma_spec.rb +200 -0
  159. data/spec/rubocop/cop/style/variable_name_spec.rb +27 -3
  160. data/spec/rubocop/cop/style/while_until_modifier_spec.rb +75 -0
  161. data/spec/rubocop/cop/style/word_array_spec.rb +1 -0
  162. data/spec/rubocop/cop/team_spec.rb +1 -1
  163. data/spec/rubocop/cop/variable_inspector/scope_spec.rb +3 -4
  164. data/spec/rubocop/file_inspector_spec.rb +1 -1
  165. data/spec/rubocop/formatter/base_formatter_spec.rb +12 -11
  166. data/spec/rubocop/formatter/colorizable_spec.rb +107 -0
  167. data/spec/rubocop/formatter/disabled_config_formatter_spec.rb +2 -0
  168. data/spec/rubocop/formatter/formatter_set_spec.rb +1 -1
  169. data/spec/rubocop/formatter/json_formatter_spec.rb +4 -3
  170. data/spec/rubocop/formatter/progress_formatter_spec.rb +2 -2
  171. data/spec/rubocop/options_spec.rb +3 -1
  172. data/spec/rubocop/target_finder_spec.rb +13 -11
  173. data/spec/spec_helper.rb +5 -1
  174. data/spec/support/shared_examples.rb +2 -2
  175. data/spec/support/statement_modifier_helper.rb +41 -0
  176. metadata +88 -30
  177. data/lib/rubocop/cop/check_assignment.rb +0 -43
  178. data/lib/rubocop/cop/style/array_syntax.rb +0 -22
  179. data/lib/rubocop/cop/style/autocorrect_alignment.rb +0 -78
  180. data/lib/rubocop/cop/style/code_length.rb +0 -35
  181. data/lib/rubocop/cop/style/configurable_enforced_style.rb +0 -51
  182. data/lib/rubocop/cop/style/configurable_max.rb +0 -17
  183. data/lib/rubocop/cop/style/configurable_naming.rb +0 -41
  184. data/lib/rubocop/cop/style/favor_modifier.rb +0 -118
  185. data/lib/rubocop/cop/style/if_then_else.rb +0 -27
  186. data/lib/rubocop/cop/style/space_after_comma_etc.rb +0 -73
  187. data/lib/rubocop/cop/style/space_inside.rb +0 -33
  188. data/lib/rubocop/cop/style/string_help.rb +0 -30
  189. data/lib/rubocop/cop/style/surrounding_space.rb +0 -44
@@ -10,11 +10,8 @@ describe Rubocop::Cop::Style::IndentationWidth do
10
10
  inspect_source(cop,
11
11
  ['if cond',
12
12
  ' func',
13
- ' func',
14
13
  'end'])
15
- expect(cop.messages)
16
- .to eq(['Use 2 (not 1) spaces for indentation.',
17
- 'Inconsistent indentation detected.'])
14
+ expect(cop.messages).to eq(['Use 2 (not 1) spaces for indentation.'])
18
15
  end
19
16
 
20
17
  it 'registers an offence for bad indentation of an else body' do
@@ -23,11 +20,8 @@ describe Rubocop::Cop::Style::IndentationWidth do
23
20
  ' func1',
24
21
  'else',
25
22
  ' func2',
26
- ' func2',
27
23
  'end'])
28
- expect(cop.messages)
29
- .to eq(['Use 2 (not 1) spaces for indentation.',
30
- 'Inconsistent indentation detected.'])
24
+ expect(cop.messages).to eq(['Use 2 (not 1) spaces for indentation.'])
31
25
  end
32
26
 
33
27
  it 'registers an offence for bad indentation of an elsif body' do
@@ -36,13 +30,10 @@ describe Rubocop::Cop::Style::IndentationWidth do
36
30
  ' b1',
37
31
  'elsif a2',
38
32
  ' b2',
39
- 'b3',
40
33
  'else',
41
34
  ' c',
42
35
  'end'])
43
- expect(cop.messages)
44
- .to eq(['Use 2 (not 1) spaces for indentation.',
45
- 'Inconsistent indentation detected.'])
36
+ expect(cop.messages).to eq(['Use 2 (not 1) spaces for indentation.'])
46
37
  end
47
38
 
48
39
  it 'registers offence for bad indentation of ternary inside else' do
@@ -218,11 +209,8 @@ describe Rubocop::Cop::Style::IndentationWidth do
218
209
  inspect_source(cop,
219
210
  ['unless cond',
220
211
  ' func',
221
- ' func',
222
212
  'end'])
223
- expect(cop.messages)
224
- .to eq(['Use 2 (not 1) spaces for indentation.',
225
- 'Inconsistent indentation detected.'])
213
+ expect(cop.messages).to eq(['Use 2 (not 1) spaces for indentation.'])
226
214
  end
227
215
 
228
216
  it 'accepts an empty unless' do
@@ -240,11 +228,8 @@ describe Rubocop::Cop::Style::IndentationWidth do
240
228
  ['case a',
241
229
  'when b',
242
230
  ' c',
243
- ' d',
244
231
  'end'])
245
- expect(cop.messages)
246
- .to eq(['Use 2 (not 1) spaces for indentation.',
247
- 'Inconsistent indentation detected.'])
232
+ expect(cop.messages).to eq(['Use 2 (not 1) spaces for indentation.'])
248
233
  end
249
234
 
250
235
  it 'registers an offence for bad indentation in a case/else body' do
@@ -256,11 +241,8 @@ describe Rubocop::Cop::Style::IndentationWidth do
256
241
  ' e',
257
242
  'else',
258
243
  ' f',
259
- ' g',
260
244
  'end'])
261
- expect(cop.messages)
262
- .to eq(['Use 2 (not 3) spaces for indentation.',
263
- 'Inconsistent indentation detected.'])
245
+ expect(cop.messages).to eq(['Use 2 (not 3) spaces for indentation.'])
264
246
  end
265
247
 
266
248
  it 'accepts correctly indented case/when/else' do
@@ -317,11 +299,8 @@ describe Rubocop::Cop::Style::IndentationWidth do
317
299
  inspect_source(cop,
318
300
  ['while cond',
319
301
  ' func',
320
- ' func',
321
302
  'end'])
322
- expect(cop.messages)
323
- .to eq(['Use 2 (not 1) spaces for indentation.',
324
- 'Inconsistent indentation detected.'])
303
+ expect(cop.messages).to eq(['Use 2 (not 1) spaces for indentation.'])
325
304
  end
326
305
 
327
306
  it 'registers an offence for bad indentation of begin/end/while' do
@@ -330,20 +309,15 @@ describe Rubocop::Cop::Style::IndentationWidth do
330
309
  ' func1',
331
310
  ' func2',
332
311
  'end while cond'])
333
- expect(cop.messages)
334
- .to eq(['Use 2 (not 1) spaces for indentation.',
335
- 'Inconsistent indentation detected.'])
312
+ expect(cop.messages).to eq(['Use 2 (not 1) spaces for indentation.'])
336
313
  end
337
314
 
338
315
  it 'registers an offence for bad indentation of an until body' do
339
316
  inspect_source(cop,
340
317
  ['until cond',
341
318
  ' func',
342
- ' func',
343
319
  'end'])
344
- expect(cop.messages)
345
- .to eq(['Use 2 (not 1) spaces for indentation.',
346
- 'Inconsistent indentation detected.'])
320
+ expect(cop.messages).to eq(['Use 2 (not 1) spaces for indentation.'])
347
321
  end
348
322
 
349
323
  it 'accepts an empty while' do
@@ -359,11 +333,8 @@ describe Rubocop::Cop::Style::IndentationWidth do
359
333
  inspect_source(cop,
360
334
  ['for var in 1..10',
361
335
  ' func',
362
- 'func',
363
336
  'end'])
364
- expect(cop.messages)
365
- .to eq(['Use 2 (not 1) spaces for indentation.',
366
- 'Inconsistent indentation detected.'])
337
+ expect(cop.messages).to eq(['Use 2 (not 1) spaces for indentation.'])
367
338
  end
368
339
 
369
340
  it 'accepts an empty for' do
@@ -379,22 +350,17 @@ describe Rubocop::Cop::Style::IndentationWidth do
379
350
  inspect_source(cop,
380
351
  ['def test',
381
352
  ' func1',
382
- ' func2',
353
+ ' func2', # No offence registered for this.
383
354
  'end'])
384
- expect(cop.messages)
385
- .to eq(['Use 2 (not 4) spaces for indentation.',
386
- 'Inconsistent indentation detected.'])
355
+ expect(cop.messages).to eq(['Use 2 (not 4) spaces for indentation.'])
387
356
  end
388
357
 
389
358
  it 'registers an offence for bad indentation of a defs body' do
390
359
  inspect_source(cop,
391
360
  ['def self.test',
392
361
  ' func',
393
- ' func',
394
362
  'end'])
395
- expect(cop.messages)
396
- .to eq(['Use 2 (not 3) spaces for indentation.',
397
- 'Inconsistent indentation detected.'])
363
+ expect(cop.messages).to eq(['Use 2 (not 3) spaces for indentation.'])
398
364
  end
399
365
 
400
366
  it 'accepts an empty def body' do
@@ -416,14 +382,10 @@ describe Rubocop::Cop::Style::IndentationWidth do
416
382
  it 'registers an offence for bad indentation of a class body' do
417
383
  inspect_source(cop,
418
384
  ['class Test',
419
- ' def func1',
385
+ ' def func',
420
386
  ' end',
421
- ' def func2',
422
- ' end',
423
387
  'end'])
424
- expect(cop.messages)
425
- .to eq(['Use 2 (not 4) spaces for indentation.',
426
- 'Inconsistent indentation detected.'])
388
+ expect(cop.messages).to eq(['Use 2 (not 4) spaces for indentation.'])
427
389
  end
428
390
 
429
391
  it 'accepts an empty class body' do
@@ -453,43 +415,16 @@ describe Rubocop::Cop::Style::IndentationWidth do
453
415
  'end'])
454
416
  expect(cop.offences).to be_empty
455
417
  end
456
-
457
- it 'registers an offence for bad indentation of def but not for ' +
458
- 'outdented public, protected, and private' do
459
- inspect_source(cop,
460
- ['class Test',
461
- 'public',
462
- '',
463
- ' def e',
464
- ' end',
465
- '',
466
- 'protected',
467
- '',
468
- ' def f',
469
- ' end',
470
- '',
471
- 'private',
472
- '',
473
- ' def g',
474
- ' end',
475
- 'end'])
476
- expect(cop.messages).to eq(['Inconsistent indentation detected.'])
477
- expect(cop.highlights).to eq([' '])
478
- end
479
418
  end
480
419
 
481
420
  context 'with module' do
482
421
  it 'registers an offence for bad indentation of a module body' do
483
422
  inspect_source(cop,
484
423
  ['module Test',
485
- ' def func1',
424
+ ' def func',
486
425
  ' end',
487
- ' def func2',
488
- ' end',
489
426
  'end'])
490
- expect(cop.messages)
491
- .to eq(['Use 2 (not 4) spaces for indentation.',
492
- 'Inconsistent indentation detected.'])
427
+ expect(cop.messages).to eq(['Use 2 (not 4) spaces for indentation.'])
493
428
  end
494
429
 
495
430
  it 'accepts an empty module body' do
@@ -505,29 +440,22 @@ describe Rubocop::Cop::Style::IndentationWidth do
505
440
  inspect_source(cop,
506
441
  ['a = func do',
507
442
  ' b',
508
- ' c',
509
443
  'end'])
510
- expect(cop.messages)
511
- .to eq(['Use 2 (not 1) spaces for indentation.',
512
- 'Inconsistent indentation detected.'])
444
+ expect(cop.messages).to eq(['Use 2 (not 1) spaces for indentation.'])
513
445
  end
514
446
 
515
447
  it 'registers an offence for bad indentation of a {} body' do
516
448
  inspect_source(cop,
517
449
  ['func {',
518
450
  ' b',
519
- ' c',
520
451
  '}'])
521
- expect(cop.messages)
522
- .to eq(['Use 2 (not 3) spaces for indentation.',
523
- 'Inconsistent indentation detected.'])
452
+ expect(cop.messages).to eq(['Use 2 (not 3) spaces for indentation.'])
524
453
  end
525
454
 
526
455
  it 'accepts a correctly indented block body' do
527
456
  inspect_source(cop,
528
457
  ['a = func do',
529
458
  ' b',
530
- ' c',
531
459
  'end'])
532
460
  expect(cop.offences).to be_empty
533
461
  end
@@ -12,6 +12,15 @@ describe Rubocop::Cop::Style::LambdaCall, :config do
12
12
  inspect_source(cop,
13
13
  ['x.(a, b)'])
14
14
  expect(cop.offences.size).to eq(1)
15
+ expect(cop.config_to_allow_offences).to eq('EnforcedStyle' => 'braces')
16
+ end
17
+
18
+ it 'registers an offence for correct + opposite' do
19
+ inspect_source(cop,
20
+ ['x.call(a, b)',
21
+ 'x.(a, b)'])
22
+ expect(cop.offences.size).to eq(1)
23
+ expect(cop.config_to_allow_offences).to eq('Enabled' => false)
15
24
  end
16
25
 
17
26
  it 'accepts x.call()' do
@@ -32,6 +41,15 @@ describe Rubocop::Cop::Style::LambdaCall, :config do
32
41
  inspect_source(cop,
33
42
  ['x.call(a, b)'])
34
43
  expect(cop.offences.size).to eq(1)
44
+ expect(cop.config_to_allow_offences).to eq('EnforcedStyle' => 'call')
45
+ end
46
+
47
+ it 'registers an offence for opposite + correct' do
48
+ inspect_source(cop,
49
+ ['x.call(a, b)',
50
+ 'x.(a, b)'])
51
+ expect(cop.offences.size).to eq(1)
52
+ expect(cop.config_to_allow_offences).to eq('Enabled' => false)
35
53
  end
36
54
 
37
55
  it 'accepts x.()' do
@@ -10,7 +10,7 @@ describe Rubocop::Cop::Style::MethodCalledOnDoEndBlock do
10
10
  inspect_source(cop, ['a do',
11
11
  ' b',
12
12
  'end.c'])
13
- expect(cop.offences).to have(1).item
13
+ expect(cop.offences.size).to eq(1)
14
14
  expect(cop.highlights).to eq(['end.c'])
15
15
  end
16
16
 
@@ -34,7 +34,7 @@ describe Rubocop::Cop::Style::MethodCalledOnDoEndBlock do
34
34
  context 'with a single-line do..end block' do
35
35
  it 'registers an offence for a chained call' do
36
36
  inspect_source(cop, ['a do b end.c'])
37
- expect(cop.offences).to have(1).item
37
+ expect(cop.offences.size).to eq(1)
38
38
  expect(cop.highlights).to eq(['end.c'])
39
39
  end
40
40
 
@@ -13,6 +13,18 @@ describe Rubocop::Cop::Style::MethodDefParentheses, :config do
13
13
  'end']
14
14
  inspect_source(cop, src)
15
15
  expect(cop.offences.size).to eq(1)
16
+ expect(cop.config_to_allow_offences).to eq('EnforcedStyle' =>
17
+ 'require_no_parentheses')
18
+ end
19
+
20
+ it 'reports an offence for correct + opposite' do
21
+ src = ['def func(a, b)',
22
+ 'end',
23
+ 'def func a, b',
24
+ 'end']
25
+ inspect_source(cop, src)
26
+ expect(cop.offences.size).to eq(1)
27
+ expect(cop.config_to_allow_offences).to eq('Enabled' => false)
16
28
  end
17
29
 
18
30
  it 'reports an offence for class def with parameters but no parens' do
@@ -29,11 +41,16 @@ describe Rubocop::Cop::Style::MethodDefParentheses, :config do
29
41
  expect(cop.offences).to be_empty
30
42
  end
31
43
 
32
- it 'auto-adds required parens' do
44
+ it 'auto-adds required parens for a def' do
33
45
  new_source = autocorrect_source(cop, 'def test param; end')
34
46
  expect(new_source).to eq('def test(param); end')
35
47
  end
36
48
 
49
+ it 'auto-adds required parens for a defs' do
50
+ new_source = autocorrect_source(cop, 'def self.test param; end')
51
+ expect(new_source).to eq('def self.test(param); end')
52
+ end
53
+
37
54
  it 'auto-adds required parens to argument lists on multiple lines' do
38
55
  new_source = autocorrect_source(cop, ['def test one,', 'two', 'end'])
39
56
  expect(new_source).to eq("def test(one,\ntwo)\nend")
@@ -48,6 +65,18 @@ describe Rubocop::Cop::Style::MethodDefParentheses, :config do
48
65
  'end']
49
66
  inspect_source(cop, src)
50
67
  expect(cop.offences.size).to eq(1)
68
+ expect(cop.config_to_allow_offences).to eq('EnforcedStyle' =>
69
+ 'require_parentheses')
70
+ end
71
+
72
+ it 'reports an offence for opposite + correct' do
73
+ src = ['def func(a, b)',
74
+ 'end',
75
+ 'def func a, b',
76
+ 'end']
77
+ inspect_source(cop, src)
78
+ expect(cop.offences.size).to eq(1)
79
+ expect(cop.config_to_allow_offences).to eq('Enabled' => false)
51
80
  end
52
81
 
53
82
  it 'reports an offence for class def with parameters with parens' do
@@ -68,5 +97,10 @@ describe Rubocop::Cop::Style::MethodDefParentheses, :config do
68
97
  new_source = autocorrect_source(cop, 'def test(param); end')
69
98
  expect(new_source).to eq('def test param; end')
70
99
  end
100
+
101
+ it 'auto-removes the parens for defs' do
102
+ new_source = autocorrect_source(cop, 'def self.test(param); end')
103
+ expect(new_source).to eq('def self.test param; end')
104
+ end
71
105
  end
72
106
  end
@@ -17,6 +17,7 @@ describe Rubocop::Cop::Style::MethodLength, :config do
17
17
  'end'])
18
18
  expect(cop.offences.size).to eq(1)
19
19
  expect(cop.offences.map(&:line).sort).to eq([1])
20
+ expect(cop.config_to_allow_offences).to eq('Max' => 6)
20
21
  end
21
22
 
22
23
  it 'accepts a method with less than 5 lines' do
@@ -9,14 +9,14 @@ describe Rubocop::Cop::Style::MethodName, :config do
9
9
  it 'registers an offence for mixed snake case and camel case' do
10
10
  inspect_source(cop, ['def visit_Arel_Nodes_SelectStatement',
11
11
  'end'])
12
- expect(cop.offences).to have(1).item
12
+ expect(cop.offences.size).to eq(1)
13
13
  expect(cop.highlights).to eq(['visit_Arel_Nodes_SelectStatement'])
14
14
  end
15
15
 
16
16
  it 'registers an offence for capitalized camel case' do
17
17
  inspect_source(cop, ['def MyMethod',
18
18
  'end'])
19
- expect(cop.offences).to have(1).item
19
+ expect(cop.offences.size).to eq(1)
20
20
  expect(cop.highlights).to eq(['MyMethod'])
21
21
  end
22
22
  end
@@ -42,15 +42,26 @@ describe Rubocop::Cop::Style::MethodName, :config do
42
42
  inspect_source(cop, ['def myMethod',
43
43
  ' # ...',
44
44
  'end'])
45
- expect(cop.offences).to have(1).item
45
+ expect(cop.offences.size).to eq(1)
46
46
  expect(cop.highlights).to eq(['myMethod'])
47
+ expect(cop.config_to_allow_offences).to eq('EnforcedStyle' =>
48
+ 'camelCase')
49
+ end
50
+
51
+ it 'registers an offence for opposite + correct' do
52
+ inspect_source(cop, ['def my_method',
53
+ 'end',
54
+ 'def myMethod',
55
+ 'end'])
56
+ expect(cop.highlights).to eq(['myMethod'])
57
+ expect(cop.config_to_allow_offences).to eq('Enabled' => false)
47
58
  end
48
59
 
49
60
  it 'registers an offence for camel case in singleton method name' do
50
61
  inspect_source(cop, ['def self.myMethod',
51
62
  ' # ...',
52
63
  'end'])
53
- expect(cop.offences).to have(1).item
64
+ expect(cop.offences.size).to eq(1)
54
65
  expect(cop.highlights).to eq(['myMethod'])
55
66
  end
56
67
 
@@ -84,8 +95,19 @@ describe Rubocop::Cop::Style::MethodName, :config do
84
95
  it 'registers an offence for snake case in names' do
85
96
  inspect_source(cop, ['def my_method',
86
97
  'end'])
87
- expect(cop.offences).to have(1).item
98
+ expect(cop.offences.size).to eq(1)
99
+ expect(cop.highlights).to eq(['my_method'])
100
+ expect(cop.config_to_allow_offences).to eq('EnforcedStyle' =>
101
+ 'snake_case')
102
+ end
103
+
104
+ it 'registers an offence for correct + opposite' do
105
+ inspect_source(cop, ['def my_method',
106
+ 'end',
107
+ 'def myMethod',
108
+ 'end'])
88
109
  expect(cop.highlights).to eq(['my_method'])
110
+ expect(cop.config_to_allow_offences).to eq('Enabled' => false)
89
111
  end
90
112
 
91
113
  include_examples 'always accepted'
@@ -12,7 +12,7 @@ describe Rubocop::Cop::Style::MultilineBlockChain do
12
12
  'end.c do',
13
13
  ' d',
14
14
  'end'])
15
- expect(cop.offences).to have(1).item
15
+ expect(cop.offences.size).to eq(1)
16
16
  expect(cop.highlights).to eq(['end.c'])
17
17
  end
18
18
 
@@ -22,7 +22,7 @@ describe Rubocop::Cop::Style::MultilineBlockChain do
22
22
  'end.c1.c2 do',
23
23
  ' d',
24
24
  'end'])
25
- expect(cop.offences).to have(1).item
25
+ expect(cop.offences.size).to eq(1)
26
26
  expect(cop.highlights).to eq(['end.c1.c2'])
27
27
  end
28
28
 
@@ -34,7 +34,7 @@ describe Rubocop::Cop::Style::MultilineBlockChain do
34
34
  'end.e do',
35
35
  ' f',
36
36
  'end'])
37
- expect(cop.offences).to have(2).item
37
+ expect(cop.offences.size).to eq(2)
38
38
  expect(cop.highlights).to eq(['end.c', 'end.e'])
39
39
  end
40
40
 
@@ -43,7 +43,7 @@ describe Rubocop::Cop::Style::MultilineBlockChain do
43
43
  inspect_source(cop, ['Thread.list.find_all { |t|',
44
44
  ' t.alive?',
45
45
  '}.map { |thread| thread.object_id }'])
46
- expect(cop.offences).to have(1).item
46
+ expect(cop.offences.size).to eq(1)
47
47
  expect(cop.highlights).to eq(['}.map'])
48
48
  end
49
49