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
@@ -2,81 +2,237 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
describe Rubocop::Cop::Style::CaseIndentation do
|
6
|
-
subject(:cop) { described_class.new }
|
7
|
-
|
8
|
-
it "registers an offence for a when clause that's deeper than case" do
|
9
|
-
source = ['case a',
|
10
|
-
' when 0 then return',
|
11
|
-
' case b',
|
12
|
-
' when 1 then return',
|
13
|
-
' end',
|
14
|
-
'end']
|
15
|
-
inspect_source(cop, source)
|
16
|
-
expect(cop.messages).to eq(
|
17
|
-
['Indent when as deep as case.'] * 2)
|
18
|
-
end
|
5
|
+
describe Rubocop::Cop::Style::CaseIndentation, :config do
|
6
|
+
subject(:cop) { described_class.new(config) }
|
19
7
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
' when 1 then return',
|
26
|
-
' when 1 then break',
|
27
|
-
' end',
|
28
|
-
' end',
|
29
|
-
'case c',
|
30
|
-
'when 2 then encoding',
|
31
|
-
'end',
|
32
|
-
'']
|
33
|
-
inspect_source(cop, source)
|
34
|
-
expect(cop.offences).to be_empty
|
35
|
-
end
|
8
|
+
context 'with IndentWhenRelativeTo: case' do
|
9
|
+
context 'with IndentOneStep: false' do
|
10
|
+
let(:cop_config) do
|
11
|
+
{ 'IndentWhenRelativeTo' => 'case', 'IndentOneStep' => false }
|
12
|
+
end
|
36
13
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
14
|
+
context 'regarding assignment where the right hand side is a case' do
|
15
|
+
it 'accepts a correcty indented assignment' do
|
16
|
+
source = ['output = case variable',
|
17
|
+
" when 'value1'",
|
18
|
+
" 'output1'",
|
19
|
+
' else',
|
20
|
+
" 'output2'",
|
21
|
+
' end']
|
22
|
+
inspect_source(cop, source)
|
23
|
+
expect(cop.offences).to be_empty
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'registers on offence for an assignment indented some other way' do
|
27
|
+
source = ['output = case variable',
|
28
|
+
" when 'value1'",
|
29
|
+
" 'output1'",
|
30
|
+
' else',
|
31
|
+
" 'output2'",
|
32
|
+
'end']
|
33
|
+
inspect_source(cop, source)
|
34
|
+
expect(cop.messages).to eq(['Indent when as deep as case.'])
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it "registers an offence for a when clause that's deeper than case" do
|
39
|
+
source = ['case a',
|
40
|
+
' when 0 then return',
|
41
|
+
' else',
|
42
|
+
' case b',
|
43
|
+
' when 1 then return',
|
44
|
+
' end',
|
45
|
+
'end']
|
46
|
+
inspect_source(cop, source)
|
47
|
+
expect(cop.messages).to eq(['Indent when as deep as case.'] * 2)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "accepts a when clause that's equally indented with case" do
|
51
|
+
source = ['y = case a',
|
52
|
+
' when 0 then break',
|
53
|
+
' when 0 then return',
|
54
|
+
' else',
|
55
|
+
' z = case b',
|
56
|
+
' when 1 then return',
|
57
|
+
' when 1 then break',
|
58
|
+
' end',
|
59
|
+
' end',
|
60
|
+
'case c',
|
61
|
+
'when 2 then encoding',
|
62
|
+
'end',
|
63
|
+
'']
|
64
|
+
inspect_source(cop, source)
|
65
|
+
expect(cop.offences).to be_empty
|
66
|
+
end
|
67
|
+
|
68
|
+
it "doesn't get confused by strings with case in them" do
|
69
|
+
source = ['a = "case"',
|
70
|
+
'case x',
|
71
|
+
'when 0',
|
72
|
+
'end',
|
73
|
+
'']
|
74
|
+
inspect_source(cop, source)
|
75
|
+
expect(cop.messages).to be_empty
|
76
|
+
end
|
77
|
+
|
78
|
+
it "doesn't get confused by symbols named case or when" do
|
79
|
+
source = ['KEYWORDS = { :case => true, :when => true }',
|
80
|
+
'case type',
|
81
|
+
'when 0',
|
82
|
+
' ParameterNode',
|
83
|
+
'when 1',
|
84
|
+
' MethodCallNode',
|
85
|
+
'end',
|
86
|
+
'']
|
87
|
+
inspect_source(cop, source)
|
88
|
+
expect(cop.messages).to be_empty
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'accepts correctly indented whens in complex combinations' do
|
92
|
+
source = ['each {',
|
93
|
+
' case state',
|
94
|
+
' when 0',
|
95
|
+
' case name',
|
96
|
+
' when :a',
|
97
|
+
' end',
|
98
|
+
' when 1',
|
99
|
+
' loop {',
|
100
|
+
' case name',
|
101
|
+
' when :b',
|
102
|
+
' end',
|
103
|
+
' }',
|
104
|
+
' end',
|
105
|
+
'}',
|
106
|
+
'case s',
|
107
|
+
'when Array',
|
108
|
+
'end',
|
109
|
+
'']
|
110
|
+
inspect_source(cop, source)
|
111
|
+
expect(cop.messages).to be_empty
|
112
|
+
end
|
113
|
+
end
|
46
114
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
115
|
+
context 'with IndentOneStep: true' do
|
116
|
+
let(:cop_config) do
|
117
|
+
{ 'IndentWhenRelativeTo' => 'case', 'IndentOneStep' => true }
|
118
|
+
end
|
119
|
+
|
120
|
+
context 'regarding assignment where the right hand side is a case' do
|
121
|
+
it 'accepts a correcty indented assignment' do
|
122
|
+
source = ['output = case variable',
|
123
|
+
" when 'value1'",
|
124
|
+
" 'output1'",
|
125
|
+
' else',
|
126
|
+
" 'output2'",
|
127
|
+
' end']
|
128
|
+
inspect_source(cop, source)
|
129
|
+
expect(cop.offences).to be_empty
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'registers on offence for an assignment indented some other way' do
|
133
|
+
source = ['output = case variable',
|
134
|
+
" when 'value1'",
|
135
|
+
" 'output1'",
|
136
|
+
' else',
|
137
|
+
" 'output2'",
|
138
|
+
' end']
|
139
|
+
inspect_source(cop, source)
|
140
|
+
expect(cop.messages).to eq(['Indent when one step more than case.'])
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
it "accepts a when clause that's 2 spaces deeper than case" do
|
145
|
+
source = ['case a',
|
146
|
+
' when 0 then return',
|
147
|
+
' else',
|
148
|
+
' case b',
|
149
|
+
' when 1 then return',
|
150
|
+
' end',
|
151
|
+
'end']
|
152
|
+
inspect_source(cop, source)
|
153
|
+
expect(cop.offences).to be_empty
|
154
|
+
end
|
155
|
+
|
156
|
+
it "registers an offence for a when clause that's equally indented " +
|
157
|
+
'with case' do
|
158
|
+
source = ['y = case a',
|
159
|
+
' when 0 then break',
|
160
|
+
' when 0 then return',
|
161
|
+
' z = case b',
|
162
|
+
' when 1 then return',
|
163
|
+
' when 1 then break',
|
164
|
+
' end',
|
165
|
+
' end',
|
166
|
+
'case c',
|
167
|
+
'when 2 then encoding',
|
168
|
+
'end',
|
169
|
+
'']
|
170
|
+
inspect_source(cop, source)
|
171
|
+
expect(cop.messages)
|
172
|
+
.to eq(['Indent when one step more than case.'] * 5)
|
173
|
+
end
|
174
|
+
end
|
58
175
|
end
|
59
176
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
177
|
+
context 'with IndentWhenRelativeTo: end' do
|
178
|
+
context 'with IndentOneStep: false' do
|
179
|
+
let(:cop_config) do
|
180
|
+
{ 'IndentWhenRelativeTo' => 'end', 'IndentOneStep' => false }
|
181
|
+
end
|
182
|
+
|
183
|
+
context 'regarding assignment where the right hand side is a case' do
|
184
|
+
it 'accepts a correcty indented assignment' do
|
185
|
+
source = ['output = case variable',
|
186
|
+
"when 'value1'",
|
187
|
+
" 'output1'",
|
188
|
+
'else',
|
189
|
+
" 'output2'",
|
190
|
+
'end']
|
191
|
+
inspect_source(cop, source)
|
192
|
+
expect(cop.offences).to be_empty
|
193
|
+
end
|
194
|
+
|
195
|
+
it 'registers on offence for an assignment indented some other way' do
|
196
|
+
source = ['output = case variable',
|
197
|
+
" when 'value1'",
|
198
|
+
" 'output1'",
|
199
|
+
' else',
|
200
|
+
" 'output2'",
|
201
|
+
'end']
|
202
|
+
inspect_source(cop, source)
|
203
|
+
expect(cop.messages).to eq(['Indent when as deep as end.'])
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
context 'with IndentOneStep: true' do
|
209
|
+
let(:cop_config) do
|
210
|
+
{ 'IndentWhenRelativeTo' => 'end', 'IndentOneStep' => true }
|
211
|
+
end
|
212
|
+
|
213
|
+
context 'regarding assignment where the right hand side is a case' do
|
214
|
+
it 'accepts a correcty indented assignment' do
|
215
|
+
source = ['output = case variable',
|
216
|
+
" when 'value1'",
|
217
|
+
" 'output1'",
|
218
|
+
' else',
|
219
|
+
" 'output2'",
|
220
|
+
'end']
|
221
|
+
inspect_source(cop, source)
|
222
|
+
expect(cop.offences).to be_empty
|
223
|
+
end
|
224
|
+
|
225
|
+
it 'registers on offence for an assignment indented some other way' do
|
226
|
+
source = ['output = case variable',
|
227
|
+
" when 'value1'",
|
228
|
+
" 'output1'",
|
229
|
+
' else',
|
230
|
+
" 'output2'",
|
231
|
+
' end']
|
232
|
+
inspect_source(cop, source)
|
233
|
+
expect(cop.messages).to eq(['Indent when one step more than end.'])
|
234
|
+
end
|
235
|
+
end
|
236
|
+
end
|
81
237
|
end
|
82
238
|
end
|
@@ -16,6 +16,8 @@ describe Rubocop::Cop::Style::ClassLength, :config do
|
|
16
16
|
' a = 6',
|
17
17
|
'end'])
|
18
18
|
expect(cop.offences.size).to eq(1)
|
19
|
+
expect(cop.messages).to eq(['Class definition is too long. [6/5]'])
|
20
|
+
expect(cop.config_to_allow_offences).to eq('Max' => 6)
|
19
21
|
end
|
20
22
|
|
21
23
|
it 'accepts a class with 5 lines' do
|
@@ -50,6 +50,12 @@ describe Rubocop::Cop::Style::ConstantName do
|
|
50
50
|
expect(cop.offences).to be_empty
|
51
51
|
end
|
52
52
|
|
53
|
+
it 'does not check if rhs is another constant' do
|
54
|
+
inspect_source(cop,
|
55
|
+
['Parser::CurrentRuby = Parser::Ruby20'])
|
56
|
+
expect(cop.offences).to be_empty
|
57
|
+
end
|
58
|
+
|
53
59
|
it 'checks qualified const names' do
|
54
60
|
inspect_source(cop,
|
55
61
|
['::AnythingGoes = 30',
|
@@ -35,6 +35,7 @@ describe Rubocop::Cop::Style::CyclomaticComplexity, :config do
|
|
35
35
|
expect(cop.messages)
|
36
36
|
.to eq(['Cyclomatic complexity for method_name is too high. [2/1]'])
|
37
37
|
expect(cop.highlights).to eq(['def'])
|
38
|
+
expect(cop.config_to_allow_offences).to eq('Max' => 2)
|
38
39
|
end
|
39
40
|
|
40
41
|
it 'registers an offence for an unless modifier' do
|
@@ -80,4 +80,16 @@ describe Rubocop::Cop::Style::Documentation do
|
|
80
80
|
])
|
81
81
|
expect(cop.offences).to be_empty
|
82
82
|
end
|
83
|
+
|
84
|
+
it 'does not raise an error for an implicit match conditional' do
|
85
|
+
pending
|
86
|
+
expect do
|
87
|
+
inspect_source(cop,
|
88
|
+
['class Test',
|
89
|
+
' if //',
|
90
|
+
' end',
|
91
|
+
'end'
|
92
|
+
])
|
93
|
+
end.to_not raise_error
|
94
|
+
end
|
83
95
|
end
|
@@ -29,6 +29,11 @@ describe Rubocop::Cop::Style::DotPosition, :config do
|
|
29
29
|
inspect_source(cop, ['l.', '(1)'])
|
30
30
|
expect(cop.offences.size).to eq(1)
|
31
31
|
end
|
32
|
+
|
33
|
+
it 'does not err on method call on same line' do
|
34
|
+
inspect_source(cop, ['something.method_name'])
|
35
|
+
expect(cop.offences).to be_empty
|
36
|
+
end
|
32
37
|
end
|
33
38
|
|
34
39
|
context 'Trailing dots style' do
|
@@ -55,6 +60,11 @@ describe Rubocop::Cop::Style::DotPosition, :config do
|
|
55
60
|
inspect_source(cop, ['l', '.(1)'])
|
56
61
|
expect(cop.offences.size).to eq(1)
|
57
62
|
end
|
63
|
+
|
64
|
+
it 'does not err on method call on same line' do
|
65
|
+
inspect_source(cop, ['something.method_name'])
|
66
|
+
expect(cop.offences).to be_empty
|
67
|
+
end
|
58
68
|
end
|
59
69
|
|
60
70
|
context 'Unknown style' do
|
@@ -14,6 +14,17 @@ describe Rubocop::Cop::Style::EmptyLinesAroundBody do
|
|
14
14
|
expect(cop.offences.size).to eq(1)
|
15
15
|
end
|
16
16
|
|
17
|
+
it 'autocorrects method body starting with a blank' do
|
18
|
+
corrected = autocorrect_source(cop,
|
19
|
+
['def some_method',
|
20
|
+
'',
|
21
|
+
' do_something',
|
22
|
+
'end'])
|
23
|
+
expect(corrected).to eq ['def some_method',
|
24
|
+
' do_something',
|
25
|
+
'end'].join("\n")
|
26
|
+
end
|
27
|
+
|
17
28
|
it 'registers an offence for class method body starting with a blank' do
|
18
29
|
inspect_source(cop,
|
19
30
|
['def Test.some_method',
|
@@ -23,6 +34,17 @@ describe Rubocop::Cop::Style::EmptyLinesAroundBody do
|
|
23
34
|
expect(cop.offences.size).to eq(1)
|
24
35
|
end
|
25
36
|
|
37
|
+
it 'autocorrects class method body starting with a blank' do
|
38
|
+
corrected = autocorrect_source(cop,
|
39
|
+
['def Test.some_method',
|
40
|
+
'',
|
41
|
+
' do_something',
|
42
|
+
'end'])
|
43
|
+
expect(corrected).to eq ['def Test.some_method',
|
44
|
+
' do_something',
|
45
|
+
'end'].join("\n")
|
46
|
+
end
|
47
|
+
|
26
48
|
it 'registers an offence for method body ending with a blank' do
|
27
49
|
inspect_source(cop,
|
28
50
|
['def some_method',
|
@@ -11,6 +11,12 @@ describe Rubocop::Cop::Style::EmptyLines do
|
|
11
11
|
expect(cop.offences.size).to eq(2)
|
12
12
|
end
|
13
13
|
|
14
|
+
it 'auto-corrects consecutive empty lines' do
|
15
|
+
corrected = autocorrect_source(cop,
|
16
|
+
['test = 5', '', '', '', 'top'])
|
17
|
+
expect(corrected).to eq ['test = 5', '', 'top'].join("\n")
|
18
|
+
end
|
19
|
+
|
14
20
|
it 'works when there are no tokens' do
|
15
21
|
inspect_source(cop,
|
16
22
|
['#comment'])
|
@@ -27,4 +27,21 @@ describe Rubocop::Cop::Style::EndOfLine do
|
|
27
27
|
expect(cop.messages.size).to eq(1)
|
28
28
|
end
|
29
29
|
end
|
30
|
+
|
31
|
+
context 'when the default external encoding is US_ASCII' do
|
32
|
+
before(:each) do
|
33
|
+
@orig_encoding = Encoding.default_external
|
34
|
+
Encoding.default_external = Encoding::US_ASCII
|
35
|
+
end
|
36
|
+
after(:each) { Encoding.default_external = @orig_encoding }
|
37
|
+
|
38
|
+
it 'does not crash on UTF-8 encoded non-ascii characters' do
|
39
|
+
inspect_source_file(cop,
|
40
|
+
['# encoding: UTF-8',
|
41
|
+
'class Epd::ReportsController < EpdAreaController',
|
42
|
+
" 'terecht bij uw ROM-coördinator.'",
|
43
|
+
'end'].join("\n"))
|
44
|
+
expect(cop.offences).to be_empty
|
45
|
+
end
|
46
|
+
end
|
30
47
|
end
|