Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positive Lint/Syntax with ruby 3.3.1 and anonymous rest arg/keyword argument forwarding #12868

Closed
kochalex opened this issue Apr 24, 2024 · 2 comments

Comments

@kochalex
Copy link

kochalex commented Apr 24, 2024

Ruby 3.3.0 changed how anonymous args/keyword args can be used and the newly released 3.3.1 contains a bugfix for some unambiguous/unintentional places where they could be safely used, see: https://bugs.ruby-lang.org/issues/20090

Expected behavior

Rubocop is able to parse & validate code that runs on ruby 3.3.1

Actual behavior

Get Lint/Syntax errors such as:
Lint/Syntax: anonymous keyword rest parameter is also used within block
Lint/Syntax: anonymous rest parameter is also used within block
Lint/Syntax: unexpected token $end

❯ bundle exec rubocop --debug
For /Users/<username>/repos/rubocop-repo: Default configuration from /Users/<username>/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/rubocop-1.63.3/config/default.yml
Use parallel by default.
Running parallel inspection
Loading cache from /Users/<username>/.cache/rubocop_cache/d8000782e70b69f8ef9f890bf197e06093695a19/6d7a3b621ca1730e04accd938619e4bdab66cfb1/14b887b108489c87a0ce57f4b58361ea46a3fdc3
Loading cache from /Users/<username>/.cache/rubocop_cache/d8000782e70b69f8ef9f890bf197e06093695a19/6d7a3b621ca1730e04accd938619e4bdab66cfb1/88559496eb2db1f6bae77024cd89412cfad0a51c
Inspecting 2 files
Scanning /Users/<username>/repos/rubocop-repo/Gemfile
Loading cache from /Users/<username>/.cache/rubocop_cache/d8000782e70b69f8ef9f890bf197e06093695a19/6d7a3b621ca1730e04accd938619e4bdab66cfb1/14b887b108489c87a0ce57f4b58361ea46a3fdc3
.Scanning /Users/<username>/repos/rubocop-repo/test.rb
Loading cache from /Users/<username>/.cache/rubocop_cache/d8000782e70b69f8ef9f890bf197e06093695a19/6d7a3b621ca1730e04accd938619e4bdab66cfb1/88559496eb2db1f6bae77024cd89412cfad0a51c
F

Offenses:

test.rb:3:10: F: Lint/Syntax: anonymous keyword rest parameter is also used within block
(Using Ruby 3.3 parser; configure using TargetRubyVersion parameter, under AllCops)
    puts(**)
         ^^
test.rb:11:10: F: Lint/Syntax: anonymous rest parameter is also used within block
(Using Ruby 3.3 parser; configure using TargetRubyVersion parameter, under AllCops)
    puts(*)
         ^
test.rb:16:1: F: Lint/Syntax: unexpected token $end
(Using Ruby 3.3 parser; configure using TargetRubyVersion parameter, under AllCops)

2 files inspected, 3 offenses detected
Finished in 0.08651399999507703 seconds

Steps to reproduce the problem

Here's a sample test case: (there are more in https://bugs.ruby-lang.org/issues/20090)

def test(**)
  [1].each do
    puts(**)
  end
end

test(a: 1)

def bar(*)
  [1].each do
    puts(*)
  end
end

bar('1')

The code works on ruby 3.3.1 (and did on 3.2), but not 3.3.0:

❯ ruby --version
ruby 3.3.1 (2024-04-23 revision c56cd86388) [arm64-darwin23]
❯ ruby test.rb
{:a=>1}
1
❯ asdf local ruby 3.3.0
❯ ruby test.rb
test.rb:
test.rb:3: anonymous keyword rest parameter is also used within block (SyntaxError)
test.rb:11: anonymous rest parameter is also used within block
❯ bundle exec rubocop
Inspecting 2 files
.F

Offenses:

test.rb:3:10: F: Lint/Syntax: anonymous keyword rest parameter is also used within block
(Using Ruby 3.3 parser; configure using TargetRubyVersion parameter, under AllCops)
    puts(**)
         ^^
test.rb:11:10: F: Lint/Syntax: anonymous rest parameter is also used within block
(Using Ruby 3.3 parser; configure using TargetRubyVersion parameter, under AllCops)
    puts(*)
         ^
test.rb:16:1: F: Lint/Syntax: unexpected token $end
(Using Ruby 3.3 parser; configure using TargetRubyVersion parameter, under AllCops)

2 files inspected, 3 offenses detected```

RuboCop version

❯ bundle exec rubocop -V
1.63.3 (using Parser 3.3.0.5, rubocop-ast 1.31.2, running on ruby 3.3.0) [arm64-darwin23]
@Earlopain
Copy link
Contributor

This requires a new release from the parser gem: whitequark/parser#1009

@kochalex
Copy link
Author

The versions ranges on rubocop allow for an updated version of the parser gem, https://github.com/whitequark/parser/releases/tag/v3.3.1.0 - but anyone who's on 3.3.0 may want to stick with previous version of parser, it doesn't have differences for patch versions of ruby.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants