rubocop 0.41.2 → 0.42.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/README.md +2 -3
- data/config/default.yml +13 -0
- data/config/disabled.yml +5 -0
- data/config/enabled.yml +20 -0
- data/lib/rubocop.rb +4 -0
- data/lib/rubocop/ast_node.rb +4 -3
- data/lib/rubocop/config.rb +1 -1
- data/lib/rubocop/config_loader.rb +2 -7
- data/lib/rubocop/cop/cop.rb +3 -3
- data/lib/rubocop/cop/lint/block_alignment.rb +18 -16
- data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +34 -19
- data/lib/rubocop/cop/lint/next_without_accumulator.rb +9 -1
- data/lib/rubocop/cop/lint/shadowed_exception.rb +23 -3
- data/lib/rubocop/cop/lint/unneeded_disable.rb +1 -1
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +41 -4
- data/lib/rubocop/cop/mixin/array_hash_indentation.rb +1 -1
- data/lib/rubocop/cop/mixin/autocorrect_alignment.rb +1 -1
- data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +3 -5
- data/lib/rubocop/cop/mixin/multiline_literal_brace_layout.rb +4 -4
- data/lib/rubocop/cop/mixin/space_inside.rb +23 -8
- data/lib/rubocop/cop/mixin/statement_modifier.rb +1 -1
- data/lib/rubocop/cop/offense.rb +33 -10
- data/lib/rubocop/cop/performance/case_when_splat.rb +16 -14
- data/lib/rubocop/cop/performance/sample.rb +0 -1
- data/lib/rubocop/cop/rails/save_bang.rb +77 -0
- data/lib/rubocop/cop/rails/validation.rb +15 -15
- data/lib/rubocop/cop/style/access_modifier_indentation.rb +1 -1
- data/lib/rubocop/cop/style/align_hash.rb +1 -1
- data/lib/rubocop/cop/style/block_comments.rb +1 -3
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +19 -10
- data/lib/rubocop/cop/style/closing_parenthesis_indentation.rb +1 -1
- data/lib/rubocop/cop/style/comment_annotation.rb +14 -14
- data/lib/rubocop/cop/style/comment_indentation.rb +1 -1
- data/lib/rubocop/cop/style/conditional_assignment.rb +25 -26
- data/lib/rubocop/cop/style/dot_position.rb +24 -19
- data/lib/rubocop/cop/style/each_for_simple_loop.rb +22 -8
- data/lib/rubocop/cop/style/each_with_object.rb +11 -1
- data/lib/rubocop/cop/style/else_alignment.rb +1 -1
- data/lib/rubocop/cop/style/empty_lines.rb +22 -11
- data/lib/rubocop/cop/style/empty_lines_around_access_modifier.rb +9 -6
- data/lib/rubocop/cop/style/empty_lines_around_block_body.rb +14 -14
- data/lib/rubocop/cop/style/empty_lines_around_class_body.rb +8 -5
- data/lib/rubocop/cop/style/empty_lines_around_method_body.rb +12 -8
- data/lib/rubocop/cop/style/empty_lines_around_module_body.rb +17 -4
- data/lib/rubocop/cop/style/empty_literal.rb +12 -7
- data/lib/rubocop/cop/style/for.rb +1 -1
- data/lib/rubocop/cop/style/indent_array.rb +1 -1
- data/lib/rubocop/cop/style/indent_hash.rb +1 -1
- data/lib/rubocop/cop/style/indentation_width.rb +1 -1
- data/lib/rubocop/cop/style/initial_indentation.rb +1 -1
- data/lib/rubocop/cop/style/lambda.rb +2 -3
- data/lib/rubocop/cop/style/method_call_parentheses.rb +6 -4
- data/lib/rubocop/cop/style/method_missing.rb +74 -0
- data/lib/rubocop/cop/style/multiline_method_call_indentation.rb +1 -1
- data/lib/rubocop/cop/style/multiline_operation_indentation.rb +1 -1
- data/lib/rubocop/cop/style/nested_modifier.rb +23 -13
- data/lib/rubocop/cop/style/next.rb +1 -1
- data/lib/rubocop/cop/style/numeric_predicate.rb +142 -0
- data/lib/rubocop/cop/style/op_method.rb +12 -4
- data/lib/rubocop/cop/style/parallel_assignment.rb +11 -3
- data/lib/rubocop/cop/style/rescue_ensure_alignment.rb +9 -6
- data/lib/rubocop/cop/style/single_line_block_params.rb +3 -2
- data/lib/rubocop/cop/style/space_inside_block_braces.rb +1 -1
- data/lib/rubocop/cop/style/space_inside_string_interpolation.rb +1 -1
- data/lib/rubocop/cop/style/symbol_array.rb +18 -10
- data/lib/rubocop/cop/style/ternary_parentheses.rb +94 -0
- data/lib/rubocop/cop/style/trailing_blank_lines.rb +1 -1
- data/lib/rubocop/cop/style/unneeded_percent_q.rb +12 -6
- data/lib/rubocop/cop/util.rb +1 -1
- data/lib/rubocop/cop/variable_force/assignment.rb +1 -1
- data/lib/rubocop/cop/variable_force/locatable.rb +1 -1
- data/lib/rubocop/formatter/disabled_config_formatter.rb +18 -7
- data/lib/rubocop/formatter/html_formatter.rb +25 -11
- data/lib/rubocop/formatter/text_util.rb +1 -1
- data/lib/rubocop/node_pattern.rb +2 -0
- data/lib/rubocop/processed_source.rb +3 -0
- data/lib/rubocop/rake_task.rb +1 -1
- data/lib/rubocop/rspec/shared_contexts.rb +4 -0
- data/lib/rubocop/runner.rb +18 -7
- data/lib/rubocop/string_util.rb +2 -5
- data/lib/rubocop/version.rb +1 -1
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a32da91af2bcd18b8deee4673be9daf3a5783d2
|
4
|
+
data.tar.gz: 8d6c1b8a6624ccdaa5014ac08c18b2483768386c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a5deb237bbedb201eabcfc8923d488bd44c11e151371cc467f8ac8678c8f04fb48fddd4d721dd0cc147a01006916bd554a333d755114f9ea665be61beaef557
|
7
|
+
data.tar.gz: 7adc5a8bc59f5fecc727ebe5e60ebdc0c87072636294d91a701263e77ac9a785a471469d1bd0d035d10dd5cefbfd7fcb4d506a5cd9c240b193591200c8af4cbe
|
data/README.md
CHANGED
@@ -51,7 +51,7 @@ haven't reached version 1.0 yet). To prevent an unwanted RuboCop update you
|
|
51
51
|
might want to use a conservative version locking in your `Gemfile`:
|
52
52
|
|
53
53
|
```rb
|
54
|
-
gem 'rubocop', '~> 0.
|
54
|
+
gem 'rubocop', '~> 0.42.0', require: false
|
55
55
|
```
|
56
56
|
|
57
57
|
## Quickstart
|
@@ -71,12 +71,11 @@ You can read a ton more about RuboCop in its [official manual](http://rubocop.re
|
|
71
71
|
|
72
72
|
RuboCop supports the following Ruby implementations:
|
73
73
|
|
74
|
-
* MRI 1.9.3
|
75
74
|
* MRI 2.0
|
76
75
|
* MRI 2.1
|
77
76
|
* MRI 2.2
|
78
77
|
* MRI 2.3
|
79
|
-
* JRuby
|
78
|
+
* JRuby 9.0+
|
80
79
|
* Rubinius 2.0+
|
81
80
|
|
82
81
|
## Team
|
data/config/default.yml
CHANGED
@@ -643,6 +643,12 @@ Style/NonNilCheck:
|
|
643
643
|
# offenses for `!x.nil?` and does no changes that might change behavior.
|
644
644
|
IncludeSemanticChanges: false
|
645
645
|
|
646
|
+
Style/NumericPredicate:
|
647
|
+
EnforcedStyle: predicate
|
648
|
+
SupportedStyles:
|
649
|
+
- predicate
|
650
|
+
- comparison
|
651
|
+
|
646
652
|
Style/MethodDefParentheses:
|
647
653
|
EnforcedStyle: require_parentheses
|
648
654
|
SupportedStyles:
|
@@ -952,6 +958,13 @@ Style/SymbolProc:
|
|
952
958
|
- respond_to
|
953
959
|
- define_method
|
954
960
|
|
961
|
+
Style/TernaryParentheses:
|
962
|
+
EnforcedStyle: require_no_parentheses
|
963
|
+
SupportedStyles:
|
964
|
+
- require_parentheses
|
965
|
+
- require_no_parentheses
|
966
|
+
AllowSafeAssignment: true
|
967
|
+
|
955
968
|
Style/TrailingBlankLines:
|
956
969
|
EnforcedStyle: final_newline
|
957
970
|
SupportedStyles:
|
data/config/disabled.yml
CHANGED
@@ -5,6 +5,11 @@
|
|
5
5
|
Rails:
|
6
6
|
Enabled: false
|
7
7
|
|
8
|
+
Rails/SaveBang:
|
9
|
+
Description: 'Identifies possible cases where Active Record save! or related should be used.'
|
10
|
+
StyleGuide: 'https://github.com/bbatsov/rails-style-guide#save-bang'
|
11
|
+
Enabled: false
|
12
|
+
|
8
13
|
Style/AutoResourceCleanup:
|
9
14
|
Description: 'Suggests the usage of an auto resource cleanup version of a method (if available).'
|
10
15
|
Enabled: false
|
data/config/enabled.yml
CHANGED
@@ -417,6 +417,11 @@ Style/MethodName:
|
|
417
417
|
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#snake-case-symbols-methods-vars'
|
418
418
|
Enabled: true
|
419
419
|
|
420
|
+
Style/MethodMissing:
|
421
|
+
Description: 'Avoid using `method_missing`.'
|
422
|
+
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-method-missing'
|
423
|
+
Enabled: true
|
424
|
+
|
420
425
|
Style/ModuleFunction:
|
421
426
|
Description: 'Checks for usage of `extend self` in modules.'
|
422
427
|
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#module-function'
|
@@ -547,6 +552,12 @@ Style/NumericLiteralPrefix:
|
|
547
552
|
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#numeric-literal-prefixes'
|
548
553
|
Enabled: true
|
549
554
|
|
555
|
+
Style/NumericPredicate:
|
556
|
+
Description: >-
|
557
|
+
Checks for the use of predicate- or comparison methods for
|
558
|
+
numeric comparisons.
|
559
|
+
Enabled: true
|
560
|
+
|
550
561
|
Style/OneLineConditional:
|
551
562
|
Description: >-
|
552
563
|
Favor the ternary operator(?:) over
|
@@ -832,6 +843,10 @@ Style/Tab:
|
|
832
843
|
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#spaces-indentation'
|
833
844
|
Enabled: true
|
834
845
|
|
846
|
+
Style/TernaryParentheses:
|
847
|
+
Description: 'Checks for use of parentheses around ternary conditions.'
|
848
|
+
Enabled: true
|
849
|
+
|
835
850
|
Style/TrailingBlankLines:
|
836
851
|
Description: 'Checks trailing blank lines and final newline.'
|
837
852
|
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#newline-eof'
|
@@ -1206,6 +1221,7 @@ Lint/UnreachableCode:
|
|
1206
1221
|
Lint/UselessAccessModifier:
|
1207
1222
|
Description: 'Checks for useless access modifiers.'
|
1208
1223
|
Enabled: true
|
1224
|
+
ContextCreatingMethods: []
|
1209
1225
|
|
1210
1226
|
Lint/UselessArraySplat:
|
1211
1227
|
Description: 'Checks for useless array splats.'
|
@@ -1400,14 +1416,17 @@ Rails/Exit:
|
|
1400
1416
|
|
1401
1417
|
Rails/FindBy:
|
1402
1418
|
Description: 'Prefer find_by over where.first.'
|
1419
|
+
StyleGuide: 'https://github.com/bbatsov/rails-style-guide#find_by'
|
1403
1420
|
Enabled: true
|
1404
1421
|
|
1405
1422
|
Rails/FindEach:
|
1406
1423
|
Description: 'Prefer all.find_each over all.find.'
|
1424
|
+
StyleGuide: 'https://github.com/bbatsov/rails-style-guide#find-each'
|
1407
1425
|
Enabled: true
|
1408
1426
|
|
1409
1427
|
Rails/HasAndBelongsToMany:
|
1410
1428
|
Description: 'Prefer has_many :through to has_and_belongs_to_many.'
|
1429
|
+
StyleGuide: 'https://github.com/bbatsov/rails-style-guide#has-many-through'
|
1411
1430
|
Enabled: true
|
1412
1431
|
|
1413
1432
|
Rails/Output:
|
@@ -1426,6 +1445,7 @@ Rails/ReadWriteAttribute:
|
|
1426
1445
|
Description: >-
|
1427
1446
|
Checks for read_attribute(:attr) and
|
1428
1447
|
write_attribute(:attr, val).
|
1448
|
+
StyleGuide: 'https://github.com/bbatsov/rails-style-guide#read-attribute'
|
1429
1449
|
Enabled: true
|
1430
1450
|
|
1431
1451
|
Rails/RequestReferer:
|
data/lib/rubocop.rb
CHANGED
@@ -268,6 +268,7 @@ require 'rubocop/cop/style/method_call_parentheses'
|
|
268
268
|
require 'rubocop/cop/style/method_called_on_do_end_block'
|
269
269
|
require 'rubocop/cop/style/method_def_parentheses'
|
270
270
|
require 'rubocop/cop/style/method_name'
|
271
|
+
require 'rubocop/cop/style/method_missing'
|
271
272
|
require 'rubocop/cop/style/missing_else'
|
272
273
|
require 'rubocop/cop/style/module_function'
|
273
274
|
require 'rubocop/cop/style/multiline_array_brace_layout'
|
@@ -293,6 +294,7 @@ require 'rubocop/cop/style/non_nil_check'
|
|
293
294
|
require 'rubocop/cop/style/not'
|
294
295
|
require 'rubocop/cop/style/numeric_literals'
|
295
296
|
require 'rubocop/cop/style/numeric_literal_prefix'
|
297
|
+
require 'rubocop/cop/style/numeric_predicate'
|
296
298
|
require 'rubocop/cop/style/one_line_conditional'
|
297
299
|
require 'rubocop/cop/style/op_method'
|
298
300
|
require 'rubocop/cop/style/option_hash'
|
@@ -352,6 +354,7 @@ require 'rubocop/cop/style/symbol_array'
|
|
352
354
|
require 'rubocop/cop/style/symbol_literal'
|
353
355
|
require 'rubocop/cop/style/symbol_proc'
|
354
356
|
require 'rubocop/cop/style/tab'
|
357
|
+
require 'rubocop/cop/style/ternary_parentheses'
|
355
358
|
require 'rubocop/cop/style/trailing_blank_lines'
|
356
359
|
require 'rubocop/cop/style/trailing_comma_in_arguments'
|
357
360
|
require 'rubocop/cop/style/trailing_comma_in_literal'
|
@@ -382,6 +385,7 @@ require 'rubocop/cop/rails/output'
|
|
382
385
|
require 'rubocop/cop/rails/pluralization_grammar'
|
383
386
|
require 'rubocop/cop/rails/read_write_attribute'
|
384
387
|
require 'rubocop/cop/rails/request_referer'
|
388
|
+
require 'rubocop/cop/rails/save_bang'
|
385
389
|
require 'rubocop/cop/rails/scope_args'
|
386
390
|
require 'rubocop/cop/rails/time_zone'
|
387
391
|
require 'rubocop/cop/rails/uniq_before_pluck'
|
data/lib/rubocop/ast_node.rb
CHANGED
@@ -113,7 +113,8 @@ module RuboCop
|
|
113
113
|
Node.new(type || @type, children || @children, properties)
|
114
114
|
end
|
115
115
|
|
116
|
-
# Returns the index of the receiver node in its siblings.
|
116
|
+
# Returns the index of the receiver node in its siblings. (Sibling index
|
117
|
+
# uses zero based numbering.)
|
117
118
|
#
|
118
119
|
# @return [Integer] the index of the receiver node in its siblings
|
119
120
|
def sibling_index
|
@@ -564,12 +565,12 @@ module RuboCop
|
|
564
565
|
def case_if_value_used?
|
565
566
|
# (case <condition> <when...>)
|
566
567
|
# (if <condition> <truebranch> <falsebranch>)
|
567
|
-
sibling_index
|
568
|
+
sibling_index.zero? ? true : parent.value_used?
|
568
569
|
end
|
569
570
|
|
570
571
|
def while_until_value_used?
|
571
572
|
# (while <condition> <body>) -> always evaluates to `nil`
|
572
|
-
sibling_index
|
573
|
+
sibling_index.zero?
|
573
574
|
end
|
574
575
|
|
575
576
|
def parent_module_name_part(node)
|
data/lib/rubocop/config.rb
CHANGED
@@ -18,7 +18,7 @@ module RuboCop
|
|
18
18
|
AutoCorrect StyleGuide Details).freeze
|
19
19
|
# 2.0 is the oldest officially supported Ruby version.
|
20
20
|
DEFAULT_RUBY_VERSION = 2.0
|
21
|
-
KNOWN_RUBIES = [1.9, 2.0, 2.1, 2.2, 2.3].freeze
|
21
|
+
KNOWN_RUBIES = [1.9, 2.0, 2.1, 2.2, 2.3, 2.4].freeze
|
22
22
|
OBSOLETE_COPS = {
|
23
23
|
'Style/TrailingComma' =>
|
24
24
|
'The `Style/TrailingComma` cop no longer exists. Please use ' \
|
@@ -140,13 +140,8 @@ module RuboCop
|
|
140
140
|
|
141
141
|
def load_yaml_configuration(absolute_path)
|
142
142
|
yaml_code = IO.read(absolute_path, encoding: 'UTF-8')
|
143
|
-
|
144
|
-
|
145
|
-
# or files that only contained comments and blank lines. This problem
|
146
|
-
# is not possible to reproduce now, but we want to avoid it in case
|
147
|
-
# it's still there. So we only load the YAML code if we find some real
|
148
|
-
# code in there.
|
149
|
-
hash = yaml_code =~ /^[A-Z]/i ? yaml_safe_load(yaml_code) : {}
|
143
|
+
hash = yaml_safe_load(yaml_code) || {}
|
144
|
+
|
150
145
|
puts "configuration from #{absolute_path}" if debug?
|
151
146
|
|
152
147
|
unless hash.is_a?(Hash)
|
data/lib/rubocop/cop/cop.rb
CHANGED
@@ -217,17 +217,17 @@ module RuboCop
|
|
217
217
|
|
218
218
|
def style_guide_url
|
219
219
|
url = cop_config['StyleGuide']
|
220
|
-
|
220
|
+
url.nil? || url.empty? ? nil : url
|
221
221
|
end
|
222
222
|
|
223
223
|
def reference_url
|
224
224
|
url = cop_config['Reference']
|
225
|
-
|
225
|
+
url.nil? || url.empty? ? nil : url
|
226
226
|
end
|
227
227
|
|
228
228
|
def details
|
229
229
|
details = cop_config && cop_config['Details']
|
230
|
-
|
230
|
+
details.nil? || details.empty? ? nil : details
|
231
231
|
end
|
232
232
|
|
233
233
|
private
|
@@ -174,24 +174,26 @@ module RuboCop
|
|
174
174
|
|
175
175
|
def autocorrect(node)
|
176
176
|
ancestor_node = start_for_block_node(node)
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
corrector.insert_before(node.loc.end, ' ' * delta)
|
187
|
-
elsif end_col > start_col
|
188
|
-
range_start = starting_position_of_block_end + start_col - end_col
|
189
|
-
range = Parser::Source::Range.new(source, range_start,
|
190
|
-
starting_position_of_block_end)
|
191
|
-
corrector.remove(range)
|
192
|
-
end
|
177
|
+
start_col = compute_start_col(ancestor_node, node)
|
178
|
+
loc_end = node.loc.end
|
179
|
+
delta = start_col - loc_end.column
|
180
|
+
|
181
|
+
if delta > 0
|
182
|
+
add_space_before(loc_end, delta)
|
183
|
+
elsif delta < 0
|
184
|
+
source = node.source_range.source_buffer
|
185
|
+
remove_space_before(loc_end.begin_pos, -delta, source)
|
193
186
|
end
|
194
187
|
end
|
188
|
+
|
189
|
+
def add_space_before(loc, delta)
|
190
|
+
->(corrector) { corrector.insert_before(loc, ' ' * delta) }
|
191
|
+
end
|
192
|
+
|
193
|
+
def remove_space_before(end_pos, delta, source)
|
194
|
+
range = Parser::Source::Range.new(source, end_pos - delta, end_pos)
|
195
|
+
->(corrector) { corrector.remove(range) }
|
196
|
+
end
|
195
197
|
end
|
196
198
|
end
|
197
199
|
end
|
@@ -91,29 +91,44 @@ module RuboCop
|
|
91
91
|
end
|
92
92
|
|
93
93
|
def check_scope(node, cur_vis = :public)
|
94
|
-
node.children.
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
cur_vis = check_scope(child, cur_vis)
|
112
|
-
end
|
94
|
+
node.children.reduce(cur_vis) do |visibility, child|
|
95
|
+
check_child_scope(child, visibility)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def check_child_scope(node, cur_vis)
|
100
|
+
if (new_vis = access_modifier(node))
|
101
|
+
cur_vis = change_visibility(node, new_vis)
|
102
|
+
elsif node.defs_type?
|
103
|
+
mark_method_as_useless(node, cur_vis) if cur_vis != :public
|
104
|
+
elsif (methods = private_class_method(node))
|
105
|
+
# don't warn about defs nodes which are followed by a call to
|
106
|
+
# `private_class_method :name`
|
107
|
+
# obviously the programmer knows what they are doing
|
108
|
+
revert_method_uselessness(methods)
|
109
|
+
elsif node.kwbegin_type?
|
110
|
+
cur_vis = check_scope(node, cur_vis)
|
113
111
|
end
|
114
112
|
|
115
113
|
cur_vis
|
116
114
|
end
|
115
|
+
|
116
|
+
def change_visibility(node, new_vis)
|
117
|
+
@last_access_modifier = node
|
118
|
+
new_vis
|
119
|
+
end
|
120
|
+
|
121
|
+
def mark_method_as_useless(node, cur_vis)
|
122
|
+
_, method_name, = *node
|
123
|
+
@useless[method_name] = [node, cur_vis, @last_access_modifier]
|
124
|
+
end
|
125
|
+
|
126
|
+
def revert_method_uselessness(methods)
|
127
|
+
methods.each do |sym|
|
128
|
+
next unless sym.sym_type?
|
129
|
+
@useless.delete(sym.children[0])
|
130
|
+
end
|
131
|
+
end
|
117
132
|
end
|
118
133
|
end
|
119
134
|
end
|
@@ -27,11 +27,19 @@ module RuboCop
|
|
27
27
|
|
28
28
|
def on_block(node)
|
29
29
|
on_body_of_reduce(node) do |body|
|
30
|
-
void_next = body.each_node(:next).find
|
30
|
+
void_next = body.each_node(:next).find do |n|
|
31
|
+
n.children.empty? && parent_block_node(n) == node
|
32
|
+
end
|
31
33
|
|
32
34
|
add_offense(void_next, :expression) if void_next
|
33
35
|
end
|
34
36
|
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def parent_block_node(node)
|
41
|
+
node.each_ancestor.find { |n| n.type == :block }
|
42
|
+
end
|
35
43
|
end
|
36
44
|
end
|
37
45
|
end
|
@@ -66,10 +66,22 @@ module RuboCop
|
|
66
66
|
end
|
67
67
|
|
68
68
|
def contains_multiple_levels_of_exceptions?(group)
|
69
|
+
if group.size > 1 && group.include?(Exception)
|
70
|
+
# Treat `Exception` as the highest level exception unless `nil` was
|
71
|
+
# also rescued
|
72
|
+
return !(group.size == 2 && group.include?(NilClass))
|
73
|
+
end
|
74
|
+
|
69
75
|
group.any? do |exception|
|
70
76
|
higher_exception = false
|
71
77
|
group.each_with_index do |_e, i|
|
72
|
-
higher_exception ||=
|
78
|
+
higher_exception ||= begin
|
79
|
+
if group[i].nil? || exception.nil?
|
80
|
+
false
|
81
|
+
else
|
82
|
+
group[i] < exception
|
83
|
+
end
|
84
|
+
end
|
73
85
|
end
|
74
86
|
|
75
87
|
higher_exception
|
@@ -83,7 +95,7 @@ module RuboCop
|
|
83
95
|
begin
|
84
96
|
converted << instance_eval(exception, __FILE__, __LINE__)
|
85
97
|
rescue StandardError, ScriptError
|
86
|
-
|
98
|
+
converted << nil
|
87
99
|
end
|
88
100
|
end
|
89
101
|
else
|
@@ -94,7 +106,15 @@ module RuboCop
|
|
94
106
|
|
95
107
|
def sort_rescued_groups(groups)
|
96
108
|
groups.sort do |x, y|
|
97
|
-
x
|
109
|
+
if x.include?(Exception)
|
110
|
+
1
|
111
|
+
elsif y.include?(Exception)
|
112
|
+
-1
|
113
|
+
elsif x.empty? || y.empty?
|
114
|
+
0
|
115
|
+
else
|
116
|
+
x <=> y || 0
|
117
|
+
end
|
98
118
|
end
|
99
119
|
end
|
100
120
|
|
@@ -56,6 +56,29 @@ module RuboCop
|
|
56
56
|
# def self.method3
|
57
57
|
# end
|
58
58
|
# end
|
59
|
+
#
|
60
|
+
# @example
|
61
|
+
# # Lint/UselessAccessModifier:
|
62
|
+
# # ContextCreatingMethods:
|
63
|
+
# # - concerning
|
64
|
+
# require 'active_support/concern'
|
65
|
+
# class Foo
|
66
|
+
# concerning :Bar do
|
67
|
+
# def some_public_method
|
68
|
+
# end
|
69
|
+
#
|
70
|
+
# private
|
71
|
+
#
|
72
|
+
# def some_private_method
|
73
|
+
# end
|
74
|
+
# end
|
75
|
+
#
|
76
|
+
# # this is not redundant because `concerning` created its own context
|
77
|
+
# private
|
78
|
+
#
|
79
|
+
# def some_other_private_method
|
80
|
+
# end
|
81
|
+
# end
|
59
82
|
class UselessAccessModifier < Cop
|
60
83
|
MSG = 'Useless `%s` access modifier.'.freeze
|
61
84
|
|
@@ -68,7 +91,7 @@ module RuboCop
|
|
68
91
|
end
|
69
92
|
|
70
93
|
def on_block(node)
|
71
|
-
return unless
|
94
|
+
return unless eval_call?(node)
|
72
95
|
|
73
96
|
check_node(node.children[2]) # block body
|
74
97
|
end
|
@@ -153,12 +176,26 @@ module RuboCop
|
|
153
176
|
|
154
177
|
def start_of_new_scope?(child)
|
155
178
|
child.module_type? || child.class_type? ||
|
156
|
-
child.sclass_type? ||
|
179
|
+
child.sclass_type? || eval_call?(child)
|
157
180
|
end
|
158
181
|
|
159
|
-
def
|
182
|
+
def eval_call?(child)
|
160
183
|
class_or_instance_eval?(child) ||
|
161
|
-
class_or_module_or_struct_new_call?(child)
|
184
|
+
class_or_module_or_struct_new_call?(child) ||
|
185
|
+
any_context_creating_methods?(child)
|
186
|
+
end
|
187
|
+
|
188
|
+
def any_context_creating_methods?(child)
|
189
|
+
cop_config.fetch('ContextCreatingMethods', []).any? do |m|
|
190
|
+
matcher_name = "#{m}_block?".to_sym
|
191
|
+
unless respond_to?(matcher_name)
|
192
|
+
self.class.def_node_matcher matcher_name, <<-PATTERN
|
193
|
+
(block (send {nil const} {:#{m}} ...) ...)
|
194
|
+
PATTERN
|
195
|
+
end
|
196
|
+
|
197
|
+
send(matcher_name, child)
|
198
|
+
end
|
162
199
|
end
|
163
200
|
end
|
164
201
|
end
|