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

Autocorrect problem with Rails/Presence in the case of a multiplication #776

Closed
theodugautier opened this issue Sep 15, 2022 · 0 comments · Fixed by #777
Closed

Autocorrect problem with Rails/Presence in the case of a multiplication #776

theodugautier opened this issue Sep 15, 2022 · 0 comments · Fixed by #777
Labels
bug Something isn't working

Comments

@theodugautier
Copy link

In my case (see below) the Rails/Presence cops does not correctly correct the case of a multiplication, which produces a Zeitwerk error.


Expected behavior

There should be a space between the parenthesis and the * or remove the parenthesis and add a space between the * and the float/integer.

Actual behavior

I have this error : C: [Correctable] Rails/Presence: Use variable.presence || price.to_f *(12.0) instead of if variable.present?
and when I execute rubocop -a, it corrects : annual_contribution.presence || month_price.to_f *(12.0)

it gives me this error when I run bin/rails zeitwerk:check :

syntax error, unexpected *, expecting end-of-input

   87  class TestingClass
  123    def test_function
❯ 124      variable.presence || price.to_f *(12.0)
  125    end
  135  end

rails aborted!

Steps to reproduce the problem

class TestingClass
  def test_function
      if variable.present?
        variable
      else
        price.to_f * 12.0
      end
  end
end

and run rubocop -a

RuboCop version

$ bundle exec rubocop -V
1.25.1 (using Parser 3.1.1.0, rubocop-ast 1.16.0, running on ruby 2.7.6 arm64-darwin20)
  - rubocop-rails 2.13.2
@koic koic transferred this issue from rubocop/rubocop Sep 15, 2022
koic added a commit to koic/rubocop-rails that referenced this issue Sep 15, 2022
Fixes rubocop#776.

This PR fixes an incorrect autocorrect for `Rails/Presence`
when using arithmetic operation in `else` branch.
@koic koic added the bug Something isn't working label Sep 15, 2022
koic added a commit to koic/rubocop-rails that referenced this issue Sep 15, 2022
Fixes rubocop#776.

This PR fixes an incorrect autocorrect for `Rails/Presence`
when using arithmetic operation in `else` branch.
@koic koic closed this as completed in #777 Sep 19, 2022
koic added a commit that referenced this issue Sep 19, 2022
…ils_presence

[Fix #776] Fix an incorrect autocorrect for `Rails/Presence`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants