A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/rubocop/rubocop/issues/14239 below:

Style/RedundantParentheses breaks pattern matching · Issue #14239 · rubocop/rubocop · GitHub

It wants to remove parens that are needed to keep precedence right.

Expected behavior
lhs = {foo: 1}
rhs = {bar: 2}
if (lhs in {foo:}) \
   && (rhs in {bar:})
  puts 32
else
  puts 23
end
$ ruby rubocop/redundant_parens.rb
32
$ bundle exec rubocop -A rubocop/redundant_parens.rb
Inspecting 1 file
F

Offenses:

rubocop/redundant_parens.rb:1:1: C: [Corrected] Style/FrozenStringLiteralComment: Missing frozen string literal comment.
lhs = {foo: 1}
^
rubocop/redundant_parens.rb:3:4: C: [Corrected] Style/RedundantParentheses: Don't use parentheses around a one-line pattern matching.
if (lhs in {foo:}) \
   ^^^^^^^^^^^^^^^
rubocop/redundant_parens.rb:4:7: C: [Corrected] Style/RedundantParentheses: Don't use parentheses around a one-line pattern matching.
   && (rhs in {bar:})
      ^^^^^^^^^^^^^^^
rubocop/redundant_parens.rb:5:4: F: Lint/Syntax: unexpected token tANDOP
(Using Ruby 3.3 parser; configure using TargetRubyVersion parameter, under AllCops)
   && rhs in {bar:}
   ^^
rubocop/redundant_parens.rb:7:1: F: Lint/Syntax: unexpected token kELSE
(Using Ruby 3.3 parser; configure using TargetRubyVersion parameter, under AllCops)
else
^^^^

1 file inspected, 5 offenses detected, 3 offenses corrected
$ ruby rubocop/redundant_parens.rb
rubocop/redundant_parens.rb: --> rubocop/redundant_parens.rb
expected `then` or `;` or '\n'cannot parse the expression
> 4  if lhs in {foo:} \
> 5     && rhs in {bar:}
> 6    puts 32
> 7  else
> 8    puts 23
> 9  end

rubocop/redundant_parens.rb:5: syntax error, unexpected &&, expecting `then' or ';' or '\n' (SyntaxError)
   && rhs in {bar:}
   ^~

RuboCop version
$ bundle exec rubocop -V
1.76.0 (using Parser 3.3.8.0, Prism 1.4.0, rubocop-ast 1.45.0, analyzing as Ruby 3.3, running on ruby 3.3.8) [arm64-darwin24]
  - rubocop-minitest 0.38.1
  - rubocop-performance 1.25.0

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4