rubocop 0.25.0 → 0.26.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 +3 -0
- data/CHANGELOG.md +37 -0
- data/README.md +2 -2
- data/assets/output.html.erb +190 -0
- data/config/default.yml +14 -2
- data/config/disabled.yml +7 -0
- data/config/enabled.yml +132 -5
- data/lib/rubocop.rb +5 -0
- data/lib/rubocop/cop/commissioner.rb +4 -10
- data/lib/rubocop/cop/lint/assignment_in_condition.rb +1 -1
- data/lib/rubocop/cop/lint/end_in_method.rb +3 -8
- data/lib/rubocop/cop/lint/ensure_return.rb +2 -2
- data/lib/rubocop/cop/lint/space_before_first_arg.rb +8 -1
- data/lib/rubocop/cop/lint/useless_assignment.rb +35 -0
- data/lib/rubocop/cop/lint/useless_setter_call.rb +2 -3
- data/lib/rubocop/cop/metrics/block_nesting.rb +3 -3
- data/lib/rubocop/cop/metrics/class_length.rb +1 -2
- data/lib/rubocop/cop/mixin/access_modifier_node.rb +5 -1
- data/lib/rubocop/cop/mixin/autocorrect_alignment.rb +2 -2
- data/lib/rubocop/cop/mixin/configurable_naming.rb +2 -2
- data/lib/rubocop/cop/mixin/method_complexity.rb +2 -4
- data/lib/rubocop/cop/mixin/statement_modifier.rb +1 -3
- data/lib/rubocop/cop/rails/delegate.rb +1 -1
- data/lib/rubocop/cop/rails/validation.rb +25 -2
- data/lib/rubocop/cop/style/alias.rb +1 -1
- data/lib/rubocop/cop/style/and_or.rb +12 -2
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +19 -12
- data/lib/rubocop/cop/style/documentation.rb +1 -1
- data/lib/rubocop/cop/style/dot_position.rb +20 -0
- data/lib/rubocop/cop/style/empty_lines_around_access_modifier.rb +5 -1
- data/lib/rubocop/cop/style/encoding.rb +4 -4
- data/lib/rubocop/cop/style/format_string.rb +12 -2
- data/lib/rubocop/cop/style/if_unless_modifier.rb +8 -11
- data/lib/rubocop/cop/style/infinite_loop.rb +57 -0
- data/lib/rubocop/cop/style/multiline_block_chain.rb +15 -16
- data/lib/rubocop/cop/style/multiline_if_then.rb +10 -0
- data/lib/rubocop/cop/style/nested_ternary_operator.rb +3 -3
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +3 -1
- data/lib/rubocop/cop/style/predicate_name.rb +23 -5
- data/lib/rubocop/cop/style/redundant_begin.rb +1 -1
- data/lib/rubocop/cop/style/single_line_block_params.rb +1 -1
- data/lib/rubocop/cop/style/space_around_equals_in_parameter_default.rb +4 -8
- data/lib/rubocop/cop/style/space_inside_hash_literal_braces.rb +9 -11
- data/lib/rubocop/cop/style/space_inside_range_literal.rb +58 -0
- data/lib/rubocop/cop/style/special_global_vars.rb +1 -1
- data/lib/rubocop/cop/style/symbol_proc.rb +71 -0
- data/lib/rubocop/cop/style/tab.rb +11 -3
- data/lib/rubocop/cop/style/unneeded_capital_w.rb +6 -2
- data/lib/rubocop/cop/style/variable_name.rb +4 -14
- data/lib/rubocop/cop/style/while_until_modifier.rb +12 -8
- data/lib/rubocop/cop/variable_force.rb +17 -30
- data/lib/rubocop/cop/variable_force/assignment.rb +15 -23
- data/lib/rubocop/cop/variable_force/locatable.rb +29 -8
- data/lib/rubocop/cop/variable_force/scope.rb +34 -23
- data/lib/rubocop/cop/variable_force/variable.rb +7 -10
- data/lib/rubocop/formatter/disabled_config_formatter.rb +3 -2
- data/lib/rubocop/formatter/formatter_set.rb +1 -0
- data/lib/rubocop/formatter/fuubar_style_formatter.rb +1 -1
- data/lib/rubocop/formatter/html_formatter.rb +90 -0
- data/lib/rubocop/formatter/progress_formatter.rb +1 -1
- data/lib/rubocop/options.rb +1 -0
- data/lib/rubocop/processed_source.rb +10 -1
- data/lib/rubocop/string_util.rb +153 -0
- data/lib/rubocop/target_finder.rb +1 -1
- data/lib/rubocop/version.rb +1 -1
- data/relnotes/v0.26.0.md +89 -0
- data/rubocop.gemspec +1 -0
- data/spec/rubocop/cli_spec.rb +60 -34
- data/spec/rubocop/config_loader_spec.rb +19 -15
- data/spec/rubocop/cop/commissioner_spec.rb +2 -2
- data/spec/rubocop/cop/lint/block_alignment_spec.rb +74 -58
- data/spec/rubocop/cop/lint/space_before_first_arg_spec.rb +7 -0
- data/spec/rubocop/cop/lint/useless_assignment_spec.rb +173 -0
- data/spec/rubocop/cop/rails/validation_spec.rb +9 -2
- data/spec/rubocop/cop/style/access_modifier_indentation_spec.rb +26 -0
- data/spec/rubocop/cop/style/and_or_spec.rb +52 -61
- data/spec/rubocop/cop/style/braces_around_hash_parameters_spec.rb +26 -8
- data/spec/rubocop/cop/style/case_indentation_spec.rb +8 -8
- data/spec/rubocop/cop/style/def_with_parentheses_spec.rb +6 -2
- data/spec/rubocop/cop/style/dot_position_spec.rb +39 -0
- data/spec/rubocop/cop/style/empty_lines_around_access_modifier_spec.rb +12 -2
- data/spec/rubocop/cop/style/encoding_spec.rb +16 -28
- data/spec/rubocop/cop/style/format_string_spec.rb +12 -0
- data/spec/rubocop/cop/style/infinite_loop_spec.rb +48 -0
- data/spec/rubocop/cop/style/method_def_parentheses_spec.rb +3 -1
- data/spec/rubocop/cop/style/multiline_if_then_spec.rb +9 -0
- data/spec/rubocop/cop/style/percent_literal_delimiters_spec.rb +21 -1
- data/spec/rubocop/cop/style/predicate_name_spec.rb +44 -13
- data/spec/rubocop/cop/style/redundant_begin_spec.rb +32 -0
- data/spec/rubocop/cop/style/space_inside_range_literal_spec.rb +52 -0
- data/spec/rubocop/cop/style/symbol_proc_spec.rb +76 -0
- data/spec/rubocop/cop/style/tab_spec.rb +30 -0
- data/spec/rubocop/cop/style/trailing_whitespace_spec.rb +2 -1
- data/spec/rubocop/cop/style/unneeded_capital_w_spec.rb +18 -5
- data/spec/rubocop/cop/style/variable_name_spec.rb +5 -5
- data/spec/rubocop/cop/style/when_then_spec.rb +3 -1
- data/spec/rubocop/cop/style/while_until_do_spec.rb +4 -2
- data/spec/rubocop/cop/util_spec.rb +1 -9
- data/spec/rubocop/cop/variable_force/assignment_spec.rb +2 -15
- data/spec/rubocop/cop/variable_force/locatable_spec.rb +2 -37
- data/spec/rubocop/cop/variable_force/scope_spec.rb +156 -49
- data/spec/rubocop/cop/variable_force/variable_spec.rb +2 -1
- data/spec/rubocop/cop/variable_force_spec.rb +2 -1
- data/spec/rubocop/formatter/emacs_style_formatter_spec.rb +2 -1
- data/spec/rubocop/formatter/html_formatter_spec.rb +145 -0
- data/spec/rubocop/formatter/simple_text_formatter_spec.rb +18 -6
- data/spec/rubocop/options_spec.rb +1 -0
- data/spec/rubocop/path_util_spec.rb +6 -4
- data/spec/rubocop/processed_source_spec.rb +17 -1
- data/spec/rubocop/string_util_spec.rb +46 -0
- metadata +33 -4
- data/spec/support/ast_helper.rb +0 -15
@@ -127,6 +127,18 @@ describe RuboCop::Cop::Style::FormatString, :config do
|
|
127
127
|
.to eq(['Favor `String#%` over `sprintf`.'])
|
128
128
|
end
|
129
129
|
|
130
|
+
it 'accepts format with 1 argument' do
|
131
|
+
inspect_source(cop,
|
132
|
+
['format :xml'])
|
133
|
+
expect(cop.offenses).to be_empty
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'accepts sprintf with 1 argument' do
|
137
|
+
inspect_source(cop,
|
138
|
+
['sprintf :xml'])
|
139
|
+
expect(cop.offenses).to be_empty
|
140
|
+
end
|
141
|
+
|
130
142
|
it 'accepts String#%' do
|
131
143
|
inspect_source(cop,
|
132
144
|
['puts "%d" % 10'])
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe RuboCop::Cop::Style::InfiniteLoop do
|
6
|
+
subject(:cop) { described_class.new }
|
7
|
+
|
8
|
+
%w(1 2.0 [1] {}).each do |lit|
|
9
|
+
it "registers an offense for a while loop with #{lit} as condition" do
|
10
|
+
inspect_source(cop,
|
11
|
+
["while #{lit}",
|
12
|
+
' top',
|
13
|
+
'end'
|
14
|
+
])
|
15
|
+
expect(cop.offenses.size).to eq(1)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
%w(false nil).each do |lit|
|
20
|
+
it "registers an offense for a until loop with #{lit} as condition" do
|
21
|
+
inspect_source(cop,
|
22
|
+
["until #{lit}",
|
23
|
+
' top',
|
24
|
+
'end'
|
25
|
+
])
|
26
|
+
expect(cop.offenses.size).to eq(1)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'accepts Kernel#loop' do
|
31
|
+
inspect_source(cop,
|
32
|
+
['loop { break if something }'])
|
33
|
+
|
34
|
+
expect(cop.offenses).to be_empty
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'auto-corrects the usage of "while/until" with do' do
|
38
|
+
new_source = autocorrect_source(cop, ['while true do',
|
39
|
+
'end'])
|
40
|
+
expect(new_source).to eq("loop do\nend")
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'auto-corrects the usage of "while/until" without do' do
|
44
|
+
new_source = autocorrect_source(cop, ['while 1',
|
45
|
+
'end'])
|
46
|
+
expect(new_source).to eq("loop do\nend")
|
47
|
+
end
|
48
|
+
end
|
@@ -53,7 +53,9 @@ describe RuboCop::Cop::Style::MethodDefParentheses, :config do
|
|
53
53
|
|
54
54
|
it 'auto-adds required parens to argument lists on multiple lines' do
|
55
55
|
new_source = autocorrect_source(cop, ['def test one,', 'two', 'end'])
|
56
|
-
expect(new_source).to eq(
|
56
|
+
expect(new_source).to eq(['def test(one,',
|
57
|
+
'two)',
|
58
|
+
'end'].join("\n"))
|
57
59
|
end
|
58
60
|
end
|
59
61
|
|
@@ -104,4 +104,13 @@ describe RuboCop::Cop::Style::MultilineIfThen do
|
|
104
104
|
'end'])
|
105
105
|
end.not_to raise_error
|
106
106
|
end
|
107
|
+
|
108
|
+
it 'auto-corrects the usage of "then" in multiline if' do
|
109
|
+
new_source = autocorrect_source(cop, ['if cond then',
|
110
|
+
' something',
|
111
|
+
'end'])
|
112
|
+
expect(new_source).to eq(['if cond',
|
113
|
+
' something',
|
114
|
+
'end'].join("\n"))
|
115
|
+
end
|
107
116
|
end
|
@@ -230,6 +230,23 @@ describe RuboCop::Cop::Style::PercentLiteralDelimiters, :config do
|
|
230
230
|
expect(new_source).to eq('%w[some words]')
|
231
231
|
end
|
232
232
|
|
233
|
+
it 'fixes a string array in a scope' do
|
234
|
+
new_source = autocorrect_source(cop, ['module Foo',
|
235
|
+
' class Bar',
|
236
|
+
' def baz',
|
237
|
+
' %(one two)',
|
238
|
+
' end',
|
239
|
+
' end',
|
240
|
+
' end'])
|
241
|
+
expect(new_source).to eq(['module Foo',
|
242
|
+
' class Bar',
|
243
|
+
' def baz',
|
244
|
+
' %[one two]',
|
245
|
+
' end',
|
246
|
+
' end',
|
247
|
+
' end'].join("\n"))
|
248
|
+
end
|
249
|
+
|
233
250
|
it 'fixes a regular expression' do
|
234
251
|
original_source = '%r(.*)'
|
235
252
|
new_source = autocorrect_source(cop, original_source)
|
@@ -256,7 +273,10 @@ describe RuboCop::Cop::Style::PercentLiteralDelimiters, :config do
|
|
256
273
|
|
257
274
|
it 'preserves line breaks when fixing a multiline array' do
|
258
275
|
new_source = autocorrect_source(cop, ['%w(', 'some', 'words', ')'])
|
259
|
-
expect(new_source).to eq(
|
276
|
+
expect(new_source).to eq(['%w[',
|
277
|
+
'some',
|
278
|
+
'words',
|
279
|
+
']'].join("\n"))
|
260
280
|
end
|
261
281
|
|
262
282
|
it 'preserves indentation when correcting a multiline array' do
|
@@ -4,23 +4,54 @@ require 'spec_helper'
|
|
4
4
|
|
5
5
|
describe RuboCop::Cop::Style::PredicateName, :config do
|
6
6
|
subject(:cop) { described_class.new(config) }
|
7
|
-
let(:cop_config) { { 'NamePrefixBlacklist' => %w(has_ is_) } }
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
context 'with blacklisted prefices' do
|
9
|
+
let(:cop_config) do
|
10
|
+
{ 'NamePrefix' => %w(has_ is_),
|
11
|
+
'NamePrefixBlacklist' => %w(has_ is_) }
|
12
|
+
end
|
13
|
+
|
14
|
+
%w(has is).each do |prefix|
|
15
|
+
it 'registers an offense when method name starts with known prefix' do
|
16
|
+
inspect_source(cop, ["def #{prefix}_attr",
|
17
|
+
' # ...',
|
18
|
+
'end'])
|
19
|
+
expect(cop.offenses.size).to eq(1)
|
20
|
+
expect(cop.messages).to eq(["Rename `#{prefix}_attr` to `attr?`."])
|
21
|
+
expect(cop.highlights).to eq(["#{prefix}_attr"])
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'accepts method name that starts with unknown prefix' do
|
26
|
+
inspect_source(cop, ['def have_attr',
|
12
27
|
' # ...',
|
13
28
|
'end'])
|
14
|
-
expect(cop.offenses
|
15
|
-
expect(cop.messages).to eq(["Rename `#{prefix}_attr` to `attr?`."])
|
16
|
-
expect(cop.highlights).to eq(["#{prefix}_attr"])
|
29
|
+
expect(cop.offenses).to be_empty
|
17
30
|
end
|
18
|
-
end
|
19
31
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
32
|
+
context 'with blacklisted prefices' do
|
33
|
+
let(:cop_config) do
|
34
|
+
{ 'NamePrefix' => %w(has_ is_), 'NamePrefixBlacklist' => [] }
|
35
|
+
end
|
36
|
+
|
37
|
+
%w(has is).each do |prefix|
|
38
|
+
it 'registers an offense when method name starts with known prefix' do
|
39
|
+
inspect_source(cop, ["def #{prefix}_attr",
|
40
|
+
' # ...',
|
41
|
+
'end'])
|
42
|
+
expect(cop.offenses.size).to eq(1)
|
43
|
+
expect(cop.messages)
|
44
|
+
.to eq(["Rename `#{prefix}_attr` to `#{prefix}_attr?`."])
|
45
|
+
expect(cop.highlights).to eq(["#{prefix}_attr"])
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'accepts method name that starts with unknown prefix' do
|
50
|
+
inspect_source(cop, ['def have_attr',
|
51
|
+
' # ...',
|
52
|
+
'end'])
|
53
|
+
expect(cop.offenses).to be_empty
|
54
|
+
end
|
55
|
+
end
|
25
56
|
end
|
26
57
|
end
|
@@ -86,4 +86,36 @@ describe RuboCop::Cop::Style::RedundantBegin do
|
|
86
86
|
new_source = autocorrect_source(cop, src)
|
87
87
|
expect(new_source).to eq(result_src)
|
88
88
|
end
|
89
|
+
|
90
|
+
it "doesn't modify spacing when auto-correcting" do
|
91
|
+
src = ['def method',
|
92
|
+
' begin',
|
93
|
+
' BlockA do |strategy|',
|
94
|
+
' foo',
|
95
|
+
' end',
|
96
|
+
'',
|
97
|
+
' BlockB do |portfolio|',
|
98
|
+
' foo',
|
99
|
+
' end',
|
100
|
+
'',
|
101
|
+
' rescue => e',
|
102
|
+
' bar',
|
103
|
+
' end',
|
104
|
+
'end']
|
105
|
+
|
106
|
+
result_src = ['def method',
|
107
|
+
' BlockA do |strategy|',
|
108
|
+
' foo',
|
109
|
+
' end',
|
110
|
+
'',
|
111
|
+
' BlockB do |portfolio|',
|
112
|
+
' foo',
|
113
|
+
' end',
|
114
|
+
'',
|
115
|
+
'rescue => e',
|
116
|
+
' bar',
|
117
|
+
'end'].join("\n")
|
118
|
+
new_source = autocorrect_source(cop, src)
|
119
|
+
expect(new_source).to eq(result_src)
|
120
|
+
end
|
89
121
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe RuboCop::Cop::Style::SpaceInsideRangeLiteral do
|
6
|
+
subject(:cop) { described_class.new }
|
7
|
+
|
8
|
+
it 'registers an offense for space inside .. literal' do
|
9
|
+
inspect_source(cop,
|
10
|
+
['1 .. 2',
|
11
|
+
'1.. 2',
|
12
|
+
'1 ..2'])
|
13
|
+
expect(cop.offenses.size).to eq(3)
|
14
|
+
expect(cop.messages)
|
15
|
+
.to eq(['Space inside range literal.'] * 3)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'accepts no space inside .. literal' do
|
19
|
+
inspect_source(cop, '1..2')
|
20
|
+
expect(cop.offenses).to be_empty
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'registers an offense for space inside ... literal' do
|
24
|
+
inspect_source(cop,
|
25
|
+
['1 ... 2',
|
26
|
+
'1... 2',
|
27
|
+
'1 ...2'])
|
28
|
+
expect(cop.offenses.size).to eq(3)
|
29
|
+
expect(cop.messages)
|
30
|
+
.to eq(['Space inside range literal.'] * 3)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'accepts no space inside ... literal' do
|
34
|
+
inspect_source(cop, '1...2')
|
35
|
+
expect(cop.offenses).to be_empty
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'accepts complex range literal with space in it' do
|
39
|
+
inspect_source(cop, '0...(line - 1)')
|
40
|
+
expect(cop.offenses).to be_empty
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'autocorrects space around .. literal' do
|
44
|
+
corrected = autocorrect_source(cop, ['1 .. 2'])
|
45
|
+
expect(corrected).to eq '1..2'
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'autocorrects space around ... literal' do
|
49
|
+
corrected = autocorrect_source(cop, ['1 ... 2'])
|
50
|
+
expect(corrected).to eq '1...2'
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe RuboCop::Cop::Style::SymbolProc, :config do
|
6
|
+
subject(:cop) { described_class.new(config) }
|
7
|
+
|
8
|
+
let(:cop_config) { { 'IgnoredMethods' => %w(respond_to) } }
|
9
|
+
|
10
|
+
it 'registers an offense for a block with paratermess method call on param' do
|
11
|
+
inspect_source(cop, 'coll.map { |e| e.upcase }')
|
12
|
+
expect(cop.offenses.size).to eq(1)
|
13
|
+
expect(cop.messages)
|
14
|
+
.to eq(['Pass `&:upcase` as an argument to `map` instead of a block.'])
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'registers an offense for a block when method in body is unary -/=' do
|
18
|
+
inspect_source(cop, ['something.map { |x| -x }'])
|
19
|
+
expect(cop.offenses.size).to eq(1)
|
20
|
+
expect(cop.messages)
|
21
|
+
.to eq(['Pass `&:-@` as an argument to `map` instead of a block.'])
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'accepts method receiving another argument beside the block' do
|
25
|
+
inspect_source(cop, ['File.open(file) { |f| f.readlines }'])
|
26
|
+
|
27
|
+
expect(cop.offenses).to be_empty
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'accepts block with more than 1 arguments' do
|
31
|
+
inspect_source(cop, ['something { |x, y| x.method }'])
|
32
|
+
|
33
|
+
expect(cop.offenses).to be_empty
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'accepts lambda with 1 argument' do
|
37
|
+
inspect_source(cop, ['->(x) { x.method }'])
|
38
|
+
|
39
|
+
expect(cop.offenses).to be_empty
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'accepts ignored method' do
|
43
|
+
inspect_source(cop, ['respond_to { |format| format.xml }'])
|
44
|
+
|
45
|
+
expect(cop.offenses).to be_empty
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'accepts block with no arguments' do
|
49
|
+
inspect_source(cop, ['something { x.method }'])
|
50
|
+
|
51
|
+
expect(cop.offenses).to be_empty
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'accepts empty block body' do
|
55
|
+
inspect_source(cop, ['something { |x| }'])
|
56
|
+
|
57
|
+
expect(cop.offenses).to be_empty
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'accepts block with more than 1 expression in body' do
|
61
|
+
inspect_source(cop, ['something { |x| x.method; something_else }'])
|
62
|
+
|
63
|
+
expect(cop.offenses).to be_empty
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'accepts block when method in body is not called on block arg' do
|
67
|
+
inspect_source(cop, ['something { |x| y.method }'])
|
68
|
+
|
69
|
+
expect(cop.offenses).to be_empty
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'autocorrects alias with symbols as proc' do
|
73
|
+
corrected = autocorrect_source(cop, ['coll.map { |s| s.upcase }'])
|
74
|
+
expect(corrected).to eq 'coll.map(&:upcase)'
|
75
|
+
end
|
76
|
+
end
|
@@ -10,8 +10,38 @@ describe RuboCop::Cop::Style::Tab do
|
|
10
10
|
expect(cop.offenses.size).to eq(1)
|
11
11
|
end
|
12
12
|
|
13
|
+
it 'registers an offence for a line indented with multiple tabs' do
|
14
|
+
inspect_source(cop, ["\t\t\tx = 0"])
|
15
|
+
expect(cop.offenses.size).to eq(1)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'registers an offence for a line indented with mixed whitespace' do
|
19
|
+
inspect_source(cop, [" \tx = 0"])
|
20
|
+
expect(cop.offenses.size).to eq(1)
|
21
|
+
end
|
22
|
+
|
13
23
|
it 'accepts a line with tab in a string' do
|
14
24
|
inspect_source(cop, ["(x = \"\t\")"])
|
15
25
|
expect(cop.offenses).to be_empty
|
16
26
|
end
|
27
|
+
|
28
|
+
it 'auto-corrects a line indented with tab' do
|
29
|
+
new_source = autocorrect_source(cop, ["\tx = 0"])
|
30
|
+
expect(new_source).to eq(' x = 0')
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'auto-corrects a line indented with multiple tabs' do
|
34
|
+
new_source = autocorrect_source(cop, ["\t\t\tx = 0"])
|
35
|
+
expect(new_source).to eq(' x = 0')
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'auto-corrects a line indented with mixed whitespace' do
|
39
|
+
new_source = autocorrect_source(cop, [" \tx = 0"])
|
40
|
+
expect(new_source).to eq(' x = 0')
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'auto-corrects a line with tab in a string indented with tab' do
|
44
|
+
new_source = autocorrect_source(cop, ["\t(x = \"\t\")"])
|
45
|
+
expect(new_source).to eq(" (x = \"\t\")")
|
46
|
+
end
|
17
47
|
end
|
@@ -29,6 +29,24 @@ describe RuboCop::Cop::Style::UnneededCapitalW do
|
|
29
29
|
expect(cop.offenses).to be_empty
|
30
30
|
end
|
31
31
|
|
32
|
+
it 'registers no offense for %W with special characters' do
|
33
|
+
source = ['def dangerous_characters',
|
34
|
+
' %W(\000) +',
|
35
|
+
' %W(\001) +',
|
36
|
+
' %W(\027) +',
|
37
|
+
' %W(\002) +',
|
38
|
+
' %W(\003) +',
|
39
|
+
' %W(\004) +',
|
40
|
+
' %W(\005) +',
|
41
|
+
' %W(\006) +',
|
42
|
+
' %W(\007) +',
|
43
|
+
' %W(\00) +',
|
44
|
+
' %W(\a)',
|
45
|
+
'end']
|
46
|
+
inspect_source(cop, source)
|
47
|
+
expect(cop.offenses).to be_empty
|
48
|
+
end
|
49
|
+
|
32
50
|
it 'registers no offense for %w without interpolation' do
|
33
51
|
inspect_source(cop,
|
34
52
|
['%w(cat dog)'])
|
@@ -75,9 +93,4 @@ describe RuboCop::Cop::Style::UnneededCapitalW do
|
|
75
93
|
new_source = autocorrect_source(cop, '%W(one two three)')
|
76
94
|
expect(new_source).to eq('%w(one two three)')
|
77
95
|
end
|
78
|
-
|
79
|
-
it 'auto-corrects an array of words and character constants' do
|
80
|
-
new_source = autocorrect_source(cop, '%W(one two ?\n ?\t)')
|
81
|
-
expect(new_source).to eq('%w(one two ?\n ?\t)')
|
82
|
-
end
|
83
96
|
end
|