rubocop 0.15.0 → 0.16.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/.rubocop.yml +1 -10
- data/.travis.yml +2 -1
- data/CHANGELOG.md +55 -0
- data/Gemfile +3 -0
- data/README.md +37 -0
- data/config/default.yml +99 -16
- data/config/enabled.yml +28 -16
- data/lib/rubocop.rb +16 -2
- data/lib/rubocop/cli.rb +10 -91
- data/lib/rubocop/config.rb +4 -1
- data/lib/rubocop/config_loader.rb +18 -10
- data/lib/rubocop/config_store.rb +3 -2
- data/lib/rubocop/cop/check_assignment.rb +43 -0
- data/lib/rubocop/cop/check_methods.rb +18 -0
- data/lib/rubocop/cop/commissioner.rb +15 -3
- data/lib/rubocop/cop/cop.rb +51 -43
- data/lib/rubocop/cop/lint/assignment_in_condition.rb +1 -1
- data/lib/rubocop/cop/lint/block_alignment.rb +7 -7
- data/lib/rubocop/cop/lint/debugger.rb +1 -1
- data/lib/rubocop/cop/lint/empty_ensure.rb +1 -1
- data/lib/rubocop/cop/lint/end_alignment.rb +56 -19
- data/lib/rubocop/cop/lint/end_in_method.rb +4 -10
- data/lib/rubocop/cop/lint/ensure_return.rb +1 -1
- data/lib/rubocop/cop/lint/eval.rb +1 -1
- data/lib/rubocop/cop/lint/handle_exceptions.rb +1 -1
- data/lib/rubocop/cop/lint/literal_in_condition.rb +2 -2
- data/lib/rubocop/cop/lint/loop.rb +1 -1
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +1 -1
- data/lib/rubocop/cop/lint/rescue_exception.rb +1 -1
- data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +1 -1
- data/lib/rubocop/cop/lint/syntax.rb +1 -1
- data/lib/rubocop/cop/lint/unreachable_code.rb +1 -1
- data/lib/rubocop/cop/lint/useless_assignment.rb +2 -2
- data/lib/rubocop/cop/lint/useless_comparison.rb +1 -1
- data/lib/rubocop/cop/lint/useless_setter_call.rb +6 -16
- data/lib/rubocop/cop/lint/void.rb +5 -5
- data/lib/rubocop/cop/rails/default_scope.rb +33 -0
- data/lib/rubocop/cop/rails/has_and_belongs_to_many.rb +2 -4
- data/lib/rubocop/cop/rails/output.rb +1 -1
- data/lib/rubocop/cop/rails/read_attribute.rb +1 -1
- data/lib/rubocop/cop/rails/validation.rb +1 -1
- data/lib/rubocop/cop/style/access_modifier_indentation.rb +31 -16
- data/lib/rubocop/cop/style/accessor_method_name.rb +53 -0
- data/lib/rubocop/cop/style/alias.rb +14 -2
- data/lib/rubocop/cop/style/align_hash.rb +15 -16
- data/lib/rubocop/cop/style/and_or.rb +3 -3
- data/lib/rubocop/cop/style/array_syntax.rb +22 -0
- data/lib/rubocop/cop/style/ascii_comments.rb +1 -1
- data/lib/rubocop/cop/style/ascii_identifiers.rb +1 -3
- data/lib/rubocop/cop/style/attr.rb +1 -1
- data/lib/rubocop/cop/style/autocorrect_alignment.rb +13 -12
- data/lib/rubocop/cop/style/begin_block.rb +1 -1
- data/lib/rubocop/cop/style/block_comments.rb +1 -1
- data/lib/rubocop/cop/style/block_nesting.rb +5 -1
- data/lib/rubocop/cop/style/blocks.rb +4 -4
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +48 -22
- data/lib/rubocop/cop/style/case_equality.rb +1 -1
- data/lib/rubocop/cop/style/case_indentation.rb +25 -6
- data/lib/rubocop/cop/style/class_and_module_camel_case.rb +1 -1
- data/lib/rubocop/cop/style/class_length.rb +7 -19
- data/lib/rubocop/cop/style/class_methods.rb +1 -1
- data/lib/rubocop/cop/style/class_vars.rb +1 -1
- data/lib/rubocop/cop/style/code_length.rb +35 -0
- data/lib/rubocop/cop/style/collection_methods.rb +1 -1
- data/lib/rubocop/cop/style/colon_method_call.rb +1 -1
- data/lib/rubocop/cop/style/comment_annotation.rb +1 -1
- data/lib/rubocop/cop/style/configurable_enforced_style.rb +51 -0
- data/lib/rubocop/cop/style/configurable_max.rb +17 -0
- data/lib/rubocop/cop/style/configurable_naming.rb +4 -10
- data/lib/rubocop/cop/style/constant_name.rb +5 -3
- data/lib/rubocop/cop/style/cyclomatic_complexity.rb +8 -13
- data/lib/rubocop/cop/style/def_parentheses.rb +4 -43
- data/lib/rubocop/cop/style/documentation.rb +1 -1
- data/lib/rubocop/cop/style/dot_position.rb +6 -2
- data/lib/rubocop/cop/style/empty_line_between_defs.rb +1 -1
- data/lib/rubocop/cop/style/empty_lines.rb +5 -1
- data/lib/rubocop/cop/style/empty_lines_around_access_modifier.rb +1 -1
- data/lib/rubocop/cop/style/empty_lines_around_body.rb +28 -13
- data/lib/rubocop/cop/style/empty_literal.rb +3 -3
- data/lib/rubocop/cop/style/encoding.rb +5 -5
- data/lib/rubocop/cop/style/end_block.rb +1 -1
- data/lib/rubocop/cop/style/end_of_line.rb +8 -6
- data/lib/rubocop/cop/style/even_odd.rb +6 -6
- data/lib/rubocop/cop/style/favor_join.rb +1 -1
- data/lib/rubocop/cop/style/favor_modifier.rb +20 -34
- data/lib/rubocop/cop/style/favor_sprintf.rb +1 -1
- data/lib/rubocop/cop/style/favor_unless_over_negated_if.rb +1 -1
- data/lib/rubocop/cop/style/final_newline.rb +1 -1
- data/lib/rubocop/cop/style/flip_flop.rb +20 -0
- data/lib/rubocop/cop/style/for.rb +34 -3
- data/lib/rubocop/cop/style/global_vars.rb +1 -1
- data/lib/rubocop/cop/style/hash_methods.rb +3 -3
- data/lib/rubocop/cop/style/hash_syntax.rb +8 -11
- data/lib/rubocop/cop/style/if_node.rb +25 -0
- data/lib/rubocop/cop/style/if_then_else.rb +1 -1
- data/lib/rubocop/cop/style/indentation_width.rb +77 -43
- data/lib/rubocop/cop/style/lambda.rb +2 -2
- data/lib/rubocop/cop/style/lambda_call.rb +4 -12
- data/lib/rubocop/cop/style/leading_comment_space.rb +1 -1
- data/lib/rubocop/cop/style/line_length.rb +9 -5
- data/lib/rubocop/cop/style/method_call_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +1 -1
- data/lib/rubocop/cop/style/method_def_parentheses.rb +52 -0
- data/lib/rubocop/cop/style/method_length.rb +9 -22
- data/lib/rubocop/cop/style/module_function.rb +1 -1
- data/lib/rubocop/cop/style/multiline_block_chain.rb +1 -1
- data/lib/rubocop/cop/style/multiline_if_then.rb +11 -1
- data/lib/rubocop/cop/style/nil_comparison.rb +1 -1
- data/lib/rubocop/cop/style/not.rb +1 -1
- data/lib/rubocop/cop/style/numeric_literals.rb +2 -2
- data/lib/rubocop/cop/style/op_method.rb +2 -2
- data/lib/rubocop/cop/style/parameter_lists.rb +2 -2
- data/lib/rubocop/cop/style/parentheses_around_condition.rb +8 -1
- data/lib/rubocop/cop/style/perl_backrefs.rb +1 -1
- data/lib/rubocop/cop/style/predicate_name.rb +54 -0
- data/lib/rubocop/cop/style/proc.rb +1 -1
- data/lib/rubocop/cop/style/raise_args.rb +4 -10
- data/lib/rubocop/cop/style/redundant_begin.rb +5 -15
- data/lib/rubocop/cop/style/redundant_exception.rb +1 -1
- data/lib/rubocop/cop/style/redundant_return.rb +9 -19
- data/lib/rubocop/cop/style/redundant_self.rb +8 -3
- data/lib/rubocop/cop/style/regexp_literal.rb +4 -3
- data/lib/rubocop/cop/style/rescue_modifier.rb +9 -17
- data/lib/rubocop/cop/style/semicolon.rb +20 -22
- data/lib/rubocop/cop/style/signal_exception.rb +10 -17
- data/lib/rubocop/cop/style/single_line_block_params.rb +62 -0
- data/lib/rubocop/cop/style/single_line_methods.rb +5 -15
- data/lib/rubocop/cop/style/space_after_comma_etc.rb +1 -3
- data/lib/rubocop/cop/style/space_after_control_keyword.rb +1 -1
- data/lib/rubocop/cop/style/space_after_method_name.rb +4 -12
- data/lib/rubocop/cop/style/space_after_not.rb +1 -1
- data/lib/rubocop/cop/style/space_around_block_braces.rb +105 -94
- data/lib/rubocop/cop/style/space_around_equals_in_parameter_default.rb +1 -1
- data/lib/rubocop/cop/style/space_around_operators.rb +38 -123
- data/lib/rubocop/cop/style/space_before_modifier_keyword.rb +1 -1
- data/lib/rubocop/cop/style/space_inside.rb +1 -3
- data/lib/rubocop/cop/style/space_inside_brackets.rb +0 -2
- data/lib/rubocop/cop/style/space_inside_hash_literal_braces.rb +5 -5
- data/lib/rubocop/cop/style/space_inside_parens.rb +0 -2
- data/lib/rubocop/cop/style/special_global_vars.rb +1 -1
- data/lib/rubocop/cop/style/string_help.rb +1 -1
- data/lib/rubocop/cop/style/string_literals.rb +4 -11
- data/lib/rubocop/cop/style/surrounding_space.rb +0 -2
- data/lib/rubocop/cop/style/symbol_array.rb +3 -10
- data/lib/rubocop/cop/style/tab.rb +5 -5
- data/lib/rubocop/cop/style/ternary_operator.rb +2 -2
- data/lib/rubocop/cop/style/trailing_blank_lines.rb +1 -1
- data/lib/rubocop/cop/style/trailing_whitespace.rb +1 -1
- data/lib/rubocop/cop/style/trivial_accessors.rb +4 -14
- data/lib/rubocop/cop/style/unless_else.rb +1 -1
- data/lib/rubocop/cop/style/variable_interpolation.rb +1 -1
- data/lib/rubocop/cop/style/when_then.rb +3 -1
- data/lib/rubocop/cop/style/while_until_do.rb +2 -2
- data/lib/rubocop/cop/style/word_array.rb +4 -10
- data/lib/rubocop/cop/util.rb +85 -12
- data/lib/rubocop/cop/variable_inspector.rb +4 -2
- data/lib/rubocop/file_inspector.rb +98 -0
- data/lib/rubocop/formatter/base_formatter.rb +2 -2
- data/lib/rubocop/formatter/disabled_config_formatter.rb +10 -2
- data/lib/rubocop/rake_task.rb +5 -1
- data/lib/rubocop/target_finder.rb +3 -3
- data/lib/rubocop/version.rb +1 -1
- data/rubocop-todo.yml +12 -0
- data/rubocop.gemspec +1 -1
- data/spec/isolated_environment_spec.rb +24 -0
- data/spec/rubocop/cli_spec.rb +120 -27
- data/spec/rubocop/config_loader_spec.rb +25 -11
- data/spec/rubocop/config_spec.rb +25 -9
- data/spec/rubocop/config_store_spec.rb +1 -1
- data/spec/rubocop/cop/cop_spec.rb +22 -3
- data/spec/rubocop/cop/lint/block_alignment_spec.rb +4 -4
- data/spec/rubocop/cop/lint/end_alignment_spec.rb +79 -47
- data/spec/rubocop/cop/lint/syntax_spec.rb +4 -3
- data/spec/rubocop/cop/rails/default_scope_spec.rb +31 -0
- data/spec/rubocop/cop/style/access_modifier_indentation_spec.rb +37 -2
- data/spec/rubocop/cop/style/accessor_method_name_spec.rb +81 -0
- data/spec/rubocop/cop/style/alias_spec.rb +10 -0
- data/spec/rubocop/cop/style/align_parameters_spec.rb +3 -3
- data/spec/rubocop/cop/style/block_nesting_spec.rb +4 -1
- data/spec/rubocop/cop/style/braces_around_hash_parameters_spec.rb +83 -0
- data/spec/rubocop/cop/style/case_indentation_spec.rb +227 -71
- data/spec/rubocop/cop/style/class_length_spec.rb +2 -0
- data/spec/rubocop/cop/style/constant_name_spec.rb +6 -0
- data/spec/rubocop/cop/style/cyclomatic_complexity_spec.rb +1 -0
- data/spec/rubocop/cop/style/documentation_spec.rb +12 -0
- data/spec/rubocop/cop/style/dot_position_spec.rb +10 -0
- data/spec/rubocop/cop/style/empty_lines_around_body_spec.rb +22 -0
- data/spec/rubocop/cop/style/empty_lines_spec.rb +6 -0
- data/spec/rubocop/cop/style/end_of_line_spec.rb +17 -0
- data/spec/rubocop/cop/style/favor_modifier_spec.rb +15 -0
- data/spec/rubocop/cop/style/flip_flop_spec.rb +23 -0
- data/spec/rubocop/cop/style/for_spec.rb +96 -18
- data/spec/rubocop/cop/style/hash_syntax_spec.rb +8 -2
- data/spec/rubocop/cop/style/indentation_width_spec.rb +185 -20
- data/spec/rubocop/cop/style/line_length_spec.rb +1 -0
- data/spec/rubocop/cop/style/method_def_parentheses_spec.rb +72 -0
- data/spec/rubocop/cop/style/multiline_if_then_spec.rb +16 -0
- data/spec/rubocop/cop/style/parentheses_around_condition_spec.rb +34 -3
- data/spec/rubocop/cop/style/predicate_name_spec.rb +25 -0
- data/spec/rubocop/cop/style/redundant_self_spec.rb +15 -0
- data/spec/rubocop/cop/style/regexp_literal_spec.rb +5 -0
- data/spec/rubocop/cop/style/semicolon_spec.rb +16 -16
- data/spec/rubocop/cop/style/{reduce_arguments_spec.rb → single_line_block_params_spec.rb} +12 -4
- data/spec/rubocop/cop/style/space_around_block_braces_spec.rb +58 -8
- data/spec/rubocop/cop/style/space_around_operators_spec.rb +71 -0
- data/spec/rubocop/cop/style/string_literals_spec.rb +18 -0
- data/spec/rubocop/file_inspector_spec.rb +78 -0
- data/spec/rubocop/formatter/clang_style_formatter_spec.rb +7 -7
- data/spec/rubocop/formatter/emacs_style_formatter_spec.rb +3 -3
- data/spec/rubocop/formatter/file_list_formatter_spec.rb +2 -2
- data/spec/rubocop/processed_source_spec.rb +7 -3
- data/spec/rubocop/token_spec.rb +1 -1
- data/spec/spec_helper.rb +3 -2
- data/spec/support/isolated_environment.rb +7 -0
- data/spec/support/shared_context.rb +5 -1
- metadata +35 -12
- data/lib/rubocop/cop/style/reduce_arguments.rb +0 -34
- data/lib/rubocop/cop/style/symbol_name.rb +0 -45
- data/spec/rubocop/cop/style/def_without_parentheses_spec.rb +0 -33
- data/spec/rubocop/cop/style/symbol_name_spec.rb +0 -138
@@ -0,0 +1,24 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe 'isolated environment', :isolated_environment do
|
6
|
+
include FileHelper
|
7
|
+
|
8
|
+
let(:cli) { Rubocop::CLI.new }
|
9
|
+
|
10
|
+
before(:each) { $stdout = StringIO.new }
|
11
|
+
after(:each) { $stdout = STDOUT }
|
12
|
+
|
13
|
+
# Configuration files above the work directory shall not disturb the
|
14
|
+
# tests. This is especially important on Windows where the temporary
|
15
|
+
# directory is under the user's home directory. On any platform we don't want
|
16
|
+
# a .rubocop.yml file in the temporary directory to affect the outcome of
|
17
|
+
# rspec.
|
18
|
+
it 'is not affected by a config file above the work directory' do
|
19
|
+
create_file('../.rubocop.yml', ['inherit_from: missing_file.yml'])
|
20
|
+
create_file('ex.rb', ['# encoding: utf-8'])
|
21
|
+
# A return value of 0 means that the erroneous config file was not read.
|
22
|
+
expect(cli.run([])).to eq(0)
|
23
|
+
end
|
24
|
+
end
|
data/spec/rubocop/cli_spec.rb
CHANGED
@@ -33,6 +33,22 @@ describe Rubocop::CLI, :isolated_environment do
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
+
describe '--auto-correct' do
|
37
|
+
it 'can correct two problems with blocks' do
|
38
|
+
# {} should be do..end and space is missing.
|
39
|
+
create_file('example.rb', ['# encoding: utf-8',
|
40
|
+
'(1..10).each{ |i|',
|
41
|
+
' puts i',
|
42
|
+
'}'])
|
43
|
+
expect(cli.run(['--auto-correct'])).to eq(1)
|
44
|
+
expect(IO.read('example.rb'))
|
45
|
+
.to eq(['# encoding: utf-8',
|
46
|
+
'(1..10).each do |i|',
|
47
|
+
' puts i',
|
48
|
+
'end'].join("\n") + "\n")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
36
52
|
describe '--auto-gen-config' do
|
37
53
|
it 'exits with error if asked to re-generate a todo list that is in ' +
|
38
54
|
'use' do
|
@@ -72,6 +88,7 @@ describe Rubocop::CLI, :isolated_environment do
|
|
72
88
|
it 'can generate a todo list' do
|
73
89
|
create_file('example1.rb', ['# encoding: utf-8',
|
74
90
|
'x= 0 ',
|
91
|
+
'#' * 90,
|
75
92
|
'#' * 85,
|
76
93
|
'y ',
|
77
94
|
'puts x'])
|
@@ -95,9 +112,12 @@ describe Rubocop::CLI, :isolated_environment do
|
|
95
112
|
'# one by one as the offences are removed from the code ' +
|
96
113
|
'base.',
|
97
114
|
'',
|
98
|
-
'
|
115
|
+
'IndentationWidth:',
|
99
116
|
' Enabled: false',
|
100
117
|
'',
|
118
|
+
'LineLength:',
|
119
|
+
' Max: 90',
|
120
|
+
'',
|
101
121
|
'SpaceAroundOperators:',
|
102
122
|
' Enabled: false',
|
103
123
|
'',
|
@@ -154,16 +174,14 @@ describe Rubocop::CLI, :isolated_environment do
|
|
154
174
|
create_file('example1.rb', "\tputs 0")
|
155
175
|
expect(cli.run(['--debug', 'example1.rb'])).to eq(1)
|
156
176
|
home = File.dirname(File.dirname(File.dirname(__FILE__)))
|
157
|
-
expect($stdout.string.lines[2,
|
177
|
+
expect($stdout.string.lines[2, 5].map(&:chomp).join("\n"))
|
158
178
|
.to eq(["For #{abs('')}:" +
|
159
179
|
" configuration from #{home}/config/default.yml",
|
160
180
|
"Inheriting configuration from #{home}/config/enabled.yml",
|
161
181
|
"Inheriting configuration from #{home}/config/" +
|
162
182
|
'disabled.yml',
|
163
183
|
"AllCops/Excludes configuration from #{home}/.rubocop.yml",
|
164
|
-
"Inheriting configuration from #{home}/
|
165
|
-
"Inheriting configuration from #{home}/config/enabled.yml",
|
166
|
-
"Inheriting configuration from #{home}/config/disabled.yml"
|
184
|
+
"Inheriting configuration from #{home}/rubocop-todo.yml"
|
167
185
|
].join("\n"))
|
168
186
|
end
|
169
187
|
|
@@ -323,6 +341,10 @@ describe Rubocop::CLI, :isolated_environment do
|
|
323
341
|
'example2.rb:2:1: C: Tab detected.',
|
324
342
|
"\tx",
|
325
343
|
'^',
|
344
|
+
'example2.rb:3:1: C: Inconsistent indentation ' +
|
345
|
+
'detected.',
|
346
|
+
'def a',
|
347
|
+
'',
|
326
348
|
'example2.rb:4:1: C: Use 2 (not 3) spaces for ' +
|
327
349
|
'indentation.',
|
328
350
|
' puts',
|
@@ -340,7 +362,7 @@ describe Rubocop::CLI, :isolated_environment do
|
|
340
362
|
' end',
|
341
363
|
' ^^^',
|
342
364
|
'',
|
343
|
-
'3 files inspected,
|
365
|
+
'3 files inspected, 10 offences detected',
|
344
366
|
''].join("\n"))
|
345
367
|
end
|
346
368
|
end
|
@@ -362,6 +384,8 @@ describe Rubocop::CLI, :isolated_environment do
|
|
362
384
|
"#{abs('example1.rb')}:2:5: C: Trailing whitespace detected.",
|
363
385
|
"#{abs('example1.rb')}:3:2: C: Trailing whitespace detected.",
|
364
386
|
"#{abs('example2.rb')}:2:1: C: Tab detected.",
|
387
|
+
"#{abs('example2.rb')}:3:1: C: Inconsistent indentation " +
|
388
|
+
'detected.',
|
365
389
|
''].join("\n")
|
366
390
|
expect($stdout.string).to eq(expected_output)
|
367
391
|
end
|
@@ -683,34 +707,36 @@ describe Rubocop::CLI, :isolated_environment do
|
|
683
707
|
|
684
708
|
describe 'enabling/disabling rails cops' do
|
685
709
|
it 'by default does not run rails cops' do
|
686
|
-
create_file('example1.rb', ['# encoding: utf-8',
|
687
|
-
|
688
|
-
expect(cli.run(['--format', 'simple', 'example1.rb']))
|
710
|
+
create_file('app/models/example1.rb', ['# encoding: utf-8',
|
711
|
+
'read_attribute(:test)'])
|
712
|
+
expect(cli.run(['--format', 'simple', 'app/models/example1.rb']))
|
713
|
+
.to eq(0)
|
689
714
|
end
|
690
715
|
|
691
716
|
it 'with -R given runs rails cops' do
|
692
|
-
create_file('example1.rb', ['# encoding: utf-8',
|
693
|
-
|
694
|
-
expect(cli.run(['--format', 'simple', '-R', 'example1.rb']))
|
717
|
+
create_file('app/models/example1.rb', ['# encoding: utf-8',
|
718
|
+
'read_attribute(:test)'])
|
719
|
+
expect(cli.run(['--format', 'simple', '-R', 'app/models/example1.rb']))
|
720
|
+
.to eq(1)
|
695
721
|
expect($stdout.string).to include('Prefer self[:attribute]')
|
696
722
|
end
|
697
723
|
|
698
724
|
it 'with configation option true in one dir runs rails cops there' do
|
699
|
-
create_file('dir1/example1.rb', ['# encoding: utf-8',
|
700
|
-
|
725
|
+
create_file('dir1/app/models/example1.rb', ['# encoding: utf-8',
|
726
|
+
'read_attribute(:test)'])
|
701
727
|
create_file('dir1/.rubocop.yml', [
|
702
728
|
'AllCops:',
|
703
729
|
' RunRailsCops: true',
|
704
730
|
])
|
705
|
-
create_file('dir2/example2.rb', ['# encoding: utf-8',
|
706
|
-
|
731
|
+
create_file('dir2/app/models/example2.rb', ['# encoding: utf-8',
|
732
|
+
'read_attribute(:test)'])
|
707
733
|
create_file('dir2/.rubocop.yml', [
|
708
734
|
'AllCops:',
|
709
735
|
' RunRailsCops: false',
|
710
736
|
])
|
711
737
|
expect(cli.run(['--format', 'simple', 'dir1', 'dir2'])).to eq(1)
|
712
738
|
expect($stdout.string)
|
713
|
-
.to eq(['== dir1/example1.rb ==',
|
739
|
+
.to eq(['== dir1/app/models/example1.rb ==',
|
714
740
|
'C: 2: 1: Prefer self[:attribute] over read_attribute' +
|
715
741
|
'(:attribute).',
|
716
742
|
'',
|
@@ -719,13 +745,14 @@ describe Rubocop::CLI, :isolated_environment do
|
|
719
745
|
end
|
720
746
|
|
721
747
|
it 'with configation option false but -R given runs rails cops' do
|
722
|
-
create_file('example1.rb', ['# encoding: utf-8',
|
723
|
-
|
748
|
+
create_file('app/models/example1.rb', ['# encoding: utf-8',
|
749
|
+
'read_attribute(:test)'])
|
724
750
|
create_file('.rubocop.yml', [
|
725
751
|
'AllCops:',
|
726
752
|
' RunRailsCops: false',
|
727
753
|
])
|
728
|
-
expect(cli.run(['--format', 'simple', '-R', 'example1.rb']))
|
754
|
+
expect(cli.run(['--format', 'simple', '-R', 'app/models/example1.rb']))
|
755
|
+
.to eq(1)
|
729
756
|
expect($stdout.string).to include('Prefer self[:attribute]')
|
730
757
|
end
|
731
758
|
end
|
@@ -1111,14 +1138,80 @@ describe Rubocop::CLI, :isolated_environment do
|
|
1111
1138
|
abs('example/.rubocop.yml'),
|
1112
1139
|
''].join("\n"))
|
1113
1140
|
end
|
1114
|
-
end
|
1115
1141
|
|
1116
|
-
|
1117
|
-
|
1118
|
-
|
1119
|
-
|
1120
|
-
|
1121
|
-
|
1142
|
+
it 'works when a configuration file passed by -c specifies Excludes with regexp' do
|
1143
|
+
create_file('example/example1.rb', [
|
1144
|
+
'# encoding: utf-8',
|
1145
|
+
'#' * 90
|
1146
|
+
])
|
1147
|
+
|
1148
|
+
create_file('rubocop.yml', [
|
1149
|
+
'AllCops:',
|
1150
|
+
' Excludes:',
|
1151
|
+
' - !ruby/regexp /example1\.rb$/'
|
1152
|
+
])
|
1153
|
+
|
1154
|
+
cli.run(%w(--format simple -c rubocop.yml))
|
1155
|
+
expect($stdout.string)
|
1156
|
+
.to eq(['', '0 files inspected, no offences detected',
|
1157
|
+
''].join("\n"))
|
1158
|
+
end
|
1159
|
+
|
1160
|
+
it 'works when a configuration file passed by -c specifies Excludes with strings' do
|
1161
|
+
create_file('example/example1.rb', [
|
1162
|
+
'# encoding: utf-8',
|
1163
|
+
'#' * 90
|
1164
|
+
])
|
1165
|
+
|
1166
|
+
create_file('rubocop.yml', [
|
1167
|
+
'AllCops:',
|
1168
|
+
' Excludes:',
|
1169
|
+
' - example/**'
|
1170
|
+
])
|
1171
|
+
|
1172
|
+
cli.run(%w(--format simple -c rubocop.yml))
|
1173
|
+
expect($stdout.string)
|
1174
|
+
.to eq(['', '0 files inspected, no offences detected',
|
1175
|
+
''].join("\n"))
|
1176
|
+
end
|
1177
|
+
|
1178
|
+
it 'works when a configuration file specifies a Severity' do
|
1179
|
+
create_file('example/example1.rb', [
|
1180
|
+
'# encoding: utf-8',
|
1181
|
+
'#' * 90
|
1182
|
+
])
|
1183
|
+
|
1184
|
+
create_file('rubocop.yml', [
|
1185
|
+
'LineLength:',
|
1186
|
+
' Severity: error',
|
1187
|
+
])
|
1188
|
+
|
1189
|
+
cli.run(%w(--format simple -c rubocop.yml))
|
1190
|
+
expect($stdout.string)
|
1191
|
+
.to eq(['== example/example1.rb ==',
|
1192
|
+
'E: 2: 80: Line is too long. [90/79]',
|
1193
|
+
'',
|
1194
|
+
'1 file inspected, 1 offence detected',
|
1195
|
+
''].join("\n"))
|
1196
|
+
expect($stderr.string).to eq('')
|
1197
|
+
end
|
1198
|
+
|
1199
|
+
it 'fails when a configuration file specifies an invalid Severity' do
|
1200
|
+
create_file('example/example1.rb', [
|
1201
|
+
'# encoding: utf-8',
|
1202
|
+
'#' * 90
|
1203
|
+
])
|
1204
|
+
|
1205
|
+
create_file('rubocop.yml', [
|
1206
|
+
'LineLength:',
|
1207
|
+
' Severity: superbad',
|
1208
|
+
])
|
1209
|
+
|
1210
|
+
cli.run(%w(--format simple -c rubocop.yml))
|
1211
|
+
expect($stderr.string)
|
1212
|
+
.to eq("Warning: Invalid severity 'superbad'. " +
|
1213
|
+
'Valid severities are refactor, convention, ' +
|
1214
|
+
"warning, error, fatal.\n")
|
1122
1215
|
end
|
1123
1216
|
end
|
1124
1217
|
end
|
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
DEFAULT_CONFIG = Rubocop::ConfigLoader.load_file('config/default.yml')
|
6
|
-
|
7
5
|
describe Rubocop::ConfigLoader do
|
8
6
|
include FileHelper
|
9
7
|
|
8
|
+
let(:default_config) { Rubocop::ConfigLoader.default_configuration }
|
9
|
+
|
10
10
|
describe '.configuration_file_for', :isolated_environment do
|
11
11
|
subject(:configuration_file_for) do
|
12
12
|
described_class.configuration_file_for(dir_path)
|
@@ -72,10 +72,10 @@ describe Rubocop::ConfigLoader do
|
|
72
72
|
' Enabled: false'])
|
73
73
|
end
|
74
74
|
it 'returns a configuration inheriting from default.yml' do
|
75
|
-
config =
|
75
|
+
config = default_config['Encoding'].dup
|
76
76
|
config['Enabled'] = false
|
77
77
|
expect(configuration_from_file)
|
78
|
-
.to eql(
|
78
|
+
.to eql(default_config.merge('Encoding' => config))
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
@@ -121,6 +121,20 @@ describe Rubocop::ConfigLoader do
|
|
121
121
|
end
|
122
122
|
end
|
123
123
|
|
124
|
+
context 'when a file inherits from an empty parent file' do
|
125
|
+
let(:file_path) { 'dir/.rubocop.yml' }
|
126
|
+
|
127
|
+
before do
|
128
|
+
create_file('.rubocop.yml', [''])
|
129
|
+
|
130
|
+
create_file(file_path, ['inherit_from: ../.rubocop.yml'])
|
131
|
+
end
|
132
|
+
|
133
|
+
it 'does not fail to load' do
|
134
|
+
expect { configuration_from_file }.not_to raise_error
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
124
138
|
context 'when a file inherits from a sibling file' do
|
125
139
|
let(:file_path) { 'dir/.rubocop.yml' }
|
126
140
|
|
@@ -172,16 +186,16 @@ describe Rubocop::ConfigLoader do
|
|
172
186
|
end
|
173
187
|
|
174
188
|
it 'returns the ancestor configuration plus local overrides' do
|
175
|
-
config =
|
189
|
+
config = default_config
|
176
190
|
.merge('LineLength' => {
|
177
191
|
'Description' =>
|
178
|
-
|
192
|
+
default_config['LineLength']['Description'],
|
179
193
|
'Enabled' => true,
|
180
194
|
'Max' => 77
|
181
195
|
},
|
182
196
|
'MethodLength' => {
|
183
197
|
'Description' =>
|
184
|
-
|
198
|
+
default_config['MethodLength']['Description'],
|
185
199
|
'Enabled' => true,
|
186
200
|
'CountComments' => false,
|
187
201
|
'Max' => 5
|
@@ -302,12 +316,12 @@ describe Rubocop::ConfigLoader do
|
|
302
316
|
end
|
303
317
|
end
|
304
318
|
|
305
|
-
describe 'configuration for
|
306
|
-
describe '
|
319
|
+
describe 'configuration for AssignmentInCondition' do
|
320
|
+
describe 'AllowSafeAssignment' do
|
307
321
|
it 'is enabled by default' do
|
308
322
|
default_config = described_class.default_configuration
|
309
|
-
symbol_name_config = default_config.for_cop('
|
310
|
-
expect(symbol_name_config['
|
323
|
+
symbol_name_config = default_config.for_cop('AssignmentInCondition')
|
324
|
+
expect(symbol_name_config['AllowSafeAssignment']).to be_true
|
311
325
|
end
|
312
326
|
end
|
313
327
|
end
|
data/spec/rubocop/config_spec.rb
CHANGED
@@ -32,10 +32,9 @@ describe Rubocop::Config do
|
|
32
32
|
end
|
33
33
|
|
34
34
|
it 'raises validation error' do
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end
|
35
|
+
expect { configuration.validate }
|
36
|
+
.to raise_error(described_class::ValidationError,
|
37
|
+
/^unrecognized cop LyneLenth/)
|
39
38
|
end
|
40
39
|
end
|
41
40
|
|
@@ -49,11 +48,28 @@ describe Rubocop::Config do
|
|
49
48
|
end
|
50
49
|
|
51
50
|
it 'raises validation error' do
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
51
|
+
expect { configuration.validate }
|
52
|
+
.to raise_error(described_class::ValidationError,
|
53
|
+
/^unrecognized parameter LineLength:Min/)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'when the configuration includes any common parameter' do
|
58
|
+
# Common parameters are parameters that are not in the default
|
59
|
+
# configuration, but are nonetheless allowed for any cop.
|
60
|
+
before do
|
61
|
+
create_file(configuration_path, [
|
62
|
+
'LineLength:',
|
63
|
+
' Exclude:',
|
64
|
+
' - lib/file.rb',
|
65
|
+
' Include:',
|
66
|
+
' - lib/file.xyz',
|
67
|
+
' Severity: warning',
|
68
|
+
])
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'does not raise validation error' do
|
72
|
+
expect { configuration.validate }.to_not raise_error
|
57
73
|
end
|
58
74
|
end
|
59
75
|
end
|
@@ -23,7 +23,7 @@ describe Rubocop::ConfigStore do
|
|
23
23
|
|
24
24
|
describe '.for' do
|
25
25
|
it 'always uses config specified in command line' do
|
26
|
-
config_store.
|
26
|
+
config_store.options_config = :options_config
|
27
27
|
expect(config_store.for('file1')).to eq('merged options_config loaded')
|
28
28
|
end
|
29
29
|
|
@@ -15,20 +15,39 @@ describe Rubocop::Cop::Cop do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'keeps track of offences' do
|
18
|
-
cop.
|
18
|
+
cop.add_offence(nil, location, 'message')
|
19
19
|
|
20
20
|
expect(cop.offences.size).to eq(1)
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'will report registered offences' do
|
24
|
-
cop.
|
24
|
+
cop.add_offence(nil, location, 'message')
|
25
25
|
|
26
26
|
expect(cop.offences).not_to be_empty
|
27
27
|
end
|
28
28
|
|
29
|
+
it 'will set default severity' do
|
30
|
+
cop.add_offence(nil, location, 'message')
|
31
|
+
|
32
|
+
expect(cop.offences.first.severity).to eq(:convention)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'will set custom severity if present' do
|
36
|
+
cop.config[cop.name] = { 'Severity' => 'warning' }
|
37
|
+
cop.add_offence(nil, location, 'message')
|
38
|
+
|
39
|
+
expect(cop.offences.first.severity).to eq(:warning)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'will warn if custom severity is invalid' do
|
43
|
+
cop.config[cop.name] = { 'Severity' => 'superbad' }
|
44
|
+
cop.should_receive(:warn)
|
45
|
+
cop.add_offence(nil, location, 'message')
|
46
|
+
end
|
47
|
+
|
29
48
|
it 'registers offence with its name' do
|
30
49
|
cop = Rubocop::Cop::Style::For.new
|
31
|
-
cop.
|
50
|
+
cop.add_offence(nil, location, 'message')
|
32
51
|
expect(cop.offences.first.cop_name).to eq('For')
|
33
52
|
end
|
34
53
|
|