rubocop 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.rubocop.yml +4 -262
- data/CHANGELOG.md +65 -1
- data/Gemfile +4 -0
- data/README.md +89 -2
- data/Rakefile +2 -2
- data/bin/rubocop +15 -10
- data/lib/rubocop/cli.rb +156 -114
- data/lib/rubocop/config.rb +202 -0
- data/lib/rubocop/config_store.rb +37 -0
- data/lib/rubocop/cop/alias.rb +2 -5
- data/lib/rubocop/cop/align_parameters.rb +1 -1
- data/lib/rubocop/cop/array_literal.rb +43 -4
- data/lib/rubocop/cop/{ascii_identifiers_and_comments.rb → ascii_comments.rb} +3 -3
- data/lib/rubocop/cop/ascii_identifiers.rb +18 -0
- data/lib/rubocop/cop/avoid_for.rb +2 -4
- data/lib/rubocop/cop/avoid_global_vars.rb +49 -0
- data/lib/rubocop/cop/block_comments.rb +17 -0
- data/lib/rubocop/cop/brace_after_percent.rb +9 -5
- data/lib/rubocop/cop/{indentation.rb → case_indentation.rb} +1 -1
- data/lib/rubocop/cop/class_methods.rb +20 -0
- data/lib/rubocop/cop/colon_method_call.rb +44 -0
- data/lib/rubocop/cop/cop.rb +33 -0
- data/lib/rubocop/cop/def_parentheses.rb +1 -1
- data/lib/rubocop/cop/empty_line_between_defs.rb +26 -0
- data/lib/rubocop/cop/empty_lines.rb +10 -13
- data/lib/rubocop/cop/eval.rb +22 -0
- data/lib/rubocop/cop/favor_join.rb +37 -0
- data/lib/rubocop/cop/grammar.rb +2 -2
- data/lib/rubocop/cop/hash_literal.rb +43 -4
- data/lib/rubocop/cop/hash_syntax.rb +2 -2
- data/lib/rubocop/cop/if_then_else.rb +1 -1
- data/lib/rubocop/cop/leading_comment_space.rb +20 -0
- data/lib/rubocop/cop/line_continuation.rb +18 -0
- data/lib/rubocop/cop/line_length.rb +1 -1
- data/lib/rubocop/cop/method_and_variable_snake_case.rb +7 -6
- data/lib/rubocop/cop/method_length.rb +4 -15
- data/lib/rubocop/cop/not.rb +15 -0
- data/lib/rubocop/cop/offence.rb +9 -0
- data/lib/rubocop/cop/op_method.rb +6 -1
- data/lib/rubocop/cop/semicolon.rb +74 -3
- data/lib/rubocop/cop/single_line_methods.rb +60 -0
- data/lib/rubocop/cop/space_after_comma_etc.rb +4 -5
- data/lib/rubocop/cop/space_after_control_keyword.rb +28 -0
- data/lib/rubocop/cop/surrounding_space.rb +48 -9
- data/lib/rubocop/cop/symbol_array.rb +29 -0
- data/lib/rubocop/cop/symbol_snake_case.rb +20 -0
- data/lib/rubocop/cop/trivial_accessors.rb +103 -0
- data/lib/rubocop/cop/unless_else.rb +1 -1
- data/lib/rubocop/cop/variable_interpolation.rb +3 -2
- data/lib/rubocop/cop/word_array.rb +38 -0
- data/lib/rubocop/report/plain_text.rb +1 -1
- data/lib/rubocop/version.rb +1 -1
- data/lib/rubocop.rb +22 -7
- data/rubocop.gemspec +11 -7
- data/spec/project_spec.rb +27 -0
- data/spec/rubocop/cli_spec.rb +556 -388
- data/spec/rubocop/config_spec.rb +399 -0
- data/spec/rubocop/config_store_spec.rb +66 -0
- data/spec/rubocop/cops/alias_spec.rb +7 -0
- data/spec/rubocop/cops/array_literal_spec.rb +18 -1
- data/spec/rubocop/cops/ascii_comments_spec.rb +27 -0
- data/spec/rubocop/cops/ascii_identifiers_spec.rb +27 -0
- data/spec/rubocop/cops/avoid_for_spec.rb +15 -1
- data/spec/rubocop/cops/avoid_global_vars.rb +32 -0
- data/spec/rubocop/cops/block_comments_spec.rb +29 -0
- data/spec/rubocop/cops/brace_after_percent_spec.rb +19 -13
- data/spec/rubocop/cops/{indentation_spec.rb → case_indentation_spec.rb} +2 -2
- data/spec/rubocop/cops/class_methods_spec.rb +49 -0
- data/spec/rubocop/cops/colon_method_call_spec.rb +47 -0
- data/spec/rubocop/cops/empty_line_between_defs_spec.rb +83 -0
- data/spec/rubocop/cops/empty_lines_spec.rb +6 -63
- data/spec/rubocop/cops/eval_spec.rb +36 -0
- data/spec/rubocop/cops/favor_join_spec.rb +39 -0
- data/spec/rubocop/cops/hash_literal_spec.rb +18 -1
- data/spec/rubocop/cops/leading_comment_space_spec.rb +60 -0
- data/spec/rubocop/cops/line_continuation_spec.rb +24 -0
- data/spec/rubocop/cops/line_length_spec.rb +1 -0
- data/spec/rubocop/cops/method_and_variable_snake_case_spec.rb +20 -0
- data/spec/rubocop/cops/method_length_spec.rb +2 -5
- data/spec/rubocop/cops/new_lambda_literal_spec.rb +2 -3
- data/spec/rubocop/cops/not_spec.rb +34 -0
- data/spec/rubocop/cops/offence_spec.rb +7 -0
- data/spec/rubocop/cops/op_method_spec.rb +11 -0
- data/spec/rubocop/cops/semicolon_spec.rb +79 -4
- data/spec/rubocop/cops/single_line_methods_spec.rb +50 -0
- data/spec/rubocop/cops/space_after_control_keyword_spec.rb +28 -0
- data/spec/rubocop/cops/space_after_semicolon_spec.rb +5 -0
- data/spec/rubocop/cops/space_around_equals_in_default_parameter_spec.rb +11 -1
- data/spec/rubocop/cops/space_inside_hash_literal_braces_spec.rb +74 -0
- data/spec/rubocop/cops/symbol_array_spec.rb +25 -0
- data/spec/rubocop/cops/symbol_snake_case_spec.rb +13 -0
- data/spec/rubocop/cops/trivial_accessors_spec.rb +332 -0
- data/spec/rubocop/cops/variable_interpolation_spec.rb +10 -1
- data/spec/rubocop/cops/word_array_spec.rb +39 -0
- data/spec/spec_helper.rb +18 -5
- data/spec/support/file_helper.rb +21 -0
- data/spec/support/isolated_environment.rb +27 -0
- metadata +82 -36
- data/spec/rubocop/cops/ascii_identifiers_and_comments_spec.rb +0 -38
|
@@ -6,21 +6,27 @@ module Rubocop
|
|
|
6
6
|
module Cop
|
|
7
7
|
describe BraceAfterPercent do
|
|
8
8
|
let(:bap) { BraceAfterPercent.new }
|
|
9
|
+
literals = %w(q Q r i I w W x s)
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
literals.each do |literal|
|
|
12
|
+
# %i and %I are new in ruby 2.0
|
|
13
|
+
tag = literal.downcase == 'i' ? { ruby: 2.0 } : {}
|
|
14
|
+
|
|
15
|
+
it "registers an offence for %#{literal}[", tag do
|
|
16
|
+
inspect_source(bap,
|
|
17
|
+
'file.rb',
|
|
18
|
+
["puts %#{literal}[test top]"])
|
|
19
|
+
expect(bap.offences.size).to eq(1)
|
|
20
|
+
expect(bap.offences.map(&:message))
|
|
21
|
+
.to eq([BraceAfterPercent::ERROR_MESSAGE])
|
|
22
|
+
end
|
|
18
23
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
it "does not registers an offence for %#{literal}(", tag do
|
|
25
|
+
inspect_source(bap,
|
|
26
|
+
'file.rb',
|
|
27
|
+
["puts %#{literal}(test top)"])
|
|
28
|
+
expect(bap.offences).to be_empty
|
|
29
|
+
end
|
|
24
30
|
end
|
|
25
31
|
end
|
|
26
32
|
end
|
|
@@ -4,8 +4,8 @@ require 'spec_helper'
|
|
|
4
4
|
|
|
5
5
|
module Rubocop
|
|
6
6
|
module Cop
|
|
7
|
-
describe
|
|
8
|
-
let(:ind) {
|
|
7
|
+
describe CaseIndentation do
|
|
8
|
+
let(:ind) { CaseIndentation.new }
|
|
9
9
|
|
|
10
10
|
it "registers an offence for a when clause that's deeper than case" do
|
|
11
11
|
source = ['case a',
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
module Rubocop
|
|
6
|
+
module Cop
|
|
7
|
+
describe ClassMethods do
|
|
8
|
+
let(:cm) { ClassMethods.new }
|
|
9
|
+
|
|
10
|
+
it 'registers an offence for methods using a class name' do
|
|
11
|
+
inspect_source(cm, 'file.rb',
|
|
12
|
+
['class Test',
|
|
13
|
+
' def Test.some_method',
|
|
14
|
+
' do_something',
|
|
15
|
+
' end',
|
|
16
|
+
'end'])
|
|
17
|
+
expect(cm.offences.size).to eq(1)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it 'registers an offence for methods using a module name' do
|
|
21
|
+
inspect_source(cm, 'file.rb',
|
|
22
|
+
['module Test',
|
|
23
|
+
' def Test.some_method',
|
|
24
|
+
' do_something',
|
|
25
|
+
' end',
|
|
26
|
+
'end'])
|
|
27
|
+
expect(cm.offences.size).to eq(1)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it 'does not register an offence for methods using self' do
|
|
31
|
+
inspect_source(cm, 'file.rb',
|
|
32
|
+
['module Test',
|
|
33
|
+
' def self.some_method',
|
|
34
|
+
' do_something',
|
|
35
|
+
' end',
|
|
36
|
+
'end'])
|
|
37
|
+
expect(cm.offences).to be_empty
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it 'does not register an offence outside class/module bodies' do
|
|
41
|
+
inspect_source(cm, 'file.rb',
|
|
42
|
+
['def self.some_method',
|
|
43
|
+
' do_something',
|
|
44
|
+
'end'])
|
|
45
|
+
expect(cm.offences).to be_empty
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
module Rubocop
|
|
6
|
+
module Cop
|
|
7
|
+
describe ColonMethodCall do
|
|
8
|
+
let(:smc) { ColonMethodCall.new }
|
|
9
|
+
|
|
10
|
+
it 'registers an offence for instance method call' do
|
|
11
|
+
inspect_source(smc,
|
|
12
|
+
'file.rb',
|
|
13
|
+
['test::method_name'])
|
|
14
|
+
expect(smc.offences.size).to eq(1)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it 'registers an offence for instance method call with arg' do
|
|
18
|
+
inspect_source(smc,
|
|
19
|
+
'file.rb',
|
|
20
|
+
['test::method_name(arg)'])
|
|
21
|
+
expect(smc.offences.size).to eq(1)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it 'registers an offence for class method call' do
|
|
25
|
+
inspect_source(smc,
|
|
26
|
+
'file.rb',
|
|
27
|
+
['Class::method_name'])
|
|
28
|
+
expect(smc.offences.size).to eq(1)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it 'registers an offence for class method call with arg' do
|
|
32
|
+
inspect_source(smc,
|
|
33
|
+
'file.rb',
|
|
34
|
+
['Class::method_name(arg, arg2)'])
|
|
35
|
+
expect(smc.offences.size).to eq(1)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it 'does not register an offence for constant access' do
|
|
39
|
+
inspect_source(smc,
|
|
40
|
+
'file.rb',
|
|
41
|
+
['Tip::Top::SOME_CONST'])
|
|
42
|
+
expect(smc.offences).to be_empty
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
module Rubocop
|
|
6
|
+
module Cop
|
|
7
|
+
describe EmptyLineBetweenDefs do
|
|
8
|
+
let(:empty_lines) { EmptyLineBetweenDefs.new }
|
|
9
|
+
|
|
10
|
+
it 'finds offences in inner classes' do
|
|
11
|
+
inspect_source(empty_lines, '', ['class K',
|
|
12
|
+
' def m',
|
|
13
|
+
' end',
|
|
14
|
+
' class J',
|
|
15
|
+
' def n',
|
|
16
|
+
' end',
|
|
17
|
+
' def o',
|
|
18
|
+
' end',
|
|
19
|
+
' end',
|
|
20
|
+
' # checks something',
|
|
21
|
+
' def p',
|
|
22
|
+
' end',
|
|
23
|
+
'end'])
|
|
24
|
+
expect(empty_lines.offences.size).to eq(2)
|
|
25
|
+
expect(empty_lines.offences.map(&:line_number).sort).to eq([7, 11])
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Only one def, so rule about empty line *between* defs does not
|
|
29
|
+
# apply.
|
|
30
|
+
it 'accepts a def that follows a line with code' do
|
|
31
|
+
inspect_source(empty_lines, '', ['x = 0',
|
|
32
|
+
'def m',
|
|
33
|
+
'end'])
|
|
34
|
+
expect(empty_lines.offences).to be_empty
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Only one def, so rule about empty line *between* defs does not
|
|
38
|
+
# apply.
|
|
39
|
+
it 'accepts a def that follows code and a comment' do
|
|
40
|
+
inspect_source(empty_lines, '', [' x = 0',
|
|
41
|
+
' # 123',
|
|
42
|
+
' def m',
|
|
43
|
+
' end'])
|
|
44
|
+
expect(empty_lines.offences).to be_empty
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it 'accepts the first def without leading empty line in a class' do
|
|
48
|
+
inspect_source(empty_lines, '', ['class K',
|
|
49
|
+
' def m',
|
|
50
|
+
' end',
|
|
51
|
+
'end'])
|
|
52
|
+
expect(empty_lines.offences).to be_empty
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it 'accepts a def that follows an empty line and then a comment' do
|
|
56
|
+
inspect_source(empty_lines, '', ['class A',
|
|
57
|
+
' # calculates value',
|
|
58
|
+
' def m',
|
|
59
|
+
' end',
|
|
60
|
+
'',
|
|
61
|
+
' private',
|
|
62
|
+
' # calculates size',
|
|
63
|
+
' def n',
|
|
64
|
+
' end',
|
|
65
|
+
'end',
|
|
66
|
+
])
|
|
67
|
+
expect(empty_lines.offences).to be_empty
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it 'accepts a def that is the first of a module' do
|
|
71
|
+
source = ['module Util',
|
|
72
|
+
' public',
|
|
73
|
+
' #',
|
|
74
|
+
' def html_escape(s)',
|
|
75
|
+
' end',
|
|
76
|
+
'end',
|
|
77
|
+
]
|
|
78
|
+
inspect_source(empty_lines, '', source)
|
|
79
|
+
expect(empty_lines.offences.map(&:message)).to be_empty
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
@@ -7,77 +7,20 @@ module Rubocop
|
|
|
7
7
|
describe EmptyLines do
|
|
8
8
|
let(:empty_lines) { EmptyLines.new }
|
|
9
9
|
|
|
10
|
-
it '
|
|
11
|
-
inspect_source(empty_lines, '',
|
|
12
|
-
|
|
13
|
-
' end',
|
|
14
|
-
' class J',
|
|
15
|
-
' def n',
|
|
16
|
-
' end',
|
|
17
|
-
' def o',
|
|
18
|
-
' end',
|
|
19
|
-
' end',
|
|
20
|
-
' # checks something',
|
|
21
|
-
' def p',
|
|
22
|
-
' end',
|
|
23
|
-
'end'])
|
|
10
|
+
it 'registers an offence for consecutive empty lines' do
|
|
11
|
+
inspect_source(empty_lines, 'file.rb',
|
|
12
|
+
['test = 5', '', '', '', 'top'])
|
|
24
13
|
expect(empty_lines.offences.size).to eq(2)
|
|
25
|
-
expect(empty_lines.offences.map(&:line_number).sort).to eq([7, 11])
|
|
26
14
|
end
|
|
27
15
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
it 'accepts a def that follows a line with code' do
|
|
31
|
-
inspect_source(empty_lines, '', ['x = 0',
|
|
32
|
-
'def m',
|
|
33
|
-
'end'])
|
|
34
|
-
expect(empty_lines.offences).to be_empty
|
|
35
|
-
end
|
|
16
|
+
it 'does not register an offence for empty lines in a string' do
|
|
17
|
+
inspect_source(empty_lines, 'file.rb', ['result = "test
|
|
36
18
|
|
|
37
|
-
# Only one def, so rule about empty line *between* defs does not
|
|
38
|
-
# apply.
|
|
39
|
-
it 'accepts a def that follows code and a comment' do
|
|
40
|
-
inspect_source(empty_lines, '', [' x = 0',
|
|
41
|
-
' # 123',
|
|
42
|
-
' def m',
|
|
43
|
-
' end'])
|
|
44
|
-
expect(empty_lines.offences).to be_empty
|
|
45
|
-
end
|
|
46
19
|
|
|
47
|
-
it 'accepts the first def without leading empty line in a class' do
|
|
48
|
-
inspect_source(empty_lines, '', ['class K',
|
|
49
|
-
' def m',
|
|
50
|
-
' end',
|
|
51
|
-
'end'])
|
|
52
|
-
expect(empty_lines.offences).to be_empty
|
|
53
|
-
end
|
|
54
20
|
|
|
55
|
-
|
|
56
|
-
inspect_source(empty_lines, '', ['class A',
|
|
57
|
-
' # calculates value',
|
|
58
|
-
' def m',
|
|
59
|
-
' end',
|
|
60
|
-
'',
|
|
61
|
-
' private',
|
|
62
|
-
' # calculates size',
|
|
63
|
-
' def n',
|
|
64
|
-
' end',
|
|
65
|
-
'end',
|
|
66
|
-
])
|
|
21
|
+
string"'])
|
|
67
22
|
expect(empty_lines.offences).to be_empty
|
|
68
23
|
end
|
|
69
|
-
|
|
70
|
-
it 'accepts a def that is the first of a module' do
|
|
71
|
-
source = ['module Util',
|
|
72
|
-
' public',
|
|
73
|
-
' #',
|
|
74
|
-
' def html_escape(s)',
|
|
75
|
-
' end',
|
|
76
|
-
'end',
|
|
77
|
-
]
|
|
78
|
-
inspect_source(empty_lines, '', source)
|
|
79
|
-
expect(empty_lines.offences.map(&:message)).to be_empty
|
|
80
|
-
end
|
|
81
24
|
end
|
|
82
25
|
end
|
|
83
26
|
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
module Rubocop
|
|
6
|
+
module Cop
|
|
7
|
+
describe Eval do
|
|
8
|
+
let(:a) { Eval.new }
|
|
9
|
+
|
|
10
|
+
it 'registers an offence for eval as function' do
|
|
11
|
+
inspect_source(a,
|
|
12
|
+
'file.rb',
|
|
13
|
+
['eval(something)'])
|
|
14
|
+
expect(a.offences.size).to eq(1)
|
|
15
|
+
expect(a.offences.map(&:message))
|
|
16
|
+
.to eq([Eval::ERROR_MESSAGE])
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'registers an offence for eval as command' do
|
|
20
|
+
inspect_source(a,
|
|
21
|
+
'file.rb',
|
|
22
|
+
['eval something'])
|
|
23
|
+
expect(a.offences.size).to eq(1)
|
|
24
|
+
expect(a.offences.map(&:message))
|
|
25
|
+
.to eq([Eval::ERROR_MESSAGE])
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it 'does not register an offence for eval as variable' do
|
|
29
|
+
inspect_source(a,
|
|
30
|
+
'file.rb',
|
|
31
|
+
['eval = something'])
|
|
32
|
+
expect(a.offences).to be_empty
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
module Rubocop
|
|
6
|
+
module Cop
|
|
7
|
+
describe FavorJoin do
|
|
8
|
+
let(:fj) { FavorJoin.new }
|
|
9
|
+
|
|
10
|
+
it 'registers an offence for an array followed by string' do
|
|
11
|
+
inspect_source(fj,
|
|
12
|
+
'file.rb',
|
|
13
|
+
['%w(one two three) * ", "'])
|
|
14
|
+
expect(fj.offences.size).to eq(1)
|
|
15
|
+
expect(fj.offences.map(&:message))
|
|
16
|
+
.to eq([FavorJoin::ERROR_MESSAGE])
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'does not register an offence for numbers' do
|
|
20
|
+
inspect_source(fj,
|
|
21
|
+
'file.rb',
|
|
22
|
+
['%w(one two three) * 4'])
|
|
23
|
+
expect(fj.offences).to be_empty
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it 'does not register an offence for ambiguous cases' do
|
|
27
|
+
inspect_source(fj,
|
|
28
|
+
'file.rb',
|
|
29
|
+
['test * ", "'])
|
|
30
|
+
expect(fj.offences).to be_empty
|
|
31
|
+
|
|
32
|
+
inspect_source(fj,
|
|
33
|
+
'file.rb',
|
|
34
|
+
['%w(one two three) * test'])
|
|
35
|
+
expect(fj.offences).to be_empty
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -16,7 +16,14 @@ module Rubocop
|
|
|
16
16
|
.to eq([HashLiteral::ERROR_MESSAGE])
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
-
it 'registers an offence for Hash.new'
|
|
19
|
+
it 'registers an offence for Hash.new' do
|
|
20
|
+
inspect_source(a,
|
|
21
|
+
'file.rb',
|
|
22
|
+
['test = Hash.new'])
|
|
23
|
+
expect(a.offences.size).to eq(1)
|
|
24
|
+
expect(a.offences.map(&:message))
|
|
25
|
+
.to eq([HashLiteral::ERROR_MESSAGE])
|
|
26
|
+
end
|
|
20
27
|
|
|
21
28
|
it 'does not register an offence for Hash.new(3)' do
|
|
22
29
|
inspect_source(a,
|
|
@@ -24,6 +31,16 @@ module Rubocop
|
|
|
24
31
|
['test = Hash.new(3)'])
|
|
25
32
|
expect(a.offences).to be_empty
|
|
26
33
|
end
|
|
34
|
+
|
|
35
|
+
it 'does not crash when a method is called on super' do
|
|
36
|
+
inspect_source(a,
|
|
37
|
+
'file.rb',
|
|
38
|
+
['class Derived < Base',
|
|
39
|
+
' def func',
|
|
40
|
+
' super.slice(1..2)',
|
|
41
|
+
' end',
|
|
42
|
+
'end'])
|
|
43
|
+
end
|
|
27
44
|
end
|
|
28
45
|
end
|
|
29
46
|
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
module Rubocop
|
|
6
|
+
module Cop
|
|
7
|
+
describe LeadingCommentSpace do
|
|
8
|
+
let(:lcs) { LeadingCommentSpace.new }
|
|
9
|
+
|
|
10
|
+
it 'registers an offence for comment without leading space' do
|
|
11
|
+
inspect_source(lcs,
|
|
12
|
+
'file.rb',
|
|
13
|
+
['#missing space'])
|
|
14
|
+
expect(lcs.offences.size).to eq(1)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it 'does not register an offence for # followed by no text' do
|
|
18
|
+
inspect_source(lcs,
|
|
19
|
+
'file.rb',
|
|
20
|
+
['#'])
|
|
21
|
+
expect(lcs.offences).to be_empty
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it 'does not register an offence for more than one space' do
|
|
25
|
+
inspect_source(lcs,
|
|
26
|
+
'file.rb',
|
|
27
|
+
['# heavily indented'])
|
|
28
|
+
expect(lcs.offences).to be_empty
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it 'does not register an offence for more than one #' do
|
|
32
|
+
inspect_source(lcs,
|
|
33
|
+
'file.rb',
|
|
34
|
+
['###### heavily indented'])
|
|
35
|
+
expect(lcs.offences).to be_empty
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it 'does not register an offence for only #s' do
|
|
39
|
+
inspect_source(lcs,
|
|
40
|
+
'file.rb',
|
|
41
|
+
['######'])
|
|
42
|
+
expect(lcs.offences).to be_empty
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it 'does not register an offence for #! on first line' do
|
|
46
|
+
inspect_source(lcs,
|
|
47
|
+
'file.rb',
|
|
48
|
+
['#!/usr/bin/ruby'])
|
|
49
|
+
expect(lcs.offences).to be_empty
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it 'registers an offence for #! after the first line' do
|
|
53
|
+
inspect_source(lcs,
|
|
54
|
+
'file.rb',
|
|
55
|
+
['test', '#!/usr/bin/ruby'])
|
|
56
|
+
expect(lcs.offences.size).to eq(1)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
module Rubocop
|
|
6
|
+
module Cop
|
|
7
|
+
describe LineContinuation do
|
|
8
|
+
let(:lc) { LineContinuation.new }
|
|
9
|
+
|
|
10
|
+
it 'registers an offence for line continuation char' do
|
|
11
|
+
inspect_source(lc, 'file.rb',
|
|
12
|
+
['test = 5 \\', '+ 5'])
|
|
13
|
+
expect(lc.offences.size).to eq(1)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it 'does not register an offence for cont char in a string' do
|
|
17
|
+
inspect_source(lc, 'file.rb',
|
|
18
|
+
['result = "test string\\\n"',
|
|
19
|
+
'more'])
|
|
20
|
+
expect(lc.offences).to be_empty
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -19,6 +19,15 @@ module Rubocop
|
|
|
19
19
|
['Use snake_case for methods and variables.'] * 4)
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
+
it 'registers an offence for capitalized camel case' do
|
|
23
|
+
inspect_source(snake_case, 'file.rb',
|
|
24
|
+
['def MyMethod',
|
|
25
|
+
'end',
|
|
26
|
+
])
|
|
27
|
+
expect(snake_case.offences.map(&:message)).to eq(
|
|
28
|
+
['Use snake_case for methods and variables.'])
|
|
29
|
+
end
|
|
30
|
+
|
|
22
31
|
it 'accepts snake case in names' do
|
|
23
32
|
inspect_source(snake_case, 'file.rb',
|
|
24
33
|
['def my_method',
|
|
@@ -42,6 +51,17 @@ module Rubocop
|
|
|
42
51
|
inspect_source(snake_case, 'file.rb', ['$MY_GLOBAL = 0'])
|
|
43
52
|
expect(snake_case.offences.map(&:message)).to be_empty
|
|
44
53
|
end
|
|
54
|
+
|
|
55
|
+
it 'accepts screaming snake case constants' do
|
|
56
|
+
inspect_source(snake_case, 'file.rb', ['MY_CONSTANT = 0'])
|
|
57
|
+
expect(snake_case.offences.map(&:message)).to be_empty
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it 'accepts assigning to camel case constant' do
|
|
61
|
+
inspect_source(snake_case, 'file.rb',
|
|
62
|
+
['Paren = Struct.new :left, :right, :kind'])
|
|
63
|
+
expect(snake_case.offences.map(&:message)).to be_empty
|
|
64
|
+
end
|
|
45
65
|
end
|
|
46
66
|
end
|
|
47
67
|
end
|
|
@@ -6,10 +6,7 @@ module Rubocop
|
|
|
6
6
|
module Cop
|
|
7
7
|
describe MethodLength do
|
|
8
8
|
let(:method_length) { MethodLength.new }
|
|
9
|
-
before
|
|
10
|
-
MethodLength.stub(:max).and_return(5)
|
|
11
|
-
MethodLength.stub(:count_comments?).and_return(false)
|
|
12
|
-
end
|
|
9
|
+
before { MethodLength.config = { 'Max' => 5, 'CountComments' => false } }
|
|
13
10
|
|
|
14
11
|
it 'rejects a method with more than 5 lines' do
|
|
15
12
|
inspect_source(method_length, '', ['def m()',
|
|
@@ -133,7 +130,7 @@ module Rubocop
|
|
|
133
130
|
end
|
|
134
131
|
|
|
135
132
|
it 'has the option of counting commented lines' do
|
|
136
|
-
MethodLength.
|
|
133
|
+
MethodLength.config['CountComments'] = true
|
|
137
134
|
inspect_source(method_length, '', ['def m()',
|
|
138
135
|
' a = 1',
|
|
139
136
|
' #a = 2',
|
|
@@ -9,14 +9,13 @@ module Rubocop
|
|
|
9
9
|
|
|
10
10
|
it 'registers an offence for an old lambda call' do
|
|
11
11
|
inspect_source(lambda_literal, 'file.rb', ['f = lambda { |x| x }'])
|
|
12
|
-
expect(lambda_literal.offences.
|
|
13
|
-
['The new lambda literal syntax is preferred in Ruby 1.9.'])
|
|
12
|
+
expect(lambda_literal.offences.size).to eq(1)
|
|
14
13
|
end
|
|
15
14
|
|
|
16
15
|
it 'accepts the new lambda literal' do
|
|
17
16
|
inspect_source(lambda_literal, 'file.rb', ['lambda = ->(x) { x }',
|
|
18
17
|
'lambda.(1)'])
|
|
19
|
-
expect(lambda_literal.offences
|
|
18
|
+
expect(lambda_literal.offences).to be_empty
|
|
20
19
|
end
|
|
21
20
|
end
|
|
22
21
|
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
module Rubocop
|
|
6
|
+
module Cop
|
|
7
|
+
describe Not do
|
|
8
|
+
let(:a) { Not.new }
|
|
9
|
+
|
|
10
|
+
it 'registers an offence for not' do
|
|
11
|
+
inspect_source(a,
|
|
12
|
+
'file.rb',
|
|
13
|
+
['not test'])
|
|
14
|
+
expect(a.offences.size).to eq(1)
|
|
15
|
+
expect(a.offences.map(&:message))
|
|
16
|
+
.to eq([Not::ERROR_MESSAGE])
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'does not register an offence for !' do
|
|
20
|
+
inspect_source(a,
|
|
21
|
+
'file.rb',
|
|
22
|
+
['!test'])
|
|
23
|
+
expect(a.offences).to be_empty
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it 'does not register an offence for :not' do
|
|
27
|
+
inspect_source(a,
|
|
28
|
+
'file.rb',
|
|
29
|
+
['[:not, :if, :else]'])
|
|
30
|
+
expect(a.offences).to be_empty
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -24,6 +24,13 @@ module Rubocop
|
|
|
24
24
|
|
|
25
25
|
expect(offence.to_s).to eq('C: 1: message % test')
|
|
26
26
|
end
|
|
27
|
+
|
|
28
|
+
it 'redefines == to compare offences based on their contents' do
|
|
29
|
+
o1 = Offence.new(:test, 1, 'message')
|
|
30
|
+
o2 = Offence.new(:test, 1, 'message')
|
|
31
|
+
|
|
32
|
+
expect(o1 == o2).to be_true
|
|
33
|
+
end
|
|
27
34
|
end
|
|
28
35
|
end
|
|
29
36
|
end
|
|
@@ -18,6 +18,17 @@ module Rubocop
|
|
|
18
18
|
.to eq([sprintf(OpMethod::ERROR_MESSAGE, '+')])
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
+
it 'works properly even if the argument is not surrounded with braces' do
|
|
22
|
+
inspect_source(om,
|
|
23
|
+
'file.rb',
|
|
24
|
+
['def + another',
|
|
25
|
+
' another',
|
|
26
|
+
'end'])
|
|
27
|
+
expect(om.offences.size).to eq(1)
|
|
28
|
+
expect(om.offences.map(&:message))
|
|
29
|
+
.to eq([sprintf(OpMethod::ERROR_MESSAGE, '+')])
|
|
30
|
+
end
|
|
31
|
+
|
|
21
32
|
it 'does not register an offence for arg named other' do
|
|
22
33
|
inspect_source(om,
|
|
23
34
|
'file.rb',
|