rubocop 1.50.0 → 1.50.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/config/default.yml +2 -0
- data/lib/rubocop/cop/gemspec/deprecated_attribute_assignment.rb +1 -1
- data/lib/rubocop/cop/layout/first_array_element_line_break.rb +25 -34
- data/lib/rubocop/cop/layout/first_hash_element_line_break.rb +7 -19
- data/lib/rubocop/cop/layout/first_method_argument_line_break.rb +42 -52
- data/lib/rubocop/cop/layout/first_method_parameter_line_break.rb +38 -55
- data/lib/rubocop/cop/layout/multiline_array_line_breaks.rb +8 -27
- data/lib/rubocop/cop/layout/multiline_hash_key_line_breaks.rb +7 -26
- data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +4 -21
- data/lib/rubocop/cop/layout/multiline_method_parameter_line_breaks.rb +6 -30
- data/lib/rubocop/cop/lint/duplicate_match_pattern.rb +25 -5
- data/lib/rubocop/cop/style/collection_compact.rb +3 -0
- data/lib/rubocop/cop/style/parallel_assignment.rb +26 -18
- data/lib/rubocop/cop/style/redundant_fetch_block.rb +6 -4
- data/lib/rubocop/cop/style/redundant_line_continuation.rb +16 -4
- data/lib/rubocop/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 67accbc10c4c2ae80033ab2a3713fce8a190d772234cbd52c5584e5c69895915
|
4
|
+
data.tar.gz: 69e7f99ee66c192619b2dc26df6d0ac73c794bb088bade8182f3eceb1cb8d8c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 21005d0d16a207a998640686ee7dcf251683899ab8e746baa861888fd26f2e58791733b48869a085b1b365ce2b67e64b216b4cfe6c1a2e26a2ecc699da0ea085
|
7
|
+
data.tar.gz: 461a588bb95269c194efee4ee8570c166ce009695664aa31181f1f0806220f451e4685d4feff8751d4135f196d3cb42ec100c171b905526e06ed968cd9bb47f9
|
data/config/default.yml
CHANGED
@@ -4067,7 +4067,9 @@ Style/InverseMethods:
|
|
4067
4067
|
Style/InvertibleUnlessCondition:
|
4068
4068
|
Description: 'Favor `if` with inverted condition over `unless`.'
|
4069
4069
|
Enabled: false
|
4070
|
+
Safe: false
|
4070
4071
|
VersionAdded: '1.44'
|
4072
|
+
VersionChanged: '1.50'
|
4071
4073
|
# `InverseMethods` are methods that can be inverted in a `unless` condition.
|
4072
4074
|
# The relationship of inverse methods needs to be defined in both directions.
|
4073
4075
|
# Keys and values both need to be defined as symbols.
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Gemspec
|
6
|
-
# Checks that deprecated
|
6
|
+
# Checks that deprecated attributes are not set in a gemspec file.
|
7
7
|
# Removing deprecated attributes allows the user to receive smaller packed gems.
|
8
8
|
#
|
9
9
|
# @example
|
@@ -6,49 +6,40 @@ module RuboCop
|
|
6
6
|
# Checks for a line break before the first element in a
|
7
7
|
# multi-line array.
|
8
8
|
#
|
9
|
-
# @example
|
9
|
+
# @example
|
10
10
|
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
11
|
+
# # bad
|
12
|
+
# [ :a,
|
13
|
+
# :b]
|
14
14
|
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
15
|
+
# # good
|
16
|
+
# [
|
17
|
+
# :a,
|
18
|
+
# :b]
|
19
19
|
#
|
20
|
-
#
|
21
|
-
#
|
20
|
+
# # good
|
21
|
+
# [:a, :b]
|
22
22
|
#
|
23
|
-
#
|
24
|
-
# [
|
25
|
-
# :a,
|
26
|
-
# :b]
|
23
|
+
# @example AllowMultilineFinalElement: false (default)
|
27
24
|
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
# }]
|
25
|
+
# # bad
|
26
|
+
# [ :a, {
|
27
|
+
# :b => :c
|
28
|
+
# }]
|
33
29
|
#
|
34
|
-
#
|
30
|
+
# # good
|
31
|
+
# [
|
32
|
+
# :a, {
|
33
|
+
# :b => :c
|
34
|
+
# }]
|
35
35
|
#
|
36
|
-
#
|
37
|
-
# [ :a,
|
38
|
-
# :b]
|
39
|
-
#
|
40
|
-
# # good
|
41
|
-
# [ :a, {
|
42
|
-
# :b => :c
|
43
|
-
# }]
|
36
|
+
# @example AllowMultilineFinalElement: true
|
44
37
|
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
38
|
+
# # good
|
39
|
+
# [:a, {
|
40
|
+
# :b => :c
|
41
|
+
# }]
|
49
42
|
#
|
50
|
-
# # good
|
51
|
-
# [:a, :b]
|
52
43
|
class FirstArrayElementLineBreak < Base
|
53
44
|
include FirstElementLineBreak
|
54
45
|
extend AutoCorrector
|
@@ -6,17 +6,12 @@ module RuboCop
|
|
6
6
|
# Checks for a line break before the first element in a
|
7
7
|
# multi-line hash.
|
8
8
|
#
|
9
|
-
# @example
|
9
|
+
# @example
|
10
10
|
#
|
11
11
|
# # bad
|
12
12
|
# { a: 1,
|
13
13
|
# b: 2}
|
14
14
|
#
|
15
|
-
# # bad
|
16
|
-
# { a: 1, b: {
|
17
|
-
# c: 3
|
18
|
-
# }}
|
19
|
-
#
|
20
15
|
# # good
|
21
16
|
# {
|
22
17
|
# a: 1,
|
@@ -28,11 +23,14 @@ module RuboCop
|
|
28
23
|
# c: 3
|
29
24
|
# }}
|
30
25
|
#
|
31
|
-
# @example AllowMultilineFinalElement:
|
26
|
+
# @example AllowMultilineFinalElement: false (default)
|
32
27
|
#
|
33
28
|
# # bad
|
34
|
-
# { a: 1,
|
35
|
-
#
|
29
|
+
# { a: 1, b: {
|
30
|
+
# c: 3
|
31
|
+
# }}
|
32
|
+
#
|
33
|
+
# @example AllowMultilineFinalElement: true
|
36
34
|
#
|
37
35
|
# # bad
|
38
36
|
# { a: 1,
|
@@ -45,16 +43,6 @@ module RuboCop
|
|
45
43
|
# c: 3
|
46
44
|
# }}
|
47
45
|
#
|
48
|
-
# # good
|
49
|
-
# {
|
50
|
-
# a: 1,
|
51
|
-
# b: 2 }
|
52
|
-
#
|
53
|
-
# # good
|
54
|
-
# {
|
55
|
-
# a: 1, b: {
|
56
|
-
# c: 3
|
57
|
-
# }}
|
58
46
|
class FirstHashElementLineBreak < Base
|
59
47
|
include FirstElementLineBreak
|
60
48
|
extend AutoCorrector
|
@@ -6,73 +6,63 @@ module RuboCop
|
|
6
6
|
# Checks for a line break before the first argument in a
|
7
7
|
# multi-line method call.
|
8
8
|
#
|
9
|
-
# @example
|
10
|
-
#
|
11
|
-
# # bad
|
12
|
-
# method(foo, bar,
|
13
|
-
# baz)
|
14
|
-
#
|
15
|
-
# # bad
|
16
|
-
# method(foo, bar, {
|
17
|
-
# baz: "a",
|
18
|
-
# qux: "b",
|
19
|
-
# })
|
9
|
+
# @example
|
20
10
|
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
# baz)
|
11
|
+
# # bad
|
12
|
+
# method(foo, bar,
|
13
|
+
# baz)
|
25
14
|
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
# qux: "b",
|
31
|
-
# })
|
15
|
+
# # good
|
16
|
+
# method(
|
17
|
+
# foo, bar,
|
18
|
+
# baz)
|
32
19
|
#
|
33
20
|
# # ignored
|
34
21
|
# method foo, bar,
|
35
22
|
# baz
|
36
23
|
#
|
37
|
-
# @example AllowMultilineFinalElement:
|
24
|
+
# @example AllowMultilineFinalElement: false (default)
|
25
|
+
#
|
26
|
+
# # bad
|
27
|
+
# method(foo, bar, {
|
28
|
+
# baz: "a",
|
29
|
+
# qux: "b",
|
30
|
+
# })
|
38
31
|
#
|
39
|
-
#
|
40
|
-
#
|
41
|
-
#
|
32
|
+
# # good
|
33
|
+
# method(
|
34
|
+
# foo, bar, {
|
35
|
+
# baz: "a",
|
36
|
+
# qux: "b",
|
37
|
+
# })
|
42
38
|
#
|
43
|
-
#
|
44
|
-
# method(foo,
|
45
|
-
# bar,
|
46
|
-
# {
|
47
|
-
# baz: "a",
|
48
|
-
# qux: "b",
|
49
|
-
# }
|
50
|
-
# )
|
39
|
+
# @example AllowMultilineFinalElement: true
|
51
40
|
#
|
52
|
-
#
|
53
|
-
#
|
41
|
+
# # bad
|
42
|
+
# method(foo,
|
43
|
+
# bar,
|
44
|
+
# {
|
54
45
|
# baz: "a",
|
55
46
|
# qux: "b",
|
56
|
-
# }
|
47
|
+
# }
|
48
|
+
# )
|
57
49
|
#
|
58
|
-
#
|
59
|
-
#
|
60
|
-
#
|
61
|
-
#
|
50
|
+
# # good
|
51
|
+
# method(foo, bar, {
|
52
|
+
# baz: "a",
|
53
|
+
# qux: "b",
|
54
|
+
# })
|
62
55
|
#
|
63
|
-
#
|
64
|
-
#
|
65
|
-
#
|
66
|
-
#
|
67
|
-
#
|
68
|
-
#
|
69
|
-
#
|
70
|
-
#
|
71
|
-
#
|
56
|
+
# # good
|
57
|
+
# method(
|
58
|
+
# foo,
|
59
|
+
# bar,
|
60
|
+
# {
|
61
|
+
# baz: "a",
|
62
|
+
# qux: "b",
|
63
|
+
# }
|
64
|
+
# )
|
72
65
|
#
|
73
|
-
# # ignored
|
74
|
-
# method foo, bar,
|
75
|
-
# baz
|
76
66
|
class FirstMethodArgumentLineBreak < Base
|
77
67
|
include FirstElementLineBreak
|
78
68
|
extend AutoCorrector
|
@@ -6,69 +6,52 @@ module RuboCop
|
|
6
6
|
# Checks for a line break before the first parameter in a
|
7
7
|
# multi-line method parameter definition.
|
8
8
|
#
|
9
|
-
# @example
|
10
|
-
#
|
11
|
-
# # bad
|
12
|
-
# def method(foo, bar,
|
13
|
-
# baz)
|
14
|
-
# do_something
|
15
|
-
# end
|
16
|
-
#
|
17
|
-
# # bad
|
18
|
-
# def method(foo, bar, baz = {
|
19
|
-
# :a => "b",
|
20
|
-
# })
|
21
|
-
# do_something
|
22
|
-
# end
|
9
|
+
# @example
|
23
10
|
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
# end
|
11
|
+
# # bad
|
12
|
+
# def method(foo, bar,
|
13
|
+
# baz)
|
14
|
+
# do_something
|
15
|
+
# end
|
30
16
|
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
# foo, bar,
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
# end
|
17
|
+
# # good
|
18
|
+
# def method(
|
19
|
+
# foo, bar,
|
20
|
+
# baz)
|
21
|
+
# do_something
|
22
|
+
# end
|
38
23
|
#
|
39
|
-
#
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
43
|
-
#
|
24
|
+
# # ignored
|
25
|
+
# def method foo,
|
26
|
+
# bar
|
27
|
+
# do_something
|
28
|
+
# end
|
44
29
|
#
|
45
|
-
# @example AllowMultilineFinalElement:
|
30
|
+
# @example AllowMultilineFinalElement: false (default)
|
46
31
|
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#
|
51
|
-
#
|
32
|
+
# # bad
|
33
|
+
# def method(foo, bar, baz = {
|
34
|
+
# :a => "b",
|
35
|
+
# })
|
36
|
+
# do_something
|
37
|
+
# end
|
52
38
|
#
|
53
|
-
#
|
54
|
-
#
|
55
|
-
#
|
56
|
-
#
|
57
|
-
#
|
58
|
-
#
|
39
|
+
# # good
|
40
|
+
# def method(
|
41
|
+
# foo, bar, baz = {
|
42
|
+
# :a => "b",
|
43
|
+
# })
|
44
|
+
# do_something
|
45
|
+
# end
|
59
46
|
#
|
60
|
-
#
|
61
|
-
# def method(
|
62
|
-
# foo, bar,
|
63
|
-
# baz)
|
64
|
-
# do_something
|
65
|
-
# end
|
47
|
+
# @example AllowMultilineFinalElement: true
|
66
48
|
#
|
67
|
-
#
|
68
|
-
#
|
69
|
-
#
|
70
|
-
#
|
71
|
-
#
|
49
|
+
# # good
|
50
|
+
# def method(foo, bar, baz = {
|
51
|
+
# :a => "b",
|
52
|
+
# })
|
53
|
+
# do_something
|
54
|
+
# end
|
72
55
|
#
|
73
56
|
class FirstMethodParameterLineBreak < Base
|
74
57
|
include FirstElementLineBreak
|
@@ -6,7 +6,7 @@ module RuboCop
|
|
6
6
|
# Ensures that each item in a multi-line array
|
7
7
|
# starts on a separate line.
|
8
8
|
#
|
9
|
-
# @example
|
9
|
+
# @example
|
10
10
|
#
|
11
11
|
# # bad
|
12
12
|
# [
|
@@ -14,11 +14,6 @@ module RuboCop
|
|
14
14
|
# c
|
15
15
|
# ]
|
16
16
|
#
|
17
|
-
# # bad
|
18
|
-
# [ a, b, foo(
|
19
|
-
# bar
|
20
|
-
# )]
|
21
|
-
#
|
22
17
|
# # good
|
23
18
|
# [
|
24
19
|
# a,
|
@@ -35,34 +30,20 @@ module RuboCop
|
|
35
30
|
# )
|
36
31
|
# ]
|
37
32
|
#
|
38
|
-
# @example AllowMultilineFinalElement:
|
33
|
+
# @example AllowMultilineFinalElement: false (default)
|
39
34
|
#
|
40
35
|
# # bad
|
41
|
-
# [
|
42
|
-
# a, b,
|
43
|
-
# c
|
44
|
-
# ]
|
45
|
-
#
|
46
|
-
# # good
|
47
|
-
# [ a, b, foo(
|
36
|
+
# [a, b, foo(
|
48
37
|
# bar
|
49
38
|
# )]
|
50
39
|
#
|
51
|
-
#
|
52
|
-
# [
|
53
|
-
# a,
|
54
|
-
# b,
|
55
|
-
# c
|
56
|
-
# ]
|
40
|
+
# @example AllowMultilineFinalElement: true
|
57
41
|
#
|
58
42
|
# # good
|
59
|
-
# [
|
60
|
-
#
|
61
|
-
#
|
62
|
-
#
|
63
|
-
# bar
|
64
|
-
# )
|
65
|
-
# ]
|
43
|
+
# [a, b, foo(
|
44
|
+
# bar
|
45
|
+
# )]
|
46
|
+
#
|
66
47
|
class MultilineArrayLineBreaks < Base
|
67
48
|
include MultilineElementLineBreaks
|
68
49
|
extend AutoCorrector
|
@@ -6,7 +6,7 @@ module RuboCop
|
|
6
6
|
# Ensures that each key in a multi-line hash
|
7
7
|
# starts on a separate line.
|
8
8
|
#
|
9
|
-
# @example
|
9
|
+
# @example
|
10
10
|
#
|
11
11
|
# # bad
|
12
12
|
# {
|
@@ -14,11 +14,6 @@ module RuboCop
|
|
14
14
|
# c: 3
|
15
15
|
# }
|
16
16
|
#
|
17
|
-
# # bad
|
18
|
-
# { a: 1, b: {
|
19
|
-
# c: 3,
|
20
|
-
# }}
|
21
|
-
#
|
22
17
|
# # good
|
23
18
|
# {
|
24
19
|
# a: 1,
|
@@ -34,34 +29,20 @@ module RuboCop
|
|
34
29
|
# }
|
35
30
|
# }
|
36
31
|
#
|
37
|
-
# @example AllowMultilineFinalElement:
|
32
|
+
# @example AllowMultilineFinalElement: false (default)
|
38
33
|
#
|
39
34
|
# # bad
|
40
|
-
# {
|
41
|
-
# a: 1, b: 2,
|
42
|
-
# c: 3
|
43
|
-
# }
|
44
|
-
#
|
45
|
-
# # good
|
46
35
|
# { a: 1, b: {
|
47
36
|
# c: 3,
|
48
37
|
# }}
|
49
38
|
#
|
50
|
-
#
|
51
|
-
# {
|
52
|
-
# a: 1,
|
53
|
-
# b: 2,
|
54
|
-
# c: 3
|
55
|
-
# }
|
56
|
-
#
|
39
|
+
# @example AllowMultilineFinalElement: true
|
57
40
|
#
|
58
41
|
# # good
|
59
|
-
# {
|
60
|
-
#
|
61
|
-
#
|
62
|
-
#
|
63
|
-
# }
|
64
|
-
# }
|
42
|
+
# { a: 1, b: {
|
43
|
+
# c: 3,
|
44
|
+
# }}
|
45
|
+
#
|
65
46
|
class MultilineHashKeyLineBreaks < Base
|
66
47
|
include MultilineElementLineBreaks
|
67
48
|
extend AutoCorrector
|
@@ -9,7 +9,7 @@ module RuboCop
|
|
9
9
|
# NOTE: This cop does not move the first argument, if you want that to
|
10
10
|
# be on a separate line, see `Layout/FirstMethodArgumentLineBreak`.
|
11
11
|
#
|
12
|
-
# @example
|
12
|
+
# @example
|
13
13
|
#
|
14
14
|
# # bad
|
15
15
|
# foo(a, b,
|
@@ -31,6 +31,8 @@ module RuboCop
|
|
31
31
|
# # good
|
32
32
|
# foo(a, b, c)
|
33
33
|
#
|
34
|
+
# @example AllowMultilineFinalElement: false (default)
|
35
|
+
#
|
34
36
|
# # good
|
35
37
|
# foo(
|
36
38
|
# a,
|
@@ -42,26 +44,6 @@ module RuboCop
|
|
42
44
|
#
|
43
45
|
# @example AllowMultilineFinalElement: true
|
44
46
|
#
|
45
|
-
# # bad
|
46
|
-
# foo(a, b,
|
47
|
-
# c
|
48
|
-
# )
|
49
|
-
#
|
50
|
-
# # good
|
51
|
-
# foo(a, b, {
|
52
|
-
# foo: "bar",
|
53
|
-
# })
|
54
|
-
#
|
55
|
-
# # good
|
56
|
-
# foo(
|
57
|
-
# a,
|
58
|
-
# b,
|
59
|
-
# c
|
60
|
-
# )
|
61
|
-
#
|
62
|
-
# # good
|
63
|
-
# foo(a, b, c)
|
64
|
-
#
|
65
47
|
# # good
|
66
48
|
# foo(
|
67
49
|
# a,
|
@@ -70,6 +52,7 @@ module RuboCop
|
|
70
52
|
# foo: "bar",
|
71
53
|
# }
|
72
54
|
# )
|
55
|
+
#
|
73
56
|
class MultilineMethodArgumentLineBreaks < Base
|
74
57
|
include MultilineElementLineBreaks
|
75
58
|
extend AutoCorrector
|
@@ -9,7 +9,7 @@ module RuboCop
|
|
9
9
|
# NOTE: This cop does not move the first argument, if you want that to
|
10
10
|
# be on a separate line, see `Layout/FirstMethodParameterLineBreak`.
|
11
11
|
#
|
12
|
-
# @example
|
12
|
+
# @example
|
13
13
|
#
|
14
14
|
# # bad
|
15
15
|
# def foo(a, b,
|
@@ -17,12 +17,6 @@ module RuboCop
|
|
17
17
|
# )
|
18
18
|
# end
|
19
19
|
#
|
20
|
-
# # bad
|
21
|
-
# def foo(a, b = {
|
22
|
-
# foo: "bar",
|
23
|
-
# })
|
24
|
-
# end
|
25
|
-
#
|
26
20
|
# # good
|
27
21
|
# def foo(
|
28
22
|
# a,
|
@@ -44,40 +38,22 @@ module RuboCop
|
|
44
38
|
# def foo(a, b, c)
|
45
39
|
# end
|
46
40
|
#
|
47
|
-
# @example AllowMultilineFinalElement:
|
41
|
+
# @example AllowMultilineFinalElement: false (default)
|
48
42
|
#
|
49
43
|
# # bad
|
50
|
-
# def foo(a, b,
|
51
|
-
# c
|
52
|
-
# )
|
53
|
-
# end
|
54
|
-
#
|
55
|
-
# # good
|
56
44
|
# def foo(a, b = {
|
57
45
|
# foo: "bar",
|
58
46
|
# })
|
59
47
|
# end
|
60
48
|
#
|
61
|
-
#
|
62
|
-
# def foo(
|
63
|
-
# a,
|
64
|
-
# b,
|
65
|
-
# c
|
66
|
-
# )
|
67
|
-
# end
|
49
|
+
# @example AllowMultilineFinalElement: true
|
68
50
|
#
|
69
51
|
# # good
|
70
|
-
# def foo(
|
71
|
-
#
|
72
|
-
#
|
73
|
-
# foo: "bar",
|
74
|
-
# }
|
75
|
-
# )
|
52
|
+
# def foo(a, b = {
|
53
|
+
# foo: "bar",
|
54
|
+
# })
|
76
55
|
# end
|
77
56
|
#
|
78
|
-
# # good
|
79
|
-
# def foo(a, b, c)
|
80
|
-
# end
|
81
57
|
class MultilineMethodParameterLineBreaks < Base
|
82
58
|
include MultilineElementLineBreaks
|
83
59
|
extend AutoCorrector
|
@@ -71,6 +71,22 @@ module RuboCop
|
|
71
71
|
# second_method
|
72
72
|
# end
|
73
73
|
#
|
74
|
+
# # bad - repeated the same patterns and guard conditions
|
75
|
+
# case x
|
76
|
+
# in foo if bar
|
77
|
+
# first_method
|
78
|
+
# in foo if bar
|
79
|
+
# second_method
|
80
|
+
# end
|
81
|
+
#
|
82
|
+
# # good
|
83
|
+
# case x
|
84
|
+
# in foo if bar
|
85
|
+
# first_method
|
86
|
+
# in foo if baz
|
87
|
+
# second_method
|
88
|
+
# end
|
89
|
+
#
|
74
90
|
class DuplicateMatchPattern < Base
|
75
91
|
extend TargetRubyVersion
|
76
92
|
|
@@ -90,11 +106,15 @@ module RuboCop
|
|
90
106
|
private
|
91
107
|
|
92
108
|
def pattern_identity(pattern)
|
93
|
-
if pattern.hash_pattern_type? || pattern.match_alt_type?
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
109
|
+
pattern_source = if pattern.hash_pattern_type? || pattern.match_alt_type?
|
110
|
+
pattern.children.map(&:source).sort.to_s
|
111
|
+
else
|
112
|
+
pattern.source
|
113
|
+
end
|
114
|
+
|
115
|
+
return pattern_source unless (guard = pattern.parent.children[1])
|
116
|
+
|
117
|
+
pattern_source + guard.source
|
98
118
|
end
|
99
119
|
end
|
100
120
|
end
|
@@ -36,11 +36,14 @@ module RuboCop
|
|
36
36
|
class CollectionCompact < Base
|
37
37
|
include RangeHelp
|
38
38
|
extend AutoCorrector
|
39
|
+
extend TargetRubyVersion
|
39
40
|
|
40
41
|
MSG = 'Use `%<good>s` instead of `%<bad>s`.'
|
41
42
|
RESTRICT_ON_SEND = %i[reject reject! select select!].freeze
|
42
43
|
TO_ENUM_METHODS = %i[to_enum lazy].freeze
|
43
44
|
|
45
|
+
minimum_target_ruby_version 2.4
|
46
|
+
|
44
47
|
# @!method reject_method_with_block_pass?(node)
|
45
48
|
def_node_matcher :reject_method_with_block_pass?, <<~PATTERN
|
46
49
|
(send !nil? {:reject :reject!}
|
@@ -31,22 +31,26 @@ module RuboCop
|
|
31
31
|
def on_masgn(node)
|
32
32
|
lhs, rhs = *node
|
33
33
|
lhs_elements = *lhs
|
34
|
+
rhs = rhs.body if rhs.rescue_type?
|
34
35
|
rhs_elements = Array(rhs).compact # edge case for one constant
|
35
36
|
|
36
37
|
return if allowed_lhs?(lhs) || allowed_rhs?(rhs) ||
|
37
38
|
allowed_masign?(lhs_elements, rhs_elements)
|
38
39
|
|
39
|
-
|
40
|
+
range = node.source_range.begin.join(rhs.source_range.end)
|
41
|
+
|
42
|
+
add_offense(range) do |corrector|
|
43
|
+
autocorrect(corrector, node, lhs, rhs)
|
44
|
+
end
|
40
45
|
end
|
41
46
|
|
42
47
|
private
|
43
48
|
|
44
|
-
def autocorrect(corrector, node)
|
45
|
-
|
46
|
-
|
47
|
-
right_elements = Array(right).compact
|
49
|
+
def autocorrect(corrector, node, lhs, rhs)
|
50
|
+
left_elements = *lhs
|
51
|
+
right_elements = Array(rhs).compact
|
48
52
|
order = find_valid_order(left_elements, right_elements)
|
49
|
-
correction = assignment_corrector(node, order)
|
53
|
+
correction = assignment_corrector(node, rhs, order)
|
50
54
|
|
51
55
|
corrector.replace(correction.correction_range, correction.correction)
|
52
56
|
end
|
@@ -77,14 +81,19 @@ module RuboCop
|
|
77
81
|
node.block_type? || node.send_type?
|
78
82
|
end
|
79
83
|
|
80
|
-
def assignment_corrector(node, order)
|
81
|
-
|
84
|
+
def assignment_corrector(node, rhs, order)
|
85
|
+
if node.parent&.rescue_type?
|
86
|
+
_assignment, modifier = *node.parent
|
87
|
+
else
|
88
|
+
_assignment, modifier = *rhs.parent
|
89
|
+
end
|
90
|
+
|
82
91
|
if modifier_statement?(node.parent)
|
83
|
-
ModifierCorrector.new(node, config, order)
|
92
|
+
ModifierCorrector.new(node, rhs, modifier, config, order)
|
84
93
|
elsif rescue_modifier?(modifier)
|
85
|
-
RescueCorrector.new(node, config, order)
|
94
|
+
RescueCorrector.new(node, rhs, modifier, config, order)
|
86
95
|
else
|
87
|
-
GenericCorrector.new(node, config, order)
|
96
|
+
GenericCorrector.new(node, rhs, modifier, config, order)
|
88
97
|
end
|
89
98
|
end
|
90
99
|
|
@@ -181,10 +190,12 @@ module RuboCop
|
|
181
190
|
class GenericCorrector
|
182
191
|
include Alignment
|
183
192
|
|
184
|
-
attr_reader :
|
193
|
+
attr_reader :node, :rhs, :rescue_result, :config
|
185
194
|
|
186
|
-
def initialize(node, config, new_elements)
|
195
|
+
def initialize(node, rhs, modifier, config, new_elements)
|
187
196
|
@node = node
|
197
|
+
@rhs = rhs
|
198
|
+
_, _, @rescue_result = *modifier
|
188
199
|
@config = config
|
189
200
|
@new_elements = new_elements
|
190
201
|
end
|
@@ -228,13 +239,10 @@ module RuboCop
|
|
228
239
|
# protected by rescue
|
229
240
|
class RescueCorrector < GenericCorrector
|
230
241
|
def correction
|
231
|
-
_node, rescue_clause = *node.parent
|
232
|
-
_, _, rescue_result = *rescue_clause
|
233
|
-
|
234
242
|
# If the parallel assignment uses a rescue modifier and it is the
|
235
243
|
# only contents of a method, then we want to make use of the
|
236
244
|
# implicit begin
|
237
|
-
if
|
245
|
+
if rhs.parent.parent.parent&.def_type?
|
238
246
|
super + def_correction(rescue_result)
|
239
247
|
else
|
240
248
|
begin_correction(rescue_result)
|
@@ -242,7 +250,7 @@ module RuboCop
|
|
242
250
|
end
|
243
251
|
|
244
252
|
def correction_range
|
245
|
-
|
253
|
+
rhs.parent.parent.source_range
|
246
254
|
end
|
247
255
|
|
248
256
|
private
|
@@ -3,11 +3,13 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Style
|
6
|
-
# Identifies places where `fetch(key) { value }`
|
7
|
-
# can be replaced by `fetch(key, value)`.
|
6
|
+
# Identifies places where `fetch(key) { value }` can be replaced by `fetch(key, value)`.
|
8
7
|
#
|
9
|
-
# In such cases `fetch(key, value)` method is faster
|
10
|
-
#
|
8
|
+
# In such cases `fetch(key, value)` method is faster than `fetch(key) { value }`.
|
9
|
+
#
|
10
|
+
# NOTE: The block string `'value'` in `hash.fetch(:key) { 'value' }` is detected
|
11
|
+
# when frozen string literal magic comment is enabled (i.e. `# frozen_string_literal: true`),
|
12
|
+
# but not when disabled.
|
11
13
|
#
|
12
14
|
# @safety
|
13
15
|
# This cop is unsafe because it cannot be guaranteed that the receiver
|
@@ -90,7 +90,7 @@ module RuboCop
|
|
90
90
|
!ends_with_backslash_without_comment?(range.source_line) ||
|
91
91
|
string_concatenation?(range.source_line) ||
|
92
92
|
start_with_arithmetic_operator?(processed_source[range.line]) ||
|
93
|
-
|
93
|
+
inside_string_literal_or_method_with_argument?(range)
|
94
94
|
end
|
95
95
|
|
96
96
|
def ends_with_backslash_without_comment?(source_line)
|
@@ -101,9 +101,9 @@ module RuboCop
|
|
101
101
|
/["']\s*\\\z/.match?(source_line)
|
102
102
|
end
|
103
103
|
|
104
|
-
def
|
105
|
-
processed_source.tokens.
|
106
|
-
|
104
|
+
def inside_string_literal_or_method_with_argument?(range)
|
105
|
+
processed_source.tokens.each_cons(2).any? do |token, next_token|
|
106
|
+
inside_string_literal?(range, token) || method_with_argument?(token, next_token)
|
107
107
|
end
|
108
108
|
end
|
109
109
|
|
@@ -115,6 +115,18 @@ module RuboCop
|
|
115
115
|
parse(source.gsub(/\\\n/, "\n")).valid_syntax?
|
116
116
|
end
|
117
117
|
|
118
|
+
def inside_string_literal?(range, token)
|
119
|
+
ALLOWED_STRING_TOKENS.include?(token.type) && token.pos.overlaps?(range)
|
120
|
+
end
|
121
|
+
|
122
|
+
# A method call without parentheses such as the following cannot remove `\`:
|
123
|
+
#
|
124
|
+
# do_something \
|
125
|
+
# argument
|
126
|
+
def method_with_argument?(current_token, next_token)
|
127
|
+
current_token.type == :tIDENTIFIER && next_token.type == :tIDENTIFIER
|
128
|
+
end
|
129
|
+
|
118
130
|
def argument_newline?(node)
|
119
131
|
node = node.children.first if node.root? && node.begin_type?
|
120
132
|
|
data/lib/rubocop/version.rb
CHANGED
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: 1.50.
|
4
|
+
version: 1.50.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bozhidar Batsov
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2023-04-
|
13
|
+
date: 2023-04-17 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: json
|