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 positives for Rails/SaveBang for nested assignments #1422

Open
ydakuka opened this issue Jan 19, 2025 · 2 comments
Open

False positives for Rails/SaveBang for nested assignments #1422

ydakuka opened this issue Jan 19, 2025 · 2 comments

Comments

@ydakuka
Copy link
Contributor

ydakuka commented Jan 19, 2025

Describe the solution you'd like

it "does not register an offense when using persisted? after create and nested assignments" do
  expect_no_offenses(<<~RUBY)
    temp = (user = User.create)

    if temp.persisted?
      foo
    end
  RUBY
end

it "does not register an offense when assigning inside an if statement" do
  expect_no_offenses(<<~RUBY)
    if (user = User.create).persisted?
      foo
    end
  RUBY
end

Rubocop

$ rubocop -V
1.70.0 (using Parser 3.3.6.0, rubocop-ast 1.37.0, analyzing as Ruby 2.7, running on ruby 2.7.8) [x86_64-linux]
  - rubocop-capybara 2.21.0
  - rubocop-factory_bot 2.26.1
  - rubocop-performance 1.23.1
  - rubocop-rails 2.28.0
  - rubocop-rake 0.6.0
  - rubocop-rspec 3.3.0
  - rubocop-rspec_rails 2.30.0
  - rubocop-thread_safety 0.6.0
@tejasbubane
Copy link
Contributor

I think this is because the cop is disabled by default?

Rails/SaveBang:
Description: 'Identifies possible cases where Active Record save! or related should be used.'
StyleGuide: 'https://rails.rubystyle.guide#save-bang'
Enabled: false
VersionAdded: '0.42'
VersionChanged: '0.59'
AllowImplicitReturn: true
AllowedReceivers: []
SafeAutoCorrect: false

@ydakuka
Copy link
Contributor Author

ydakuka commented Jan 20, 2025

No, I've checked it within rubocop-rails.

@ydakuka ydakuka changed the title False positives for Rails/SaveBank for nested assignments False positives for Rails/SaveBang for nested assignments Jan 22, 2025
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