rubocop 1.29.0 → 1.29.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: 155e1b253bffe887bc046c38febc46563a88b77ce29d4cbacc3e33f034e6e7be
4
- data.tar.gz: 16d70c60ef38d1fab5de15d98f5408f9304ef07de75c10d99a798d7ce2228d8d
3
+ metadata.gz: dc3f8c82f30de8d481011d509c430f07627740062258586008ada7a2e301935d
4
+ data.tar.gz: 4a41b97adf892a9acce8faec7325b822734c717b03a46ead788f154e0db27a41
5
5
  SHA512:
6
- metadata.gz: 18820cc0427edc64afcbb6e057f9d0dc6c091632ea31f140992cbccf0b075abf7c1484257aab61391bdbb6e31a2341c5469f64caf666e6edb68fd61606d4ebe5
7
- data.tar.gz: 286cfc060c368697258b551ae330dc7cead75710baaba53c33622da59026c6a36f4db313af2a1610ed522696d57695e6f2f87ab939a93b5b5f43e584f420ba0e
6
+ metadata.gz: 7222d77b9e5dcfe8908311c2d551da58959136fa9c560afd6aac17c53b0c9abcac9d9d241e31883e35e1276e5274d8b8a33cb5f5a7b917dff27602de1e3f10fb
7
+ data.tar.gz: 296507dfa80b4166a3e4960bc56c43262ca25cc32feb280d49824c335cae916c2d45bfc353ac592857c2c83aa39cd90ffe6ff568ba2d3ed2329361e0788f3b26
data/config/default.yml CHANGED
@@ -895,7 +895,7 @@ Layout/HeredocArgumentClosingParenthesis:
895
895
  VersionAdded: '0.68'
896
896
 
897
897
  Layout/HeredocIndentation:
898
- Description: 'This cop checks the indentation of the here document bodies.'
898
+ Description: 'Checks the indentation of the here document bodies.'
899
899
  StyleGuide: '#squiggly-heredocs'
900
900
  Enabled: true
901
901
  VersionAdded: '0.49'
@@ -1514,7 +1514,7 @@ Lint/BigDecimalNew:
1514
1514
  VersionAdded: '0.53'
1515
1515
 
1516
1516
  Lint/BinaryOperatorWithIdenticalOperands:
1517
- Description: 'This cop checks for places where binary operator has identical operands.'
1517
+ Description: 'Checks for places where binary operator has identical operands.'
1518
1518
  Enabled: true
1519
1519
  Safe: false
1520
1520
  VersionAdded: '0.89'
@@ -1696,7 +1696,7 @@ Lint/ElseLayout:
1696
1696
  VersionChanged: '1.2'
1697
1697
 
1698
1698
  Lint/EmptyBlock:
1699
- Description: 'This cop checks for blocks without a body.'
1699
+ Description: 'Checks for blocks without a body.'
1700
1700
  Enabled: pending
1701
1701
  VersionAdded: '1.1'
1702
1702
  VersionChanged: '1.15'
@@ -1710,7 +1710,7 @@ Lint/EmptyClass:
1710
1710
  AllowComments: false
1711
1711
 
1712
1712
  Lint/EmptyConditionalBody:
1713
- Description: 'This cop checks for the presence of `if`, `elsif` and `unless` branches without a body.'
1713
+ Description: 'Checks for the presence of `if`, `elsif` and `unless` branches without a body.'
1714
1714
  Enabled: true
1715
1715
  AllowComments: true
1716
1716
  VersionAdded: '0.89'
@@ -1889,7 +1889,7 @@ Lint/MissingCopEnableDirective:
1889
1889
 
1890
1890
  Lint/MissingSuper:
1891
1891
  Description: >-
1892
- This cop checks for the presence of constructors and lifecycle callbacks
1892
+ Checks for the presence of constructors and lifecycle callbacks
1893
1893
  without calls to `super`.
1894
1894
  Enabled: true
1895
1895
  VersionAdded: '0.89'
@@ -2218,7 +2218,7 @@ Lint/Syntax:
2218
2218
  VersionAdded: '0.9'
2219
2219
 
2220
2220
  Lint/ToEnumArguments:
2221
- Description: 'This cop ensures that `to_enum`/`enum_for`, called for the current method, has correct arguments.'
2221
+ Description: 'Ensures that `to_enum`/`enum_for`, called for the current method, has correct arguments.'
2222
2222
  Enabled: pending
2223
2223
  VersionAdded: '1.1'
2224
2224
 
@@ -2228,12 +2228,12 @@ Lint/ToJSON:
2228
2228
  VersionAdded: '0.66'
2229
2229
 
2230
2230
  Lint/TopLevelReturnWithArgument:
2231
- Description: 'This cop detects top level return statements with argument.'
2231
+ Description: 'Detects top level return statements with argument.'
2232
2232
  Enabled: true
2233
2233
  VersionAdded: '0.89'
2234
2234
 
2235
2235
  Lint/TrailingCommaInAttributeDeclaration:
2236
- Description: 'This cop checks for trailing commas in attribute declarations.'
2236
+ Description: 'Checks for trailing commas in attribute declarations.'
2237
2237
  Enabled: true
2238
2238
  VersionAdded: '0.90'
2239
2239
 
@@ -2282,7 +2282,7 @@ Lint/UnreachableCode:
2282
2282
  VersionAdded: '0.9'
2283
2283
 
2284
2284
  Lint/UnreachableLoop:
2285
- Description: 'This cop checks for loops that will have at most one iteration.'
2285
+ Description: 'Checks for loops that will have at most one iteration.'
2286
2286
  Enabled: true
2287
2287
  VersionAdded: '0.89'
2288
2288
  VersionChanged: '1.7'
@@ -3109,7 +3109,7 @@ Style/CaseEquality:
3109
3109
  AllowOnConstant: false
3110
3110
 
3111
3111
  Style/CaseLikeIf:
3112
- Description: 'This cop identifies places where `if-elsif` constructions can be replaced with `case-when`.'
3112
+ Description: 'Identifies places where `if-elsif` constructions can be replaced with `case-when`.'
3113
3113
  StyleGuide: '#case-vs-if-else'
3114
3114
  Enabled: true
3115
3115
  Safe: false
@@ -3549,7 +3549,7 @@ Style/ExponentialNotation:
3549
3549
 
3550
3550
  Style/FetchEnvVar:
3551
3551
  Description: >-
3552
- This cop suggests `ENV.fetch` for the replacement of `ENV[]`.
3552
+ Suggests `ENV.fetch` for the replacement of `ENV[]`.
3553
3553
  Reference:
3554
3554
  - https://rubystyle.guide/#hash-fetch-defaults
3555
3555
  Enabled: pending
@@ -4146,7 +4146,7 @@ Style/NegatedIf:
4146
4146
 
4147
4147
  Style/NegatedIfElseCondition:
4148
4148
  Description: >-
4149
- This cop checks for uses of `if-else` and ternary operators with a negated condition
4149
+ Checks for uses of `if-else` and ternary operators with a negated condition
4150
4150
  which can be simplified by inverting condition and swapping branches.
4151
4151
  Enabled: pending
4152
4152
  VersionAdded: '1.2'
@@ -4703,7 +4703,7 @@ Style/ReturnNil:
4703
4703
 
4704
4704
  Style/SafeNavigation:
4705
4705
  Description: >-
4706
- This cop transforms usages of a method call safeguarded by
4706
+ Transforms usages of a method call safeguarded by
4707
4707
  a check for the existence of the object to
4708
4708
  safe navigation (`&.`).
4709
4709
  Auto-correction is unsafe as it assumes the object will
@@ -4930,7 +4930,7 @@ Style/StructInheritance:
4930
4930
  VersionChanged: '1.20'
4931
4931
 
4932
4932
  Style/SwapValues:
4933
- Description: 'This cop enforces the use of shorthand-style swapping of 2 variables.'
4933
+ Description: 'Enforces the use of shorthand-style swapping of 2 variables.'
4934
4934
  StyleGuide: '#values-swapping'
4935
4935
  Enabled: pending
4936
4936
  VersionAdded: '1.1'
@@ -4980,7 +4980,7 @@ Style/TernaryParentheses:
4980
4980
  AllowSafeAssignment: true
4981
4981
 
4982
4982
  Style/TopLevelMethodDefinition:
4983
- Description: 'This cop looks for top-level method definitions.'
4983
+ Description: 'Looks for top-level method definitions.'
4984
4984
  StyleGuide: '#top-level-methods'
4985
4985
  Enabled: false
4986
4986
  VersionAdded: '1.15'
@@ -62,6 +62,9 @@ module RuboCop
62
62
  class ErbNewArguments < Base
63
63
  include RangeHelp
64
64
  extend AutoCorrector
65
+ extend TargetRubyVersion
66
+
67
+ minimum_target_ruby_version 2.6
65
68
 
66
69
  MESSAGES = [
67
70
  'Passing safe_level with the 2nd argument of `ERB.new` is ' \
@@ -143,19 +143,19 @@ module RuboCop
143
143
 
144
144
  # @!method method_require?(node)
145
145
  def_node_matcher :method_require?, <<~PATTERN
146
- (block-pass (send nil? :method (sym :require)))
146
+ (block-pass (send nil? :method (sym {:require :require_relative})))
147
147
  PATTERN
148
148
 
149
149
  # @!method unsorted_dir_glob_pass?(node)
150
150
  def_node_matcher :unsorted_dir_glob_pass?, <<~PATTERN
151
151
  (send (const {nil? cbase} :Dir) :glob ...
152
- (block-pass (send nil? :method (sym :require))))
152
+ (block-pass (send nil? :method (sym {:require :require_relative}))))
153
153
  PATTERN
154
154
 
155
155
  # @!method unsorted_dir_each_pass?(node)
156
156
  def_node_matcher :unsorted_dir_each_pass?, <<~PATTERN
157
157
  (send (send (const {nil? cbase} :Dir) {:[] :glob} ...) :each
158
- (block-pass (send nil? :method (sym :require))))
158
+ (block-pass (send nil? :method (sym {:require :require_relative}))))
159
159
  PATTERN
160
160
 
161
161
  # @!method loop_variable(node)
@@ -165,7 +165,7 @@ module RuboCop
165
165
 
166
166
  # @!method var_is_required?(node, name)
167
167
  def_node_search :var_is_required?, <<~PATTERN
168
- (send nil? :require (lvar %1))
168
+ (send nil? {:require :require_relative} (lvar %1))
169
169
  PATTERN
170
170
  end
171
171
  end
@@ -214,13 +214,14 @@ module RuboCop
214
214
  end
215
215
 
216
216
  def mask_input(str)
217
- return str if @allowed_regex.nil?
218
-
219
217
  safe_str = if str.valid_encoding?
220
218
  str
221
219
  else
222
220
  str.encode('UTF-8', invalid: :replace, undef: :replace)
223
221
  end
222
+
223
+ return safe_str if @allowed_regex.nil?
224
+
224
225
  safe_str.gsub(@allowed_regex) { |match| '*' * match.size }
225
226
  end
226
227
 
@@ -97,7 +97,9 @@ module RuboCop
97
97
 
98
98
  def used_as_flag?(node)
99
99
  return false if node.root?
100
- return true if node.parent.if_type?
100
+
101
+ if_node = node.ancestors.find(&:if_type?)
102
+ return true if if_node&.condition == node
101
103
 
102
104
  node.parent.send_type? && (node.parent.prefix_bang? || node.parent.comparison_method?)
103
105
  end
@@ -29,8 +29,11 @@ module RuboCop
29
29
  #
30
30
  class MapToHash < Base
31
31
  extend AutoCorrector
32
+ extend TargetRubyVersion
32
33
  include RangeHelp
33
34
 
35
+ minimum_target_ruby_version 2.6
36
+
34
37
  MSG = 'Pass a block to `to_h` instead of calling `%<method>s.to_h`.'
35
38
  RESTRICT_ON_SEND = %i[to_h].freeze
36
39
 
@@ -91,6 +91,9 @@ module RuboCop
91
91
 
92
92
  def check_compact(node)
93
93
  if node.arguments.size > 1
94
+ exception = node.first_argument
95
+ return if exception.send_type? && exception.first_argument&.hash_type?
96
+
94
97
  add_offense(node, message: format(COMPACT_MSG, method: node.method_name)) do |corrector|
95
98
  replacement = correction_exploded_to_compact(node)
96
99
 
@@ -44,9 +44,9 @@ module RuboCop
44
44
  message = message(node)
45
45
 
46
46
  add_offense(range_of_offense(node), message: message) do |corrector|
47
- if node.ternary?
47
+ if node.ternary? && !branches_have_method?(node)
48
48
  correct_ternary(corrector, node)
49
- elsif node.modifier_form? || !node.else_branch
49
+ elsif redudant_condition?(node)
50
50
  corrector.replace(node, node.if_branch.source)
51
51
  else
52
52
  corrected = make_ternary_form(node)
@@ -59,7 +59,7 @@ module RuboCop
59
59
  private
60
60
 
61
61
  def message(node)
62
- if node.modifier_form? || !node.else_branch
62
+ if redudant_condition?(node)
63
63
  REDUNDANT_CONDITION
64
64
  else
65
65
  MSG
@@ -68,6 +68,7 @@ module RuboCop
68
68
 
69
69
  def range_of_offense(node)
70
70
  return node.loc.expression unless node.ternary?
71
+ return node.loc.expression if node.ternary? && branches_have_method?(node)
71
72
 
72
73
  range_between(node.loc.question.begin_pos, node.loc.colon.end_pos)
73
74
  end
@@ -81,6 +82,10 @@ module RuboCop
81
82
  (node.ternary? || !else_branch.instance_of?(AST::Node) || else_branch.single_line?)
82
83
  end
83
84
 
85
+ def redudant_condition?(node)
86
+ node.modifier_form? || !node.else_branch
87
+ end
88
+
84
89
  def use_if_branch?(else_branch)
85
90
  else_branch&.if_type?
86
91
  end
@@ -89,6 +94,10 @@ module RuboCop
89
94
  else_branch&.send_type? && else_branch&.method?(:[]=)
90
95
  end
91
96
 
97
+ def use_hash_key_access?(node)
98
+ node.send_type? && node.method?(:[])
99
+ end
100
+
92
101
  def synonymous_condition_and_branch?(node)
93
102
  condition, if_branch, _else_branch = *node
94
103
  # e.g.
@@ -113,7 +122,8 @@ module RuboCop
113
122
  # else
114
123
  # test.value = another_value?
115
124
  # end
116
- branches_have_method?(node) && condition == if_branch.first_argument
125
+ branches_have_method?(node) && condition == if_branch.first_argument &&
126
+ !use_hash_key_access?(if_branch)
117
127
  end
118
128
 
119
129
  def branches_have_assignment?(node)
@@ -140,6 +150,14 @@ module RuboCop
140
150
  if_branch.method?(else_branch.method_name)
141
151
  end
142
152
 
153
+ def if_source(if_branch)
154
+ if branches_have_method?(if_branch.parent) && if_branch.parenthesized?
155
+ if_branch.source.delete_suffix(')')
156
+ else
157
+ if_branch.source
158
+ end
159
+ end
160
+
143
161
  def else_source(else_branch)
144
162
  if branches_have_method?(else_branch.parent)
145
163
  else_source_if_has_method(else_branch)
@@ -157,6 +175,8 @@ module RuboCop
157
175
  def else_source_if_has_method(else_branch)
158
176
  if require_parentheses?(else_branch.first_argument)
159
177
  "(#{else_branch.first_argument.source})"
178
+ elsif require_braces?(else_branch.first_argument)
179
+ "{ #{else_branch.first_argument.source} }"
160
180
  else
161
181
  else_branch.first_argument.source
162
182
  end
@@ -165,6 +185,8 @@ module RuboCop
165
185
  def else_source_if_has_assignment(else_branch)
166
186
  if require_parentheses?(else_branch.expression)
167
187
  "(#{else_branch.expression.source})"
188
+ elsif require_braces?(else_branch.expression)
189
+ "{ #{else_branch.expression.source} }"
168
190
  else
169
191
  else_branch.expression.source
170
192
  end
@@ -172,7 +194,8 @@ module RuboCop
172
194
 
173
195
  def make_ternary_form(node)
174
196
  _condition, if_branch, else_branch = *node
175
- ternary_form = [if_branch.source, else_source(else_branch)].join(' || ')
197
+ ternary_form = [if_source(if_branch), else_source(else_branch)].join(' || ')
198
+ ternary_form += ')' if branches_have_method?(node) && if_branch.parenthesized?
176
199
 
177
200
  if node.parent&.send_type?
178
201
  "(#{ternary_form})"
@@ -196,6 +219,10 @@ module RuboCop
196
219
  (node.respond_to?(:semantic_operator?) && node.semantic_operator?)
197
220
  end
198
221
 
222
+ def require_braces?(node)
223
+ node.hash_type? && !node.braces?
224
+ end
225
+
199
226
  def without_argument_parentheses_method?(node)
200
227
  node.send_type? && !node.arguments.empty? &&
201
228
  !node.parenthesized? && !node.operator_method? && !node.assignment_method?
@@ -27,6 +27,9 @@ module RuboCop
27
27
  # items[1..]
28
28
  class SlicingWithRange < Base
29
29
  extend AutoCorrector
30
+ extend TargetRubyVersion
31
+
32
+ minimum_target_ruby_version 2.6
30
33
 
31
34
  MSG = 'Prefer ary[n..] over ary[n..-1].'
32
35
  RESTRICT_ON_SEND = %i[[]].freeze
@@ -116,6 +116,10 @@ RSpec.shared_context 'mock console output' do
116
116
  end
117
117
  end
118
118
 
119
+ RSpec.shared_context 'ruby 2.5', :ruby25 do
120
+ let(:ruby_version) { 2.5 }
121
+ end
122
+
119
123
  RSpec.shared_context 'ruby 2.6', :ruby26 do
120
124
  let(:ruby_version) { 2.6 }
121
125
  end
@@ -4,7 +4,7 @@ module RuboCop
4
4
  # The kind of Ruby that code inspected by RuboCop is written in.
5
5
  # @api private
6
6
  class TargetRuby
7
- KNOWN_RUBIES = [2.6, 2.7, 3.0, 3.1, 3.2].freeze
7
+ KNOWN_RUBIES = [2.5, 2.6, 2.7, 3.0, 3.1, 3.2].freeze
8
8
  DEFAULT_VERSION = KNOWN_RUBIES.first
9
9
 
10
10
  OBSOLETE_RUBIES = {
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  # This module holds the RuboCop version information.
5
5
  module Version
6
- STRING = '1.29.0'
6
+ STRING = '1.29.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.29.0
4
+ version: 1.29.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-06 00:00:00.000000000 Z
13
+ date: 2022-05-12 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: parallel
@@ -945,7 +945,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
945
945
  - !ruby/object:Gem::Version
946
946
  version: '0'
947
947
  requirements: []
948
- rubygems_version: 3.2.22
948
+ rubygems_version: 3.1.2
949
949
  signing_key:
950
950
  specification_version: 4
951
951
  summary: Automatic Ruby code style checking tool.