rubocop 0.80.1 → 0.81.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/config/default.yml +62 -15
- data/lib/rubocop.rb +4 -1
- data/lib/rubocop/ast/builder.rb +2 -0
- data/lib/rubocop/ast/node.rb +11 -6
- data/lib/rubocop/ast/node/block_node.rb +5 -1
- data/lib/rubocop/ast/node/case_match_node.rb +56 -0
- data/lib/rubocop/ast/traversal.rb +11 -9
- data/lib/rubocop/config_obsoletion.rb +1 -0
- data/lib/rubocop/cop/layout/array_alignment.rb +53 -10
- data/lib/rubocop/cop/layout/block_end_newline.rb +5 -3
- data/lib/rubocop/cop/layout/else_alignment.rb +8 -0
- data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +1 -1
- data/lib/rubocop/cop/lint/boolean_symbol.rb +12 -0
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +1 -1
- data/lib/rubocop/cop/lint/loop.rb +6 -4
- data/lib/rubocop/cop/lint/nested_method_definition.rb +2 -2
- data/lib/rubocop/cop/lint/raise_exception.rb +39 -0
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +1 -1
- data/lib/rubocop/cop/lint/struct_new_override.rb +58 -0
- data/lib/rubocop/cop/lint/suppressed_exception.rb +12 -22
- data/lib/rubocop/cop/lint/unused_method_argument.rb +32 -6
- data/lib/rubocop/cop/migration/department_name.rb +22 -9
- data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +6 -1
- data/lib/rubocop/cop/mixin/method_complexity.rb +5 -0
- data/lib/rubocop/cop/naming/method_name.rb +30 -0
- data/lib/rubocop/cop/style/access_modifier_declarations.rb +26 -6
- data/lib/rubocop/cop/style/collection_methods.rb +2 -0
- data/lib/rubocop/cop/style/documentation.rb +43 -5
- data/lib/rubocop/cop/style/end_block.rb +6 -0
- data/lib/rubocop/cop/style/hash_each_methods.rb +2 -0
- data/lib/rubocop/cop/style/hash_transform_keys.rb +6 -2
- data/lib/rubocop/cop/style/hash_transform_values.rb +6 -2
- data/lib/rubocop/cop/style/inverse_methods.rb +1 -1
- data/lib/rubocop/cop/style/lambda.rb +1 -0
- data/lib/rubocop/cop/style/module_function.rb +56 -10
- data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +2 -2
- data/lib/rubocop/cop/style/one_line_conditional.rb +3 -2
- data/lib/rubocop/cop/style/redundant_sort.rb +2 -2
- data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +34 -0
- data/lib/rubocop/cop/style/trailing_comma_in_array_literal.rb +41 -0
- data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +85 -0
- data/lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb +44 -0
- data/lib/rubocop/formatter/clang_style_formatter.rb +1 -1
- data/lib/rubocop/formatter/junit_formatter.rb +17 -6
- data/lib/rubocop/formatter/tap_formatter.rb +1 -1
- data/lib/rubocop/processed_source.rb +1 -1
- data/lib/rubocop/version.rb +1 -1
- metadata +8 -5
- data/lib/rubocop/cop/lint/end_in_method.rb +0 -40
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af0dab74354064816d5756cb5a49ab7160c444292ef32e9ee7980dff8a18110f
|
4
|
+
data.tar.gz: 96288aa5f77f19813ef7cac495f7c86d912f3be28da021b01d30136a2ef28f99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 015244a9c6aff6e2d5640e68b286127944418221bb8c76db04273c5c35b5bc41e03bf7d85c44a3b630a0dd8a24f5a4531ddaf61adb0b75a0b39e2e6c2e08d8cf
|
7
|
+
data.tar.gz: 8e209ee81ebf1d5a3215292c7d7eddabaacb64e0fa1da7935372495ad13e5bdd896b7fd27fde25fc0e8ffaa7d1b0873f47c40f505d4828e23a52f0ca2ee847e6
|
data/README.md
CHANGED
@@ -53,7 +53,7 @@ haven't reached version 1.0 yet). To prevent an unwanted RuboCop update you
|
|
53
53
|
might want to use a conservative version lock in your `Gemfile`:
|
54
54
|
|
55
55
|
```rb
|
56
|
-
gem 'rubocop', '~> 0.
|
56
|
+
gem 'rubocop', '~> 0.81.0', require: false
|
57
57
|
```
|
58
58
|
|
59
59
|
## Quickstart
|
data/config/default.yml
CHANGED
@@ -255,10 +255,30 @@ Layout/ArrayAlignment:
|
|
255
255
|
Description: >-
|
256
256
|
Align the elements of an array literal if they span more than
|
257
257
|
one line.
|
258
|
-
StyleGuide: '#
|
258
|
+
StyleGuide: '#no-double-indent'
|
259
259
|
Enabled: true
|
260
260
|
VersionAdded: '0.49'
|
261
261
|
VersionChanged: '0.77'
|
262
|
+
# Alignment of elements of a multi-line array.
|
263
|
+
#
|
264
|
+
# The `with_first_parameter` style aligns the following lines along the same
|
265
|
+
# column as the first element.
|
266
|
+
#
|
267
|
+
# array = [1, 2, 3,
|
268
|
+
# 4, 5, 6]
|
269
|
+
#
|
270
|
+
# The `with_fixed_indentation` style aligns the following lines with one
|
271
|
+
# level of indentation relative to the start of the line with start of array.
|
272
|
+
#
|
273
|
+
# array = [1, 2, 3,
|
274
|
+
# 4, 5, 6]
|
275
|
+
EnforcedStyle: with_first_element
|
276
|
+
SupportedStyles:
|
277
|
+
- with_first_element
|
278
|
+
- with_fixed_indentation
|
279
|
+
# By default, the indentation width from Layout/IndentationWidth is used
|
280
|
+
# But it can be overridden by setting this parameter
|
281
|
+
IndentationWidth: ~
|
262
282
|
|
263
283
|
Layout/AssignmentIndentation:
|
264
284
|
Description: >-
|
@@ -1303,6 +1323,7 @@ Lint/BooleanSymbol:
|
|
1303
1323
|
Description: 'Check for `:true` and `:false` symbols.'
|
1304
1324
|
Enabled: true
|
1305
1325
|
VersionAdded: '0.50'
|
1326
|
+
VersionChanged: '0.81'
|
1306
1327
|
|
1307
1328
|
Lint/CircularArgumentReference:
|
1308
1329
|
Description: "Default values in optional keyword arguments and optional ordinal arguments should not refer back to the name of the argument."
|
@@ -1375,11 +1396,6 @@ Lint/EmptyWhen:
|
|
1375
1396
|
Enabled: true
|
1376
1397
|
VersionAdded: '0.45'
|
1377
1398
|
|
1378
|
-
Lint/EndInMethod:
|
1379
|
-
Description: 'END blocks should not be placed inside method definitions.'
|
1380
|
-
Enabled: true
|
1381
|
-
VersionAdded: '0.9'
|
1382
|
-
|
1383
1399
|
Lint/EnsureReturn:
|
1384
1400
|
Description: 'Do not use return in an ensure block.'
|
1385
1401
|
StyleGuide: '#no-return-ensure'
|
@@ -1546,6 +1562,12 @@ Lint/PercentSymbolArray:
|
|
1546
1562
|
Enabled: true
|
1547
1563
|
VersionAdded: '0.41'
|
1548
1564
|
|
1565
|
+
Lint/RaiseException:
|
1566
|
+
Description: Checks for `raise` or `fail` statements which are raising `Exception` class.
|
1567
|
+
StyleGuide: '#raise-exception'
|
1568
|
+
Enabled: pending
|
1569
|
+
VersionAdded: '0.81'
|
1570
|
+
|
1549
1571
|
Lint/RandOne:
|
1550
1572
|
Description: >-
|
1551
1573
|
Checks for `rand(1)` calls. Such calls always return `0`
|
@@ -1574,7 +1596,7 @@ Lint/RedundantRequireStatement:
|
|
1574
1596
|
Lint/RedundantSplatExpansion:
|
1575
1597
|
Description: 'Checks for splat unnecessarily being called on literals.'
|
1576
1598
|
Enabled: true
|
1577
|
-
|
1599
|
+
VersionAdded: '0.76'
|
1578
1600
|
|
1579
1601
|
Lint/RedundantStringCoercion:
|
1580
1602
|
Description: 'Checks for Object#to_s usage in string interpolation.'
|
@@ -1688,13 +1710,18 @@ Lint/ShadowingOuterLocalVariable:
|
|
1688
1710
|
Enabled: true
|
1689
1711
|
VersionAdded: '0.9'
|
1690
1712
|
|
1713
|
+
Lint/StructNewOverride:
|
1714
|
+
Description: 'Disallow overriding the `Struct` built-in methods via `Struct.new`.'
|
1715
|
+
Enabled: pending
|
1716
|
+
VersionAdded: '0.81'
|
1717
|
+
|
1691
1718
|
Lint/SuppressedException:
|
1692
1719
|
Description: "Don't suppress exceptions."
|
1693
1720
|
StyleGuide: '#dont-hide-exceptions'
|
1694
1721
|
Enabled: true
|
1695
|
-
AllowComments:
|
1722
|
+
AllowComments: true
|
1696
1723
|
VersionAdded: '0.9'
|
1697
|
-
VersionChanged: '0.
|
1724
|
+
VersionChanged: '0.81'
|
1698
1725
|
|
1699
1726
|
Lint/Syntax:
|
1700
1727
|
Description: 'Checks syntax error.'
|
@@ -1705,6 +1732,7 @@ Lint/Syntax:
|
|
1705
1732
|
Lint/ToJSON:
|
1706
1733
|
Description: 'Ensure #to_json includes an optional argument.'
|
1707
1734
|
Enabled: true
|
1735
|
+
VersionAdded: '0.66'
|
1708
1736
|
|
1709
1737
|
Lint/UnderscorePrefixedVariableName:
|
1710
1738
|
Description: 'Do not use prefix `_` for a variable that is used.'
|
@@ -1736,9 +1764,10 @@ Lint/UnusedMethodArgument:
|
|
1736
1764
|
StyleGuide: '#underscore-unused-vars'
|
1737
1765
|
Enabled: true
|
1738
1766
|
VersionAdded: '0.21'
|
1739
|
-
VersionChanged: '0.
|
1767
|
+
VersionChanged: '0.81'
|
1740
1768
|
AllowUnusedKeywordArguments: false
|
1741
1769
|
IgnoreEmptyMethods: true
|
1770
|
+
IgnoreNotImplementedMethods: true
|
1742
1771
|
|
1743
1772
|
Lint/UriEscapeUnescape:
|
1744
1773
|
Description: >-
|
@@ -1804,9 +1833,10 @@ Metrics/AbcSize:
|
|
1804
1833
|
- https://en.wikipedia.org/wiki/ABC_Software_Metric
|
1805
1834
|
Enabled: true
|
1806
1835
|
VersionAdded: '0.27'
|
1807
|
-
VersionChanged: '0.
|
1836
|
+
VersionChanged: '0.81'
|
1808
1837
|
# The ABC size is a calculated magnitude, so this number can be an Integer or
|
1809
1838
|
# a Float.
|
1839
|
+
IgnoredMethods: []
|
1810
1840
|
Max: 15
|
1811
1841
|
|
1812
1842
|
Metrics/BlockLength:
|
@@ -1846,6 +1876,8 @@ Metrics/CyclomaticComplexity:
|
|
1846
1876
|
of test cases needed to validate a method.
|
1847
1877
|
Enabled: true
|
1848
1878
|
VersionAdded: '0.25'
|
1879
|
+
VersionChanged: '0.81'
|
1880
|
+
IgnoredMethods: []
|
1849
1881
|
Max: 6
|
1850
1882
|
|
1851
1883
|
Metrics/MethodLength:
|
@@ -1879,6 +1911,8 @@ Metrics/PerceivedComplexity:
|
|
1879
1911
|
human reader.
|
1880
1912
|
Enabled: true
|
1881
1913
|
VersionAdded: '0.25'
|
1914
|
+
VersionChanged: '0.81'
|
1915
|
+
IgnoredMethods: []
|
1882
1916
|
Max: 7
|
1883
1917
|
|
1884
1918
|
################## Migration #############################
|
@@ -1888,6 +1922,7 @@ Migration/DepartmentName:
|
|
1888
1922
|
Check that cop names in rubocop:disable (etc) comments are
|
1889
1923
|
given with department name.
|
1890
1924
|
Enabled: true
|
1925
|
+
VersionAdded: '0.75'
|
1891
1926
|
|
1892
1927
|
#################### Naming ##############################
|
1893
1928
|
|
@@ -2178,10 +2213,12 @@ Style/AccessModifierDeclarations:
|
|
2178
2213
|
Description: 'Checks style of how access modifiers are used.'
|
2179
2214
|
Enabled: true
|
2180
2215
|
VersionAdded: '0.57'
|
2216
|
+
VersionChanged: '0.81'
|
2181
2217
|
EnforcedStyle: group
|
2182
2218
|
SupportedStyles:
|
2183
2219
|
- inline
|
2184
2220
|
- group
|
2221
|
+
AllowModifiersOnSymbols: true
|
2185
2222
|
|
2186
2223
|
Style/Alias:
|
2187
2224
|
Description: 'Use alias instead of alias_method.'
|
@@ -2435,7 +2472,7 @@ Style/ClassVars:
|
|
2435
2472
|
# Align with the style guide.
|
2436
2473
|
Style/CollectionMethods:
|
2437
2474
|
Description: 'Preferred collection methods.'
|
2438
|
-
StyleGuide: '#map-find-select-reduce-size'
|
2475
|
+
StyleGuide: '#map-find-select-reduce-include-size'
|
2439
2476
|
Enabled: false
|
2440
2477
|
VersionAdded: '0.9'
|
2441
2478
|
VersionChanged: '0.27'
|
@@ -2452,6 +2489,7 @@ Style/CollectionMethods:
|
|
2452
2489
|
inject: 'reduce'
|
2453
2490
|
detect: 'find'
|
2454
2491
|
find_all: 'select'
|
2492
|
+
member?: 'include?'
|
2455
2493
|
|
2456
2494
|
Style/ColonMethodCall:
|
2457
2495
|
Description: 'Do not use :: for method call.'
|
@@ -2677,6 +2715,7 @@ Style/EndBlock:
|
|
2677
2715
|
StyleGuide: '#no-END-blocks'
|
2678
2716
|
Enabled: true
|
2679
2717
|
VersionAdded: '0.9'
|
2718
|
+
VersionChanged: '0.81'
|
2680
2719
|
|
2681
2720
|
Style/EvalWithLocation:
|
2682
2721
|
Description: 'Pass `__FILE__` and `__LINE__` to `eval` method, as they are used by backtraces.'
|
@@ -2937,7 +2976,7 @@ Style/LambdaCall:
|
|
2937
2976
|
Description: 'Use lambda.call(...) instead of lambda.(...).'
|
2938
2977
|
StyleGuide: '#proc-call'
|
2939
2978
|
Enabled: true
|
2940
|
-
VersionAdded: '0.13
|
2979
|
+
VersionAdded: '0.13'
|
2941
2980
|
VersionChanged: '0.14'
|
2942
2981
|
EnforcedStyle: call
|
2943
2982
|
SupportedStyles:
|
@@ -3067,6 +3106,7 @@ Style/ModuleFunction:
|
|
3067
3106
|
SupportedStyles:
|
3068
3107
|
- module_function
|
3069
3108
|
- extend_self
|
3109
|
+
- forbidden
|
3070
3110
|
Autocorrect: false
|
3071
3111
|
SafeAutoCorrect: false
|
3072
3112
|
|
@@ -3806,22 +3846,29 @@ Style/TrailingCommaInArrayLiteral:
|
|
3806
3846
|
StyleGuide: '#no-trailing-array-commas'
|
3807
3847
|
Enabled: true
|
3808
3848
|
VersionAdded: '0.53'
|
3849
|
+
# If `comma`, the cop requires a comma after the last item in an array,
|
3809
3850
|
# but only when each item is on its own line.
|
3810
3851
|
# If `consistent_comma`, the cop requires a comma after the last item of all
|
3811
|
-
# non-empty array literals.
|
3852
|
+
# non-empty, multiline array literals.
|
3812
3853
|
EnforcedStyleForMultiline: no_comma
|
3813
3854
|
SupportedStylesForMultiline:
|
3814
3855
|
- comma
|
3815
3856
|
- consistent_comma
|
3816
3857
|
- no_comma
|
3817
3858
|
|
3859
|
+
Style/TrailingCommaInBlockArgs:
|
3860
|
+
Description: 'Checks for useless trailing commas in block arguments.'
|
3861
|
+
Enabled: false
|
3862
|
+
Safe: false
|
3863
|
+
VersionAdded: '0.81'
|
3864
|
+
|
3818
3865
|
Style/TrailingCommaInHashLiteral:
|
3819
3866
|
Description: 'Checks for trailing comma in hash literals.'
|
3820
3867
|
Enabled: true
|
3821
3868
|
# If `comma`, the cop requires a comma after the last item in a hash,
|
3822
3869
|
# but only when each item is on its own line.
|
3823
3870
|
# If `consistent_comma`, the cop requires a comma after the last item of all
|
3824
|
-
# non-empty hash literals.
|
3871
|
+
# non-empty, multiline hash literals.
|
3825
3872
|
EnforcedStyleForMultiline: no_comma
|
3826
3873
|
SupportedStylesForMultiline:
|
3827
3874
|
- comma
|
data/lib/rubocop.rb
CHANGED
@@ -37,6 +37,7 @@ require_relative 'rubocop/ast/node/args_node'
|
|
37
37
|
require_relative 'rubocop/ast/node/array_node'
|
38
38
|
require_relative 'rubocop/ast/node/block_node'
|
39
39
|
require_relative 'rubocop/ast/node/break_node'
|
40
|
+
require_relative 'rubocop/ast/node/case_match_node'
|
40
41
|
require_relative 'rubocop/ast/node/case_node'
|
41
42
|
require_relative 'rubocop/ast/node/class_node'
|
42
43
|
require_relative 'rubocop/ast/node/def_node'
|
@@ -299,7 +300,6 @@ require_relative 'rubocop/cop/lint/empty_ensure'
|
|
299
300
|
require_relative 'rubocop/cop/lint/empty_expression'
|
300
301
|
require_relative 'rubocop/cop/lint/empty_interpolation'
|
301
302
|
require_relative 'rubocop/cop/lint/empty_when'
|
302
|
-
require_relative 'rubocop/cop/lint/end_in_method'
|
303
303
|
require_relative 'rubocop/cop/lint/ensure_return'
|
304
304
|
require_relative 'rubocop/cop/lint/erb_new_arguments'
|
305
305
|
require_relative 'rubocop/cop/lint/flip_flop'
|
@@ -325,6 +325,7 @@ require_relative 'rubocop/cop/lint/ordered_magic_comments'
|
|
325
325
|
require_relative 'rubocop/cop/lint/parentheses_as_grouped_expression'
|
326
326
|
require_relative 'rubocop/cop/lint/percent_string_array'
|
327
327
|
require_relative 'rubocop/cop/lint/percent_symbol_array'
|
328
|
+
require_relative 'rubocop/cop/lint/raise_exception'
|
328
329
|
require_relative 'rubocop/cop/lint/rand_one'
|
329
330
|
require_relative 'rubocop/cop/lint/redundant_cop_disable_directive'
|
330
331
|
require_relative 'rubocop/cop/lint/redundant_cop_enable_directive'
|
@@ -346,6 +347,7 @@ require_relative 'rubocop/cop/lint/send_with_mixin_argument'
|
|
346
347
|
require_relative 'rubocop/cop/lint/shadowed_argument'
|
347
348
|
require_relative 'rubocop/cop/lint/shadowed_exception'
|
348
349
|
require_relative 'rubocop/cop/lint/shadowing_outer_local_variable'
|
350
|
+
require_relative 'rubocop/cop/lint/struct_new_override'
|
349
351
|
require_relative 'rubocop/cop/lint/suppressed_exception'
|
350
352
|
require_relative 'rubocop/cop/lint/syntax'
|
351
353
|
require_relative 'rubocop/cop/lint/to_json'
|
@@ -555,6 +557,7 @@ require_relative 'rubocop/cop/style/trailing_body_on_method_definition'
|
|
555
557
|
require_relative 'rubocop/cop/style/trailing_body_on_module'
|
556
558
|
require_relative 'rubocop/cop/style/trailing_comma_in_arguments'
|
557
559
|
require_relative 'rubocop/cop/style/trailing_comma_in_array_literal'
|
560
|
+
require_relative 'rubocop/cop/style/trailing_comma_in_block_args'
|
558
561
|
require_relative 'rubocop/cop/style/trailing_comma_in_hash_literal'
|
559
562
|
require_relative 'rubocop/cop/style/trailing_method_end_statement'
|
560
563
|
require_relative 'rubocop/cop/style/trailing_underscore_variable'
|
data/lib/rubocop/ast/builder.rb
CHANGED
data/lib/rubocop/ast/node.rb
CHANGED
@@ -98,7 +98,7 @@ module RuboCop
|
|
98
98
|
@mutable_attributes.frozen?
|
99
99
|
end
|
100
100
|
|
101
|
-
protected :parent=
|
101
|
+
protected :parent=
|
102
102
|
|
103
103
|
# Override `AST::Node#updated` so that `AST::Processor` does not try to
|
104
104
|
# mutate our ASTs. Since we keep references from children to parents and
|
@@ -291,7 +291,7 @@ module RuboCop
|
|
291
291
|
## Destructuring
|
292
292
|
|
293
293
|
def_node_matcher :receiver, <<~PATTERN
|
294
|
-
{(send $_ ...) (block (send $_ ...) ...)}
|
294
|
+
{(send $_ ...) ({block numblock} (send $_ ...) ...)}
|
295
295
|
PATTERN
|
296
296
|
|
297
297
|
def_node_matcher :str_content, '(str $_)'
|
@@ -313,9 +313,8 @@ module RuboCop
|
|
313
313
|
(casgn $_ $_ (send (const nil? {:Class :Module}) :new ...))
|
314
314
|
(casgn $_ $_ (block (send (const nil? {:Class :Module}) :new ...) ...))}
|
315
315
|
PATTERN
|
316
|
-
|
316
|
+
|
317
317
|
private :defined_module0
|
318
|
-
# rubocop:enable Style/AccessModifierDeclarations
|
319
318
|
|
320
319
|
def defined_module
|
321
320
|
namespace, name = *defined_module0
|
@@ -469,7 +468,13 @@ module RuboCop
|
|
469
468
|
irange_type? || erange_type?
|
470
469
|
end
|
471
470
|
|
472
|
-
|
471
|
+
def guard_clause?
|
472
|
+
node = and_type? || or_type? ? rhs : self
|
473
|
+
|
474
|
+
node.match_guard_clause?
|
475
|
+
end
|
476
|
+
|
477
|
+
def_node_matcher :match_guard_clause?, <<~PATTERN
|
473
478
|
[${(send nil? {:raise :fail} ...) return break next} single_line?]
|
474
479
|
PATTERN
|
475
480
|
|
@@ -479,7 +484,7 @@ module RuboCop
|
|
479
484
|
(send (const nil? :Proc) :new)}
|
480
485
|
PATTERN
|
481
486
|
|
482
|
-
def_node_matcher :lambda?, '(block (send nil? :lambda) ...)'
|
487
|
+
def_node_matcher :lambda?, '({block numblock} (send nil? :lambda) ...)'
|
483
488
|
def_node_matcher :lambda_or_proc?, '{lambda? proc?}'
|
484
489
|
|
485
490
|
def_node_matcher :class_constructor?, <<~PATTERN
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module AST
|
5
|
+
# A node extension for `case_match` nodes. This will be used in place of
|
6
|
+
# a plain node when the builder constructs the AST, making its methods
|
7
|
+
# available to all `case_match` nodes within RuboCop.
|
8
|
+
class CaseMatchNode < Node
|
9
|
+
include ConditionalNode
|
10
|
+
|
11
|
+
# Returns the keyword of the `case` statement as a string.
|
12
|
+
#
|
13
|
+
# @return [String] the keyword of the `case` statement
|
14
|
+
def keyword
|
15
|
+
'case'
|
16
|
+
end
|
17
|
+
|
18
|
+
# Calls the given block for each `in_pattern` node in the `in` statement.
|
19
|
+
# If no block is given, an `Enumerator` is returned.
|
20
|
+
#
|
21
|
+
# @return [self] if a block is given
|
22
|
+
# @return [Enumerator] if no block is given
|
23
|
+
def each_in_pattern
|
24
|
+
return in_pattern_branches.to_enum(__method__) unless block_given?
|
25
|
+
|
26
|
+
in_pattern_branches.each do |condition|
|
27
|
+
yield condition
|
28
|
+
end
|
29
|
+
|
30
|
+
self
|
31
|
+
end
|
32
|
+
|
33
|
+
# Returns an array of all the when branches in the `case` statement.
|
34
|
+
#
|
35
|
+
# @return [Array<Node>] an array of `in_pattern` nodes
|
36
|
+
def in_pattern_branches
|
37
|
+
node_parts[1...-1]
|
38
|
+
end
|
39
|
+
|
40
|
+
# Returns the else branch of the `case` statement, if any.
|
41
|
+
#
|
42
|
+
# @return [Node] the else branch node of the `case` statement
|
43
|
+
# @return [nil] if the case statement does not have an else branch.
|
44
|
+
def else_branch
|
45
|
+
node_parts[-1]
|
46
|
+
end
|
47
|
+
|
48
|
+
# Checks whether this case statement has an `else` branch.
|
49
|
+
#
|
50
|
+
# @return [Boolean] whether the `case` statement has an `else` branch
|
51
|
+
def else?
|
52
|
+
!loc.else.nil?
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -21,7 +21,7 @@ module RuboCop
|
|
21
21
|
arg restarg blockarg shadowarg
|
22
22
|
kwrestarg zsuper lambda redo retry
|
23
23
|
forward_args forwarded_args
|
24
|
-
match_var match_nil_pattern].freeze
|
24
|
+
match_var match_nil_pattern empty_else].freeze
|
25
25
|
ONE_CHILD_NODE = %i[splat kwsplat block_pass not break next
|
26
26
|
preexe postexe match_current_line defined?
|
27
27
|
arg_expr pin match_rest if_guard unless_guard
|
@@ -31,7 +31,7 @@ module RuboCop
|
|
31
31
|
undef alias args super yield or and
|
32
32
|
while_post until_post iflipflop eflipflop
|
33
33
|
match_with_lvasgn begin kwbegin return
|
34
|
-
in_match
|
34
|
+
in_match match_alt
|
35
35
|
match_as array_pattern array_pattern_with_tail
|
36
36
|
hash_pattern const_pattern].freeze
|
37
37
|
SECOND_CHILD_ONLY = %i[lvasgn ivasgn cvasgn gvasgn optarg kwarg
|
@@ -178,13 +178,15 @@ module RuboCop
|
|
178
178
|
nil
|
179
179
|
end
|
180
180
|
|
181
|
-
alias on_rescue
|
182
|
-
alias on_resbody
|
183
|
-
alias on_ensure
|
184
|
-
alias on_for
|
185
|
-
alias on_when
|
186
|
-
alias
|
187
|
-
alias
|
181
|
+
alias on_rescue on_case
|
182
|
+
alias on_resbody on_case
|
183
|
+
alias on_ensure on_case
|
184
|
+
alias on_for on_case
|
185
|
+
alias on_when on_case
|
186
|
+
alias on_case_match on_case
|
187
|
+
alias on_in_pattern on_case
|
188
|
+
alias on_irange on_case
|
189
|
+
alias on_erange on_case
|
188
190
|
|
189
191
|
def on_numblock(node)
|
190
192
|
children = node.children
|