rubocop 0.20.1 → 0.21.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 (128) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +46 -0
  3. data/README.md +16 -4
  4. data/config/default.yml +37 -10
  5. data/config/enabled.yml +25 -7
  6. data/lib/rubocop.rb +15 -19
  7. data/lib/rubocop/cli.rb +2 -2
  8. data/lib/rubocop/config.rb +40 -3
  9. data/lib/rubocop/config_loader.rb +6 -37
  10. data/lib/rubocop/config_store.rb +0 -1
  11. data/lib/rubocop/cop/commissioner.rb +12 -9
  12. data/lib/rubocop/cop/cop.rb +17 -5
  13. data/lib/rubocop/cop/force.rb +41 -0
  14. data/lib/rubocop/cop/ignored_node.rb +10 -10
  15. data/lib/rubocop/cop/lint/ambiguous_operator.rb +1 -1
  16. data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +2 -2
  17. data/lib/rubocop/cop/lint/block_alignment.rb +2 -2
  18. data/lib/rubocop/cop/lint/condition_position.rb +2 -0
  19. data/lib/rubocop/cop/lint/debugger.rb +17 -3
  20. data/lib/rubocop/cop/lint/end_alignment.rb +3 -11
  21. data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +1 -1
  22. data/lib/rubocop/cop/lint/rescue_exception.rb +11 -0
  23. data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +4 -6
  24. data/lib/rubocop/cop/lint/underscore_prefixed_variable_name.rb +39 -0
  25. data/lib/rubocop/cop/lint/unused_block_argument.rb +81 -0
  26. data/lib/rubocop/cop/lint/unused_method_argument.rb +52 -0
  27. data/lib/rubocop/cop/lint/useless_assignment.rb +6 -8
  28. data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +6 -0
  29. data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -1
  30. data/lib/rubocop/cop/lint/void.rb +1 -1
  31. data/lib/rubocop/cop/mixin/autocorrect_alignment.rb +2 -2
  32. data/lib/rubocop/cop/mixin/autocorrect_unless_changing_ast.rb +7 -3
  33. data/lib/rubocop/cop/mixin/check_assignment.rb +11 -0
  34. data/lib/rubocop/cop/mixin/check_methods.rb +12 -0
  35. data/lib/rubocop/cop/mixin/percent_literal.rb +26 -0
  36. data/lib/rubocop/cop/mixin/space_after_punctuation.rb +2 -2
  37. data/lib/rubocop/cop/mixin/string_help.rb +0 -4
  38. data/lib/rubocop/cop/rails/delegate.rb +109 -0
  39. data/lib/rubocop/cop/style/align_hash.rb +3 -3
  40. data/lib/rubocop/cop/style/class_and_module_children.rb +2 -2
  41. data/lib/rubocop/cop/style/colon_method_call.rb +2 -2
  42. data/lib/rubocop/cop/style/dot_position.rb +1 -1
  43. data/lib/rubocop/cop/style/encoding.rb +44 -16
  44. data/lib/rubocop/cop/style/indentation_width.rb +29 -19
  45. data/lib/rubocop/cop/style/lambda_call.rb +1 -1
  46. data/lib/rubocop/cop/style/line_end_concatenation.rb +1 -1
  47. data/lib/rubocop/cop/style/percent_literal_delimiters.rb +3 -21
  48. data/lib/rubocop/cop/style/predicate_name.rb +1 -1
  49. data/lib/rubocop/cop/style/raise_args.rb +1 -1
  50. data/lib/rubocop/cop/style/redundant_begin.rb +18 -2
  51. data/lib/rubocop/cop/style/redundant_self.rb +2 -2
  52. data/lib/rubocop/cop/style/regexp_literal.rb +29 -37
  53. data/lib/rubocop/cop/style/space_after_method_name.rb +1 -1
  54. data/lib/rubocop/cop/style/string_literals.rb +1 -1
  55. data/lib/rubocop/cop/style/trailing_blank_lines.rb +37 -23
  56. data/lib/rubocop/cop/style/trailing_comma.rb +2 -3
  57. data/lib/rubocop/cop/style/trivial_accessors.rb +40 -4
  58. data/lib/rubocop/cop/style/unneeded_capital_w.rb +29 -0
  59. data/lib/rubocop/cop/team.rb +10 -2
  60. data/lib/rubocop/cop/util.rb +2 -2
  61. data/lib/rubocop/cop/{variable_inspector.rb → variable_force.rb} +45 -37
  62. data/lib/rubocop/cop/{variable_inspector → variable_force}/assignment.rb +1 -1
  63. data/lib/rubocop/cop/{variable_inspector → variable_force}/locatable.rb +1 -1
  64. data/lib/rubocop/cop/{variable_inspector → variable_force}/reference.rb +13 -1
  65. data/lib/rubocop/cop/{variable_inspector → variable_force}/scope.rb +9 -1
  66. data/lib/rubocop/cop/{variable_inspector → variable_force}/variable.rb +14 -4
  67. data/lib/rubocop/cop/{variable_inspector → variable_force}/variable_table.rb +1 -1
  68. data/lib/rubocop/file_inspector.rb +3 -1
  69. data/lib/rubocop/formatter/base_formatter.rb +1 -1
  70. data/lib/rubocop/formatter/disabled_config_formatter.rb +2 -2
  71. data/lib/rubocop/formatter/disabled_lines_formatter.rb +2 -2
  72. data/lib/rubocop/formatter/offense_count_formatter.rb +11 -10
  73. data/lib/rubocop/formatter/progress_formatter.rb +2 -2
  74. data/lib/rubocop/formatter/simple_text_formatter.rb +1 -1
  75. data/lib/rubocop/options.rb +74 -58
  76. data/lib/rubocop/path_util.rb +17 -2
  77. data/lib/rubocop/rake_task.rb +23 -5
  78. data/lib/rubocop/version.rb +1 -1
  79. data/relnotes/v0.21.0.md +45 -0
  80. data/rubocop-todo.yml +6 -6
  81. data/rubocop.gemspec +1 -1
  82. data/spec/rubocop/cli_spec.rb +170 -59
  83. data/spec/rubocop/config_spec.rb +48 -3
  84. data/spec/rubocop/config_store_spec.rb +3 -3
  85. data/spec/rubocop/cop/commissioner_spec.rb +9 -7
  86. data/spec/rubocop/cop/cop_spec.rb +0 -2
  87. data/spec/rubocop/cop/force_spec.rb +29 -0
  88. data/spec/rubocop/cop/lint/ambiguous_operator_spec.rb +2 -2
  89. data/spec/rubocop/cop/lint/ambiguous_regexp_literal_spec.rb +1 -1
  90. data/spec/rubocop/cop/lint/block_alignment_spec.rb +24 -24
  91. data/spec/rubocop/cop/lint/condition_position_spec.rb +7 -5
  92. data/spec/rubocop/cop/lint/debugger_spec.rb +26 -9
  93. data/spec/rubocop/cop/lint/end_alignment_spec.rb +6 -3
  94. data/spec/rubocop/cop/lint/invalid_character_literal_spec.rb +7 -6
  95. data/spec/rubocop/cop/lint/rescue_exception_spec.rb +36 -0
  96. data/spec/rubocop/cop/lint/shadowing_outer_local_variable_spec.rb +4 -4
  97. data/spec/rubocop/cop/lint/underscore_prefixed_variable_name_spec.rb +179 -0
  98. data/spec/rubocop/cop/lint/unused_block_argument_spec.rb +147 -0
  99. data/spec/rubocop/cop/lint/unused_method_argument_spec.rb +140 -0
  100. data/spec/rubocop/cop/lint/useless_assignment_spec.rb +50 -48
  101. data/spec/rubocop/cop/lint/useless_else_without_rescue_spec.rb +1 -1
  102. data/spec/rubocop/cop/lint/useless_setter_call_spec.rb +2 -0
  103. data/spec/rubocop/cop/rails/delegate_spec.rb +152 -0
  104. data/spec/rubocop/cop/style/encoding_spec.rb +131 -36
  105. data/spec/rubocop/cop/style/indentation_width_spec.rb +79 -0
  106. data/spec/rubocop/cop/style/redundant_begin_spec.rb +32 -0
  107. data/spec/rubocop/cop/style/regexp_literal_spec.rb +83 -13
  108. data/spec/rubocop/cop/style/string_literals_spec.rb +9 -3
  109. data/spec/rubocop/cop/style/trailing_blank_lines_spec.rb +65 -25
  110. data/spec/rubocop/cop/style/trivial_accessors_spec.rb +76 -0
  111. data/spec/rubocop/cop/style/unneeded_capital_w_spec.rb +85 -0
  112. data/spec/rubocop/cop/team_spec.rb +43 -0
  113. data/spec/rubocop/cop/{variable_inspector → variable_force}/assignment_spec.rb +3 -3
  114. data/spec/rubocop/cop/{variable_inspector → variable_force}/locatable_spec.rb +3 -3
  115. data/spec/rubocop/cop/{variable_inspector → variable_force}/scope_spec.rb +30 -2
  116. data/spec/rubocop/cop/{variable_inspector → variable_force}/variable_spec.rb +12 -27
  117. data/spec/rubocop/cop/{variable_inspector → variable_force}/variable_table_spec.rb +1 -1
  118. data/spec/rubocop/cop/{variable_inspector_spec.rb → variable_force_spec.rb} +4 -8
  119. data/spec/rubocop/formatter/base_formatter_spec.rb +2 -2
  120. data/spec/rubocop/formatter/offense_count_formatter_spec.rb +1 -1
  121. data/spec/rubocop/formatter/progress_formatter_spec.rb +1 -1
  122. data/spec/rubocop/options_spec.rb +2 -2
  123. data/spec/rubocop/path_util_spec.rb +47 -14
  124. data/spec/spec_helper.rb +9 -3
  125. data/spec/support/file_helper.rb +2 -0
  126. metadata +43 -26
  127. data/lib/rubocop/cop/style/final_newline.rb +0 -29
  128. data/spec/rubocop/cop/style/final_newline_spec.rb +0 -30
@@ -3,7 +3,7 @@
3
3
  module Rubocop
4
4
  # This module holds the RuboCop version information.
5
5
  module Version
6
- STRING = '0.20.1'
6
+ STRING = '0.21.0'
7
7
 
8
8
  MSG = '%s (using Parser %s, running on %s %s %s)'
9
9
 
@@ -0,0 +1,45 @@
1
+ This release brings a few new cops and extended auto-correction support. The most significant
2
+ change is that we've changed the syntax for excluding/including to be closer to that of shell globbing.
3
+
4
+ Below is the list of all the gory details. Enjoy!
5
+
6
+
7
+ ### New features
8
+
9
+ * [#835](https://github.com/bbatsov/rubocop/issues/835): New cop `UnneededCapitalW` checks for `%W` when interpolation not necessary and `%w` would do. ([@sfeldon][])
10
+ * [#934](https://github.com/bbatsov/rubocop/issues/934): New cop `UnderscorePrefixedVariableName` checks for `_`-prefixed variables that are actually used. ([@yujinakayama][])
11
+ * [#934](https://github.com/bbatsov/rubocop/issues/934): New cop `UnusedMethodArgument` checks for unused method arguments. ([@yujinakayama][])
12
+ * [#934](https://github.com/bbatsov/rubocop/issues/934): New cop `UnusedBlockArgument` checks for unused block arguments. ([@yujinakayama][])
13
+ * [#964](https://github.com/bbatsov/rubocop/issues/964): `RedundantBegin` cop does auto-correction. ([@tamird][])
14
+ * [#966](https://github.com/bbatsov/rubocop/issues/966): `RescueException` cop does auto-correction. ([@tamird][])
15
+ * [#967](https://github.com/bbatsov/rubocop/issues/967): `TrivialAccessors` cop does auto-correction. ([@tamird][])
16
+ * [#963](https://github.com/bbatsov/rubocop/issues/963): Add `AllowDSLWriters` options to `TrivialAccessors`. ([@tamird][])
17
+ * [#969](https://github.com/bbatsov/rubocop/issues/969): Let the `Debugger` cop check for forgotten calls to byebug. ([@bquorning][])
18
+ * [#971](https://github.com/bbatsov/rubocop/issues/971): Configuration format deprecation warnings include the path to the problematic config file. ([@bcobb][])
19
+ * [#490](https://github.com/bbatsov/rubocop/issues/490): Add EnforcedStyle config option to TrailingBlankLines. ([@jonas054][])
20
+ * Add `auto_correct` task to Rake integration. ([@irrationalfab][])
21
+ * [#986](https://github.com/bbatsov/rubocop/issues/986): The `--only` option can take a comma-separated list of cops. ([@jonas054][])
22
+ * New Rails cop `Delegate` that checks for delegations that could be replaced by the `delegate` method. ([@geniou][])
23
+ * Add configuration to `Encoding` cop to only enforce encoding comment if there are non ASCII characters. ([@geniou][])
24
+
25
+ ### Changes
26
+
27
+ * Removed `FinalNewline` cop as its check is now performed by `TrailingBlankLines`. ([@jonas054][])
28
+ * [#1011](https://github.com/bbatsov/rubocop/issues/1011): Pattern matching with `Dir#[]` for config parameters added. ([@jonas054][])
29
+
30
+ ### Bugs fixed
31
+
32
+ * Update description on `LineEndConcatenation` cop. ([@mockdeep][])
33
+ * [#978](https://github.com/bbatsov/rubocop/issues/978): Fix regression in `IndentationWidth` handling method calls. ([@tamird][])
34
+ * [#976](https://github.com/bbatsov/rubocop/issues/976): Fix `EndAlignment` not handling element assignment correctly. ([@tamird][])
35
+ * [#976](https://github.com/bbatsov/rubocop/issues/976): Fix `IndentationWidth` not handling element assignment correctly. ([@tamird][])
36
+ * [#800](https://github.com/bbatsov/rubocop/issues/800): Do not report `[Corrected]` in `--auto-correct` mode if correction wasn't done. ([@jonas054][])
37
+ * [#968](https://github.com/bbatsov/rubocop/issues/968): Fix bug when running Rubocop with `-c .rubocop.yml`. ([@bquorning][])
38
+ * [#975](https://github.com/bbatsov/rubocop/pull/975): Fix infinite correction in `IndentationWidth`. ([@jonas054][])
39
+ * [#986](https://github.com/bbatsov/rubocop/issues/986): When `--lint` is used together with `--only`, all lint cops are run in addition to the given cops. ([@jonas054][])
40
+ * [#997](https://github.com/bbatsov/rubocop/issues/997): Fix handling of file paths for matching against `Exclude` property when `rubocop .` is called. ([@jonas054][])
41
+ * [#1000](https://github.com/bbatsov/rubocop/issues/1000): Support modifier (e.g., `private`) and `def` on the same line (Ruby >= 2.1) in `IndentationWidth`. ([@jonas054][])
42
+ * [#1001](https://github.com/bbatsov/rubocop/issues/1001): Fix `--auto-gen-config` logic for `RegexpLiteral`. ([@jonas054][])
43
+ * [#993](https://github.com/bbatsov/rubocop/issues/993): Do not report any offenses for the contents of an empty file. ([@jonas054][])
44
+ * [#1016](https://github.com/bbatsov/rubocop/issues/1016): Fix a false positive in `ConditionPosition` regarding statement modifiers. ([@bbatsov][])
45
+ * [#1014](https://github.com/bbatsov/rubocop/issues/1014): Fix handling of strings nested in `dstr` nodes. ([@bbatsov][])
data/rubocop-todo.yml CHANGED
@@ -1,20 +1,20 @@
1
1
  # This configuration was generated by `rubocop --auto-gen-config`
2
- # on 2014-03-01 12:00:46 +1100 using RuboCop version 0.18.1.
2
+ # on 2014-04-06 16:06:47 +0200 using RuboCop version 0.20.1.
3
3
  # The point is for the user to remove these configuration records
4
4
  # one by one as the offenses are removed from the code base.
5
5
  # Note that changes in the inspected code, or installation of new
6
6
  # versions of RuboCop, may require this file to be generated again.
7
7
 
8
- # Offense count: 6
8
+ # Offense count: 8
9
9
  # Configuration parameters: CountComments.
10
10
  ClassLength:
11
- Max: 146
11
+ Max: 121
12
12
 
13
- # Offense count: 16
13
+ # Offense count: 22
14
14
  CyclomaticComplexity:
15
15
  Max: 10
16
16
 
17
- # Offense count: 105
17
+ # Offense count: 115
18
18
  # Configuration parameters: CountComments.
19
19
  MethodLength:
20
- Max: 22
20
+ Max: 20
data/rubocop.gemspec CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |s|
27
27
  s.summary = 'Automatic Ruby code style checking tool.'
28
28
 
29
29
  s.add_runtime_dependency('rainbow', '>= 1.99.1', '< 3.0')
30
- s.add_runtime_dependency('parser', '~> 2.1.7')
30
+ s.add_runtime_dependency('parser', '~> 2.1.9')
31
31
  s.add_runtime_dependency('powerpack', '~> 0.0.6')
32
32
  s.add_runtime_dependency('json', '>= 1.7.7', '< 2')
33
33
  s.add_runtime_dependency('ruby-progressbar', '~> 1.4')
@@ -61,15 +61,15 @@ describe Rubocop::CLI, :isolated_environment do
61
61
  e = abs('example.rb')
62
62
  expect($stdout.string)
63
63
  .to eq(["#{e}:2:35: C: [Corrected] Redundant curly braces around " \
64
- "a hash parameter.",
64
+ 'a hash parameter.',
65
65
  "#{e}:2:35: C: [Corrected] Use the new Ruby 1.9 hash " \
66
- "syntax.",
66
+ 'syntax.',
67
67
  # TODO: Don't report that a problem is corrected when it
68
68
  # actually went away due to another correction.
69
69
  "#{e}:2:35: C: [Corrected] Space inside { missing.",
70
70
  # TODO: Don't report duplicates (HashSyntax in this case).
71
71
  "#{e}:2:36: C: [Corrected] Use the new Ruby 1.9 hash " \
72
- "syntax.",
72
+ 'syntax.',
73
73
  "#{e}:2:50: C: [Corrected] Space inside } missing.",
74
74
  ''].join("\n"))
75
75
  end
@@ -299,9 +299,9 @@ describe Rubocop::CLI, :isolated_environment do
299
299
  expect(cli.run(%w(-D --auto-correct --format emacs))).to eq(1)
300
300
  expect($stdout.string)
301
301
  .to eq(["#{abs('example.rb')}:2:21: C: [Corrected] " \
302
- "SpaceAfterComma: Space missing after comma.",
302
+ 'SpaceAfterComma: Space missing after comma.',
303
303
  "#{abs('example.rb')}:2:22: C: [Corrected] " \
304
- "HashSyntax: Use the new Ruby 1.9 hash syntax.",
304
+ 'HashSyntax: Use the new Ruby 1.9 hash syntax.',
305
305
  ''].join("\n"))
306
306
  expect(IO.read('example.rb'))
307
307
  .to eq(['# encoding: utf-8',
@@ -319,9 +319,9 @@ describe Rubocop::CLI, :isolated_environment do
319
319
  ''].join("\n"))
320
320
  expect($stdout.string)
321
321
  .to eq(["#{abs('example.rb')}:2:3: C: [Corrected] HashSyntax: Use " \
322
- "the new Ruby 1.9 hash syntax.",
322
+ 'the new Ruby 1.9 hash syntax.',
323
323
  "#{abs('example.rb')}:2:5: C: [Corrected] " \
324
- "SpaceAroundOperators: Surrounding space missing for " \
324
+ 'SpaceAroundOperators: Surrounding space missing for ' \
325
325
  "operator '=>'.",
326
326
  ''].join("\n"))
327
327
  end
@@ -337,7 +337,7 @@ describe Rubocop::CLI, :isolated_environment do
337
337
  ''].join("\n"))
338
338
  expect($stdout.string)
339
339
  .to eq(["#{abs('example.rb')}:2:3: C: [Corrected] Use the new " \
340
- "Ruby 1.9 hash syntax.",
340
+ 'Ruby 1.9 hash syntax.',
341
341
  ''].join("\n"))
342
342
  end
343
343
 
@@ -349,13 +349,12 @@ describe Rubocop::CLI, :isolated_environment do
349
349
  '',
350
350
  ''])
351
351
  expect(cli.run(%w(--auto-correct --format emacs))).to eq(1)
352
- expect($stderr.string).to eq('')
353
352
  expect(IO.read('example.rb')).to eq("# encoding: utf-8\n")
354
353
  expect($stdout.string)
355
354
  .to eq(["#{abs('example.rb')}:2:1: C: [Corrected] 3 trailing " \
356
- "blank lines detected.",
355
+ 'blank lines detected.',
357
356
  "#{abs('example.rb')}:3:1: C: [Corrected] Trailing " \
358
- "whitespace detected.",
357
+ 'whitespace detected.',
359
358
  ''].join("\n"))
360
359
  end
361
360
 
@@ -370,9 +369,9 @@ describe Rubocop::CLI, :isolated_environment do
370
369
  ''].join("\n"))
371
370
  expect($stdout.string)
372
371
  .to eq(["#{abs('example.rb')}:2:1: C: [Corrected] Use hash " \
373
- "literal {} instead of Hash.new.",
372
+ 'literal {} instead of Hash.new.',
374
373
  "#{abs('example.rb')}:2:9: C: [Corrected] Do not use " \
375
- "parentheses for method calls with no arguments.",
374
+ 'parentheses for method calls with no arguments.',
376
375
  ''].join("\n"))
377
376
  end
378
377
 
@@ -400,6 +399,29 @@ describe Rubocop::CLI, :isolated_environment do
400
399
  ''].join("\n"))
401
400
  end
402
401
 
402
+ it 'does not say [Corrected] if correction was avoided' do
403
+ create_file('example.rb', ['# encoding: utf-8',
404
+ 'func a and b',
405
+ 'not a && b',
406
+ 'func a do b end'])
407
+ expect(cli.run(%w(-a -f simple))).to eq(1)
408
+ expect($stderr.string).to eq('')
409
+ expect(IO.read('example.rb')).to eq(['# encoding: utf-8',
410
+ 'func a and b',
411
+ 'not a && b',
412
+ 'func a do b end',
413
+ ''].join("\n"))
414
+ expect($stdout.string)
415
+ .to eq(['== example.rb ==',
416
+ 'C: 2: 8: Use && instead of and.',
417
+ 'C: 3: 1: Use ! instead of not.',
418
+ 'C: 4: 8: Prefer {...} over do...end for single-line ' \
419
+ 'blocks.',
420
+ '',
421
+ '1 file inspected, 3 offenses detected',
422
+ ''].join("\n"))
423
+ end
424
+
403
425
  it 'should not hang SpaceAfterPunctuation and SpaceInsideParens' do
404
426
  create_file('example.rb',
405
427
  ['# encoding: utf-8',
@@ -611,44 +633,92 @@ describe Rubocop::CLI, :isolated_environment do
611
633
  end
612
634
 
613
635
  describe '--only' do
614
- it 'runs just one cop' do
615
- create_file('example.rb', ['if x== 0 ',
616
- "\ty",
617
- 'end'])
618
- # IfUnlessModifier depends on the configuration of LineLength.
636
+ context 'when one cop is given' do
637
+ it 'runs just one cop' do
638
+ create_file('example.rb', ['if x== 0 ',
639
+ "\ty",
640
+ 'end'])
641
+ # IfUnlessModifier depends on the configuration of LineLength.
642
+
643
+ expect(cli.run(['--format', 'simple',
644
+ '--only', 'IfUnlessModifier',
645
+ 'example.rb'])).to eq(1)
646
+ expect($stdout.string)
647
+ .to eq(['== example.rb ==',
648
+ 'C: 1: 1: Favor modifier if usage when ' \
649
+ 'having a single-line body. Another good alternative is ' \
650
+ 'the usage of control flow &&/||.',
651
+ '',
652
+ '1 file inspected, 1 offense detected',
653
+ ''].join("\n"))
654
+ end
619
655
 
620
- expect(cli.run(['--format', 'simple',
621
- '--only', 'IfUnlessModifier',
622
- 'example.rb'])).to eq(1)
623
- expect($stdout.string)
624
- .to eq(['== example.rb ==',
625
- 'C: 1: 1: Favor modifier if usage when ' \
626
- 'having a single-line body. Another good alternative is ' \
627
- 'the usage of control flow &&/||.',
628
- '',
629
- '1 file inspected, 1 offense detected',
630
- ''].join("\n"))
656
+ it 'enables the given cop' do
657
+ create_file('example.rb', ['x = 0 ',
658
+ # Disabling comments still apply.
659
+ '# rubocop:disable TrailingWhitespace',
660
+ 'y = 1 '])
661
+
662
+ create_file('.rubocop.yml', ['TrailingWhitespace:',
663
+ ' Enabled: false'])
664
+
665
+ expect(cli.run(['--format', 'simple',
666
+ '--only', 'TrailingWhitespace',
667
+ 'example.rb'])).to eq(1)
668
+ expect($stderr.string).to eq('')
669
+ expect($stdout.string)
670
+ .to eq(['== example.rb ==',
671
+ 'C: 1: 6: Trailing whitespace detected.',
672
+ '',
673
+ '1 file inspected, 1 offense detected',
674
+ ''].join("\n"))
675
+ end
631
676
  end
632
677
 
633
- it 'enables the given cop' do
634
- create_file('example.rb', ['x = 0 ',
635
- # Disabling comments still apply.
636
- '# rubocop:disable TrailingWhitespace',
637
- 'y = 1 '])
638
-
639
- create_file('.rubocop.yml', ['TrailingWhitespace:',
640
- ' Enabled: false'])
678
+ context 'when several cops are given' do
679
+ it 'runs the given cops' do
680
+ create_file('example.rb', ['if x== 100000000000000 ',
681
+ "\ty",
682
+ 'end'])
683
+ expect(cli.run(['--format', 'simple',
684
+ '--only',
685
+ 'IfUnlessModifier,Tab,SpaceAroundOperators',
686
+ 'example.rb'])).to eq(1)
687
+ expect($stderr.string).to eq('')
688
+ expect($stdout.string)
689
+ .to eq(['== example.rb ==',
690
+ 'C: 1: 1: Favor modifier if usage when ' \
691
+ 'having a single-line body. Another good alternative is ' \
692
+ 'the usage of control flow &&/||.',
693
+ "C: 1: 5: Surrounding space missing for operator '=='.",
694
+ 'C: 2: 1: Tab detected.',
695
+ '',
696
+ '1 file inspected, 3 offenses detected',
697
+ ''].join("\n"))
698
+ end
641
699
 
642
- expect(cli.run(['--format', 'simple',
643
- '--only', 'TrailingWhitespace',
644
- 'example.rb'])).to eq(1)
645
- expect($stderr.string).to eq('')
646
- expect($stdout.string)
647
- .to eq(['== example.rb ==',
648
- 'C: 1: 6: Trailing whitespace detected.',
649
- '',
650
- '1 file inspected, 1 offense detected',
651
- ''].join("\n"))
700
+ context 'and --lint' do
701
+ it 'runs the given cops plus all enabled lint cops' do
702
+ create_file('example.rb', ['if x== 100000000000000 ',
703
+ "\ty = 3",
704
+ ' end'])
705
+ create_file('.rubocop.yml', ['EndAlignment:',
706
+ ' Enabled: false'])
707
+ expect(cli.run(['--format', 'simple',
708
+ '--only', 'Tab,SpaceAroundOperators',
709
+ '--lint',
710
+ 'example.rb'])).to eq(1)
711
+ expect($stdout.string)
712
+ .to eq(['== example.rb ==',
713
+ 'C: 1: 5: Surrounding space missing for operator ' \
714
+ "'=='.",
715
+ 'C: 2: 1: Tab detected.',
716
+ 'W: 2: 2: Useless assignment to variable - y.',
717
+ '',
718
+ '1 file inspected, 3 offenses detected',
719
+ ''].join("\n"))
720
+ end
721
+ end
652
722
  end
653
723
  end
654
724
 
@@ -953,11 +1023,11 @@ describe Rubocop::CLI, :isolated_environment do
953
1023
  output.puts "started: #{all_files.join(',')}"
954
1024
  end
955
1025
 
956
- def file_started(file, options)
1026
+ def file_started(file, _options)
957
1027
  output.puts "file_started: #{file}"
958
1028
  end
959
1029
 
960
- def file_finished(file, offenses)
1030
+ def file_finished(file, _offenses)
961
1031
  output.puts "file_finished: #{file}"
962
1032
  end
963
1033
 
@@ -1161,7 +1231,7 @@ describe Rubocop::CLI, :isolated_environment do
1161
1231
  .to eq(["#{abs('example.rb')}:2:6: W: " \
1162
1232
  'Ambiguous splat operator. Parenthesize the method arguments ' \
1163
1233
  "if it's surely a splat operator, or add a whitespace to the " \
1164
- 'right of the * if it should be a multiplication.',
1234
+ 'right of the `*` if it should be a multiplication.',
1165
1235
  "#{abs('example.rb')}:3:1: C: " \
1166
1236
  'Favor the ternary operator (?:) over if/then/else/end ' \
1167
1237
  'constructs.',
@@ -1261,6 +1331,13 @@ describe Rubocop::CLI, :isolated_environment do
1261
1331
  .to eq(['', '1 file inspected, no offenses detected', ''].join("\n"))
1262
1332
  end
1263
1333
 
1334
+ it 'does not register any offenses for an empty file' do
1335
+ create_file('example.rb', '')
1336
+ expect(cli.run(%w(--format simple))).to eq(0)
1337
+ expect($stdout.string)
1338
+ .to eq(['', '1 file inspected, no offenses detected', ''].join("\n"))
1339
+ end
1340
+
1264
1341
  describe 'rails cops' do
1265
1342
  describe 'enabling/disabling' do
1266
1343
  it 'by default does not run rails cops' do
@@ -1285,16 +1362,16 @@ describe Rubocop::CLI, :isolated_environment do
1285
1362
  create_file('dir1/.rubocop.yml', ['AllCops:',
1286
1363
  ' RunRailsCops: true',
1287
1364
  '',
1288
- 'ReadAttribute:',
1365
+ 'ReadWriteAttribute:',
1289
1366
  ' Include:',
1290
- ' - app/models/*.rb'])
1367
+ ' - app/models/**/*.rb'])
1291
1368
  create_file('dir2/app/models/example2.rb', source)
1292
1369
  create_file('dir2/.rubocop.yml', ['AllCops:',
1293
1370
  ' RunRailsCops: false',
1294
1371
  '',
1295
- 'ReadAttribute:',
1372
+ 'ReadWriteAttribute:',
1296
1373
  ' Include:',
1297
- ' - app/models/*.rb'])
1374
+ ' - app/models/**/*.rb'])
1298
1375
  expect(cli.run(%w(--format simple dir1 dir2))).to eq(1)
1299
1376
  expect($stdout.string)
1300
1377
  .to eq(['== dir1/app/models/example1.rb ==',
@@ -1334,7 +1411,7 @@ describe Rubocop::CLI, :isolated_environment do
1334
1411
  '',
1335
1412
  'ReadWriteAttribute:',
1336
1413
  ' Exclude:',
1337
- ' - example2.rb',
1414
+ ' - "**/example2.rb"',
1338
1415
  '',
1339
1416
  'DefaultScope:',
1340
1417
  ' Exclude:',
@@ -1384,6 +1461,19 @@ describe Rubocop::CLI, :isolated_environment do
1384
1461
  end
1385
1462
 
1386
1463
  describe 'configuration from file' do
1464
+ it 'allows the default configuration file as the -c argument' do
1465
+ create_file('example.rb', ['# encoding: utf-8',
1466
+ 'x = 0',
1467
+ 'puts x'
1468
+ ])
1469
+ create_file('.rubocop.yml', [])
1470
+
1471
+ expect(cli.run(%w(--format simple -c .rubocop.yml))).to eq(0)
1472
+ expect($stdout.string)
1473
+ .to eq(['', '1 file inspected, no offenses detected',
1474
+ ''].join("\n"))
1475
+ end
1476
+
1387
1477
  it 'finds included files' do
1388
1478
  create_file('example', ['# encoding: utf-8',
1389
1479
  'x = 0',
@@ -1430,6 +1520,27 @@ describe Rubocop::CLI, :isolated_environment do
1430
1520
  ''].join("\n"))
1431
1521
  end
1432
1522
 
1523
+ it 'matches included/excluded files corectly when . argument is given' do
1524
+ create_file('example.rb', 'x = 0')
1525
+ create_file('special.dsl', ['# encoding: utf-8',
1526
+ 'setup { "stuff" }'
1527
+ ])
1528
+ create_file('.rubocop.yml', ['AllCops:',
1529
+ ' Include:',
1530
+ ' - "*.dsl"',
1531
+ ' Exclude:',
1532
+ ' - example.rb'
1533
+ ])
1534
+ expect(cli.run(%w(--format simple .))).to eq(1)
1535
+ expect($stdout.string)
1536
+ .to eq(['== special.dsl ==',
1537
+ "C: 2: 9: Prefer single-quoted strings when you don't " \
1538
+ 'need string interpolation or special symbols.',
1539
+ '',
1540
+ '1 file inspected, 1 offense detected',
1541
+ ''].join("\n"))
1542
+ end
1543
+
1433
1544
  # With rubinius 2.0.0.rc1 + rspec 2.13.1,
1434
1545
  # File.stub(:open).and_call_original causes SystemStackError.
1435
1546
  it 'does not read files in excluded list', broken: :rbx do
@@ -1638,7 +1749,7 @@ describe Rubocop::CLI, :isolated_environment do
1638
1749
  create_file('example/.rubocop.yml', ['AllCops:',
1639
1750
  ' Exclude:',
1640
1751
  ' - src/**',
1641
- ' - etc/**',
1752
+ ' - etc/**/*',
1642
1753
  ' - tmp/spec/**'])
1643
1754
 
1644
1755
  expect(cli.run(%w(--format simple example))).to eq(1)
@@ -1663,7 +1774,7 @@ describe Rubocop::CLI, :isolated_environment do
1663
1774
  create_file('.rubocop.yml',
1664
1775
  ['AllCops:',
1665
1776
  ' Exclude:',
1666
- ' - vendor/**'])
1777
+ ' - vendor/**/*'])
1667
1778
 
1668
1779
  cli.run(%w(--format simple))
1669
1780
  expect($stdout.string)
@@ -1698,7 +1809,7 @@ describe Rubocop::CLI, :isolated_environment do
1698
1809
  create_file('.rubocop.yml',
1699
1810
  ['AllCops:',
1700
1811
  ' Exclude:',
1701
- ' - vendor/**'])
1812
+ ' - vendor/**/*'])
1702
1813
 
1703
1814
  cli.run(%w(--format simple))
1704
1815
  expect($stderr.string).to eq('')
@@ -1726,7 +1837,7 @@ describe Rubocop::CLI, :isolated_environment do
1726
1837
  create_file('config/default.yml',
1727
1838
  ['AllCops:',
1728
1839
  ' Exclude:',
1729
- ' - vendor/**'])
1840
+ ' - vendor/**/*'])
1730
1841
 
1731
1842
  cli.run(%w(--format simple))
1732
1843
  expect($stdout.string)