rubocop 1.30.0 → 1.30.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0673938234ff5977c3ab1c53a4f9ef762cc253190841bb32983d70f58a671bd2'
4
- data.tar.gz: e00b40528ad180408126a237f060f4e4e82c61948e3f8302b39322ef873343ef
3
+ metadata.gz: 86a53f724e77a824d22b44ec21ac28819f73e5766ffcc5734b1908edda92d37d
4
+ data.tar.gz: 924864c8350f97c98bea2f25420d1adda3f6595474baced2edec3b409302c413
5
5
  SHA512:
6
- metadata.gz: e16ae7755f064b7c12e1e2648bd3c10b276e81102af3b5f5ee1fa728c62989b1fb270a2d8619d8f40e829b71fafa2a40e3fa63457dabaa4a363a883e8285f068
7
- data.tar.gz: 733bfa4dd50a59533b2fd450c7c3e4766c11848144da8768bbea14071922df7b7613f9f0ba83a7a8d4d2e2bd7e8b599c999b730662b56c0af97c731e6a731fcc
6
+ metadata.gz: f8b462b23760d3f4a51c0a94dfa01c0b43c0715255b65d58883fd8b67f6841d5d8384c367d3711d68ba6f8f4d72fac1533fdaa33d817986434c185a5c6574f13
7
+ data.tar.gz: 3751cee1ebfd9d5968f6510d1440675286bbcb5a4f20c9bebb1cdd916ac70a07d4fd8f111352c10fa90ec546bfa36dc2cdae413b25bd24afcf62ed54db7c78a3
data/README.md CHANGED
@@ -73,11 +73,13 @@ You can read a lot more about RuboCop in its [official docs](https://docs.ruboco
73
73
 
74
74
  ## Compatibility
75
75
 
76
- RuboCop officially supports the following Ruby implementations:
76
+ RuboCop officially supports the following runtime Ruby implementations:
77
77
 
78
78
  * MRI 2.6+
79
79
  * JRuby 9.3+
80
80
 
81
+ Targets Ruby 2.0+ code analysis.
82
+
81
83
  See the [compatibility documentation](https://docs.rubocop.org/rubocop/compatibility.html) for further details.
82
84
 
83
85
  ## Readme Badge
@@ -104,13 +104,17 @@ module RuboCop
104
104
  def alert_about_unrecognized_cops(invalid_cop_names)
105
105
  unknown_cops = list_unknown_cops(invalid_cop_names)
106
106
 
107
+ return if unknown_cops.empty?
108
+
107
109
  if ConfigLoader.ignore_unrecognized_cops
108
110
  warn Rainbow('The following cops or departments are not '\
109
111
  'recognized and will be ignored:').yellow
110
112
  warn unknown_cops.join("\n")
111
- elsif unknown_cops.any?
112
- raise ValidationError, unknown_cops.join("\n")
113
+
114
+ return
113
115
  end
116
+
117
+ raise ValidationError, unknown_cops.join("\n")
114
118
  end
115
119
 
116
120
  def list_unknown_cops(invalid_cop_names)
@@ -145,7 +145,7 @@ module RuboCop
145
145
  return false unless hash_argument_config['Enabled']
146
146
 
147
147
  RuboCop::Cop::Layout::HashAlignment::SEPARATOR_ALIGNMENT_STYLES.any? do |style|
148
- hash_argument_config[style] == 'separator'
148
+ hash_argument_config[style]&.include?('separator')
149
149
  end
150
150
  end
151
151
 
@@ -6,20 +6,20 @@ module RuboCop
6
6
  # Checks if empty lines around the bodies of blocks match
7
7
  # the configuration.
8
8
  #
9
- # @example EnforcedStyle: empty_lines
9
+ # @example EnforcedStyle: no_empty_lines (default)
10
10
  # # good
11
11
  #
12
12
  # foo do |bar|
13
- #
14
13
  # # ...
15
- #
16
14
  # end
17
15
  #
18
- # @example EnforcedStyle: no_empty_lines (default)
16
+ # @example EnforcedStyle: empty_lines
19
17
  # # good
20
18
  #
21
19
  # foo do |bar|
20
+ #
22
21
  # # ...
22
+ #
23
23
  # end
24
24
  class EmptyLinesAroundBlockBody < Base
25
25
  include EmptyLinesAroundBody
@@ -6,6 +6,15 @@ module RuboCop
6
6
  # Checks if empty lines around the bodies of classes match
7
7
  # the configuration.
8
8
  #
9
+ # @example EnforcedStyle: no_empty_lines (default)
10
+ # # good
11
+ #
12
+ # class Foo
13
+ # def bar
14
+ # # ...
15
+ # end
16
+ # end
17
+ #
9
18
  # @example EnforcedStyle: empty_lines
10
19
  # # good
11
20
  #
@@ -55,15 +64,6 @@ module RuboCop
55
64
  # end
56
65
  #
57
66
  # end
58
- #
59
- # @example EnforcedStyle: no_empty_lines (default)
60
- # # good
61
- #
62
- # class Foo
63
- # def bar
64
- # # ...
65
- # end
66
- # end
67
67
  class EmptyLinesAroundClassBody < Base
68
68
  include EmptyLinesAroundBody
69
69
  extend AutoCorrector
@@ -6,6 +6,15 @@ module RuboCop
6
6
  # Checks if empty lines around the bodies of modules match
7
7
  # the configuration.
8
8
  #
9
+ # @example EnforcedStyle: no_empty_lines (default)
10
+ # # good
11
+ #
12
+ # module Foo
13
+ # def bar
14
+ # # ...
15
+ # end
16
+ # end
17
+ #
9
18
  # @example EnforcedStyle: empty_lines
10
19
  # # good
11
20
  #
@@ -35,15 +44,6 @@ module RuboCop
35
44
  # def bar; end
36
45
  #
37
46
  # end
38
- #
39
- # @example EnforcedStyle: no_empty_lines (default)
40
- # # good
41
- #
42
- # module Foo
43
- # def bar
44
- # # ...
45
- # end
46
- # end
47
47
  class EmptyLinesAroundModuleBody < Base
48
48
  include EmptyLinesAroundBody
49
49
  extend AutoCorrector
@@ -37,9 +37,10 @@ module RuboCop
37
37
  # nested_first_param),
38
38
  # second_param
39
39
  #
40
- # @example EnforcedStyle: consistent
41
- # # The first argument should always be indented one step more than the
42
- # # preceding line.
40
+ # @example EnforcedStyle: special_for_inner_method_call_in_parentheses (default)
41
+ # # Same as `special_for_inner_method_call` except that the special rule
42
+ # # only applies if the outer method call encloses its arguments in
43
+ # # parentheses.
43
44
  #
44
45
  # # good
45
46
  # some_method(
@@ -51,7 +52,7 @@ module RuboCop
51
52
  # second_param)
52
53
  #
53
54
  # foo = some_method(nested_call(
54
- # nested_first_param),
55
+ # nested_first_param),
55
56
  # second_param)
56
57
  #
57
58
  # foo = some_method(
@@ -63,9 +64,9 @@ module RuboCop
63
64
  # nested_first_param),
64
65
  # second_param
65
66
  #
66
- # @example EnforcedStyle: consistent_relative_to_receiver
67
- # # The first argument should always be indented one level relative to
68
- # # the parent that is receiving the argument
67
+ # @example EnforcedStyle: consistent
68
+ # # The first argument should always be indented one step more than the
69
+ # # preceding line.
69
70
  #
70
71
  # # good
71
72
  # some_method(
@@ -73,27 +74,25 @@ module RuboCop
73
74
  # second_param)
74
75
  #
75
76
  # foo = some_method(
76
- # first_param,
77
+ # first_param,
77
78
  # second_param)
78
79
  #
79
80
  # foo = some_method(nested_call(
80
- # nested_first_param),
81
+ # nested_first_param),
81
82
  # second_param)
82
83
  #
83
84
  # foo = some_method(
84
- # nested_call(
85
- # nested_first_param),
85
+ # nested_call(
86
+ # nested_first_param),
86
87
  # second_param)
87
88
  #
88
89
  # some_method nested_call(
89
- # nested_first_param),
90
- # second_params
90
+ # nested_first_param),
91
+ # second_param
91
92
  #
92
- # @example EnforcedStyle: special_for_inner_method_call
93
- # # The first argument should normally be indented one step more than
94
- # # the preceding line, but if it's a argument for a method call that
95
- # # is itself a argument in a method call, then the inner argument
96
- # # should be indented relative to the inner method.
93
+ # @example EnforcedStyle: consistent_relative_to_receiver
94
+ # # The first argument should always be indented one level relative to
95
+ # # the parent that is receiving the argument
97
96
  #
98
97
  # # good
99
98
  # some_method(
@@ -101,7 +100,7 @@ module RuboCop
101
100
  # second_param)
102
101
  #
103
102
  # foo = some_method(
104
- # first_param,
103
+ # first_param,
105
104
  # second_param)
106
105
  #
107
106
  # foo = some_method(nested_call(
@@ -109,18 +108,19 @@ module RuboCop
109
108
  # second_param)
110
109
  #
111
110
  # foo = some_method(
112
- # nested_call(
113
- # nested_first_param),
111
+ # nested_call(
112
+ # nested_first_param),
114
113
  # second_param)
115
114
  #
116
115
  # some_method nested_call(
117
116
  # nested_first_param),
118
- # second_param
117
+ # second_params
119
118
  #
120
- # @example EnforcedStyle: special_for_inner_method_call_in_parentheses (default)
121
- # # Same as `special_for_inner_method_call` except that the special rule
122
- # # only applies if the outer method call encloses its arguments in
123
- # # parentheses.
119
+ # @example EnforcedStyle: special_for_inner_method_call
120
+ # # The first argument should normally be indented one step more than
121
+ # # the preceding line, but if it's a argument for a method call that
122
+ # # is itself a argument in a method call, then the inner argument
123
+ # # should be indented relative to the inner method.
124
124
  #
125
125
  # # good
126
126
  # some_method(
@@ -141,7 +141,7 @@ module RuboCop
141
141
  # second_param)
142
142
  #
143
143
  # some_method nested_call(
144
- # nested_first_param),
144
+ # nested_first_param),
145
145
  # second_param
146
146
  #
147
147
  class FirstArgumentIndentation < Base
@@ -6,16 +6,6 @@ module RuboCop
6
6
  # Checks that brackets used for array literals have or don't have
7
7
  # surrounding space depending on configuration.
8
8
  #
9
- # @example EnforcedStyle: space
10
- # # The `space` style enforces that array literals have
11
- # # surrounding space.
12
- #
13
- # # bad
14
- # array = [a, b, c, d]
15
- #
16
- # # good
17
- # array = [ a, b, c, d ]
18
- #
19
9
  # @example EnforcedStyle: no_space (default)
20
10
  # # The `no_space` style enforces that array literals have
21
11
  # # no surrounding space.
@@ -26,6 +16,16 @@ module RuboCop
26
16
  # # good
27
17
  # array = [a, b, c, d]
28
18
  #
19
+ # @example EnforcedStyle: space
20
+ # # The `space` style enforces that array literals have
21
+ # # surrounding space.
22
+ #
23
+ # # bad
24
+ # array = [a, b, c, d]
25
+ #
26
+ # # good
27
+ # array = [ a, b, c, d ]
28
+ #
29
29
  # @example EnforcedStyle: compact
30
30
  # # The `compact` style normally requires a space inside
31
31
  # # array brackets, with the exception that successive left
@@ -6,12 +6,12 @@ module RuboCop
6
6
  # Looks for trailing blank lines and a final newline in the
7
7
  # source code.
8
8
  #
9
- # @example EnforcedStyle: final_blank_line
10
- # # `final_blank_line` looks for one blank line followed by a new line
11
- # # at the end of files.
9
+ # @example EnforcedStyle: final_newline (default)
10
+ # # `final_newline` looks for one newline at the end of files.
12
11
  #
13
12
  # # bad
14
13
  # class Foo; end
14
+ #
15
15
  # # EOF
16
16
  #
17
17
  # # bad
@@ -19,15 +19,14 @@ module RuboCop
19
19
  #
20
20
  # # good
21
21
  # class Foo; end
22
- #
23
22
  # # EOF
24
23
  #
25
- # @example EnforcedStyle: final_newline (default)
26
- # # `final_newline` looks for one newline at the end of files.
24
+ # @example EnforcedStyle: final_blank_line
25
+ # # `final_blank_line` looks for one blank line followed by a new line
26
+ # # at the end of files.
27
27
  #
28
28
  # # bad
29
29
  # class Foo; end
30
- #
31
30
  # # EOF
32
31
  #
33
32
  # # bad
@@ -35,6 +34,7 @@ module RuboCop
35
34
  #
36
35
  # # good
37
36
  # class Foo; end
37
+ #
38
38
  # # EOF
39
39
  #
40
40
  class TrailingEmptyLines < Base
@@ -63,7 +63,9 @@ module RuboCop
63
63
  end
64
64
 
65
65
  def bad_writer_name?(node)
66
- node.method_name.to_s.start_with?('set_') && node.arguments.one?
66
+ node.method_name.to_s.start_with?('set_') &&
67
+ node.arguments.one? &&
68
+ node.first_argument.arg_type?
67
69
  end
68
70
  end
69
71
  end
@@ -11,23 +11,6 @@ module RuboCop
11
11
  # can be used to specify whether method names and symbols should be checked.
12
12
  # Both are enabled by default.
13
13
  #
14
- # @example EnforcedStyle: snake_case
15
- # # bad
16
- # :some_sym1
17
- # variable1 = 1
18
- #
19
- # def some_method1; end
20
- #
21
- # def some_method_1(arg1); end
22
- #
23
- # # good
24
- # :some_sym_1
25
- # variable_1 = 1
26
- #
27
- # def some_method_1; end
28
- #
29
- # def some_method_1(arg_1); end
30
- #
31
14
  # @example EnforcedStyle: normalcase (default)
32
15
  # # bad
33
16
  # :some_sym_1
@@ -45,6 +28,23 @@ module RuboCop
45
28
  #
46
29
  # def some_method1(arg1); end
47
30
  #
31
+ # @example EnforcedStyle: snake_case
32
+ # # bad
33
+ # :some_sym1
34
+ # variable1 = 1
35
+ #
36
+ # def some_method1; end
37
+ #
38
+ # def some_method_1(arg1); end
39
+ #
40
+ # # good
41
+ # :some_sym_1
42
+ # variable_1 = 1
43
+ #
44
+ # def some_method_1; end
45
+ #
46
+ # def some_method_1(arg_1); end
47
+ #
48
48
  # @example EnforcedStyle: non_integer
49
49
  # # bad
50
50
  # :some_sym1
@@ -12,10 +12,7 @@ module RuboCop
12
12
  # between logical operators (`&&` and `||`) and semantic operators (`and` and `or`),
13
13
  # and that might change the behavior.
14
14
  #
15
- # @example EnforcedStyle: always
16
- # # bad
17
- # foo.save and return
18
- #
15
+ # @example EnforcedStyle: conditionals (default)
19
16
  # # bad
20
17
  # if foo and bar
21
18
  # end
@@ -24,10 +21,16 @@ module RuboCop
24
21
  # foo.save && return
25
22
  #
26
23
  # # good
24
+ # foo.save and return
25
+ #
26
+ # # good
27
27
  # if foo && bar
28
28
  # end
29
29
  #
30
- # @example EnforcedStyle: conditionals (default)
30
+ # @example EnforcedStyle: always
31
+ # # bad
32
+ # foo.save and return
33
+ #
31
34
  # # bad
32
35
  # if foo and bar
33
36
  # end
@@ -36,9 +39,6 @@ module RuboCop
36
39
  # foo.save && return
37
40
  #
38
41
  # # good
39
- # foo.save and return
40
- #
41
- # # good
42
42
  # if foo && bar
43
43
  # end
44
44
  class AndOr < Base
@@ -6,20 +6,20 @@ module RuboCop
6
6
  # Checks for empty else-clauses, possibly including comments and/or an
7
7
  # explicit `nil` depending on the EnforcedStyle.
8
8
  #
9
- # @example EnforcedStyle: empty
10
- # # warn only on empty else
9
+ # @example EnforcedStyle: both (default)
10
+ # # warn on empty else and else with nil in it
11
11
  #
12
12
  # # bad
13
13
  # if condition
14
14
  # statement
15
15
  # else
16
+ # nil
16
17
  # end
17
18
  #
18
- # # good
19
+ # # bad
19
20
  # if condition
20
21
  # statement
21
22
  # else
22
- # nil
23
23
  # end
24
24
  #
25
25
  # # good
@@ -34,20 +34,20 @@ module RuboCop
34
34
  # statement
35
35
  # end
36
36
  #
37
- # @example EnforcedStyle: nil
38
- # # warn on else with nil in it
37
+ # @example EnforcedStyle: empty
38
+ # # warn only on empty else
39
39
  #
40
40
  # # bad
41
41
  # if condition
42
42
  # statement
43
43
  # else
44
- # nil
45
44
  # end
46
45
  #
47
46
  # # good
48
47
  # if condition
49
48
  # statement
50
49
  # else
50
+ # nil
51
51
  # end
52
52
  #
53
53
  # # good
@@ -62,8 +62,8 @@ module RuboCop
62
62
  # statement
63
63
  # end
64
64
  #
65
- # @example EnforcedStyle: both (default)
66
- # # warn on empty else and else with nil in it
65
+ # @example EnforcedStyle: nil
66
+ # # warn on else with nil in it
67
67
  #
68
68
  # # bad
69
69
  # if condition
@@ -72,7 +72,7 @@ module RuboCop
72
72
  # nil
73
73
  # end
74
74
  #
75
- # # bad
75
+ # # good
76
76
  # if condition
77
77
  # statement
78
78
  # else
@@ -112,13 +112,20 @@ module RuboCop
112
112
  end
113
113
 
114
114
  def used_in_condition?(node, condition)
115
- if condition.send_type? && (!condition.comparison_method? && !condition.predicate_method?)
116
- return false
115
+ if condition.send_type?
116
+ return true if condition.assignment_method? && partial_matched?(node, condition)
117
+ return false if !condition.comparison_method? && !condition.predicate_method?
117
118
  end
118
119
 
119
120
  condition.child_nodes.any?(node)
120
121
  end
121
122
 
123
+ # Avoid offending in the following cases:
124
+ # `ENV['key'] if ENV['key'] = x`
125
+ def partial_matched?(node, condition)
126
+ node.child_nodes == node.child_nodes & condition.child_nodes
127
+ end
128
+
122
129
  def offensive?(node)
123
130
  !(allowed_var?(node) || allowable_use?(node))
124
131
  end
@@ -10,25 +10,25 @@ module RuboCop
10
10
  #
11
11
  # Supported styles are: if, case, both.
12
12
  #
13
- # @example EnforcedStyle: if
14
- # # warn when an `if` expression is missing an `else` branch.
13
+ # @example EnforcedStyle: both (default)
14
+ # # warn when an `if` or `case` expression is missing an `else` branch.
15
15
  #
16
16
  # # bad
17
17
  # if condition
18
18
  # statement
19
19
  # end
20
20
  #
21
- # # good
22
- # if condition
21
+ # # bad
22
+ # case var
23
+ # when condition
23
24
  # statement
24
- # else
25
- # # the content of `else` branch will be determined by Style/EmptyElse
26
25
  # end
27
26
  #
28
27
  # # good
29
- # case var
30
- # when condition
28
+ # if condition
31
29
  # statement
30
+ # else
31
+ # # the content of `else` branch will be determined by Style/EmptyElse
32
32
  # end
33
33
  #
34
34
  # # good
@@ -39,59 +39,59 @@ module RuboCop
39
39
  # # the content of `else` branch will be determined by Style/EmptyElse
40
40
  # end
41
41
  #
42
- # @example EnforcedStyle: case
43
- # # warn when a `case` expression is missing an `else` branch.
42
+ # @example EnforcedStyle: if
43
+ # # warn when an `if` expression is missing an `else` branch.
44
44
  #
45
45
  # # bad
46
- # case var
47
- # when condition
46
+ # if condition
48
47
  # statement
49
48
  # end
50
49
  #
51
50
  # # good
52
- # case var
53
- # when condition
51
+ # if condition
54
52
  # statement
55
53
  # else
56
54
  # # the content of `else` branch will be determined by Style/EmptyElse
57
55
  # end
58
56
  #
59
57
  # # good
60
- # if condition
58
+ # case var
59
+ # when condition
61
60
  # statement
62
61
  # end
63
62
  #
64
63
  # # good
65
- # if condition
64
+ # case var
65
+ # when condition
66
66
  # statement
67
67
  # else
68
68
  # # the content of `else` branch will be determined by Style/EmptyElse
69
69
  # end
70
70
  #
71
- # @example EnforcedStyle: both (default)
72
- # # warn when an `if` or `case` expression is missing an `else` branch.
71
+ # @example EnforcedStyle: case
72
+ # # warn when a `case` expression is missing an `else` branch.
73
73
  #
74
74
  # # bad
75
- # if condition
75
+ # case var
76
+ # when condition
76
77
  # statement
77
78
  # end
78
79
  #
79
- # # bad
80
+ # # good
80
81
  # case var
81
82
  # when condition
82
83
  # statement
84
+ # else
85
+ # # the content of `else` branch will be determined by Style/EmptyElse
83
86
  # end
84
87
  #
85
88
  # # good
86
89
  # if condition
87
90
  # statement
88
- # else
89
- # # the content of `else` branch will be determined by Style/EmptyElse
90
91
  # end
91
92
  #
92
93
  # # good
93
- # case var
94
- # when condition
94
+ # if condition
95
95
  # statement
96
96
  # else
97
97
  # # the content of `else` branch will be determined by Style/EmptyElse
@@ -7,21 +7,21 @@ module RuboCop
7
7
  # styles `implicit` and `explicit`. This cop will not register an offense
8
8
  # if any error other than `StandardError` is specified.
9
9
  #
10
- # @example EnforcedStyle: implicit
11
- # # `implicit` will enforce using `rescue` instead of
12
- # # `rescue StandardError`.
10
+ # @example EnforcedStyle: explicit (default)
11
+ # # `explicit` will enforce using `rescue StandardError`
12
+ # # instead of `rescue`.
13
13
  #
14
14
  # # bad
15
15
  # begin
16
16
  # foo
17
- # rescue StandardError
17
+ # rescue
18
18
  # bar
19
19
  # end
20
20
  #
21
21
  # # good
22
22
  # begin
23
23
  # foo
24
- # rescue
24
+ # rescue StandardError
25
25
  # bar
26
26
  # end
27
27
  #
@@ -39,21 +39,21 @@ module RuboCop
39
39
  # bar
40
40
  # end
41
41
  #
42
- # @example EnforcedStyle: explicit (default)
43
- # # `explicit` will enforce using `rescue StandardError`
44
- # # instead of `rescue`.
42
+ # @example EnforcedStyle: implicit
43
+ # # `implicit` will enforce using `rescue` instead of
44
+ # # `rescue StandardError`.
45
45
  #
46
46
  # # bad
47
47
  # begin
48
48
  # foo
49
- # rescue
49
+ # rescue StandardError
50
50
  # bar
51
51
  # end
52
52
  #
53
53
  # # good
54
54
  # begin
55
55
  # foo
56
- # rescue StandardError
56
+ # rescue
57
57
  # bar
58
58
  # end
59
59
  #
@@ -80,11 +80,14 @@ module RuboCop
80
80
  include NilMethods
81
81
  include RangeHelp
82
82
  extend AutoCorrector
83
+ extend TargetRubyVersion
83
84
 
84
85
  MSG = 'Use safe navigation (`&.`) instead of checking if an object ' \
85
86
  'exists before calling the method.'
86
87
  LOGIC_JUMP_KEYWORDS = %i[break fail next raise return throw yield].freeze
87
88
 
89
+ minimum_target_ruby_version 2.3
90
+
88
91
  # if format: (if checked_variable body nil)
89
92
  # unless format: (if checked_variable nil body)
90
93
  # @!method modifier_if_safe_navigation_candidate(node)
@@ -76,7 +76,7 @@ module RuboCop
76
76
 
77
77
  topmost_plus_node = find_topmost_plus_node(node)
78
78
  parts = collect_parts(topmost_plus_node)
79
- return unless parts[0..-2].any? { |receiver_node| offensive_for_mode?(receiver_node) }
79
+ return if mode == :conservative && !parts.first.str_type?
80
80
 
81
81
  register_offense(topmost_plus_node, parts)
82
82
  end
@@ -95,11 +95,6 @@ module RuboCop
95
95
  end
96
96
  end
97
97
 
98
- def offensive_for_mode?(receiver_node)
99
- mode = cop_config['Mode'].to_sym
100
- mode == :aggressive || (mode == :conservative && receiver_node.str_type?)
101
- end
102
-
103
98
  def line_end_concatenation?(node)
104
99
  # If the concatenation happens at the end of the line,
105
100
  # and both the receiver and argument are strings, allow
@@ -173,6 +168,10 @@ module RuboCop
173
168
  def single_quoted?(str_node)
174
169
  str_node.source.start_with?("'")
175
170
  end
171
+
172
+ def mode
173
+ cop_config['Mode'].to_sym
174
+ end
176
175
  end
177
176
  end
178
177
  end
@@ -34,17 +34,34 @@ class CopsDocumentationGenerator # rubocop:disable Metrics/ClassLength
34
34
  end
35
35
 
36
36
  def cops_body(cop, description, examples_objects, safety_objects, pars) # rubocop:disable Metrics/AbcSize
37
+ check_examples_to_have_the_default_enforced_style!(examples_objects, cop)
38
+
37
39
  content = h2(cop.cop_name)
38
40
  content << required_ruby_version(cop)
39
41
  content << properties(cop)
40
42
  content << "#{description}\n"
41
43
  content << safety_object(safety_objects) if safety_objects.any? { |s| !s.text.blank? }
42
- content << examples(examples_objects) if examples_objects.count.positive?
44
+ content << examples(examples_objects) if examples_objects.any?
43
45
  content << configurations(pars)
44
46
  content << references(cop)
45
47
  content
46
48
  end
47
49
 
50
+ def check_examples_to_have_the_default_enforced_style!(examples_object, cop)
51
+ return if examples_object.none?
52
+
53
+ examples_describing_enforced_style = examples_object.map(&:name).grep(/EnforcedStyle:/)
54
+ return if examples_describing_enforced_style.none?
55
+
56
+ if examples_describing_enforced_style.index { |name| name.match?('default') }.nonzero?
57
+ raise "Put the example with the default EnforcedStyle on top for #{cop.cop_name}"
58
+ end
59
+
60
+ return if examples_describing_enforced_style.any? { |name| name.match?('default') }
61
+
62
+ raise "Specify the default EnforcedStyle for #{cop.cop_name}"
63
+ end
64
+
48
65
  def examples(examples_object)
49
66
  examples_object.each_with_object(h3('Examples').dup) do |example, content|
50
67
  content << "\n" unless content.end_with?("\n\n")
@@ -123,7 +123,7 @@ module RuboCop
123
123
  cop_class = Cop::Registry.global.find_by_cop_name(cop_name)
124
124
  default_cfg = default_config(cop_name)
125
125
 
126
- if supports_safe_auto_correct?(cop_class, default_cfg)
126
+ if supports_safe_autocorrect?(cop_class, default_cfg)
127
127
  output_buffer.puts '# This cop supports safe autocorrection (--autocorrect).'
128
128
  elsif supports_unsafe_autocorrect?(cop_class, default_cfg)
129
129
  output_buffer.puts '# This cop supports unsafe autocorrection (--autocorrect-all).'
@@ -137,13 +137,12 @@ module RuboCop
137
137
  output_cop_param_comments(output_buffer, params, default_cfg)
138
138
  end
139
139
 
140
- def supports_safe_auto_correct?(cop_class, default_cfg)
141
- cop_class&.support_autocorrect? &&
142
- (default_cfg.nil? || default_cfg['Safe'] || default_cfg['Safe'].nil?)
140
+ def supports_safe_autocorrect?(cop_class, default_cfg)
141
+ cop_class&.support_autocorrect? && (default_cfg.nil? || safe_autocorrect?(default_cfg))
143
142
  end
144
143
 
145
144
  def supports_unsafe_autocorrect?(cop_class, default_cfg)
146
- cop_class&.support_autocorrect? && !default_cfg.nil? && default_cfg['Safe'] == false
145
+ cop_class&.support_autocorrect? && !safe_autocorrect?(default_cfg)
147
146
  end
148
147
 
149
148
  def cop_config_params(default_cfg, cfg)
@@ -242,6 +241,10 @@ module RuboCop
242
241
  regexp = exclude_path
243
242
  output_buffer.puts " - !ruby/regexp /#{regexp.source}/"
244
243
  end
244
+
245
+ def safe_autocorrect?(config)
246
+ config.fetch('Safe', true) && config.fetch('SafeAutoCorrect', true)
247
+ end
245
248
  end
246
249
  end
247
250
  end
@@ -226,7 +226,7 @@ module RuboCop
226
226
  end
227
227
 
228
228
  def handle_deprecated_option(old_option, new_option)
229
- warn "#{old_option} is deprecated; use #{new_option}"
229
+ warn rainbow.wrap("#{old_option} is deprecated; use #{new_option} instead.").yellow
230
230
  @options[long_opt_symbol([new_option])] = @options.delete(long_opt_symbol([old_option]))
231
231
  end
232
232
 
@@ -382,7 +382,7 @@ module RuboCop
382
382
  if @options[:display_only_fail_level_offenses]
383
383
  offenses.select { |o| considered_failure?(o) }
384
384
  elsif @options[:display_only_safe_correctable]
385
- offenses.select { |o| supports_safe_auto_correct?(o) }
385
+ offenses.select { |o| supports_safe_autocorrect?(o) }
386
386
  elsif @options[:display_only_correctable]
387
387
  offenses.select(&:correctable?)
388
388
  else
@@ -390,7 +390,7 @@ module RuboCop
390
390
  end
391
391
  end
392
392
 
393
- def supports_safe_auto_correct?(offense)
393
+ def supports_safe_autocorrect?(offense)
394
394
  cop_class = Cop::Registry.global.find_by_cop_name(offense.cop_name)
395
395
  default_cfg = default_config(offense.cop_name)
396
396
 
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  # This module holds the RuboCop version information.
5
5
  module Version
6
- STRING = '1.30.0'
6
+ STRING = '1.30.1'
7
7
 
8
8
  MSG = '%<version>s (using Parser %<parser_version>s, '\
9
9
  'rubocop-ast %<rubocop_ast_version>s, ' \
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.30.0
4
+ version: 1.30.1
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: 2022-05-26 00:00:00.000000000 Z
13
+ date: 2022-06-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: parallel