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
@@ -10,6 +10,7 @@ describe Rubocop::Cop::Style::LineLength, :config do
|
|
10
10
|
inspect_source(cop, ['#' * 80])
|
11
11
|
expect(cop.offences.size).to eq(1)
|
12
12
|
expect(cop.offences.first.message).to eq('Line is too long. [80/79]')
|
13
|
+
expect(cop.config_to_allow_offences).to eq('Max' => 80)
|
13
14
|
end
|
14
15
|
|
15
16
|
it "accepts a line that's 79 characters wide" do
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Rubocop::Cop::Style::MethodDefParentheses, :config do
|
6
|
+
subject(:cop) { described_class.new(config) }
|
7
|
+
|
8
|
+
context 'require_parentheses' do
|
9
|
+
let(:cop_config) { { 'EnforcedStyle' => 'require_parentheses' } }
|
10
|
+
|
11
|
+
it 'reports an offence for def with parameters but no parens' do
|
12
|
+
src = ['def func a, b',
|
13
|
+
'end']
|
14
|
+
inspect_source(cop, src)
|
15
|
+
expect(cop.offences.size).to eq(1)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'reports an offence for class def with parameters but no parens' do
|
19
|
+
src = ['def Test.func a, b',
|
20
|
+
'end']
|
21
|
+
inspect_source(cop, src)
|
22
|
+
expect(cop.offences.size).to eq(1)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'accepts def with no args and no parens' do
|
26
|
+
src = ['def func',
|
27
|
+
'end']
|
28
|
+
inspect_source(cop, src)
|
29
|
+
expect(cop.offences).to be_empty
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'auto-adds required parens' do
|
33
|
+
new_source = autocorrect_source(cop, 'def test param; end')
|
34
|
+
expect(new_source).to eq('def test(param); end')
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'auto-adds required parens to argument lists on multiple lines' do
|
38
|
+
new_source = autocorrect_source(cop, ['def test one,', 'two', 'end'])
|
39
|
+
expect(new_source).to eq("def test(one,\ntwo)\nend")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'require_no_parentheses' do
|
44
|
+
let(:cop_config) { { 'EnforcedStyle' => 'require_no_parentheses' } }
|
45
|
+
|
46
|
+
it 'reports an offence for def with parameters with parens' do
|
47
|
+
src = ['def func(a, b)',
|
48
|
+
'end']
|
49
|
+
inspect_source(cop, src)
|
50
|
+
expect(cop.offences.size).to eq(1)
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'reports an offence for class def with parameters with parens' do
|
54
|
+
src = ['def Test.func(a, b)',
|
55
|
+
'end']
|
56
|
+
inspect_source(cop, src)
|
57
|
+
expect(cop.offences.size).to eq(1)
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'reports an offence for def with no args and parens' do
|
61
|
+
src = ['def func()',
|
62
|
+
'end']
|
63
|
+
inspect_source(cop, src)
|
64
|
+
expect(cop.offences.size).to eq(1)
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'auto-removes the parens' do
|
68
|
+
new_source = autocorrect_source(cop, 'def test(param); end')
|
69
|
+
expect(new_source).to eq('def test param; end')
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -58,6 +58,14 @@ describe Rubocop::Cop::Style::MultilineIfThen do
|
|
58
58
|
expect(cop.offences).to be_empty
|
59
59
|
end
|
60
60
|
|
61
|
+
it 'does not raise an error for an implicit match if' do
|
62
|
+
expect do
|
63
|
+
inspect_source(cop,
|
64
|
+
['if //',
|
65
|
+
'end'])
|
66
|
+
end.not_to raise_error
|
67
|
+
end
|
68
|
+
|
61
69
|
# unless
|
62
70
|
|
63
71
|
it 'registers an offence for then in multiline unless' do
|
@@ -88,4 +96,12 @@ describe Rubocop::Cop::Style::MultilineIfThen do
|
|
88
96
|
])
|
89
97
|
expect(cop.offences).to be_empty
|
90
98
|
end
|
99
|
+
|
100
|
+
it 'does not raise an error for an implicit match unless' do
|
101
|
+
expect do
|
102
|
+
inspect_source(cop,
|
103
|
+
['unless //',
|
104
|
+
'end'])
|
105
|
+
end.not_to raise_error
|
106
|
+
end
|
91
107
|
end
|
@@ -24,6 +24,37 @@ describe Rubocop::Cop::Style::ParenthesesAroundCondition, :config do
|
|
24
24
|
expect(cop.offences.size).to eq(9)
|
25
25
|
end
|
26
26
|
|
27
|
+
it 'auto-corrects parentheses around condition' do
|
28
|
+
corrected = autocorrect_source(cop, ['if (x > 10)',
|
29
|
+
'elsif (x < 3)',
|
30
|
+
'end',
|
31
|
+
'unless (x > 10)',
|
32
|
+
'end',
|
33
|
+
'while (x > 10)',
|
34
|
+
'end',
|
35
|
+
'until (x > 10)',
|
36
|
+
'end',
|
37
|
+
'x += 1 if (x < 10)',
|
38
|
+
'x += 1 unless (x < 10)',
|
39
|
+
'x += 1 while (x < 10)',
|
40
|
+
'x += 1 until (x < 10)',
|
41
|
+
])
|
42
|
+
expect(corrected).to eq ['if x > 10',
|
43
|
+
'elsif x < 3',
|
44
|
+
'end',
|
45
|
+
'unless x > 10',
|
46
|
+
'end',
|
47
|
+
'while x > 10',
|
48
|
+
'end',
|
49
|
+
'until x > 10',
|
50
|
+
'end',
|
51
|
+
'x += 1 if x < 10',
|
52
|
+
'x += 1 unless x < 10',
|
53
|
+
'x += 1 while x < 10',
|
54
|
+
'x += 1 until x < 10',
|
55
|
+
].join("\n")
|
56
|
+
end
|
57
|
+
|
27
58
|
it 'accepts condition without parentheses' do
|
28
59
|
inspect_source(cop, ['if x > 10',
|
29
60
|
'end',
|
@@ -41,7 +72,7 @@ describe Rubocop::Cop::Style::ParenthesesAroundCondition, :config do
|
|
41
72
|
expect(cop.offences).to be_empty
|
42
73
|
end
|
43
74
|
|
44
|
-
it 'is not confused by leading
|
75
|
+
it 'is not confused by leading parenthesis in subexpression' do
|
45
76
|
inspect_source(cop, ['(a > b) && other ? one : two'])
|
46
77
|
expect(cop.offences).to be_empty
|
47
78
|
end
|
@@ -53,7 +84,7 @@ describe Rubocop::Cop::Style::ParenthesesAroundCondition, :config do
|
|
53
84
|
end
|
54
85
|
|
55
86
|
context 'safe assignment is allowed' do
|
56
|
-
it 'accepts = in condition surrounded with
|
87
|
+
it 'accepts = in condition surrounded with parentheses' do
|
57
88
|
inspect_source(cop,
|
58
89
|
['if (test = 10)',
|
59
90
|
'end'
|
@@ -66,7 +97,7 @@ describe Rubocop::Cop::Style::ParenthesesAroundCondition, :config do
|
|
66
97
|
context 'safe assignment is not allowed' do
|
67
98
|
let(:cop_config) { { 'AllowSafeAssignment' => false } }
|
68
99
|
|
69
|
-
it 'does not
|
100
|
+
it 'does not accept = in condition surrounded with parentheses' do
|
70
101
|
inspect_source(cop,
|
71
102
|
['if (test = 10)',
|
72
103
|
'end'
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Rubocop::Cop::Style::PredicateName, :config do
|
6
|
+
subject(:cop) { described_class.new(config) }
|
7
|
+
let(:cop_config) { { 'NamePrefixBlacklist' => %w(has_ is_) } }
|
8
|
+
|
9
|
+
%w(has_ is_).each do |prefix|
|
10
|
+
it 'registers an offence for blacklisted method_name' do
|
11
|
+
inspect_source(cop, ["def #{prefix}_attr",
|
12
|
+
' # ...',
|
13
|
+
'end'])
|
14
|
+
expect(cop.offences.size).to eq(1)
|
15
|
+
expect(cop.highlights).to eq(["#{prefix}_attr"])
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'accepts non-blacklisted method name' do
|
20
|
+
inspect_source(cop, ['def have_attr',
|
21
|
+
' # ...',
|
22
|
+
'end'])
|
23
|
+
expect(cop.offences).to be_empty
|
24
|
+
end
|
25
|
+
end
|
@@ -107,6 +107,15 @@ describe Rubocop::Cop::Style::RedundantSelf do
|
|
107
107
|
expect(cop.offences).to be_empty
|
108
108
|
end
|
109
109
|
|
110
|
+
it 'accepts a self receiver used to distinguish from argument' do
|
111
|
+
src = ['def requested_specs(final = true)',
|
112
|
+
' something if self.final != final',
|
113
|
+
'end',
|
114
|
+
]
|
115
|
+
inspect_source(cop, src)
|
116
|
+
expect(cop.offences).to be_empty
|
117
|
+
end
|
118
|
+
|
110
119
|
it 'accepts a self receiver used to distinguish from local variable' do
|
111
120
|
src = ['def requested_specs',
|
112
121
|
' @requested_specs ||= begin',
|
@@ -120,6 +129,12 @@ describe Rubocop::Cop::Style::RedundantSelf do
|
|
120
129
|
expect(cop.offences).to be_empty
|
121
130
|
end
|
122
131
|
|
132
|
+
it 'accepts a self receiver used to distinguish from constant' do
|
133
|
+
src = ['self.Foo']
|
134
|
+
inspect_source(cop, src)
|
135
|
+
expect(cop.offences).to be_empty
|
136
|
+
end
|
137
|
+
|
123
138
|
it 'auto-corrects by removing redundant self' do
|
124
139
|
new_source = autocorrect_source(cop, ['self.x'])
|
125
140
|
expect(new_source).to eq('x')
|
@@ -52,6 +52,11 @@ describe Rubocop::Cop::Style::RegexpLiteral, :config do
|
|
52
52
|
expect(cop.offences).to be_empty
|
53
53
|
end
|
54
54
|
end
|
55
|
+
|
56
|
+
it 'ignores slashes do not belong regexp' do
|
57
|
+
inspect_source(cop, ['x =~ /\s{#{x[/\s+/].length}}/'])
|
58
|
+
expect(cop.offences).to be_empty
|
59
|
+
end
|
55
60
|
end
|
56
61
|
|
57
62
|
context 'when a regexp uses %r delimiters' do
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
@@ -82,19 +82,19 @@ describe Rubocop::Cop::Style::Semicolon, :config do
|
|
82
82
|
expect(cop.offences).to be_empty
|
83
83
|
end
|
84
84
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
85
|
+
context 'when AllowAsExpressionSeparator is true' do
|
86
|
+
let(:cop_config) { { 'AllowAsExpressionSeparator' => true } }
|
87
|
+
|
88
|
+
it 'accepts several expressions' do
|
89
|
+
inspect_source(cop,
|
90
|
+
['puts "this is a test"; puts "So is this"'])
|
91
|
+
expect(cop.offences).to be_empty
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'accepts one line method with two statements' do
|
95
|
+
inspect_source(cop,
|
96
|
+
['def foo(a) x(1); y(2); z(3); end'])
|
97
|
+
expect(cop.offences).to be_empty
|
98
|
+
end
|
99
|
+
end
|
100
100
|
end
|
@@ -2,8 +2,14 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
describe Rubocop::Cop::Style::
|
6
|
-
subject(:cop) { described_class.new }
|
5
|
+
describe Rubocop::Cop::Style::SingleLineBlockParams, :config do
|
6
|
+
subject(:cop) { described_class.new(config) }
|
7
|
+
let(:cop_config) do
|
8
|
+
{ 'Methods' =>
|
9
|
+
[{ 'reduce' => %w(a e) },
|
10
|
+
{ 'test' => %w(x y) }]
|
11
|
+
}
|
12
|
+
end
|
7
13
|
|
8
14
|
it 'find wrong argument names in calls with different syntax' do
|
9
15
|
inspect_source(cop,
|
@@ -14,9 +20,10 @@ describe Rubocop::Cop::Style::ReduceArguments do
|
|
14
20
|
' [0, 1].reduce(5){ |c, d| c + d }',
|
15
21
|
' [0, 1].reduce (5) { |c, d| c + d }',
|
16
22
|
' [0, 1].reduce(5) { |c, d| c + d }',
|
23
|
+
' ala.test { |x, z| bala }',
|
17
24
|
'end'])
|
18
|
-
expect(cop.offences.size).to eq(
|
19
|
-
expect(cop.offences.map(&:line).sort).to eq((2..
|
25
|
+
expect(cop.offences.size).to eq(7)
|
26
|
+
expect(cop.offences.map(&:line).sort).to eq((2..8).to_a)
|
20
27
|
end
|
21
28
|
|
22
29
|
it 'allows calls with proper argument names' do
|
@@ -28,6 +35,7 @@ describe Rubocop::Cop::Style::ReduceArguments do
|
|
28
35
|
' [0, 1].reduce(5){ |a, e| a + e }',
|
29
36
|
' [0, 1].reduce (5) { |a, e| a + e }',
|
30
37
|
' [0, 1].reduce(5) { |a, e| a + e }',
|
38
|
+
' ala.test { |x, y| bala }',
|
31
39
|
'end'])
|
32
40
|
expect(cop.offences).to be_empty
|
33
41
|
end
|
@@ -2,11 +2,18 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
describe Rubocop::Cop::Style::SpaceAroundBlockBraces
|
5
|
+
describe Rubocop::Cop::Style::SpaceAroundBlockBraces do
|
6
|
+
SUPPORTED_STYLES = %w(space_inside_braces no_space_inside_braces)
|
7
|
+
|
6
8
|
subject(:cop) { described_class.new(config) }
|
9
|
+
let(:config) do
|
10
|
+
Rubocop::Config.new('Blocks' => { 'Enabled' => false },
|
11
|
+
'SpaceAroundBlockBraces' => cop_config)
|
12
|
+
end
|
7
13
|
let(:cop_config) do
|
8
14
|
{
|
9
15
|
'EnforcedStyle' => 'space_inside_braces',
|
16
|
+
'SupportedStyles' => SUPPORTED_STYLES,
|
10
17
|
'SpaceBeforeBlockParameters' => true
|
11
18
|
}
|
12
19
|
end
|
@@ -19,15 +26,32 @@ describe Rubocop::Cop::Style::SpaceAroundBlockBraces, :config do
|
|
19
26
|
expect(cop.messages).to be_empty
|
20
27
|
end
|
21
28
|
|
29
|
+
it 'accepts empty braces with line break inside' do
|
30
|
+
inspect_source(cop, [' each {',
|
31
|
+
' }'])
|
32
|
+
expect(cop.messages).to be_empty
|
33
|
+
end
|
34
|
+
|
22
35
|
it 'registers an offence for empty braces with space inside' do
|
23
36
|
inspect_source(cop, ['each { }'])
|
24
37
|
expect(cop.messages).to eq(['Space inside empty braces detected.'])
|
38
|
+
expect(cop.highlights).to eq([' '])
|
25
39
|
end
|
26
40
|
|
27
41
|
it 'auto-corrects unwanted space' do
|
28
42
|
new_source = autocorrect_source(cop, 'each { }')
|
29
43
|
expect(new_source).to eq('each {}')
|
30
44
|
end
|
45
|
+
|
46
|
+
it 'does not auto-correct when braces are not empty' do
|
47
|
+
old_source = <<-END
|
48
|
+
a {
|
49
|
+
b
|
50
|
+
}
|
51
|
+
END
|
52
|
+
new_source = autocorrect_source(cop, old_source)
|
53
|
+
expect(new_source).to eq(old_source)
|
54
|
+
end
|
31
55
|
end
|
32
56
|
|
33
57
|
context 'with space inside empty braces allowed' do
|
@@ -41,6 +65,7 @@ describe Rubocop::Cop::Style::SpaceAroundBlockBraces, :config do
|
|
41
65
|
it 'registers an offence for empty braces with no space inside' do
|
42
66
|
inspect_source(cop, ['each {}'])
|
43
67
|
expect(cop.messages).to eq(['Space missing inside empty braces.'])
|
68
|
+
expect(cop.highlights).to eq(['{}'])
|
44
69
|
end
|
45
70
|
|
46
71
|
it 'auto-corrects missing space' do
|
@@ -64,7 +89,7 @@ describe Rubocop::Cop::Style::SpaceAroundBlockBraces, :config do
|
|
64
89
|
it 'registers an offence for left brace without inner space' do
|
65
90
|
inspect_source(cop, ['each {puts }'])
|
66
91
|
expect(cop.messages).to eq(['Space missing inside {.'])
|
67
|
-
expect(cop.highlights).to eq(['
|
92
|
+
expect(cop.highlights).to eq(['p'])
|
68
93
|
end
|
69
94
|
|
70
95
|
it 'registers an offence for right brace without inner space' do
|
@@ -74,7 +99,7 @@ describe Rubocop::Cop::Style::SpaceAroundBlockBraces, :config do
|
|
74
99
|
end
|
75
100
|
|
76
101
|
it 'auto-corrects missing space' do
|
77
|
-
new_source = autocorrect_source(cop, 'each {
|
102
|
+
new_source = autocorrect_source(cop, 'each {puts}')
|
78
103
|
expect(new_source).to eq('each { puts }')
|
79
104
|
end
|
80
105
|
|
@@ -88,7 +113,7 @@ describe Rubocop::Cop::Style::SpaceAroundBlockBraces, :config do
|
|
88
113
|
it 'registers an offence for left brace without inner space' do
|
89
114
|
inspect_source(cop, ['each {|x| puts }'])
|
90
115
|
expect(cop.messages).to eq(['Space between { and | missing.'])
|
91
|
-
expect(cop.highlights).to eq(['{'])
|
116
|
+
expect(cop.highlights).to eq(['{|'])
|
92
117
|
end
|
93
118
|
|
94
119
|
it 'auto-corrects missing space' do
|
@@ -96,10 +121,33 @@ describe Rubocop::Cop::Style::SpaceAroundBlockBraces, :config do
|
|
96
121
|
expect(new_source).to eq('each { |x| puts }')
|
97
122
|
end
|
98
123
|
|
124
|
+
context 'and Blocks cop enabled' do
|
125
|
+
let(:config) do
|
126
|
+
Rubocop::Config.new('Blocks' => { 'Enabled' => true },
|
127
|
+
'SpaceAroundBlockBraces' => cop_config)
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'does auto-correction for single-line blocks' do
|
131
|
+
new_source = autocorrect_source(cop, 'each{|x| puts}')
|
132
|
+
expect(new_source).to eq('each { |x| puts }')
|
133
|
+
end
|
134
|
+
|
135
|
+
it 'does not do auto-correction for multi-line blocks' do
|
136
|
+
# {} will be changed to do..end by the Blocks cop, and then this cop is
|
137
|
+
# not relevant anymore.
|
138
|
+
old_source = ['each{|x|',
|
139
|
+
' puts',
|
140
|
+
'}']
|
141
|
+
new_source = autocorrect_source(cop, old_source)
|
142
|
+
expect(new_source).to eq(old_source.join("\n"))
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
99
146
|
context 'and space before block parameters not allowed' do
|
100
147
|
let(:cop_config) do
|
101
148
|
{
|
102
|
-
'EnforcedStyle'
|
149
|
+
'EnforcedStyle' => 'space_inside_braces',
|
150
|
+
'SupportedStyles' => SUPPORTED_STYLES,
|
103
151
|
'SpaceBeforeBlockParameters' => false
|
104
152
|
}
|
105
153
|
end
|
@@ -126,7 +174,8 @@ describe Rubocop::Cop::Style::SpaceAroundBlockBraces, :config do
|
|
126
174
|
context 'configured with no_space_inside_braces' do
|
127
175
|
let(:cop_config) do
|
128
176
|
{
|
129
|
-
'EnforcedStyle'
|
177
|
+
'EnforcedStyle' => 'no_space_inside_braces',
|
178
|
+
'SupportedStyles' => SUPPORTED_STYLES,
|
130
179
|
'SpaceBeforeBlockParameters' => true
|
131
180
|
}
|
132
181
|
end
|
@@ -171,7 +220,7 @@ describe Rubocop::Cop::Style::SpaceAroundBlockBraces, :config do
|
|
171
220
|
it 'registers an offence for left brace without inner space' do
|
172
221
|
inspect_source(cop, ['each {|x| puts}'])
|
173
222
|
expect(cop.messages).to eq(['Space between { and | missing.'])
|
174
|
-
expect(cop.highlights).to eq(['{'])
|
223
|
+
expect(cop.highlights).to eq(['{|'])
|
175
224
|
end
|
176
225
|
|
177
226
|
it 'auto-corrects missing space' do
|
@@ -183,7 +232,8 @@ describe Rubocop::Cop::Style::SpaceAroundBlockBraces, :config do
|
|
183
232
|
context 'and space before block parameters not allowed' do
|
184
233
|
let(:cop_config) do
|
185
234
|
{
|
186
|
-
'EnforcedStyle'
|
235
|
+
'EnforcedStyle' => 'no_space_inside_braces',
|
236
|
+
'SupportedStyles' => SUPPORTED_STYLES,
|
187
237
|
'SpaceBeforeBlockParameters' => false
|
188
238
|
}
|
189
239
|
end
|