Skip to content

Style/TrailingCommaInArguments crashes on trailing comma before chained call #14736

@pihaland

Description

@pihaland

I discovered that the Style/TrailingCommaInArguments cop crashes after upgrading RuboCop from 1.81.7 to 1.82.0

Steps to reproduce the problem

  1. File foo.rb
#foo.rb
class Foo
  def self.call(arg1:, arg2:)
    new
    @arg1 = arg1
    @arg2 = arg2
  end
end

Foo.(arg1: 1,
     arg2: 2).tap do |result|
  puts result
end
  1. Run rubocop foo.rb --only Style/TrailingCommaInArguments

  2. Output:


Inspecting 1 file
.

1 file inspected, no offenses detected
The following cops were added to RuboCop, but are not configured. Please set Enabled to either `true` or `false` in your `.rubocop.yml` file.
                                                                                                                                                                                                                                                                                                                                                                                    
Please also note that you can opt-in to new cops by default by adding this to your config:                                                                                                                                                                                                                                                                                          
  AllCops:                                                                                                                                                                                                                                                                                                                                                                          
    NewCops: enable                                                                                                                                                                                                                                                                                                                                                                 
                                                                                                                                                                                                                                                                                                                                                                                    
Style/ModuleMemberExistenceCheck: # new in 1.82
  Enabled: true
For more information: https://docs.rubocop.org/rubocop/versioning.html
An error occurred while Style/TrailingCommaInArguments cop was inspecting /home/coldquite/RubymineProjects/enectiva/app/assets/snapshots/foo.rb:11:0.
To see the complete backtrace run rubocop -d.

1 error occurred:                                                                                                                                                                                                                                                                                                                                                                   
An error occurred while Style/TrailingCommaInArguments cop was inspecting /home/coldquite/RubymineProjects/enectiva/app/assets/snapshots/foo.rb:11:0.
Errors are usually caused by RuboCop bugs.
Please, update to the latest RuboCop version if not already in use, and report a bug if the issue still occurs on this version.                                                                                                                                                                                                                                                     
https://github.com/rubocop/rubocop/issues                                                                                                                                                                                                                                                                                                                                           
                                                                                                                                                                                                                                                                                                                                                                                    
Mention the following information in the issue report:                                                                                                                                                                                                                                                                                                                              
1.82.0 (using Parser 3.3.10.0, Prism 1.7.0, rubocop-ast 1.48.0, analyzing as Ruby 3.3, running on ruby 3.3.7) +server [x86_64-linux]                                                                                                                                                                                                                                                

This is extremely important! Providing us with a reliable way to reproduce
a problem will expedite its solution.

Expected behavior

The cop should finish without raising an exception; it should either report an offense or none, but not crash.

Actual behavior

Style/TrailingCommaInArguments crashes when there is a trailing comma before the closing parenthesis followed by a method chain (e.g., ).tap).

RuboCop version

$ [bundle exec] rubocop -V
1.82.0 (using Parser 3.3.10.0, Prism 1.7.0, rubocop-ast 1.48.0, analyzing as Ruby 3.3, running on ruby 3.3.7) +server [x86_64-linux]
  - rubocop-rspec 3.8.0
  - rubocop-factory_bot 2.28.0
  - rubocop-rspec_rails 2.32.0
  - rubocop-capybara 2.22.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions