rubocop 0.7.2 → 0.8.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/.travis.yml +7 -1
- data/CHANGELOG.md +19 -0
- data/README.md +4 -8
- data/bin/rubocop +2 -2
- data/config/default.yml +8 -0
- data/config/enabled.yml +21 -24
- data/lib/rubocop.rb +9 -7
- data/lib/rubocop/cli.rb +73 -52
- data/lib/rubocop/config.rb +8 -5
- data/lib/rubocop/cop/access_control.rb +41 -0
- data/lib/rubocop/cop/alias.rb +7 -5
- data/lib/rubocop/cop/align_parameters.rb +20 -96
- data/lib/rubocop/cop/and_or.rb +26 -0
- data/lib/rubocop/cop/ascii_comments.rb +3 -8
- data/lib/rubocop/cop/ascii_identifiers.rb +6 -5
- data/lib/rubocop/cop/avoid_class_vars.rb +5 -10
- data/lib/rubocop/cop/avoid_for.rb +7 -5
- data/lib/rubocop/cop/avoid_global_vars.rb +19 -7
- data/lib/rubocop/cop/avoid_perl_backrefs.rb +7 -10
- data/lib/rubocop/cop/avoid_perlisms.rb +11 -10
- data/lib/rubocop/cop/block_comments.rb +4 -6
- data/lib/rubocop/cop/blocks.rb +11 -47
- data/lib/rubocop/cop/case_indentation.rb +9 -31
- data/lib/rubocop/cop/class_and_module_camel_case.rb +20 -11
- data/lib/rubocop/cop/class_methods.rb +5 -10
- data/lib/rubocop/cop/collection_methods.rb +16 -16
- data/lib/rubocop/cop/colon_method_call.rb +8 -32
- data/lib/rubocop/cop/constant_name.rb +24 -0
- data/lib/rubocop/cop/cop.rb +20 -78
- data/lib/rubocop/cop/def_parentheses.rb +43 -35
- data/lib/rubocop/cop/empty_line_between_defs.rb +11 -15
- data/lib/rubocop/cop/empty_lines.rb +20 -9
- data/lib/rubocop/cop/empty_literal.rb +47 -0
- data/lib/rubocop/cop/encoding.rb +3 -3
- data/lib/rubocop/cop/end_of_line.rb +3 -3
- data/lib/rubocop/cop/ensure_return.rb +6 -23
- data/lib/rubocop/cop/eval.rb +7 -10
- data/lib/rubocop/cop/favor_join.rb +9 -24
- data/lib/rubocop/cop/favor_modifier.rb +38 -48
- data/lib/rubocop/cop/favor_percent_r.rb +7 -7
- data/lib/rubocop/cop/favor_sprintf.rb +8 -24
- data/lib/rubocop/cop/favor_unless_over_negated_if.rb +19 -17
- data/lib/rubocop/cop/handle_exceptions.rb +7 -11
- data/lib/rubocop/cop/hash_syntax.rb +29 -14
- data/lib/rubocop/cop/if_then_else.rb +32 -29
- data/lib/rubocop/cop/leading_comment_space.rb +5 -8
- data/lib/rubocop/cop/line_continuation.rb +4 -7
- data/lib/rubocop/cop/line_length.rb +3 -3
- data/lib/rubocop/cop/loop.rb +33 -0
- data/lib/rubocop/cop/method_and_variable_snake_case.rb +42 -19
- data/lib/rubocop/cop/method_length.rb +34 -37
- data/lib/rubocop/cop/new_lambda_literal.rb +8 -6
- data/lib/rubocop/cop/not.rb +10 -4
- data/lib/rubocop/cop/numeric_literals.rb +9 -7
- data/lib/rubocop/cop/offence.rb +1 -1
- data/lib/rubocop/cop/op_method.rb +12 -22
- data/lib/rubocop/cop/parameter_lists.rb +12 -6
- data/lib/rubocop/cop/parentheses_around_condition.rb +11 -11
- data/lib/rubocop/cop/percent_r.rb +7 -7
- data/lib/rubocop/cop/reduce_arguments.rb +13 -51
- data/lib/rubocop/cop/rescue_exception.rb +13 -29
- data/lib/rubocop/cop/rescue_modifier.rb +5 -8
- data/lib/rubocop/cop/semicolon.rb +15 -74
- data/lib/rubocop/cop/single_line_methods.rb +28 -44
- data/lib/rubocop/cop/space_after_comma_etc.rb +29 -9
- data/lib/rubocop/cop/space_after_control_keyword.rb +16 -15
- data/lib/rubocop/cop/string_literals.rb +9 -35
- data/lib/rubocop/cop/surrounding_space.rb +213 -112
- data/lib/rubocop/cop/symbol_array.rb +9 -7
- data/lib/rubocop/cop/symbol_name.rb +23 -0
- data/lib/rubocop/cop/syntax.rb +14 -7
- data/lib/rubocop/cop/tab.rb +3 -3
- data/lib/rubocop/cop/ternary_operator.rb +26 -24
- data/lib/rubocop/cop/trailing_whitespace.rb +3 -5
- data/lib/rubocop/cop/trivial_accessors.rb +18 -95
- data/lib/rubocop/cop/unless_else.rb +11 -7
- data/lib/rubocop/cop/util.rb +26 -0
- data/lib/rubocop/cop/variable_interpolation.rb +18 -10
- data/lib/rubocop/cop/when_then.rb +6 -17
- data/lib/rubocop/cop/word_array.rb +18 -19
- data/lib/rubocop/version.rb +1 -1
- data/rubocop.gemspec +1 -0
- data/spec/project_spec.rb +1 -1
- data/spec/rubocop/cli_spec.rb +16 -9
- data/spec/rubocop/config_spec.rb +13 -3
- data/spec/rubocop/cops/access_control_spec.rb +129 -0
- data/spec/rubocop/cops/alias_spec.rb +2 -6
- data/spec/rubocop/cops/align_parameters_spec.rb +58 -71
- data/spec/rubocop/cops/and_or_spec.rb +37 -0
- data/spec/rubocop/cops/ascii_comments_spec.rb +3 -4
- data/spec/rubocop/cops/ascii_identifiers_spec.rb +3 -4
- data/spec/rubocop/cops/avoid_class_vars_spec.rb +7 -2
- data/spec/rubocop/cops/avoid_for_spec.rb +1 -4
- data/spec/rubocop/cops/{avoid_global_vars.rb → avoid_global_vars_spec.rb} +4 -4
- data/spec/rubocop/cops/avoid_perl_backrefs_spec.rb +1 -1
- data/spec/rubocop/cops/avoid_perlisms_spec.rb +5 -5
- data/spec/rubocop/cops/block_comments_spec.rb +0 -4
- data/spec/rubocop/cops/blocks_spec.rb +33 -0
- data/spec/rubocop/cops/case_indentation_spec.rb +5 -5
- data/spec/rubocop/cops/class_and_module_camel_case_spec.rb +15 -5
- data/spec/rubocop/cops/class_methods_spec.rb +4 -4
- data/spec/rubocop/cops/collection_methods_spec.rb +9 -4
- data/spec/rubocop/cops/colon_method_call_spec.rb +11 -5
- data/spec/rubocop/cops/constant_name_spec.rb +42 -0
- data/spec/rubocop/cops/def_with_parentheses_spec.rb +13 -8
- data/spec/rubocop/cops/def_without_parentheses_spec.rb +11 -5
- data/spec/rubocop/cops/empty_line_between_defs_spec.rb +38 -38
- data/spec/rubocop/cops/empty_lines_spec.rb +15 -3
- data/spec/rubocop/cops/empty_literal_spec.rb +90 -0
- data/spec/rubocop/cops/encoding_spec.rb +9 -9
- data/spec/rubocop/cops/end_of_line_spec.rb +2 -2
- data/spec/rubocop/cops/ensure_return_spec.rb +1 -3
- data/spec/rubocop/cops/eval_spec.rb +8 -5
- data/spec/rubocop/cops/favor_join_spec.rb +1 -5
- data/spec/rubocop/cops/favor_modifier_spec.rb +16 -14
- data/spec/rubocop/cops/{favor_percent_r.rb → favor_percent_r_spec.rb} +6 -6
- data/spec/rubocop/cops/favor_sprintf_spec.rb +3 -9
- data/spec/rubocop/cops/favor_unless_over_negated_if_spec.rb +4 -4
- data/spec/rubocop/cops/favor_until_over_negated_while_spec.rb +3 -3
- data/spec/rubocop/cops/handle_exceptions_spec.rb +1 -3
- data/spec/rubocop/cops/hash_syntax_spec.rb +11 -6
- data/spec/rubocop/cops/if_with_semicolon_spec.rb +7 -1
- data/spec/rubocop/cops/leading_comment_space_spec.rb +0 -7
- data/spec/rubocop/cops/line_continuation_spec.rb +2 -2
- data/spec/rubocop/cops/line_length_spec.rb +2 -2
- data/spec/rubocop/cops/loop_spec.rb +31 -0
- data/spec/rubocop/cops/method_and_variable_snake_case_spec.rb +38 -12
- data/spec/rubocop/cops/method_length_spec.rb +85 -85
- data/spec/rubocop/cops/multiline_if_then_spec.rb +15 -15
- data/spec/rubocop/cops/new_lambda_literal_spec.rb +3 -3
- data/spec/rubocop/cops/not_spec.rb +1 -4
- data/spec/rubocop/cops/numeric_literals_spec.rb +13 -13
- data/spec/rubocop/cops/one_line_conditional_spec.rb +1 -1
- data/spec/rubocop/cops/op_method_spec.rb +2 -9
- data/spec/rubocop/cops/parameter_lists_spec.rb +7 -7
- data/spec/rubocop/cops/parentheses_around_condition_spec.rb +41 -44
- data/spec/rubocop/cops/percent_r_spec.rb +6 -6
- data/spec/rubocop/cops/reduce_arguments_spec.rb +4 -4
- data/spec/rubocop/cops/rescue_exception_spec.rb +48 -8
- data/spec/rubocop/cops/rescue_modifier_spec.rb +2 -5
- data/spec/rubocop/cops/semicolon_spec.rb +2 -30
- data/spec/rubocop/cops/single_line_methods_spec.rb +13 -13
- data/spec/rubocop/cops/space_after_colon_spec.rb +3 -3
- data/spec/rubocop/cops/space_after_comma_spec.rb +14 -2
- data/spec/rubocop/cops/space_after_control_keyword_spec.rb +42 -3
- data/spec/rubocop/cops/space_after_semicolon_spec.rb +2 -2
- data/spec/rubocop/cops/space_around_braces_spec.rb +18 -3
- data/spec/rubocop/cops/space_around_equals_in_default_parameter_spec.rb +4 -4
- data/spec/rubocop/cops/space_around_operators_spec.rb +82 -27
- data/spec/rubocop/cops/space_inside_brackets_spec.rb +13 -7
- data/spec/rubocop/cops/space_inside_hash_literal_braces_spec.rb +14 -9
- data/spec/rubocop/cops/space_inside_parens_spec.rb +7 -3
- data/spec/rubocop/cops/string_literals_spec.rb +17 -5
- data/spec/rubocop/cops/symbol_array_spec.rb +18 -2
- data/spec/rubocop/cops/symbol_name_spec.rb +119 -0
- data/spec/rubocop/cops/syntax_spec.rb +25 -18
- data/spec/rubocop/cops/tab_spec.rb +2 -2
- data/spec/rubocop/cops/ternary_operator_spec.rb +13 -17
- data/spec/rubocop/cops/trailing_whitespace_spec.rb +3 -3
- data/spec/rubocop/cops/trivial_accessors_spec.rb +17 -20
- data/spec/rubocop/cops/unless_else_spec.rb +8 -8
- data/spec/rubocop/cops/variable_interpolation_spec.rb +0 -5
- data/spec/rubocop/cops/when_then_spec.rb +14 -21
- data/spec/rubocop/cops/word_array_spec.rb +12 -4
- data/spec/spec_helper.rb +12 -4
- metadata +40 -31
- data/.document +0 -5
- data/lib/rubocop/cop/ampersands_pipes_vs_and_or.rb +0 -25
- data/lib/rubocop/cop/array_literal.rb +0 -61
- data/lib/rubocop/cop/brace_after_percent.rb +0 -32
- data/lib/rubocop/cop/grammar.rb +0 -138
- data/lib/rubocop/cop/hash_literal.rb +0 -61
- data/lib/rubocop/cop/percent_literals.rb +0 -25
- data/lib/rubocop/cop/symbol_snake_case.rb +0 -47
- data/spec/rubocop/cops/ampersands_pipes_vs_and_or_spec.rb +0 -57
- data/spec/rubocop/cops/array_literal_spec.rb +0 -46
- data/spec/rubocop/cops/brace_after_percent_spec.rb +0 -33
- data/spec/rubocop/cops/grammar_spec.rb +0 -81
- data/spec/rubocop/cops/hash_literal_spec.rb +0 -46
- data/spec/rubocop/cops/multiline_blocks_spec.rb +0 -24
- data/spec/rubocop/cops/percent_literals_spec.rb +0 -47
- data/spec/rubocop/cops/single_line_blocks_spec.rb +0 -22
- data/spec/rubocop/cops/symbol_snake_case_spec.rb +0 -93
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
module Rubocop
|
6
|
+
module Cop
|
7
|
+
describe AndOr do
|
8
|
+
let(:amp) { AndOr.new }
|
9
|
+
|
10
|
+
it 'registers an offence for OR' do
|
11
|
+
inspect_source(amp,
|
12
|
+
['test if a or b'])
|
13
|
+
expect(amp.offences.size).to eq(1)
|
14
|
+
expect(amp.messages).to eq(['Use || instead of or.'])
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'registers an offence for AND' do
|
18
|
+
inspect_source(amp,
|
19
|
+
['test if a and b'])
|
20
|
+
expect(amp.offences.size).to eq(1)
|
21
|
+
expect(amp.messages).to eq(['Use && instead of and.'])
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'accepts ||' do
|
25
|
+
inspect_source(amp,
|
26
|
+
['test if a || b'])
|
27
|
+
expect(amp.offences).to be_empty
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'accepts &&' do
|
31
|
+
inspect_source(amp,
|
32
|
+
['test if a && b'])
|
33
|
+
expect(amp.offences).to be_empty
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -9,16 +9,15 @@ module Rubocop
|
|
9
9
|
|
10
10
|
it 'registers an offence for a comment with non-ascii chars' do
|
11
11
|
inspect_source(ascii,
|
12
|
-
'
|
13
|
-
|
12
|
+
['# encoding: utf-8',
|
13
|
+
'# 这是什么?'])
|
14
14
|
expect(ascii.offences.size).to eq(1)
|
15
15
|
expect(ascii.offences.map(&:message))
|
16
|
-
.to eq([AsciiComments::
|
16
|
+
.to eq([AsciiComments::MSG])
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'accepts comments with only ascii chars' do
|
20
20
|
inspect_source(ascii,
|
21
|
-
'file.rb',
|
22
21
|
['# AZaz1@$%~,;*_`|'])
|
23
22
|
expect(ascii.offences).to be_empty
|
24
23
|
end
|
@@ -9,16 +9,15 @@ module Rubocop
|
|
9
9
|
|
10
10
|
it 'registers an offence for a variable name with non-ascii chars' do
|
11
11
|
inspect_source(ascii,
|
12
|
-
'
|
13
|
-
|
12
|
+
['# encoding: utf-8',
|
13
|
+
'älg = 1'])
|
14
14
|
expect(ascii.offences.size).to eq(1)
|
15
15
|
expect(ascii.offences.map(&:message))
|
16
|
-
.to eq([AsciiIdentifiers::
|
16
|
+
.to eq([AsciiIdentifiers::MSG])
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'accepts identifiers with only ascii chars' do
|
20
20
|
inspect_source(ascii,
|
21
|
-
'file.rb',
|
22
21
|
['x.empty?'])
|
23
22
|
expect(ascii.offences).to be_empty
|
24
23
|
end
|
@@ -7,14 +7,19 @@ module Rubocop
|
|
7
7
|
describe AvoidClassVars do
|
8
8
|
let(:acv) { AvoidClassVars.new }
|
9
9
|
|
10
|
-
it 'registers an offence for class
|
10
|
+
it 'registers an offence for class variable declaration' do
|
11
11
|
inspect_source(acv,
|
12
|
-
'file.rb',
|
13
12
|
['class TestClass; @@test = 10; end'])
|
14
13
|
expect(acv.offences.size).to eq(1)
|
15
14
|
expect(acv.offences.map(&:message))
|
16
15
|
.to eq(['Replace class var @@test with a class instance var.'])
|
17
16
|
end
|
17
|
+
|
18
|
+
it 'does not register an offence for class variable usage' do
|
19
|
+
inspect_source(acv,
|
20
|
+
['@@test.test(20)'])
|
21
|
+
expect(acv.offences).to be_empty
|
22
|
+
end
|
18
23
|
end
|
19
24
|
end
|
20
25
|
end
|
@@ -9,7 +9,6 @@ module Rubocop
|
|
9
9
|
|
10
10
|
it 'registers an offence for for' do
|
11
11
|
inspect_source(af,
|
12
|
-
'file.rb',
|
13
12
|
['def func',
|
14
13
|
' for n in [1, 2, 3] do',
|
15
14
|
' puts n',
|
@@ -17,19 +16,17 @@ module Rubocop
|
|
17
16
|
'end'])
|
18
17
|
expect(af.offences.size).to eq(1)
|
19
18
|
expect(af.offences.map(&:message))
|
20
|
-
.to eq([AvoidFor::
|
19
|
+
.to eq([AvoidFor::MSG])
|
21
20
|
end
|
22
21
|
|
23
22
|
it 'does not register an offence for :for' do
|
24
23
|
inspect_source(af,
|
25
|
-
'file.rb',
|
26
24
|
['[:for, :ala, :bala]'])
|
27
25
|
expect(af.offences).to be_empty
|
28
26
|
end
|
29
27
|
|
30
28
|
it 'does not register an offence for def for' do
|
31
29
|
inspect_source(af,
|
32
|
-
'file.rb',
|
33
30
|
['def for; end'])
|
34
31
|
expect(af.offences).to be_empty
|
35
32
|
end
|
@@ -8,23 +8,23 @@ module Rubocop
|
|
8
8
|
let(:ap) { AvoidGlobalVars.new }
|
9
9
|
|
10
10
|
it 'registers an offence for $custom' do
|
11
|
-
inspect_source(ap,
|
11
|
+
inspect_source(ap, ['puts $custom'])
|
12
12
|
expect(ap.offences.size).to eq(1)
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'does not register an offence for $"' do
|
16
|
-
inspect_source(ap,
|
16
|
+
inspect_source(ap, ['puts $"'])
|
17
17
|
|
18
18
|
expect(ap.offences).to be_empty
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'does not register an offence for $ORS' do
|
22
|
-
inspect_source(ap,
|
22
|
+
inspect_source(ap, ['puts $0'])
|
23
23
|
expect(ap.offences).to be_empty
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'does not register an offence for backrefs like $1' do
|
27
|
-
inspect_source(ap,
|
27
|
+
inspect_source(ap, ['puts $1'])
|
28
28
|
expect(ap.offences).to be_empty
|
29
29
|
end
|
30
30
|
end
|
@@ -8,7 +8,7 @@ module Rubocop
|
|
8
8
|
let(:ap) { AvoidPerlBackrefs.new }
|
9
9
|
|
10
10
|
it 'registers an offence for $1' do
|
11
|
-
inspect_source(ap,
|
11
|
+
inspect_source(ap, ['puts $1'])
|
12
12
|
expect(ap.offences.size).to eq(1)
|
13
13
|
expect(ap.offences.map(&:message))
|
14
14
|
.to eq(['Prefer the use of MatchData over $1.'])
|
@@ -8,35 +8,35 @@ module Rubocop
|
|
8
8
|
let(:ap) { AvoidPerlisms.new }
|
9
9
|
|
10
10
|
it 'registers an offence for $:' do
|
11
|
-
inspect_source(ap,
|
11
|
+
inspect_source(ap, ['puts $:'])
|
12
12
|
expect(ap.offences.size).to eq(1)
|
13
13
|
expect(ap.offences.map(&:message))
|
14
14
|
.to eq(['Prefer $LOAD_PATH over $:.'])
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'registers an offence for $"' do
|
18
|
-
inspect_source(ap,
|
18
|
+
inspect_source(ap, ['puts $"'])
|
19
19
|
expect(ap.offences.size).to eq(1)
|
20
20
|
expect(ap.offences.map(&:message))
|
21
21
|
.to eq(['Prefer $LOADED_FEATURES over $".'])
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'registers an offence for $0' do
|
25
|
-
inspect_source(ap,
|
25
|
+
inspect_source(ap, ['puts $0'])
|
26
26
|
expect(ap.offences.size).to eq(1)
|
27
27
|
expect(ap.offences.map(&:message))
|
28
28
|
.to eq(['Prefer $PROGRAM_NAME over $0.'])
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'registers an offence for $$' do
|
32
|
-
inspect_source(ap,
|
32
|
+
inspect_source(ap, ['puts $$'])
|
33
33
|
expect(ap.offences.size).to eq(1)
|
34
34
|
expect(ap.offences.map(&:message))
|
35
35
|
.to eq(['Prefer $PID or $PROCESS_ID from English library over $$.'])
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'does not register an offence for backrefs like $1' do
|
39
|
-
inspect_source(ap,
|
39
|
+
inspect_source(ap, ['puts $1'])
|
40
40
|
expect(ap.offences).to be_empty
|
41
41
|
end
|
42
42
|
end
|
@@ -9,18 +9,14 @@ module Rubocop
|
|
9
9
|
|
10
10
|
it 'registers an offence for block comments' do
|
11
11
|
inspect_source(block,
|
12
|
-
'file.rb',
|
13
12
|
['=begin',
|
14
13
|
'comment',
|
15
14
|
'=end'])
|
16
15
|
expect(block.offences.size).to eq(1)
|
17
|
-
expect(block.offences.map(&:message))
|
18
|
-
.to eq([BlockComments::ERROR_MESSAGE])
|
19
16
|
end
|
20
17
|
|
21
18
|
it 'accepts regular comments' do
|
22
19
|
inspect_source(block,
|
23
|
-
'file.rb',
|
24
20
|
['# comment'])
|
25
21
|
expect(block.offences).to be_empty
|
26
22
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
module Rubocop
|
6
|
+
module Cop
|
7
|
+
describe Blocks do
|
8
|
+
let(:blocks) { Blocks.new }
|
9
|
+
|
10
|
+
it 'registers an offence for a multiline block with braces' do
|
11
|
+
inspect_source(blocks, ['each { |x|',
|
12
|
+
'}'])
|
13
|
+
expect(blocks.messages).to eq([Blocks::MULTI_LINE_MSG])
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'accepts a multiline block with do-end' do
|
17
|
+
inspect_source(blocks, ['each do |x|',
|
18
|
+
'end'])
|
19
|
+
expect(blocks.offences.map(&:message)).to be_empty
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'registers an offence for a single line block with do-end' do
|
23
|
+
inspect_source(blocks, ['each do |x| end'])
|
24
|
+
expect(blocks.messages).to eq([Blocks::SINGLE_LINE_MSG])
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'accepts a single line block with braces' do
|
28
|
+
inspect_source(blocks, ['each { |x| }'])
|
29
|
+
expect(blocks.offences.map(&:message)).to be_empty
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -14,7 +14,7 @@ module Rubocop
|
|
14
14
|
' when 1 then return',
|
15
15
|
' end',
|
16
16
|
'end']
|
17
|
-
inspect_source(ind,
|
17
|
+
inspect_source(ind, source)
|
18
18
|
expect(ind.offences.map(&:message)).to eq(
|
19
19
|
['Indent when as deep as case.'] * 2)
|
20
20
|
end
|
@@ -32,7 +32,7 @@ module Rubocop
|
|
32
32
|
'when 2 then encoding',
|
33
33
|
'end',
|
34
34
|
'']
|
35
|
-
inspect_source(ind,
|
35
|
+
inspect_source(ind, source)
|
36
36
|
expect(ind.offences).to be_empty
|
37
37
|
end
|
38
38
|
|
@@ -42,7 +42,7 @@ module Rubocop
|
|
42
42
|
'when 0',
|
43
43
|
'end',
|
44
44
|
'']
|
45
|
-
inspect_source(ind,
|
45
|
+
inspect_source(ind, source)
|
46
46
|
expect(ind.offences.map(&:message)).to be_empty
|
47
47
|
end
|
48
48
|
|
@@ -55,7 +55,7 @@ module Rubocop
|
|
55
55
|
' MethodCallNode',
|
56
56
|
'end',
|
57
57
|
'']
|
58
|
-
inspect_source(ind,
|
58
|
+
inspect_source(ind, source)
|
59
59
|
expect(ind.offences.map(&:message)).to be_empty
|
60
60
|
end
|
61
61
|
|
@@ -78,7 +78,7 @@ module Rubocop
|
|
78
78
|
'when Array',
|
79
79
|
'end',
|
80
80
|
'']
|
81
|
-
inspect_source(ind,
|
81
|
+
inspect_source(ind, source)
|
82
82
|
expect(ind.offences.map(&:message)).to be_empty
|
83
83
|
end
|
84
84
|
end
|
@@ -8,26 +8,36 @@ module Rubocop
|
|
8
8
|
let(:camel_case) { ClassAndModuleCamelCase.new }
|
9
9
|
|
10
10
|
it 'registers an offence for underscore in class and module name' do
|
11
|
-
inspect_source(camel_case,
|
11
|
+
inspect_source(camel_case,
|
12
12
|
['class My_Class',
|
13
13
|
'end',
|
14
14
|
'',
|
15
15
|
'module My_Module',
|
16
16
|
'end',
|
17
17
|
])
|
18
|
-
expect(camel_case.offences.
|
19
|
-
|
18
|
+
expect(camel_case.offences.size).to eq(2)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'is not fooled by qualified names' do
|
22
|
+
inspect_source(camel_case,
|
23
|
+
['class Top::My_Class',
|
24
|
+
'end',
|
25
|
+
'',
|
26
|
+
'module My_Module::Ala',
|
27
|
+
'end',
|
28
|
+
])
|
29
|
+
expect(camel_case.offences.size).to eq(2)
|
20
30
|
end
|
21
31
|
|
22
32
|
it 'accepts CamelCase names' do
|
23
|
-
inspect_source(camel_case,
|
33
|
+
inspect_source(camel_case,
|
24
34
|
['class MyClass',
|
25
35
|
'end',
|
26
36
|
'',
|
27
37
|
'module Mine',
|
28
38
|
'end',
|
29
39
|
])
|
30
|
-
expect(camel_case.offences
|
40
|
+
expect(camel_case.offences).to be_empty
|
31
41
|
end
|
32
42
|
end
|
33
43
|
end
|
@@ -8,7 +8,7 @@ module Rubocop
|
|
8
8
|
let(:cm) { ClassMethods.new }
|
9
9
|
|
10
10
|
it 'registers an offence for methods using a class name' do
|
11
|
-
inspect_source(cm,
|
11
|
+
inspect_source(cm,
|
12
12
|
['class Test',
|
13
13
|
' def Test.some_method',
|
14
14
|
' do_something',
|
@@ -18,7 +18,7 @@ module Rubocop
|
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'registers an offence for methods using a module name' do
|
21
|
-
inspect_source(cm,
|
21
|
+
inspect_source(cm,
|
22
22
|
['module Test',
|
23
23
|
' def Test.some_method',
|
24
24
|
' do_something',
|
@@ -28,7 +28,7 @@ module Rubocop
|
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'does not register an offence for methods using self' do
|
31
|
-
inspect_source(cm,
|
31
|
+
inspect_source(cm,
|
32
32
|
['module Test',
|
33
33
|
' def self.some_method',
|
34
34
|
' do_something',
|
@@ -38,7 +38,7 @@ module Rubocop
|
|
38
38
|
end
|
39
39
|
|
40
40
|
it 'does not register an offence outside class/module bodies' do
|
41
|
-
inspect_source(cm,
|
41
|
+
inspect_source(cm,
|
42
42
|
['def self.some_method',
|
43
43
|
' do_something',
|
44
44
|
'end'])
|
@@ -8,32 +8,37 @@ module Rubocop
|
|
8
8
|
let(:cm) { CollectionMethods.new }
|
9
9
|
|
10
10
|
it 'registers an offence for collect' do
|
11
|
-
inspect_source(cm,
|
11
|
+
inspect_source(cm, ['[1, 2, 3].collect { |e| e + 1 }'])
|
12
12
|
expect(cm.offences.size).to eq(1)
|
13
13
|
expect(cm.offences.map(&:message))
|
14
14
|
.to eq(['Prefer map over collect.'])
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'registers an offence for inject' do
|
18
|
-
inspect_source(cm,
|
18
|
+
inspect_source(cm, ['[1, 2, 3].inject { |e| e + 1 }'])
|
19
19
|
expect(cm.offences.size).to eq(1)
|
20
20
|
expect(cm.offences.map(&:message))
|
21
21
|
.to eq(['Prefer reduce over inject.'])
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'registers an offence for detect' do
|
25
|
-
inspect_source(cm,
|
25
|
+
inspect_source(cm, ['[1, 2, 3].detect { |e| e + 1 }'])
|
26
26
|
expect(cm.offences.size).to eq(1)
|
27
27
|
expect(cm.offences.map(&:message))
|
28
28
|
.to eq(['Prefer find over detect.'])
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'registers an offence for find_all' do
|
32
|
-
inspect_source(cm,
|
32
|
+
inspect_source(cm, ['[1, 2, 3].find_all { |e| e + 1 }'])
|
33
33
|
expect(cm.offences.size).to eq(1)
|
34
34
|
expect(cm.offences.map(&:message))
|
35
35
|
.to eq(['Prefer select over find_all.'])
|
36
36
|
end
|
37
|
+
|
38
|
+
it 'ignores find_all without an explicit receiver' do
|
39
|
+
inspect_source(cm, ['find_all { |e| e + 1 }'])
|
40
|
+
expect(cm.offences).to be_empty
|
41
|
+
end
|
37
42
|
end
|
38
43
|
end
|
39
44
|
end
|
@@ -9,39 +9,45 @@ module Rubocop
|
|
9
9
|
|
10
10
|
it 'registers an offence for instance method call' do
|
11
11
|
inspect_source(smc,
|
12
|
-
'file.rb',
|
13
12
|
['test::method_name'])
|
14
13
|
expect(smc.offences.size).to eq(1)
|
15
14
|
end
|
16
15
|
|
17
16
|
it 'registers an offence for instance method call with arg' do
|
18
17
|
inspect_source(smc,
|
19
|
-
'file.rb',
|
20
18
|
['test::method_name(arg)'])
|
21
19
|
expect(smc.offences.size).to eq(1)
|
22
20
|
end
|
23
21
|
|
24
22
|
it 'registers an offence for class method call' do
|
25
23
|
inspect_source(smc,
|
26
|
-
'file.rb',
|
27
24
|
['Class::method_name'])
|
28
25
|
expect(smc.offences.size).to eq(1)
|
29
26
|
end
|
30
27
|
|
31
28
|
it 'registers an offence for class method call with arg' do
|
32
29
|
inspect_source(smc,
|
33
|
-
'file.rb',
|
34
30
|
['Class::method_name(arg, arg2)'])
|
35
31
|
expect(smc.offences.size).to eq(1)
|
36
32
|
end
|
37
33
|
|
38
34
|
it 'does not register an offence for constant access' do
|
39
35
|
inspect_source(smc,
|
40
|
-
'file.rb',
|
41
36
|
['Tip::Top::SOME_CONST'])
|
42
37
|
expect(smc.offences).to be_empty
|
43
38
|
end
|
44
39
|
|
40
|
+
it 'does not register an offence for nested class' do
|
41
|
+
inspect_source(smc,
|
42
|
+
['Tip::Top.some_method'])
|
43
|
+
expect(smc.offences).to be_empty
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'does not register an offence for op methods' do
|
47
|
+
inspect_source(smc,
|
48
|
+
['Tip::Top.some_method[3]'])
|
49
|
+
expect(smc.offences).to be_empty
|
50
|
+
end
|
45
51
|
end
|
46
52
|
end
|
47
53
|
end
|