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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +46 -0
- data/README.md +16 -4
- data/config/default.yml +37 -10
- data/config/enabled.yml +25 -7
- data/lib/rubocop.rb +15 -19
- data/lib/rubocop/cli.rb +2 -2
- data/lib/rubocop/config.rb +40 -3
- data/lib/rubocop/config_loader.rb +6 -37
- data/lib/rubocop/config_store.rb +0 -1
- data/lib/rubocop/cop/commissioner.rb +12 -9
- data/lib/rubocop/cop/cop.rb +17 -5
- data/lib/rubocop/cop/force.rb +41 -0
- data/lib/rubocop/cop/ignored_node.rb +10 -10
- data/lib/rubocop/cop/lint/ambiguous_operator.rb +1 -1
- data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +2 -2
- data/lib/rubocop/cop/lint/block_alignment.rb +2 -2
- data/lib/rubocop/cop/lint/condition_position.rb +2 -0
- data/lib/rubocop/cop/lint/debugger.rb +17 -3
- data/lib/rubocop/cop/lint/end_alignment.rb +3 -11
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +1 -1
- data/lib/rubocop/cop/lint/rescue_exception.rb +11 -0
- data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +4 -6
- data/lib/rubocop/cop/lint/underscore_prefixed_variable_name.rb +39 -0
- data/lib/rubocop/cop/lint/unused_block_argument.rb +81 -0
- data/lib/rubocop/cop/lint/unused_method_argument.rb +52 -0
- data/lib/rubocop/cop/lint/useless_assignment.rb +6 -8
- data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +6 -0
- data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -1
- data/lib/rubocop/cop/lint/void.rb +1 -1
- data/lib/rubocop/cop/mixin/autocorrect_alignment.rb +2 -2
- data/lib/rubocop/cop/mixin/autocorrect_unless_changing_ast.rb +7 -3
- data/lib/rubocop/cop/mixin/check_assignment.rb +11 -0
- data/lib/rubocop/cop/mixin/check_methods.rb +12 -0
- data/lib/rubocop/cop/mixin/percent_literal.rb +26 -0
- data/lib/rubocop/cop/mixin/space_after_punctuation.rb +2 -2
- data/lib/rubocop/cop/mixin/string_help.rb +0 -4
- data/lib/rubocop/cop/rails/delegate.rb +109 -0
- data/lib/rubocop/cop/style/align_hash.rb +3 -3
- data/lib/rubocop/cop/style/class_and_module_children.rb +2 -2
- data/lib/rubocop/cop/style/colon_method_call.rb +2 -2
- data/lib/rubocop/cop/style/dot_position.rb +1 -1
- data/lib/rubocop/cop/style/encoding.rb +44 -16
- data/lib/rubocop/cop/style/indentation_width.rb +29 -19
- data/lib/rubocop/cop/style/lambda_call.rb +1 -1
- data/lib/rubocop/cop/style/line_end_concatenation.rb +1 -1
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +3 -21
- data/lib/rubocop/cop/style/predicate_name.rb +1 -1
- data/lib/rubocop/cop/style/raise_args.rb +1 -1
- data/lib/rubocop/cop/style/redundant_begin.rb +18 -2
- data/lib/rubocop/cop/style/redundant_self.rb +2 -2
- data/lib/rubocop/cop/style/regexp_literal.rb +29 -37
- data/lib/rubocop/cop/style/space_after_method_name.rb +1 -1
- data/lib/rubocop/cop/style/string_literals.rb +1 -1
- data/lib/rubocop/cop/style/trailing_blank_lines.rb +37 -23
- data/lib/rubocop/cop/style/trailing_comma.rb +2 -3
- data/lib/rubocop/cop/style/trivial_accessors.rb +40 -4
- data/lib/rubocop/cop/style/unneeded_capital_w.rb +29 -0
- data/lib/rubocop/cop/team.rb +10 -2
- data/lib/rubocop/cop/util.rb +2 -2
- data/lib/rubocop/cop/{variable_inspector.rb → variable_force.rb} +45 -37
- data/lib/rubocop/cop/{variable_inspector → variable_force}/assignment.rb +1 -1
- data/lib/rubocop/cop/{variable_inspector → variable_force}/locatable.rb +1 -1
- data/lib/rubocop/cop/{variable_inspector → variable_force}/reference.rb +13 -1
- data/lib/rubocop/cop/{variable_inspector → variable_force}/scope.rb +9 -1
- data/lib/rubocop/cop/{variable_inspector → variable_force}/variable.rb +14 -4
- data/lib/rubocop/cop/{variable_inspector → variable_force}/variable_table.rb +1 -1
- data/lib/rubocop/file_inspector.rb +3 -1
- data/lib/rubocop/formatter/base_formatter.rb +1 -1
- data/lib/rubocop/formatter/disabled_config_formatter.rb +2 -2
- data/lib/rubocop/formatter/disabled_lines_formatter.rb +2 -2
- data/lib/rubocop/formatter/offense_count_formatter.rb +11 -10
- data/lib/rubocop/formatter/progress_formatter.rb +2 -2
- data/lib/rubocop/formatter/simple_text_formatter.rb +1 -1
- data/lib/rubocop/options.rb +74 -58
- data/lib/rubocop/path_util.rb +17 -2
- data/lib/rubocop/rake_task.rb +23 -5
- data/lib/rubocop/version.rb +1 -1
- data/relnotes/v0.21.0.md +45 -0
- data/rubocop-todo.yml +6 -6
- data/rubocop.gemspec +1 -1
- data/spec/rubocop/cli_spec.rb +170 -59
- data/spec/rubocop/config_spec.rb +48 -3
- data/spec/rubocop/config_store_spec.rb +3 -3
- data/spec/rubocop/cop/commissioner_spec.rb +9 -7
- data/spec/rubocop/cop/cop_spec.rb +0 -2
- data/spec/rubocop/cop/force_spec.rb +29 -0
- data/spec/rubocop/cop/lint/ambiguous_operator_spec.rb +2 -2
- data/spec/rubocop/cop/lint/ambiguous_regexp_literal_spec.rb +1 -1
- data/spec/rubocop/cop/lint/block_alignment_spec.rb +24 -24
- data/spec/rubocop/cop/lint/condition_position_spec.rb +7 -5
- data/spec/rubocop/cop/lint/debugger_spec.rb +26 -9
- data/spec/rubocop/cop/lint/end_alignment_spec.rb +6 -3
- data/spec/rubocop/cop/lint/invalid_character_literal_spec.rb +7 -6
- data/spec/rubocop/cop/lint/rescue_exception_spec.rb +36 -0
- data/spec/rubocop/cop/lint/shadowing_outer_local_variable_spec.rb +4 -4
- data/spec/rubocop/cop/lint/underscore_prefixed_variable_name_spec.rb +179 -0
- data/spec/rubocop/cop/lint/unused_block_argument_spec.rb +147 -0
- data/spec/rubocop/cop/lint/unused_method_argument_spec.rb +140 -0
- data/spec/rubocop/cop/lint/useless_assignment_spec.rb +50 -48
- data/spec/rubocop/cop/lint/useless_else_without_rescue_spec.rb +1 -1
- data/spec/rubocop/cop/lint/useless_setter_call_spec.rb +2 -0
- data/spec/rubocop/cop/rails/delegate_spec.rb +152 -0
- data/spec/rubocop/cop/style/encoding_spec.rb +131 -36
- data/spec/rubocop/cop/style/indentation_width_spec.rb +79 -0
- data/spec/rubocop/cop/style/redundant_begin_spec.rb +32 -0
- data/spec/rubocop/cop/style/regexp_literal_spec.rb +83 -13
- data/spec/rubocop/cop/style/string_literals_spec.rb +9 -3
- data/spec/rubocop/cop/style/trailing_blank_lines_spec.rb +65 -25
- data/spec/rubocop/cop/style/trivial_accessors_spec.rb +76 -0
- data/spec/rubocop/cop/style/unneeded_capital_w_spec.rb +85 -0
- data/spec/rubocop/cop/team_spec.rb +43 -0
- data/spec/rubocop/cop/{variable_inspector → variable_force}/assignment_spec.rb +3 -3
- data/spec/rubocop/cop/{variable_inspector → variable_force}/locatable_spec.rb +3 -3
- data/spec/rubocop/cop/{variable_inspector → variable_force}/scope_spec.rb +30 -2
- data/spec/rubocop/cop/{variable_inspector → variable_force}/variable_spec.rb +12 -27
- data/spec/rubocop/cop/{variable_inspector → variable_force}/variable_table_spec.rb +1 -1
- data/spec/rubocop/cop/{variable_inspector_spec.rb → variable_force_spec.rb} +4 -8
- data/spec/rubocop/formatter/base_formatter_spec.rb +2 -2
- data/spec/rubocop/formatter/offense_count_formatter_spec.rb +1 -1
- data/spec/rubocop/formatter/progress_formatter_spec.rb +1 -1
- data/spec/rubocop/options_spec.rb +2 -2
- data/spec/rubocop/path_util_spec.rb +47 -14
- data/spec/spec_helper.rb +9 -3
- data/spec/support/file_helper.rb +2 -0
- metadata +43 -26
- data/lib/rubocop/cop/style/final_newline.rb +0 -29
- data/spec/rubocop/cop/style/final_newline_spec.rb +0 -30
data/lib/rubocop/version.rb
CHANGED
data/relnotes/v0.21.0.md
ADDED
@@ -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-
|
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:
|
8
|
+
# Offense count: 8
|
9
9
|
# Configuration parameters: CountComments.
|
10
10
|
ClassLength:
|
11
|
-
Max:
|
11
|
+
Max: 121
|
12
12
|
|
13
|
-
# Offense count:
|
13
|
+
# Offense count: 22
|
14
14
|
CyclomaticComplexity:
|
15
15
|
Max: 10
|
16
16
|
|
17
|
-
# Offense count:
|
17
|
+
# Offense count: 115
|
18
18
|
# Configuration parameters: CountComments.
|
19
19
|
MethodLength:
|
20
|
-
Max:
|
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.
|
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')
|
data/spec/rubocop/cli_spec.rb
CHANGED
@@ -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
|
-
|
64
|
+
'a hash parameter.',
|
65
65
|
"#{e}:2:35: C: [Corrected] Use the new Ruby 1.9 hash " \
|
66
|
-
|
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
|
-
|
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
|
-
|
302
|
+
'SpaceAfterComma: Space missing after comma.',
|
303
303
|
"#{abs('example.rb')}:2:22: C: [Corrected] " \
|
304
|
-
|
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
|
-
|
322
|
+
'the new Ruby 1.9 hash syntax.',
|
323
323
|
"#{abs('example.rb')}:2:5: C: [Corrected] " \
|
324
|
-
|
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
|
-
|
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
|
-
|
355
|
+
'blank lines detected.',
|
357
356
|
"#{abs('example.rb')}:3:1: C: [Corrected] Trailing " \
|
358
|
-
|
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
|
-
|
372
|
+
'literal {} instead of Hash.new.',
|
374
373
|
"#{abs('example.rb')}:2:9: C: [Corrected] Do not use " \
|
375
|
-
|
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
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
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
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
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
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
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
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
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,
|
1026
|
+
def file_started(file, _options)
|
957
1027
|
output.puts "file_started: #{file}"
|
958
1028
|
end
|
959
1029
|
|
960
|
-
def file_finished(file,
|
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
|
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
|
-
'
|
1365
|
+
'ReadWriteAttribute:',
|
1289
1366
|
' Include:',
|
1290
|
-
' - app/models
|
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
|
-
'
|
1372
|
+
'ReadWriteAttribute:',
|
1296
1373
|
' Include:',
|
1297
|
-
' - app/models
|
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)
|