KEMBAR78
Unsafe autocorrection with Style/SingleLineMethods with a calculation · Issue #14346 · rubocop/rubocop · GitHub
Skip to content

Unsafe autocorrection with Style/SingleLineMethods with a calculation #14346

@jibai31

Description

@jibai31

When I run the autocorrection for Style/SingleLineMethods on the following line, it does a breaking change:

def notification_attributes() [:email] + editable_fields - [:message] end

Expected behavior

I'm expecting the autocorrect to output the following:

def notification_attributes = [:email] + editable_fields - [:message]

Actual behavior

But I get the following:

def notification_attributes = [:email] + editable_fields.-([:message])

The dot after editable_fields breaks the code.

Steps to reproduce the problem

# app/models/task.rb
class Task
  def notification_attributes() [:email] + editable_fields - [:message] end
end

Then run:

bundle exec rubocop -a app/models/task.rb

RuboCop version

$ bundle exec rubocop -V
1.77.0 (using Parser 3.3.8.0, rubocop-ast 1.45.1, analyzing as Ruby 3.2, running on ruby 3.2.8) [arm64-darwin24]
  - rubocop-capybara 2.22.1
  - rubocop-factory_bot 2.27.1
  - rubocop-performance 1.25.0
  - rubocop-rails 2.32.0
  - rubocop-rspec 3.6.0
  - rubocop-rspec_rails 2.31.0

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