rubocop 0.24.0 → 0.24.1
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/CHANGELOG.md +11 -0
- data/lib/rubocop/cop/lint/unused_method_argument.rb +6 -3
- data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -1
- data/lib/rubocop/cop/mixin/autocorrect_alignment.rb +3 -1
- data/lib/rubocop/cop/mixin/unused_argument.rb +8 -7
- data/lib/rubocop/cop/style/indentation_width.rb +17 -1
- data/lib/rubocop/cop/style/line_length.rb +1 -1
- data/lib/rubocop/cop/style/next.rb +6 -2
- data/lib/rubocop/cop/variable_force/variable.rb +4 -0
- data/lib/rubocop/options.rb +0 -8
- data/lib/rubocop/processed_source.rb +4 -6
- data/lib/rubocop/runner.rb +9 -0
- data/lib/rubocop/version.rb +1 -1
- data/relnotes/v0.24.1.md +15 -0
- data/rubocop.gemspec +1 -1
- data/spec/rubocop/cli_spec.rb +42 -0
- data/spec/rubocop/cop/lint/unused_method_argument_spec.rb +116 -88
- data/spec/rubocop/cop/style/align_parameters_spec.rb +17 -0
- data/spec/rubocop/cop/style/indentation_width_spec.rb +2 -2
- data/spec/rubocop/cop/style/line_length_spec.rb +13 -0
- data/spec/rubocop/cop/style/next_spec.rb +9 -0
- data/spec/rubocop/options_spec.rb +0 -7
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df336e05887bac795bd4e9c4f04e3bc3749a154c
|
4
|
+
data.tar.gz: fad8eb6558bbf7656b4be594a3c4995b566ae4b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8c03f04da1bb7f176f622482ac3f4244f736b8318fcc334c680faa752eb063eaac721949849c582d313b71c9fbb0903d82c4f6fd5df2b0b62574f8e7a154c36
|
7
|
+
data.tar.gz: b5d740c5335105d5256e3b59396776139c79ffd3857072761c00a630eb575df01478a4d98f6980b517c58cf9e32d6897fc9d3018d192f2cfa23d247f67a56837
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,17 @@
|
|
2
2
|
|
3
3
|
## master (unreleased)
|
4
4
|
|
5
|
+
## 0.24.1 (03/07/2014)
|
6
|
+
|
7
|
+
### Bugs fixed
|
8
|
+
|
9
|
+
* [#1174](https://github.com/bbatsov/rubocop/issues/1174): Fix `--auto-correct` crash in `AlignParameters`. ([@jonas054][])
|
10
|
+
* [#1176](https://github.com/bbatsov/rubocop/issues/1176): Fix `--auto-correct` crash in `IndentationWidth`. ([@jonas054][])
|
11
|
+
* [#1177](https://github.com/bbatsov/rubocop/issues/1177): Avoid suggesting underscore-prefixed name for unused keyword arguments and auto-correcting in that way. ([@yujinakayama][])
|
12
|
+
* [#1157](https://github.com/bbatsov/rubocop/issues/1157): Validate `--only` arguments later when all cop names are known. ([@jonas054][])
|
13
|
+
* [#1188](https://github.com/bbatsov/rubocop/issues/1188), [#1190](https://github.com/bbatsov/rubocop/issues/1190): Fix crash in `LineLength` cop when `AllowURI` option is enabled. ([@yujinakayama][])
|
14
|
+
* [#1191](https://github.com/bbatsov/rubocop/issues/1191): Fix crash on empty body branches in a loop in `Next` cop. ([@yujinakayama][])
|
15
|
+
|
5
16
|
## 0.24.0 (25/06/2014)
|
6
17
|
|
7
18
|
### New features
|
@@ -19,9 +19,12 @@ module RuboCop
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def message(variable)
|
22
|
-
message = "Unused method argument - `#{variable.name}`.
|
23
|
-
|
24
|
-
|
22
|
+
message = "Unused method argument - `#{variable.name}`."
|
23
|
+
|
24
|
+
unless variable.keyword_argument?
|
25
|
+
message << " If it's necessary, use `_` or `_#{variable.name}` " \
|
26
|
+
"as an argument name to indicate that it won't be used."
|
27
|
+
end
|
25
28
|
|
26
29
|
scope = variable.scope
|
27
30
|
all_arguments = scope.variables.each_value.select(&:method_argument?)
|
@@ -58,7 +58,9 @@ module RuboCop
|
|
58
58
|
|
59
59
|
heredoc_ranges = []
|
60
60
|
on_node(:dstr, arg) do |n|
|
61
|
-
|
61
|
+
if n.loc.respond_to?(:heredoc_body)
|
62
|
+
heredoc_ranges << n.loc.heredoc_body.join(n.loc.heredoc_end)
|
63
|
+
end
|
62
64
|
end
|
63
65
|
heredoc_ranges
|
64
66
|
end
|
@@ -9,13 +9,6 @@ module RuboCop
|
|
9
9
|
force_class == VariableForce
|
10
10
|
end
|
11
11
|
|
12
|
-
def autocorrect(node)
|
13
|
-
new_name = node.loc.expression.source.sub(/(\W?)(\w+)/, '\\1_\\2')
|
14
|
-
@corrections << lambda do |corrector|
|
15
|
-
corrector.replace(node.loc.expression, new_name)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
12
|
def after_leaving_scope(scope, _variable_table)
|
20
13
|
scope.variables.each_value do |variable|
|
21
14
|
check_argument(variable)
|
@@ -29,6 +22,14 @@ module RuboCop
|
|
29
22
|
message = message(variable)
|
30
23
|
add_offense(variable.declaration_node, :name, message)
|
31
24
|
end
|
25
|
+
|
26
|
+
def autocorrect(node)
|
27
|
+
return if [:kwarg, :kwoptarg].include?(node.type)
|
28
|
+
|
29
|
+
@corrections << lambda do |corrector|
|
30
|
+
corrector.insert_before(node.loc.name, '_')
|
31
|
+
end
|
32
|
+
end
|
32
33
|
end
|
33
34
|
end
|
34
35
|
end
|
@@ -96,7 +96,23 @@ module RuboCop
|
|
96
96
|
latest_when = nil
|
97
97
|
branches.compact.each do |b|
|
98
98
|
if b.type == :when
|
99
|
-
|
99
|
+
# TODO: Revert to the original expresson once the fix in Rubinius
|
100
|
+
# is released.
|
101
|
+
#
|
102
|
+
# Originally this expression was:
|
103
|
+
#
|
104
|
+
# *_conditions, body = *b
|
105
|
+
#
|
106
|
+
# However it fails on Rubinius 2.2.9 due to its bug:
|
107
|
+
#
|
108
|
+
# RuntimeError:
|
109
|
+
# can't modify frozen instance of Array
|
110
|
+
# # kernel/common/array.rb:988:in `pop'
|
111
|
+
# # ./lib/rubocop/cop/style/indentation_width.rb:99:in `on_case'
|
112
|
+
#
|
113
|
+
# It seems to be fixed on the current master (0a92c3c).
|
114
|
+
body = b.children.last
|
115
|
+
|
100
116
|
# Check "when" body against "when" keyword indentation.
|
101
117
|
check_indentation(b.loc.keyword, body)
|
102
118
|
latest_when = b
|
@@ -72,8 +72,12 @@ module RuboCop
|
|
72
72
|
return false unless node.type == :if
|
73
73
|
return false if style == :skip_modifier_ifs && modifier_if?(node)
|
74
74
|
|
75
|
-
|
76
|
-
|
75
|
+
# The `if` node must have only `if` body since we excluded `if` with
|
76
|
+
# `else` above.
|
77
|
+
_conditional, if_body, _else_body = *node
|
78
|
+
return true unless if_body
|
79
|
+
|
80
|
+
![:break, :return].include?(if_body.type)
|
77
81
|
end
|
78
82
|
end
|
79
83
|
end
|
data/lib/rubocop/options.rb
CHANGED
@@ -69,7 +69,6 @@ module RuboCop
|
|
69
69
|
@options[:only] = list.split(',').map do |c|
|
70
70
|
Cop::Cop.qualified_cop_name(c, '--only option')
|
71
71
|
end
|
72
|
-
validate_only_option
|
73
72
|
end
|
74
73
|
|
75
74
|
add_configuration_options(opts, args)
|
@@ -193,13 +192,6 @@ module RuboCop
|
|
193
192
|
warn message
|
194
193
|
end
|
195
194
|
|
196
|
-
def validate_only_option
|
197
|
-
@options[:only].each do |cop_to_run|
|
198
|
-
next unless Cop::Cop.all.none? { |c| c.cop_name == cop_to_run }
|
199
|
-
fail ArgumentError, "Unrecognized cop name: #{cop_to_run}."
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
203
195
|
def validate_auto_gen_config_option(args)
|
204
196
|
return unless args.any?
|
205
197
|
|
@@ -15,7 +15,7 @@ module RuboCop
|
|
15
15
|
def initialize(source, path = nil)
|
16
16
|
@path = path
|
17
17
|
@diagnostics = []
|
18
|
-
parse(source
|
18
|
+
parse(source)
|
19
19
|
end
|
20
20
|
|
21
21
|
def comment_config
|
@@ -55,15 +55,13 @@ module RuboCop
|
|
55
55
|
|
56
56
|
private
|
57
57
|
|
58
|
-
def parse(source
|
59
|
-
buffer_name = path || '(string)'
|
58
|
+
def parse(source)
|
59
|
+
buffer_name = @path || '(string)'
|
60
60
|
@buffer = Parser::Source::Buffer.new(buffer_name, 1)
|
61
61
|
|
62
62
|
begin
|
63
63
|
@buffer.source = source
|
64
|
-
rescue
|
65
|
-
# TODO: Rescue EncodingError here once the patch in Parser is released.
|
66
|
-
# https://github.com/whitequark/parser/pull/156
|
64
|
+
rescue EncodingError => error
|
67
65
|
@parser_error = error
|
68
66
|
return
|
69
67
|
end
|
data/lib/rubocop/runner.rb
CHANGED
@@ -95,6 +95,8 @@ module RuboCop
|
|
95
95
|
cop_classes = Cop::Cop.all
|
96
96
|
|
97
97
|
if @options[:only]
|
98
|
+
validate_only_option
|
99
|
+
|
98
100
|
cop_classes.select! do |c|
|
99
101
|
@options[:only].include?(c.cop_name) || @options[:lint] && c.lint?
|
100
102
|
end
|
@@ -110,6 +112,13 @@ module RuboCop
|
|
110
112
|
end
|
111
113
|
end
|
112
114
|
|
115
|
+
def validate_only_option
|
116
|
+
@options[:only].each do |cop_to_run|
|
117
|
+
next unless Cop::Cop.all.none? { |c| c.cop_name == cop_to_run }
|
118
|
+
fail ArgumentError, "Unrecognized cop name: #{cop_to_run}."
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
113
122
|
def run_rails_cops?(config)
|
114
123
|
@options[:rails] || config['AllCops']['RunRailsCops']
|
115
124
|
end
|
data/lib/rubocop/version.rb
CHANGED
data/relnotes/v0.24.1.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
RuboCop 0.24.1 is a bugfix-only release. Below is a list of the bugs we've fixed since 0.24.0:
|
2
|
+
|
3
|
+
## 0.24.1 (03/07/2014)
|
4
|
+
|
5
|
+
### Bugs fixed
|
6
|
+
|
7
|
+
* [#1174](https://github.com/bbatsov/rubocop/issues/1174): Fix `--auto-correct` crash in `AlignParameters`. ([@jonas054][])
|
8
|
+
* [#1176](https://github.com/bbatsov/rubocop/issues/1176): Fix `--auto-correct` crash in `IndentationWidth`. ([@jonas054][])
|
9
|
+
* [#1177](https://github.com/bbatsov/rubocop/issues/1177): Avoid suggesting underscore-prefixed name for unused keyword arguments and auto-correcting in that way. ([@yujinakayama][])
|
10
|
+
* [#1157](https://github.com/bbatsov/rubocop/issues/1157): Validate `--only` arguments later when all cop names are known. ([@jonas054][])
|
11
|
+
* [#1188](https://github.com/bbatsov/rubocop/issues/1188), [#1190](https://github.com/bbatsov/rubocop/issues/1190): Fix crash in `LineLength` cop when `AllowURI` option is enabled. ([@yujinakayama][])
|
12
|
+
* [#1191](https://github.com/bbatsov/rubocop/issues/1191): Fix crash on empty body branches in a loop in `Next` cop. ([@yujinakayama][])
|
13
|
+
|
14
|
+
[@jonas054]: https://github.com/jonas054
|
15
|
+
[@yujinakayama]: https://github.com/yujinakayama
|
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.99.1', '< 3.0')
|
30
|
-
s.add_runtime_dependency('parser', '>= 2.2.0.pre.
|
30
|
+
s.add_runtime_dependency('parser', '>= 2.2.0.pre.3', '< 3.0')
|
31
31
|
s.add_runtime_dependency('powerpack', '~> 0.0.6')
|
32
32
|
s.add_runtime_dependency('json', '>= 1.7.7', '< 2')
|
33
33
|
s.add_runtime_dependency('ruby-progressbar', '~> 1.4')
|
data/spec/rubocop/cli_spec.rb
CHANGED
@@ -762,6 +762,48 @@ describe RuboCop::CLI, :isolated_environment do
|
|
762
762
|
''].join("\n"))
|
763
763
|
end
|
764
764
|
|
765
|
+
it 'exits with error if an incorrect cop name is passed' do
|
766
|
+
create_file('example.rb', ['if x== 0 ',
|
767
|
+
"\ty",
|
768
|
+
'end'])
|
769
|
+
expect(cli.run(['--only', 'Style/123'])).to eq(1)
|
770
|
+
expect($stderr.string).to include('Unrecognized cop name: Style/123.')
|
771
|
+
end
|
772
|
+
|
773
|
+
it 'accepts cop names from plugins' do
|
774
|
+
create_file('.rubocop.yml', ['require: rubocop_ext',
|
775
|
+
'',
|
776
|
+
'Style/SomeCop:',
|
777
|
+
' Description: Something',
|
778
|
+
' Enabled: true'])
|
779
|
+
create_file('rubocop_ext.rb', ['module RuboCop',
|
780
|
+
' module Cop',
|
781
|
+
' module Style',
|
782
|
+
' class SomeCop < Cop',
|
783
|
+
' end',
|
784
|
+
' end',
|
785
|
+
' end',
|
786
|
+
'end'])
|
787
|
+
create_file('redirect.rb', '$stderr = STDOUT')
|
788
|
+
rubocop = "#{RuboCop::ConfigLoader::RUBOCOP_HOME}/bin/rubocop"
|
789
|
+
# Since we define a new cop class, we have to do this in a separate
|
790
|
+
# process. Otherwise, the extra cop will affect other specs.
|
791
|
+
output =
|
792
|
+
`ruby -I . #{rubocop} --require redirect.rb --only Style/SomeCop`
|
793
|
+
expect($CHILD_STATUS.success?).to be_truthy
|
794
|
+
# The warning about the unrecognized cop is expected. It's given due
|
795
|
+
# to the fact that we haven't supplied any default configuration for
|
796
|
+
# rubocop_ext in this example.
|
797
|
+
expect(output)
|
798
|
+
.to eq(['Warning: unrecognized cop Style/SomeCop found in ' \
|
799
|
+
"#{abs('.rubocop.yml')}",
|
800
|
+
'Inspecting 2 files',
|
801
|
+
'..',
|
802
|
+
'',
|
803
|
+
'2 files inspected, no offenses detected',
|
804
|
+
''].join("\n"))
|
805
|
+
end
|
806
|
+
|
765
807
|
context 'without using namespace' do
|
766
808
|
it 'runs just one cop' do
|
767
809
|
create_file('example.rb', ['if x== 0 ',
|
@@ -5,7 +5,7 @@ require 'spec_helper'
|
|
5
5
|
describe RuboCop::Cop::Lint::UnusedMethodArgument do
|
6
6
|
subject(:cop) { described_class.new }
|
7
7
|
|
8
|
-
|
8
|
+
describe 'inspection' do
|
9
9
|
before do
|
10
10
|
inspect_source(cop, source)
|
11
11
|
end
|
@@ -49,6 +49,36 @@ describe RuboCop::Cop::Lint::UnusedMethodArgument do
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
+
context 'when a required keyword argument is unused', ruby: 2.1 do
|
53
|
+
let(:source) { <<-END }
|
54
|
+
def self.some_method(foo, bar:)
|
55
|
+
puts foo
|
56
|
+
end
|
57
|
+
END
|
58
|
+
|
59
|
+
it 'registers an offense but does not suggest underscore-prefix' do
|
60
|
+
expect(cop.offenses.size).to eq(1)
|
61
|
+
expect(cop.highlights).to eq(['bar'])
|
62
|
+
expect(cop.offenses.first.message)
|
63
|
+
.to eq('Unused method argument - `bar`.')
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'when an optional keyword argument is unused', ruby: 2 do
|
68
|
+
let(:source) { <<-END }
|
69
|
+
def self.some_method(foo, bar: 1)
|
70
|
+
puts foo
|
71
|
+
end
|
72
|
+
END
|
73
|
+
|
74
|
+
it 'registers an offense but does not suggest underscore-prefix' do
|
75
|
+
expect(cop.offenses.size).to eq(1)
|
76
|
+
expect(cop.highlights).to eq(['bar'])
|
77
|
+
expect(cop.offenses.first.message)
|
78
|
+
.to eq('Unused method argument - `bar`.')
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
52
82
|
context 'when a singleton method argument is unused' do
|
53
83
|
let(:source) { <<-END }
|
54
84
|
def self.some_method(foo)
|
@@ -140,111 +170,109 @@ describe RuboCop::Cop::Lint::UnusedMethodArgument do
|
|
140
170
|
end
|
141
171
|
end
|
142
172
|
|
143
|
-
|
144
|
-
|
145
|
-
expect(autocorrect_source(cop, <<-SOURCE
|
146
|
-
def some_method(foo)
|
147
|
-
super(:something)
|
148
|
-
end
|
149
|
-
SOURCE
|
150
|
-
)).to eq(<<-CORRECTED_SOURCE
|
151
|
-
def some_method(_foo)
|
152
|
-
super(:something)
|
153
|
-
end
|
154
|
-
CORRECTED_SOURCE
|
155
|
-
)
|
156
|
-
end
|
173
|
+
describe 'auto-correction' do
|
174
|
+
let(:corrected_source) { autocorrect_source(cop, source) }
|
157
175
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
SOURCE
|
164
|
-
)).to eq(<<-CORRECTED_SOURCE
|
165
|
-
def some_method(_foo, _bar)
|
166
|
-
super(:something)
|
167
|
-
end
|
168
|
-
CORRECTED_SOURCE
|
169
|
-
)
|
170
|
-
end
|
176
|
+
context 'when multiple arguments are unused' do
|
177
|
+
let(:source) { <<-END }
|
178
|
+
def some_method(foo, bar)
|
179
|
+
end
|
180
|
+
END
|
171
181
|
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
)).to eq(<<-CORRECTED_SOURCE
|
180
|
-
def some_method(_foo,
|
181
|
-
_bar)
|
182
|
-
super(:something)
|
182
|
+
let(:expected_source) { <<-END }
|
183
|
+
def some_method(_foo, _bar)
|
184
|
+
end
|
185
|
+
END
|
186
|
+
|
187
|
+
it 'adds underscore-prefix to them' do
|
188
|
+
expect(corrected_source).to eq(expected_source)
|
183
189
|
end
|
184
|
-
CORRECTED_SOURCE
|
185
|
-
)
|
186
190
|
end
|
187
191
|
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
192
|
+
context 'when only a part of arguments is unused' do
|
193
|
+
let(:source) { <<-END }
|
194
|
+
def some_method(foo, bar)
|
195
|
+
puts foo
|
196
|
+
end
|
197
|
+
END
|
198
|
+
|
199
|
+
let(:expected_source) { <<-END }
|
200
|
+
def some_method(foo, _bar)
|
201
|
+
puts foo
|
202
|
+
end
|
203
|
+
END
|
204
|
+
|
205
|
+
it 'modifies only the unused one' do
|
206
|
+
expect(corrected_source).to eq(expected_source)
|
197
207
|
end
|
198
|
-
CORRECTED_SOURCE
|
199
|
-
)
|
200
208
|
end
|
201
209
|
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
210
|
+
context 'when there are some whitespaces around the argument' do
|
211
|
+
let(:source) { <<-END }
|
212
|
+
def some_method(foo,
|
213
|
+
bar)
|
214
|
+
puts foo
|
215
|
+
end
|
216
|
+
END
|
217
|
+
|
218
|
+
let(:expected_source) { <<-END }
|
219
|
+
def some_method(foo,
|
220
|
+
_bar)
|
221
|
+
puts foo
|
222
|
+
end
|
223
|
+
END
|
224
|
+
|
225
|
+
it 'preserves the whitespace' do
|
226
|
+
expect(corrected_source).to eq(expected_source)
|
211
227
|
end
|
212
|
-
CORRECTED_SOURCE
|
213
|
-
)
|
214
228
|
end
|
215
229
|
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
230
|
+
context 'when a splat argument is unused' do
|
231
|
+
let(:source) { <<-END }
|
232
|
+
def some_method(foo, *bar)
|
233
|
+
puts foo
|
234
|
+
end
|
235
|
+
END
|
236
|
+
|
237
|
+
let(:expected_source) { <<-END }
|
238
|
+
def some_method(foo, *_bar)
|
239
|
+
puts foo
|
240
|
+
end
|
241
|
+
END
|
242
|
+
|
243
|
+
it 'preserves the splat' do
|
244
|
+
expect(corrected_source).to eq(expected_source)
|
225
245
|
end
|
226
|
-
CORRECTED_SOURCE
|
227
|
-
)
|
228
246
|
end
|
229
247
|
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
248
|
+
context 'when an unsed argument has default value' do
|
249
|
+
let(:source) { <<-END }
|
250
|
+
def some_method(foo, bar = 1)
|
251
|
+
puts foo
|
252
|
+
end
|
253
|
+
END
|
236
254
|
|
237
|
-
|
238
|
-
|
255
|
+
let(:expected_source) { <<-END }
|
256
|
+
def some_method(foo, _bar = 1)
|
257
|
+
puts foo
|
258
|
+
end
|
259
|
+
END
|
239
260
|
|
240
|
-
|
241
|
-
|
242
|
-
def some_method(foo, bar)
|
243
|
-
super
|
261
|
+
it 'preserves the default value' do
|
262
|
+
expect(corrected_source).to eq(expected_source)
|
244
263
|
end
|
245
|
-
|
264
|
+
end
|
246
265
|
|
247
|
-
|
266
|
+
context 'when a keyword argument is unused', ruby: 2 do
|
267
|
+
let(:source) { <<-END }
|
268
|
+
def some_method(foo, bar: 1)
|
269
|
+
puts foo
|
270
|
+
end
|
271
|
+
END
|
272
|
+
|
273
|
+
it 'ignores that since modifying the name changes the method interface' do
|
274
|
+
expect(corrected_source).to eq(source)
|
275
|
+
end
|
248
276
|
end
|
249
277
|
end
|
250
278
|
end
|
@@ -245,6 +245,23 @@ describe RuboCop::Cop::Style::AlignParameters, :config do
|
|
245
245
|
new_source = autocorrect_source(cop, original_source)
|
246
246
|
expect(new_source).to eq(original_source.join("\n"))
|
247
247
|
end
|
248
|
+
|
249
|
+
it 'does not crash in autocorrect on dynamic string in parameter value' do
|
250
|
+
src = ['class MyModel < ActiveRecord::Base',
|
251
|
+
' has_many :other_models,',
|
252
|
+
' class_name: "legacy_name",',
|
253
|
+
' order: "#{leagacy_name.table_name}.published DESC"',
|
254
|
+
'',
|
255
|
+
'end']
|
256
|
+
new_source = autocorrect_source(cop, src)
|
257
|
+
expect(new_source)
|
258
|
+
.to eq ['class MyModel < ActiveRecord::Base',
|
259
|
+
' has_many :other_models,',
|
260
|
+
' class_name: "legacy_name",',
|
261
|
+
' order: "#{leagacy_name.table_name}.published DESC"',
|
262
|
+
'',
|
263
|
+
'end'].join("\n")
|
264
|
+
end
|
248
265
|
end
|
249
266
|
|
250
267
|
context 'aligned with fixed indentation' do
|
@@ -132,7 +132,7 @@ describe RuboCop::Cop::Style::IndentationWidth do
|
|
132
132
|
'foo',
|
133
133
|
'GOO',
|
134
134
|
' def baz',
|
135
|
-
' do_something',
|
135
|
+
' do_something("#{x}")',
|
136
136
|
' end',
|
137
137
|
'end',
|
138
138
|
'end'])
|
@@ -144,7 +144,7 @@ describe RuboCop::Cop::Style::IndentationWidth do
|
|
144
144
|
'foo',
|
145
145
|
'GOO',
|
146
146
|
' def baz',
|
147
|
-
' do_something',
|
147
|
+
' do_something("#{x}")',
|
148
148
|
' end',
|
149
149
|
' end',
|
150
150
|
'end'].join("\n")
|
@@ -76,6 +76,19 @@ describe RuboCop::Cop::Style::LineLength, :config do
|
|
76
76
|
expect(cop.highlights).to eq([' and'])
|
77
77
|
end
|
78
78
|
end
|
79
|
+
|
80
|
+
context 'and an error other than URI::InvalidURIError is raised ' \
|
81
|
+
'while validating an URI-ish string' do
|
82
|
+
# rubocop:disable Style/LineLength
|
83
|
+
let(:source) { <<-END }
|
84
|
+
xxxxxxxxxxxxxxxxxxxxxxxxxxxxzxxxxxxxxxxx = LDAP::DEFAULT_GROUP_UNIQUE_MEMBER_LIST_KEY
|
85
|
+
END
|
86
|
+
# rubocop:enable Style/LineLength
|
87
|
+
|
88
|
+
it 'does not crash' do
|
89
|
+
expect { inspect_source(cop, source) }.not_to raise_error
|
90
|
+
end
|
91
|
+
end
|
79
92
|
end
|
80
93
|
|
81
94
|
context 'when AllowURI option is disabled' do
|
@@ -244,4 +244,13 @@ describe RuboCop::Cop::Style::Next, :config do
|
|
244
244
|
inspect_source(cop, 'until sup; end')
|
245
245
|
expect(cop.offenses.size).to eq(0)
|
246
246
|
end
|
247
|
+
|
248
|
+
it 'does not crash with an empty body branch' do
|
249
|
+
inspect_source(cop,
|
250
|
+
['loop do',
|
251
|
+
' if true',
|
252
|
+
' end',
|
253
|
+
'end'])
|
254
|
+
expect(cop.offenses.size).to eq(1)
|
255
|
+
end
|
247
256
|
end
|
@@ -134,13 +134,6 @@ Usage: rubocop [options] [file1, file2, ...]
|
|
134
134
|
end
|
135
135
|
end
|
136
136
|
|
137
|
-
describe '--only' do
|
138
|
-
it 'exits with error if an incorrect cop name is passed' do
|
139
|
-
expect { options.parse(%w(--only 123)) }
|
140
|
-
.to raise_error(ArgumentError, /Unrecognized cop name: 123./)
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
137
|
describe '--require' do
|
145
138
|
let(:required_file_path) { './path/to/required_file.rb' }
|
146
139
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.24.
|
4
|
+
version: 0.24.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bozhidar Batsov
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-
|
13
|
+
date: 2014-07-03 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rainbow
|
@@ -38,7 +38,7 @@ dependencies:
|
|
38
38
|
requirements:
|
39
39
|
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: 2.2.0.pre.
|
41
|
+
version: 2.2.0.pre.3
|
42
42
|
- - "<"
|
43
43
|
- !ruby/object:Gem::Version
|
44
44
|
version: '3.0'
|
@@ -48,7 +48,7 @@ dependencies:
|
|
48
48
|
requirements:
|
49
49
|
- - ">="
|
50
50
|
- !ruby/object:Gem::Version
|
51
|
-
version: 2.2.0.pre.
|
51
|
+
version: 2.2.0.pre.3
|
52
52
|
- - "<"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
@@ -456,6 +456,7 @@ files:
|
|
456
456
|
- relnotes/v0.22.0.md
|
457
457
|
- relnotes/v0.23.0.md
|
458
458
|
- relnotes/v0.24.0.md
|
459
|
+
- relnotes/v0.24.1.md
|
459
460
|
- rubocop.gemspec
|
460
461
|
- spec/.rubocop.yml
|
461
462
|
- spec/isolated_environment_spec.rb
|
@@ -710,7 +711,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
710
711
|
version: '0'
|
711
712
|
requirements: []
|
712
713
|
rubyforge_project:
|
713
|
-
rubygems_version: 2.
|
714
|
+
rubygems_version: 2.3.0
|
714
715
|
signing_key:
|
715
716
|
specification_version: 4
|
716
717
|
summary: Automatic Ruby code style checking tool.
|