rubocop 0.3.2 → 0.4.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.
- data/.rubocop.yml +6 -0
- data/README.md +18 -6
- data/VERSION +1 -1
- data/bin/rubocop +1 -1
- data/lib/rubocop.rb +3 -0
- data/lib/rubocop/cli.rb +33 -16
- data/lib/rubocop/cop/collection_methods.rb +29 -0
- data/lib/rubocop/cop/cop.rb +1 -1
- data/lib/rubocop/cop/def_parentheses.rb +4 -1
- data/lib/rubocop/cop/encoding.rb +6 -4
- data/lib/rubocop/cop/favor_modifier.rb +5 -5
- data/lib/rubocop/cop/indentation.rb +1 -1
- data/lib/rubocop/cop/syntax.rb +19 -0
- data/lib/rubocop/version.rb +1 -1
- data/rubocop.gemspec +6 -5
- data/spec/rubocop/cli_spec.rb +98 -52
- data/spec/rubocop/cops/align_parameters_spec.rb +29 -29
- data/spec/rubocop/cops/ampersands_pipes_vs_and_or_spec.rb +4 -4
- data/spec/rubocop/cops/class_and_module_camel_case_spec.rb +4 -4
- data/spec/rubocop/cops/collection_methods_spec.rb +39 -0
- data/spec/rubocop/cops/cop_spec.rb +5 -5
- data/spec/rubocop/cops/def_with_parentheses_spec.rb +5 -5
- data/spec/rubocop/cops/def_without_parentheses_spec.rb +4 -4
- data/spec/rubocop/cops/empty_lines_spec.rb +8 -8
- data/spec/rubocop/cops/encoding_spec.rb +17 -11
- data/spec/rubocop/cops/end_of_line_spec.rb +5 -5
- data/spec/rubocop/cops/favor_modifier_spec.rb +12 -12
- data/spec/rubocop/cops/favor_unless_over_negated_if_spec.rb +8 -8
- data/spec/rubocop/cops/favor_until_over_negated_while_spec.rb +7 -7
- data/spec/rubocop/cops/grammar_spec.rb +14 -9
- data/spec/rubocop/cops/hash_syntax_spec.rb +10 -10
- data/spec/rubocop/cops/if_with_semicolon_spec.rb +3 -3
- data/spec/rubocop/cops/indentation_spec.rb +7 -7
- data/spec/rubocop/cops/line_length_spec.rb +4 -4
- data/spec/rubocop/cops/method_and_variable_snake_case_spec.rb +7 -7
- data/spec/rubocop/cops/multiline_blocks_spec.rb +4 -4
- data/spec/rubocop/cops/multiline_if_then_spec.rb +7 -7
- data/spec/rubocop/cops/new_lambda_literal_spec.rb +4 -4
- data/spec/rubocop/cops/numeric_literals_spec.rb +10 -10
- data/spec/rubocop/cops/offence_spec.rb +4 -4
- data/spec/rubocop/cops/one_line_conditional_spec.rb +2 -3
- data/spec/rubocop/cops/parameter_lists_spec.rb +4 -4
- data/spec/rubocop/cops/parentheses_around_condition_spec.rb +6 -6
- data/spec/rubocop/cops/single_line_blocks_spec.rb +4 -4
- data/spec/rubocop/cops/space_after_colon_spec.rb +5 -5
- data/spec/rubocop/cops/space_after_comma_spec.rb +3 -3
- data/spec/rubocop/cops/space_after_semicolon_spec.rb +3 -3
- data/spec/rubocop/cops/space_around_braces_spec.rb +6 -6
- data/spec/rubocop/cops/space_around_equals_in_default_parameter_spec.rb +4 -4
- data/spec/rubocop/cops/space_around_operators_spec.rb +28 -28
- data/spec/rubocop/cops/space_inside_brackets_spec.rb +8 -8
- data/spec/rubocop/cops/space_inside_parens_spec.rb +4 -4
- data/spec/rubocop/cops/string_literals_spec.rb +5 -5
- data/spec/rubocop/cops/syntax_spec.rb +18 -0
- data/spec/rubocop/cops/tab_spec.rb +3 -3
- data/spec/rubocop/cops/ternary_operator_spec.rb +8 -8
- data/spec/rubocop/cops/trailing_whitespace_spec.rb +4 -4
- data/spec/rubocop/cops/unless_else_spec.rb +4 -4
- data/spec/rubocop/cops/when_then_spec.rb +5 -5
- data/spec/rubocop/reports/emacs_style_spec.rb +3 -3
- data/spec/rubocop/reports/report_spec.rb +5 -5
- data/spec/spec_helper.rb +6 -0
- metadata +7 -6
- data/features/rubocop.feature +0 -9
- data/features/step_definitions/rubocop_steps.rb +0 -1
- data/features/support/env.rb +0 -15
@@ -5,12 +5,12 @@ require 'spec_helper'
|
|
5
5
|
module Rubocop
|
6
6
|
module Cop
|
7
7
|
describe SpaceAroundOperators do
|
8
|
-
let
|
8
|
+
let(:space) { SpaceAroundOperators.new }
|
9
9
|
|
10
10
|
it 'registers an offence for assignment without space on both sides' do
|
11
11
|
inspect_source(space, 'file.rb', ['x=0', 'y= 0', 'z =0'])
|
12
|
-
space.offences.map(&:message).
|
13
|
-
["Surrounding space missing for operator '='."] * 3
|
12
|
+
expect(space.offences.map(&:message)).to eq(
|
13
|
+
["Surrounding space missing for operator '='."] * 3)
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'registers an offence in presence of modifier if statement' do
|
@@ -33,59 +33,59 @@ module Rubocop
|
|
33
33
|
src = ["a=1 #{keyword} condition",
|
34
34
|
'c=2']
|
35
35
|
inspect_source(space, 'file.rb', src)
|
36
|
-
space.offences.map(&:line_number).
|
37
|
-
space.offences.map(&:message).
|
38
|
-
["Surrounding space missing for operator '='."] * 2
|
36
|
+
expect(space.offences.map(&:line_number)).to eq([1, 2])
|
37
|
+
expect(space.offences.map(&:message)).to eq(
|
38
|
+
["Surrounding space missing for operator '='."] * 2)
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'registers an offence for binary operators that could be unary' do
|
42
42
|
inspect_source(space, 'file.rb', ['a-3', 'x&0xff', 'z+0'])
|
43
|
-
space.offences.map(&:message).
|
43
|
+
expect(space.offences.map(&:message)).to eq(
|
44
44
|
["Surrounding space missing for operator '-'.",
|
45
45
|
"Surrounding space missing for operator '&'.",
|
46
|
-
"Surrounding space missing for operator '+'."]
|
46
|
+
"Surrounding space missing for operator '+'."])
|
47
47
|
end
|
48
48
|
|
49
49
|
it 'registers an offence for arguments to a method' do
|
50
50
|
inspect_source(space, 'file.rb', ['puts 1+2'])
|
51
|
-
space.offences.map(&:message).
|
52
|
-
["Surrounding space missing for operator '+'."]
|
51
|
+
expect(space.offences.map(&:message)).to eq(
|
52
|
+
["Surrounding space missing for operator '+'."])
|
53
53
|
end
|
54
54
|
|
55
55
|
it 'accepts operator symbols' do
|
56
56
|
inspect_source(space, 'file.rb', ['func(:-)'])
|
57
|
-
space.offences.map(&:message).
|
57
|
+
expect(space.offences.map(&:message)).to be_empty
|
58
58
|
end
|
59
59
|
|
60
60
|
it 'accepts ranges' do
|
61
61
|
inspect_source(space, 'file.rb', ['a, b = (1..2), (1...3)'])
|
62
|
-
space.offences.map(&:message).
|
62
|
+
expect(space.offences.map(&:message)).to be_empty
|
63
63
|
end
|
64
64
|
|
65
65
|
it 'accepts scope operator' do
|
66
66
|
source = ['@io.class == Zlib::GzipWriter']
|
67
67
|
inspect_source(space, 'file.rb', source)
|
68
|
-
space.offences.map(&:message).
|
68
|
+
expect(space.offences.map(&:message)).to be_empty
|
69
69
|
end
|
70
70
|
|
71
71
|
it 'accepts ::Kernel::raise' do
|
72
72
|
source = ['::Kernel::raise IllegalBlockError.new']
|
73
73
|
inspect_source(space, 'file.rb', source)
|
74
|
-
space.offences.map(&:message).
|
74
|
+
expect(space.offences.map(&:message)).to be_empty
|
75
75
|
end
|
76
76
|
|
77
77
|
it 'accepts exclamation point negation' do
|
78
78
|
inspect_source(space, 'file.rb', ['x = !a&&!b'])
|
79
|
-
space.offences.map(&:message).
|
80
|
-
["Surrounding space missing for operator '&&'."]
|
79
|
+
expect(space.offences.map(&:message)).to eq(
|
80
|
+
["Surrounding space missing for operator '&&'."])
|
81
81
|
end
|
82
82
|
|
83
83
|
it 'accepts exclamation point definition' do
|
84
84
|
inspect_source(space, 'file.rb', [' def !',
|
85
85
|
' !__getobj__',
|
86
86
|
' end'])
|
87
|
-
space.offences.
|
88
|
-
space.offences.map(&:message).
|
87
|
+
expect(space.offences).to be_empty
|
88
|
+
expect(space.offences.map(&:message)).to be_empty
|
89
89
|
end
|
90
90
|
|
91
91
|
it 'accepts a unary' do
|
@@ -95,52 +95,52 @@ module Rubocop
|
|
95
95
|
' *labels, &blk)',
|
96
96
|
' end',
|
97
97
|
''])
|
98
|
-
space.offences.map(&:message).
|
98
|
+
expect(space.offences.map(&:message)).to be_empty
|
99
99
|
end
|
100
100
|
|
101
101
|
it 'accepts splat operator' do
|
102
102
|
inspect_source(space, 'file.rb', ['return *list if options'])
|
103
|
-
space.offences.map(&:message).
|
103
|
+
expect(space.offences.map(&:message)).to be_empty
|
104
104
|
end
|
105
105
|
|
106
106
|
it 'accepts def of operator' do
|
107
107
|
inspect_source(space, 'file.rb', ['def +(other); end'])
|
108
|
-
space.offences.map(&:message).
|
108
|
+
expect(space.offences.map(&:message)).to be_empty
|
109
109
|
end
|
110
110
|
|
111
111
|
it 'accepts an assignment with spaces' do
|
112
112
|
inspect_source(space, 'file.rb', ['x = 0'])
|
113
|
-
space.offences.
|
113
|
+
expect(space.offences).to be_empty
|
114
114
|
end
|
115
115
|
|
116
116
|
it "accepts some operators that are exceptions and don't need spaces" do
|
117
117
|
inspect_source(space, 'file.rb', ['(1..3)',
|
118
118
|
'ActionController::Base',
|
119
119
|
'each { |s, t| }'])
|
120
|
-
space.offences.map(&:message).
|
120
|
+
expect(space.offences.map(&:message)).to be_empty
|
121
121
|
end
|
122
122
|
|
123
123
|
it 'accepts an assignment followed by newline' do
|
124
124
|
inspect_source(space, 'file.rb', ['x =\n 0'])
|
125
|
-
space.offences.
|
125
|
+
expect(space.offences).to be_empty
|
126
126
|
end
|
127
127
|
|
128
128
|
it 'registers an offences for exponent operator with spaces' do
|
129
129
|
inspect_source(space, 'file.rb', ['x = a * b ** 2'])
|
130
|
-
space.offences.map(&:message).
|
131
|
-
['Space around operator ** detected.']
|
130
|
+
expect(space.offences.map(&:message)).to eq(
|
131
|
+
['Space around operator ** detected.'])
|
132
132
|
end
|
133
133
|
|
134
134
|
it 'accepts exponent operator without spaces' do
|
135
135
|
inspect_source(space, 'file.rb', ['x = a * b**2'])
|
136
|
-
space.offences.
|
136
|
+
expect(space.offences).to be_empty
|
137
137
|
end
|
138
138
|
|
139
139
|
it 'accepts unary operators without space' do
|
140
140
|
inspect_source(space, 'file.rb', ['[].map(&:size)',
|
141
141
|
'-3',
|
142
142
|
'x = +2'])
|
143
|
-
space.offences.map(&:message).
|
143
|
+
expect(space.offences.map(&:message)).to be_empty
|
144
144
|
end
|
145
145
|
end
|
146
146
|
end
|
@@ -5,38 +5,38 @@ require 'spec_helper'
|
|
5
5
|
module Rubocop
|
6
6
|
module Cop
|
7
7
|
describe SpaceInsideBrackets do
|
8
|
-
let
|
8
|
+
let(:space) { SpaceInsideBrackets.new }
|
9
9
|
|
10
10
|
it 'registers an offence for an array literal with spaces inside' do
|
11
11
|
inspect_source(space, 'file.rb', ['a = [1, 2 ]',
|
12
12
|
'b = [ 1, 2]'])
|
13
|
-
space.offences.map(&:message).
|
13
|
+
expect(space.offences.map(&:message)).to eq(
|
14
14
|
['Space inside square brackets detected.',
|
15
|
-
'Space inside square brackets detected.']
|
15
|
+
'Space inside square brackets detected.'])
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'accepts space inside square brackets if on its own row' do
|
19
19
|
inspect_source(space, 'file.rb', ['a = [',
|
20
20
|
' 1, 2',
|
21
21
|
' ]'])
|
22
|
-
space.offences.map(&:message).
|
22
|
+
expect(space.offences.map(&:message)).to be_empty
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'accepts square brackets as method name' do
|
26
26
|
inspect_source(space, 'file.rb', ['def Vector.[](*array)',
|
27
27
|
'end'])
|
28
|
-
space.offences.map(&:message).
|
28
|
+
expect(space.offences.map(&:message)).to be_empty
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'accepts square brackets called with method call syntax' do
|
32
32
|
inspect_source(space, 'file.rb', ['subject.[](0)'])
|
33
|
-
space.offences.map(&:message).
|
33
|
+
expect(space.offences.map(&:message)).to be_empty
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'only reports a single space once' do
|
37
37
|
inspect_source(space, 'file.rb', ['[ ]'])
|
38
|
-
space.offences.map(&:message).
|
39
|
-
['Space inside square brackets detected.']
|
38
|
+
expect(space.offences.map(&:message)).to eq(
|
39
|
+
['Space inside square brackets detected.'])
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
@@ -5,21 +5,21 @@ require 'spec_helper'
|
|
5
5
|
module Rubocop
|
6
6
|
module Cop
|
7
7
|
describe SpaceInsideParens do
|
8
|
-
let
|
8
|
+
let(:space) { SpaceInsideParens.new }
|
9
9
|
|
10
10
|
it 'registers an offence for spaces inside parens' do
|
11
11
|
inspect_source(space, 'file.rb', ['f( 3)',
|
12
12
|
'g(3 )'])
|
13
|
-
space.offences.map(&:message).
|
13
|
+
expect(space.offences.map(&:message)).to eq(
|
14
14
|
['Space inside parentheses detected.',
|
15
|
-
'Space inside parentheses detected.']
|
15
|
+
'Space inside parentheses detected.'])
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'accepts parentheses in block parameter list' do
|
19
19
|
inspect_source(space, 'file.rb',
|
20
20
|
['list.inject(Tms.new) { |sum, (label, item)|',
|
21
21
|
'}'])
|
22
|
-
space.offences.map(&:message).
|
22
|
+
expect(space.offences.map(&:message)).to be_empty
|
23
23
|
end
|
24
24
|
|
25
25
|
end
|
@@ -5,13 +5,13 @@ require 'spec_helper'
|
|
5
5
|
module Rubocop
|
6
6
|
module Cop
|
7
7
|
describe StringLiterals do
|
8
|
-
let
|
8
|
+
let(:sl) { StringLiterals.new }
|
9
9
|
|
10
10
|
it 'registers an offence for double quotes when single quotes suffice' do
|
11
11
|
inspect_source(sl, 'file.rb', ['s = "abc"'])
|
12
|
-
sl.offences.map(&:message).
|
12
|
+
expect(sl.offences.map(&:message)).to eq(
|
13
13
|
["Prefer single-quoted strings when you don't need string " +
|
14
|
-
'interpolation or special symbols.']
|
14
|
+
'interpolation or special symbols.'])
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'accepts double quotes when they are needed' do
|
@@ -19,13 +19,13 @@ module Rubocop
|
|
19
19
|
'b = "#{encode_severity}:#{sprintf("%3d", line_number)}: #{m}"',
|
20
20
|
'c = "\'"']
|
21
21
|
inspect_source(sl, 'file.rb', src)
|
22
|
-
sl.offences.map(&:message).
|
22
|
+
expect(sl.offences.map(&:message)).to be_empty
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'can handle double quotes within embedded expression' do
|
26
26
|
src = ['"#{"A"}"']
|
27
27
|
inspect_source(sl, 'file.rb', src)
|
28
|
-
sl.offences.map(&:message).
|
28
|
+
expect(sl.offences.map(&:message)).to be_empty
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
module Rubocop
|
6
|
+
module Cop
|
7
|
+
describe Syntax do
|
8
|
+
let(:sc) { Syntax.new }
|
9
|
+
|
10
|
+
it 'registers an offence for unused variables', ruby: 2.0 do
|
11
|
+
sc.inspect('file.rb', ['x = 5', 'puts 10'], nil, nil)
|
12
|
+
expect(sc.offences.size).to eq(1)
|
13
|
+
expect(sc.offences.first.message)
|
14
|
+
.to eq('Assigned but unused variable - x')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -5,16 +5,16 @@ require 'spec_helper'
|
|
5
5
|
module Rubocop
|
6
6
|
module Cop
|
7
7
|
describe Tab do
|
8
|
-
let
|
8
|
+
let(:tab) { Tab.new }
|
9
9
|
|
10
10
|
it 'registers an offence for a line indented with tab' do
|
11
11
|
tab.inspect('file.rb', ["\tx = 0"], nil, nil)
|
12
|
-
tab.offences.size.
|
12
|
+
expect(tab.offences.size).to eq(1)
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'accepts a line with tab in a string' do
|
16
16
|
tab.inspect('file.rb', [%Q(x = "\t")], nil, nil)
|
17
|
-
tab.offences.
|
17
|
+
expect(tab.offences).to be_empty
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -5,30 +5,30 @@ require 'spec_helper'
|
|
5
5
|
module Rubocop
|
6
6
|
module Cop
|
7
7
|
describe MultilineTernaryOperator do
|
8
|
-
let
|
8
|
+
let(:op) { MultilineTernaryOperator.new }
|
9
9
|
|
10
10
|
it 'registers an offence for a multiline ternary operator expression' do
|
11
11
|
inspect_source(op, 'file.rb', ['a = cond ?',
|
12
12
|
' b : c'])
|
13
|
-
op.offences.map(&:message).
|
13
|
+
expect(op.offences.map(&:message)).to eq(
|
14
14
|
['Avoid multi-line ?: (the ternary operator); use if/unless ' +
|
15
|
-
'instead.']
|
15
|
+
'instead.'])
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'accepts a single line ternary operator expression' do
|
19
19
|
inspect_source(op, 'file.rb', ['a = cond ? b : c'])
|
20
|
-
op.offences.map(&:message).
|
20
|
+
expect(op.offences.map(&:message)).to be_empty
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
24
|
describe NestedTernaryOperator do
|
25
|
-
let
|
25
|
+
let(:op) { NestedTernaryOperator.new }
|
26
26
|
|
27
27
|
it 'registers an offence for a nested ternary operator expression' do
|
28
28
|
inspect_source(op, 'file.rb', ['a ? (b ? b1 : b2) : a2'])
|
29
|
-
op.offences.map(&:message).
|
29
|
+
expect(op.offences.map(&:message)).to eq(
|
30
30
|
['Ternary operators must not be nested. Prefer if/else constructs ' +
|
31
|
-
'instead.']
|
31
|
+
'instead.'])
|
32
32
|
end
|
33
33
|
|
34
34
|
it 'accepts a non-nested ternary operator within an if' do
|
@@ -37,7 +37,7 @@ module Rubocop
|
|
37
37
|
'else',
|
38
38
|
' d',
|
39
39
|
'end'])
|
40
|
-
op.offences.map(&:message).
|
40
|
+
expect(op.offences.map(&:message)).to be_empty
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
@@ -5,22 +5,22 @@ require 'spec_helper'
|
|
5
5
|
module Rubocop
|
6
6
|
module Cop
|
7
7
|
describe TrailingWhitespace do
|
8
|
-
let
|
8
|
+
let(:tws) { TrailingWhitespace.new }
|
9
9
|
|
10
10
|
it 'registers an offence for a line ending with space' do
|
11
11
|
source = ['x = 0 ']
|
12
12
|
tws.inspect('file.rb', source, nil, nil)
|
13
|
-
tws.offences.size.
|
13
|
+
expect(tws.offences.size).to eq(1)
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'registers an offence for a line ending with tab' do
|
17
17
|
tws.inspect('file.rb', ["x = 0\t"], nil, nil)
|
18
|
-
tws.offences.size.
|
18
|
+
expect(tws.offences.size).to eq(1)
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'accepts a line without trailing whitespace' do
|
22
22
|
tws.inspect('file.rb', ["x = 0\n"], nil, nil)
|
23
|
-
tws.offences.
|
23
|
+
expect(tws.offences).to be_empty
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
@@ -5,7 +5,7 @@ require 'spec_helper'
|
|
5
5
|
module Rubocop
|
6
6
|
module Cop
|
7
7
|
describe UnlessElse do
|
8
|
-
let
|
8
|
+
let(:ue) { UnlessElse.new }
|
9
9
|
|
10
10
|
it 'registers an offence for an unless with else' do
|
11
11
|
inspect_source(ue, 'file.rb', ['unless x',
|
@@ -13,16 +13,16 @@ module Rubocop
|
|
13
13
|
'else',
|
14
14
|
' a = 0',
|
15
15
|
'end'])
|
16
|
-
ue.offences.map(&:message).
|
16
|
+
expect(ue.offences.map(&:message)).to eq(
|
17
17
|
['Never use unless with else. Rewrite these with the ' +
|
18
|
-
'positive case first.']
|
18
|
+
'positive case first.'])
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'accepts an unless without else' do
|
22
22
|
inspect_source(ue, 'file.rb', ['unless x',
|
23
23
|
' a = 1',
|
24
24
|
'end'])
|
25
|
-
ue.offences.map(&:message).
|
25
|
+
expect(ue.offences.map(&:message)).to be_empty
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
@@ -5,21 +5,21 @@ require 'spec_helper'
|
|
5
5
|
module Rubocop
|
6
6
|
module Cop
|
7
7
|
describe WhenThen do
|
8
|
-
let
|
8
|
+
let(:wt) { WhenThen.new }
|
9
9
|
|
10
10
|
it 'registers an offence for when x;' do
|
11
11
|
inspect_source(wt, 'file.rb', ['case a',
|
12
12
|
'when b; c',
|
13
13
|
'end'])
|
14
|
-
wt.offences.map(&:message).
|
15
|
-
['Never use "when x;". Use "when x then" instead.']
|
14
|
+
expect(wt.offences.map(&:message)).to eq(
|
15
|
+
['Never use "when x;". Use "when x then" instead.'])
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'accepts when x then' do
|
19
19
|
inspect_source(wt, 'file.rb', ['case a',
|
20
20
|
'when b then c',
|
21
21
|
'end'])
|
22
|
-
wt.offences.map(&:message).
|
22
|
+
expect(wt.offences.map(&:message)).to be_empty
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'accepts ; separating statements in the body of when' do
|
@@ -31,7 +31,7 @@ module Rubocop
|
|
31
31
|
'when f',
|
32
32
|
' g; h',
|
33
33
|
'end'])
|
34
|
-
wt.offences.map(&:message).
|
34
|
+
expect(wt.offences.map(&:message)).to be_empty
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
@@ -6,7 +6,7 @@ require 'stringio'
|
|
6
6
|
module Rubocop
|
7
7
|
module Report
|
8
8
|
describe EmacsStyle do
|
9
|
-
let
|
9
|
+
let(:emacs_style) { Rubocop::Report.create('test', :emacs_style) }
|
10
10
|
|
11
11
|
it 'displays parsable text' do
|
12
12
|
cop = Cop::Cop.new
|
@@ -17,8 +17,8 @@ module Rubocop
|
|
17
17
|
|
18
18
|
s = StringIO.new
|
19
19
|
emacs_style.display(s)
|
20
|
-
s.string.
|
21
|
-
|
20
|
+
expect(s.string).to eq ['test:1: C: message 1',
|
21
|
+
"test:11: F: message 2\n"].join("\n")
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|