rubocop 0.10.0 → 0.11.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 +7 -0
- data/CHANGELOG.md +35 -0
- data/CONTRIBUTING.md +2 -0
- data/README.md +102 -5
- data/config/default.yml +31 -3
- data/config/enabled.yml +21 -3
- data/lib/rubocop.rb +5 -0
- data/lib/rubocop/cli.rb +27 -7
- data/lib/rubocop/config.rb +21 -2
- data/lib/rubocop/config_store.rb +4 -1
- data/lib/rubocop/cop/commissioner.rb +2 -4
- data/lib/rubocop/cop/cop.rb +8 -8
- data/lib/rubocop/cop/lint/assignment_in_condition.rb +3 -0
- data/lib/rubocop/cop/lint/block_alignment.rb +10 -20
- data/lib/rubocop/cop/lint/useless_assignment.rb +63 -0
- data/lib/rubocop/cop/lint/useless_comparison.rb +30 -0
- data/lib/rubocop/cop/style/align_parameters.rb +23 -13
- data/lib/rubocop/cop/style/and_or.rb +13 -1
- data/lib/rubocop/cop/style/blocks.rb +35 -0
- data/lib/rubocop/cop/style/character_literal.rb +1 -1
- data/lib/rubocop/cop/style/comment_annotation.rb +20 -5
- data/lib/rubocop/cop/style/dot_position.rb +7 -1
- data/lib/rubocop/cop/style/empty_line_between_defs.rb +1 -1
- data/lib/rubocop/cop/style/favor_modifier.rb +4 -4
- data/lib/rubocop/cop/style/module_function.rb +34 -0
- data/lib/rubocop/cop/style/multiline_if_then.rb +7 -9
- data/lib/rubocop/cop/style/redundant_begin.rb +7 -7
- data/lib/rubocop/cop/style/redundant_return.rb +9 -11
- data/lib/rubocop/cop/style/redundant_self.rb +5 -1
- data/lib/rubocop/cop/style/regexp_literal.rb +2 -1
- data/lib/rubocop/cop/style/signal_exception.rb +40 -0
- data/lib/rubocop/cop/style/string_literals.rb +2 -2
- data/lib/rubocop/cop/style/symbol_name.rb +11 -0
- data/lib/rubocop/cop/style/trivial_accessors.rb +22 -10
- data/lib/rubocop/cop/variable_inspector.rb +92 -71
- data/lib/rubocop/formatter/clang_style_formatter.rb +8 -3
- data/lib/rubocop/formatter/disabled_config_formatter.rb +32 -0
- data/lib/rubocop/formatter/formatter_set.rb +7 -4
- data/lib/rubocop/target_finder.rb +3 -4
- data/lib/rubocop/version.rb +1 -1
- data/rubocop.gemspec +1 -1
- data/spec/rubocop/cli_spec.rb +90 -1
- data/spec/rubocop/cops/commissioner_spec.rb +1 -1
- data/spec/rubocop/cops/lint/assignment_in_condition_spec.rb +6 -0
- data/spec/rubocop/cops/lint/block_alignment_spec.rb +16 -4
- data/spec/rubocop/cops/lint/empty_ensure_spec.rb +1 -1
- data/spec/rubocop/cops/lint/ensure_return_spec.rb +1 -1
- data/spec/rubocop/cops/lint/shadowing_outer_local_variable_spec.rb +4 -4
- data/spec/rubocop/cops/lint/unused_local_variable_spec.rb +49 -13
- data/spec/rubocop/cops/lint/useless_assignment_spec.rb +62 -0
- data/spec/rubocop/cops/lint/useless_comparison_spec.rb +31 -0
- data/spec/rubocop/cops/style/align_parameters_spec.rb +9 -0
- data/spec/rubocop/cops/style/and_or_spec.rb +12 -0
- data/spec/rubocop/cops/style/avoid_global_vars_spec.rb +1 -1
- data/spec/rubocop/cops/style/blocks_spec.rb +57 -14
- data/spec/rubocop/cops/style/character_literal_spec.rb +2 -2
- data/spec/rubocop/cops/style/comment_annotation_spec.rb +32 -4
- data/spec/rubocop/cops/style/dot_position_spec.rb +10 -0
- data/spec/rubocop/cops/style/empty_line_between_defs_spec.rb +12 -0
- data/spec/rubocop/cops/style/end_of_line_spec.rb +1 -0
- data/spec/rubocop/cops/style/favor_modifier_spec.rb +18 -0
- data/spec/rubocop/cops/style/hash_syntax_spec.rb +7 -2
- data/spec/rubocop/cops/style/module_function_spec.rb +30 -0
- data/spec/rubocop/cops/style/redundant_begin_spec.rb +2 -2
- data/spec/rubocop/cops/style/redundant_return_spec.rb +4 -4
- data/spec/rubocop/cops/style/redundant_self_spec.rb +36 -2
- data/spec/rubocop/cops/style/regexp_literal_spec.rb +1 -0
- data/spec/rubocop/cops/style/signal_exception_spec.rb +74 -0
- data/spec/rubocop/cops/style/string_literals_spec.rb +10 -0
- data/spec/rubocop/cops/style/symbol_name_spec.rb +13 -0
- data/spec/rubocop/cops/style/trivial_accessors_spec.rb +28 -3
- data/spec/rubocop/cops/variable_inspector_spec.rb +217 -36
- data/spec/rubocop/formatter/base_formatter_spec.rb +3 -3
- data/spec/rubocop/formatter/clang_style_formatter_spec.rb +19 -0
- data/spec/rubocop/formatter/disabled_config_formatter_spec.rb +48 -0
- data/spec/rubocop/formatter/formatter_set_spec.rb +1 -1
- data/spec/rubocop/processed_source_spec.rb +1 -1
- data/spec/spec_helper.rb +18 -13
- metadata +31 -38
@@ -11,9 +11,14 @@ module Rubocop
|
|
11
11
|
output.printf("%s:%d:%d: %s: %s\n",
|
12
12
|
smart_path(file).color(:cyan), o.line, o.real_column,
|
13
13
|
o.clang_severity, o.message)
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
|
15
|
+
source_line = o.location.source_line
|
16
|
+
|
17
|
+
unless source_line.strip.empty?
|
18
|
+
output.puts(source_line)
|
19
|
+
output.puts(' ' * o.location.column +
|
20
|
+
'^' * o.location.column_range.count)
|
21
|
+
end
|
17
22
|
end
|
18
23
|
end
|
19
24
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Rubocop
|
4
|
+
module Formatter
|
5
|
+
# This formatter displays a YAML configuration file where all cops that
|
6
|
+
# detected any offences are disabled.
|
7
|
+
class DisabledConfigFormatter < BaseFormatter
|
8
|
+
HEADING =
|
9
|
+
['# This configuration was generated by `rubocop --auto-gen-config`.',
|
10
|
+
'# The point is for the user to remove these configuration records',
|
11
|
+
'# one by one as the offences are removed from the code base.']
|
12
|
+
.join("\n")
|
13
|
+
|
14
|
+
def file_finished(file, offences)
|
15
|
+
@cops_with_offences ||= {}
|
16
|
+
offences.each { |o| @cops_with_offences[o.cop_name] = true }
|
17
|
+
end
|
18
|
+
|
19
|
+
def finished(inspected_files)
|
20
|
+
output.puts HEADING
|
21
|
+
@cops_with_offences.keys.sort.each do |cop_name|
|
22
|
+
output.puts
|
23
|
+
output.puts "#{cop_name}:"
|
24
|
+
output.puts ' Enabled: false'
|
25
|
+
end
|
26
|
+
puts "Created #{output.path}."
|
27
|
+
puts "Run rubocop with --config #{output.path}, or"
|
28
|
+
puts "add inherit_from: #{output.path} in a .rubocop.yml file."
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -27,11 +27,14 @@ module Rubocop
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
def add_formatter(
|
31
|
-
formatter_class =
|
32
|
-
|
30
|
+
def add_formatter(formatter_type, output_path = nil)
|
31
|
+
formatter_class = case formatter_type
|
32
|
+
when Class
|
33
|
+
formatter_type
|
34
|
+
when /\A[A-Z]/
|
35
|
+
custom_formatter_class(formatter_type)
|
33
36
|
else
|
34
|
-
builtin_formatter_class(
|
37
|
+
builtin_formatter_class(formatter_type)
|
35
38
|
end
|
36
39
|
|
37
40
|
output = output_path ? File.open(output_path, 'w') : $stdout
|
@@ -37,7 +37,8 @@ module Rubocop
|
|
37
37
|
# as its first line.
|
38
38
|
# It is possible to specify includes and excludes using the config file,
|
39
39
|
# so you can include other Ruby files like Rakefiles and gemspecs.
|
40
|
-
# @param
|
40
|
+
# @param base_dir Root directory under which to search for
|
41
|
+
# ruby source files
|
41
42
|
# @return [Array] Array of filenames
|
42
43
|
def target_files_in_dir(base_dir = Dir.pwd)
|
43
44
|
files = Dir["#{base_dir}/**/*"].select { |path| FileTest.file?(path) }
|
@@ -58,9 +59,7 @@ module Rubocop
|
|
58
59
|
first_line = File.open(file) { |f| f.readline }
|
59
60
|
first_line =~ /#!.*ruby/
|
60
61
|
rescue EOFError, ArgumentError => e
|
61
|
-
if @debug
|
62
|
-
warn "Unprocessable file #{file}: #{e.class}, #{e.message}"
|
63
|
-
end
|
62
|
+
warn "Unprocessable file #{file}: #{e.class}, #{e.message}" if @debug
|
64
63
|
false
|
65
64
|
end
|
66
65
|
end
|
data/lib/rubocop/version.rb
CHANGED
data/rubocop.gemspec
CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |s|
|
|
27
27
|
s.summary = 'Automatic Ruby code style checking tool.'
|
28
28
|
|
29
29
|
s.add_runtime_dependency('rainbow', '>= 1.1.4')
|
30
|
-
s.add_runtime_dependency('parser', '2.0.0.
|
30
|
+
s.add_runtime_dependency('parser', '~> 2.0.0.pre6')
|
31
31
|
s.add_runtime_dependency('backports', '~> 3.3.3')
|
32
32
|
s.add_runtime_dependency('powerpack', '0.0.1')
|
33
33
|
s.add_development_dependency('rake', '~> 10.1')
|
data/spec/rubocop/cli_spec.rb
CHANGED
@@ -13,6 +13,7 @@ module Rubocop
|
|
13
13
|
before(:each) do
|
14
14
|
$stdout = StringIO.new
|
15
15
|
$stderr = StringIO.new
|
16
|
+
Config.debug = false
|
16
17
|
end
|
17
18
|
|
18
19
|
after(:each) do
|
@@ -41,6 +42,8 @@ Usage: rubocop [options] [file1, file2, ...]
|
|
41
42
|
-d, --debug Display debug info.
|
42
43
|
-c, --config FILE Specify configuration file.
|
43
44
|
--only COP Run just one cop.
|
45
|
+
--auto-gen-config Generate a configuration file acting as a
|
46
|
+
TODO list.
|
44
47
|
-f, --format FORMATTER Choose an output formatter. This option
|
45
48
|
can be specified multiple times to enable
|
46
49
|
multiple formatters at the same time.
|
@@ -120,7 +123,7 @@ Usage: rubocop [options] [file1, file2, ...]
|
|
120
123
|
it 'adds a handler for SIGINT' do
|
121
124
|
expect(@interrupt_handlers).to be_empty
|
122
125
|
cli.trap_interrupt
|
123
|
-
expect(@interrupt_handlers).to
|
126
|
+
expect(@interrupt_handlers.size).to eq(1)
|
124
127
|
end
|
125
128
|
|
126
129
|
context 'with SIGINT once' do
|
@@ -268,6 +271,76 @@ Usage: rubocop [options] [file1, file2, ...]
|
|
268
271
|
''].join("\n"))
|
269
272
|
end
|
270
273
|
|
274
|
+
it 'exits with error if asked to re-generate a todo list that is in use' do
|
275
|
+
create_file('example1.rb', ['# encoding: utf-8',
|
276
|
+
'x= 0 ',
|
277
|
+
'#' * 85,
|
278
|
+
'y ',
|
279
|
+
'puts x'])
|
280
|
+
todo_contents = ['# This configuration was generated with `rubocop' +
|
281
|
+
' --auto-gen-config`',
|
282
|
+
'',
|
283
|
+
'LineLength:',
|
284
|
+
' Enabled: false']
|
285
|
+
create_file('rubocop-todo.yml', todo_contents)
|
286
|
+
expect(IO.read('rubocop-todo.yml'))
|
287
|
+
.to eq(todo_contents.join("\n") + "\n")
|
288
|
+
create_file('.rubocop.yml', ['inherit_from: rubocop-todo.yml'])
|
289
|
+
expect(cli.run(['--auto-gen-config'])).to eq(1)
|
290
|
+
expect($stderr.string).to eq('Remove rubocop-todo.yml from the current' +
|
291
|
+
' configuration before generating it' +
|
292
|
+
" again.\n")
|
293
|
+
end
|
294
|
+
|
295
|
+
it 'exits with error if file arguments are given with --auto-gen-config' do
|
296
|
+
create_file('example1.rb', ['# encoding: utf-8',
|
297
|
+
'x= 0 ',
|
298
|
+
'#' * 85,
|
299
|
+
'y ',
|
300
|
+
'puts x'])
|
301
|
+
expect(cli.run(['--auto-gen-config', 'example1.rb'])).to eq(1)
|
302
|
+
expect($stderr.string).to eq('--auto-gen-config can not be combined ' +
|
303
|
+
"with any other arguments.\n")
|
304
|
+
expect($stdout.string).to eq('')
|
305
|
+
end
|
306
|
+
|
307
|
+
it 'can generate a todo list' do
|
308
|
+
create_file('example1.rb', ['# encoding: utf-8',
|
309
|
+
'x= 0 ',
|
310
|
+
'#' * 85,
|
311
|
+
'y ',
|
312
|
+
'puts x'])
|
313
|
+
create_file('example2.rb', ['# encoding: utf-8',
|
314
|
+
"\tx = 0",
|
315
|
+
'puts x'])
|
316
|
+
expect(cli.run(['--auto-gen-config'])).to eq(1)
|
317
|
+
expect($stderr.string).to eq('')
|
318
|
+
expect($stdout.string).to include([
|
319
|
+
'Created rubocop-todo.yml.',
|
320
|
+
'Run rubocop with --config rubocop-todo.yml, or',
|
321
|
+
'add inherit_from: rubocop-todo.yml in a .rubocop.yml file.',
|
322
|
+
''].join("\n"))
|
323
|
+
expect(IO.read('rubocop-todo.yml'))
|
324
|
+
.to eq(['# This configuration was generated by `rubocop' +
|
325
|
+
' --auto-gen-config`.',
|
326
|
+
'# The point is for the user to remove these configuration' +
|
327
|
+
' records',
|
328
|
+
'# one by one as the offences are removed from the code base.',
|
329
|
+
'',
|
330
|
+
'LineLength:',
|
331
|
+
' Enabled: false',
|
332
|
+
'',
|
333
|
+
'SpaceAroundOperators:',
|
334
|
+
' Enabled: false',
|
335
|
+
'',
|
336
|
+
'Tab:',
|
337
|
+
' Enabled: false',
|
338
|
+
'',
|
339
|
+
'TrailingWhitespace:',
|
340
|
+
' Enabled: false',
|
341
|
+
''].join("\n"))
|
342
|
+
end
|
343
|
+
|
271
344
|
it 'runs just one cop if --only is passed' do
|
272
345
|
create_file('example.rb', ['if x== 0 ',
|
273
346
|
"\ty",
|
@@ -344,6 +417,22 @@ Usage: rubocop [options] [file1, file2, ...]
|
|
344
417
|
''].join("\n"))
|
345
418
|
end
|
346
419
|
|
420
|
+
it 'shows config files when --debug is passed', ruby: 2.0 do
|
421
|
+
create_file('example1.rb', "\tputs 0")
|
422
|
+
expect(cli.run(['--debug', 'example1.rb'])).to eq(1)
|
423
|
+
home = File.dirname(File.dirname(File.dirname(__FILE__)))
|
424
|
+
expect($stdout.string.lines[2, 7].map(&:chomp).join("\n"))
|
425
|
+
.to eq(["For #{abs('')}:" +
|
426
|
+
" configuration from #{home}/config/default.yml",
|
427
|
+
"Inheriting configuration from #{home}/config/enabled.yml",
|
428
|
+
"Inheriting configuration from #{home}/config/disabled.yml",
|
429
|
+
"AllCops/Excludes configuration from #{home}/.rubocop.yml",
|
430
|
+
"Inheriting configuration from #{home}/config/default.yml",
|
431
|
+
"Inheriting configuration from #{home}/config/enabled.yml",
|
432
|
+
"Inheriting configuration from #{home}/config/disabled.yml"
|
433
|
+
].join("\n"))
|
434
|
+
end
|
435
|
+
|
347
436
|
it 'shows cop names when --debug is passed', ruby: 2.0 do
|
348
437
|
create_file('example1.rb', "\tputs 0")
|
349
438
|
expect(cli.run(['--format',
|
@@ -75,6 +75,12 @@ module Rubocop
|
|
75
75
|
expect(cop.offences).to be_empty
|
76
76
|
end
|
77
77
|
|
78
|
+
it 'accepts = in a block that is called in a condition' do
|
79
|
+
inspect_source(cop,
|
80
|
+
['return 1 if any_errors? { o = inspect(file) }'])
|
81
|
+
expect(cop.offences).to be_empty
|
82
|
+
end
|
83
|
+
|
78
84
|
it 'accepts ||= in condition' do
|
79
85
|
inspect_source(cop,
|
80
86
|
['raise StandardError unless foo ||= bar'])
|
@@ -98,7 +98,7 @@ module Rubocop
|
|
98
98
|
end
|
99
99
|
|
100
100
|
context 'when the method part is a call chain that spans several lines' do
|
101
|
-
it '
|
101
|
+
it 'registers offences for pretty multiline chaining' do
|
102
102
|
src = ['def foo(bar)',
|
103
103
|
' bar.get_stuffs',
|
104
104
|
' .reject do |stuff| ',
|
@@ -111,7 +111,10 @@ module Rubocop
|
|
111
111
|
' end',
|
112
112
|
'end']
|
113
113
|
inspect_source(cop, src)
|
114
|
-
expect(cop.offences.map(&:message))
|
114
|
+
expect(cop.offences.map(&:message))
|
115
|
+
.to eq(['end at 10, 6 is not aligned with bar.get_stuffs at 2, 2',
|
116
|
+
'end at 7, 6 is not aligned with bar.get_stuffs at 2, 2',
|
117
|
+
'end at 5, 6 is not aligned with bar.get_stuffs at 2, 2'])
|
115
118
|
end
|
116
119
|
|
117
120
|
it 'registers offences for misaligned ends' do
|
@@ -127,7 +130,16 @@ module Rubocop
|
|
127
130
|
' end',
|
128
131
|
'end']
|
129
132
|
inspect_source(cop, src)
|
130
|
-
expect(cop.offences).to
|
133
|
+
expect(cop.offences.size).to eq(3)
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'accepts end indented as the start of the block' do
|
137
|
+
src = ['my_object.chaining_this_very_long_method(with_a_parameter)',
|
138
|
+
' .and_one_with_a_block do',
|
139
|
+
' do_something',
|
140
|
+
'end']
|
141
|
+
inspect_source(cop, src)
|
142
|
+
expect(cop.offences).to be_empty
|
131
143
|
end
|
132
144
|
end
|
133
145
|
|
@@ -147,7 +159,7 @@ module Rubocop
|
|
147
159
|
' i - 5',
|
148
160
|
' end']
|
149
161
|
inspect_source(cop, src)
|
150
|
-
expect(cop.offences).to
|
162
|
+
expect(cop.offences.size).to eq(1)
|
151
163
|
end
|
152
164
|
end
|
153
165
|
|
@@ -23,7 +23,7 @@ module Rubocop
|
|
23
23
|
|
24
24
|
it 'registers an offence' do
|
25
25
|
inspect_source(cop, source)
|
26
|
-
expect(cop.offences).to
|
26
|
+
expect(cop.offences.size).to eq(1)
|
27
27
|
expect(cop.offences.first.message)
|
28
28
|
.to include('Shadowing outer local variable - foo')
|
29
29
|
expect(cop.offences.first.line).to eq(4)
|
@@ -47,7 +47,7 @@ module Rubocop
|
|
47
47
|
|
48
48
|
it 'registers an offence' do
|
49
49
|
inspect_source(cop, source)
|
50
|
-
expect(cop.offences).to
|
50
|
+
expect(cop.offences.size).to eq(1)
|
51
51
|
expect(cop.offences.first.message)
|
52
52
|
.to include('Shadowing outer local variable - foo')
|
53
53
|
expect(cop.offences.first.line).to eq(4)
|
@@ -73,7 +73,7 @@ module Rubocop
|
|
73
73
|
|
74
74
|
it 'registers an offence' do
|
75
75
|
inspect_source(cop, source)
|
76
|
-
expect(cop.offences).to
|
76
|
+
expect(cop.offences.size).to eq(1)
|
77
77
|
expect(cop.offences.first.message)
|
78
78
|
.to include('Shadowing outer local variable - foo')
|
79
79
|
expect(cop.offences.first.line).to eq(4)
|
@@ -98,7 +98,7 @@ module Rubocop
|
|
98
98
|
|
99
99
|
it 'registers an offence' do
|
100
100
|
inspect_source(cop, source)
|
101
|
-
expect(cop.offences).to
|
101
|
+
expect(cop.offences.size).to eq(1)
|
102
102
|
expect(cop.offences.first.message)
|
103
103
|
.to include('Shadowing outer local variable - foo')
|
104
104
|
expect(cop.offences.first.line).to eq(4)
|
@@ -25,7 +25,7 @@ module Rubocop
|
|
25
25
|
|
26
26
|
it 'registers an offence' do
|
27
27
|
inspect_source(cop, source)
|
28
|
-
expect(cop.offences).to
|
28
|
+
expect(cop.offences.size).to eq(1)
|
29
29
|
expect(cop.offences.first.message)
|
30
30
|
.to include('unused variable - foo')
|
31
31
|
expect(cop.offences.first.line).to eq(5)
|
@@ -52,7 +52,7 @@ module Rubocop
|
|
52
52
|
|
53
53
|
it 'registers an offence' do
|
54
54
|
inspect_source(cop, source)
|
55
|
-
expect(cop.offences).to
|
55
|
+
expect(cop.offences.size).to eq(1)
|
56
56
|
expect(cop.offences.first.message)
|
57
57
|
.to include('unused variable - foo')
|
58
58
|
expect(cop.offences.first.line).to eq(5)
|
@@ -80,7 +80,7 @@ module Rubocop
|
|
80
80
|
|
81
81
|
it 'registers an offence' do
|
82
82
|
inspect_source(cop, source)
|
83
|
-
expect(cop.offences).to
|
83
|
+
expect(cop.offences.size).to eq(1)
|
84
84
|
expect(cop.offences.first.message)
|
85
85
|
.to include('unused variable - foo')
|
86
86
|
expect(cop.offences.first.line).to eq(6)
|
@@ -106,7 +106,7 @@ module Rubocop
|
|
106
106
|
|
107
107
|
it 'registers an offence' do
|
108
108
|
inspect_source(cop, source)
|
109
|
-
expect(cop.offences).to
|
109
|
+
expect(cop.offences.size).to eq(1)
|
110
110
|
expect(cop.offences.first.message)
|
111
111
|
.to include('unused variable - foo')
|
112
112
|
expect(cop.offences.first.line).to eq(5)
|
@@ -134,7 +134,7 @@ module Rubocop
|
|
134
134
|
|
135
135
|
it 'registers an offence' do
|
136
136
|
inspect_source(cop, source)
|
137
|
-
expect(cop.offences).to
|
137
|
+
expect(cop.offences.size).to eq(1)
|
138
138
|
expect(cop.offences.first.message)
|
139
139
|
.to include('unused variable - foo')
|
140
140
|
expect(cop.offences.first.line).to eq(6)
|
@@ -160,7 +160,7 @@ module Rubocop
|
|
160
160
|
|
161
161
|
it 'registers an offence' do
|
162
162
|
inspect_source(cop, source)
|
163
|
-
expect(cop.offences).to
|
163
|
+
expect(cop.offences.size).to eq(1)
|
164
164
|
expect(cop.offences.first.message)
|
165
165
|
.to include('unused variable - foo')
|
166
166
|
expect(cop.offences.first.line).to eq(5)
|
@@ -180,7 +180,7 @@ module Rubocop
|
|
180
180
|
|
181
181
|
it 'registers an offence' do
|
182
182
|
inspect_source(cop, source)
|
183
|
-
expect(cop.offences).to
|
183
|
+
expect(cop.offences.size).to eq(1)
|
184
184
|
expect(cop.offences.first.message)
|
185
185
|
.to include('unused variable - foo')
|
186
186
|
expect(cop.offences.first.line).to eq(1)
|
@@ -249,7 +249,7 @@ module Rubocop
|
|
249
249
|
|
250
250
|
it 'registers an offence' do
|
251
251
|
inspect_source(cop, source)
|
252
|
-
expect(cop.offences).to
|
252
|
+
expect(cop.offences.size).to eq(1)
|
253
253
|
expect(cop.offences.first.message)
|
254
254
|
.to include('unused variable - foo')
|
255
255
|
expect(cop.offences.first.line).to eq(1)
|
@@ -271,6 +271,42 @@ module Rubocop
|
|
271
271
|
include_examples 'mimics MRI 2.0'
|
272
272
|
end
|
273
273
|
|
274
|
+
context 'when a variable is assigned in loop body ' +
|
275
|
+
'and referenced in post while condition' do
|
276
|
+
let(:source) do
|
277
|
+
[
|
278
|
+
'begin',
|
279
|
+
' if foo',
|
280
|
+
' foo += 1',
|
281
|
+
' else',
|
282
|
+
' foo = 1',
|
283
|
+
' end',
|
284
|
+
'end while foo < 10'
|
285
|
+
]
|
286
|
+
end
|
287
|
+
|
288
|
+
include_examples 'accepts'
|
289
|
+
include_examples 'mimics MRI 2.0'
|
290
|
+
end
|
291
|
+
|
292
|
+
context 'when a variable is assigned in loop body ' +
|
293
|
+
'and referenced in post until condition' do
|
294
|
+
let(:source) do
|
295
|
+
[
|
296
|
+
'begin',
|
297
|
+
' if foo',
|
298
|
+
' foo += 1',
|
299
|
+
' else',
|
300
|
+
' foo = 1',
|
301
|
+
' end',
|
302
|
+
'end until foo > 10'
|
303
|
+
]
|
304
|
+
end
|
305
|
+
|
306
|
+
include_examples 'accepts'
|
307
|
+
include_examples 'mimics MRI 2.0'
|
308
|
+
end
|
309
|
+
|
274
310
|
context 'when a named capture is unreferenced in top level' do
|
275
311
|
let(:source) do
|
276
312
|
[
|
@@ -280,7 +316,7 @@ module Rubocop
|
|
280
316
|
|
281
317
|
it 'registers an offence' do
|
282
318
|
inspect_source(cop, source)
|
283
|
-
expect(cop.offences).to
|
319
|
+
expect(cop.offences.size).to eq(1)
|
284
320
|
expect(cop.offences.first.message)
|
285
321
|
.to include('unused variable - foo')
|
286
322
|
expect(cop.offences.first.line).to eq(1)
|
@@ -301,7 +337,7 @@ module Rubocop
|
|
301
337
|
|
302
338
|
it 'registers an offence' do
|
303
339
|
inspect_source(cop, source)
|
304
|
-
expect(cop.offences).to
|
340
|
+
expect(cop.offences.size).to eq(1)
|
305
341
|
expect(cop.offences.first.message)
|
306
342
|
.to include('unused variable - foo')
|
307
343
|
expect(cop.offences.first.line).to eq(2)
|
@@ -358,7 +394,7 @@ module Rubocop
|
|
358
394
|
|
359
395
|
it 'registers an offence' do
|
360
396
|
inspect_source(cop, source)
|
361
|
-
expect(cop.offences).to
|
397
|
+
expect(cop.offences.size).to eq(1)
|
362
398
|
expect(cop.offences.first.message)
|
363
399
|
.to include('unused variable - foo')
|
364
400
|
expect(cop.offences.first.line).to eq(2)
|
@@ -488,7 +524,7 @@ module Rubocop
|
|
488
524
|
|
489
525
|
it 'registers an offence' do
|
490
526
|
inspect_source(cop, source)
|
491
|
-
expect(cop.offences).to
|
527
|
+
expect(cop.offences.size).to eq(1)
|
492
528
|
expect(cop.offences.first.message)
|
493
529
|
.to include('unused variable - foo')
|
494
530
|
expect(cop.offences.first.line).to eq(1)
|
@@ -523,7 +559,7 @@ module Rubocop
|
|
523
559
|
|
524
560
|
it 'registers an offence' do
|
525
561
|
inspect_source(cop, source)
|
526
|
-
expect(cop.offences).to
|
562
|
+
expect(cop.offences.size).to eq(1)
|
527
563
|
expect(cop.offences.first.message)
|
528
564
|
.to include('unused variable - foo')
|
529
565
|
expect(cop.offences.first.line).to eq(1)
|