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 for Rails/ActionOrder breaks conditionally-defined actions #838

Closed
jkr2255 opened this issue Oct 26, 2022 · 0 comments · Fixed by #845
Closed

Autocorrect for Rails/ActionOrder breaks conditionally-defined actions #838

jkr2255 opened this issue Oct 26, 2022 · 0 comments · Fixed by #845
Labels
bug Something isn't working

Comments

@jkr2255
Copy link

jkr2255 commented Oct 26, 2022

When action method is defined in condition block, autocorrect for Rails/ActionOrder swaps action methods without concerning whether they are conditionally defined, thus breaking semantics.


Expected behavior

# frozen_string_literal: true

class TestController < BaseController
  if Rails.env.development?
    def index
    end
  end

  def edit
  end

end

(would be desirable; at least, autocorrect (or doing nothing) doesn't break semantics)

Actual behavior

# frozen_string_literal: true

class TestController < BaseController
  def index
  end

  if Rails.env.development?
    def edit
    end
  end
end

Steps to reproduce the problem

rubocop -a with following source

class TestController < BaseController
  def edit
  end

  if Rails.env.development?
    def index
    end
  end
end

RuboCop version

Include the output of rubocop -V or bundle exec rubocop -V if using Bundler. Here's an example:
You can see extension cop versions (e.g. rubocop-rails, rubocop-performance, and others) output by rubocop -V,
include them as well. Here's an example:

$ [bundle exec] rubocop -V
1.37.1 (using Parser 3.1.2.1, rubocop-ast 1.23.0, running on ruby 2.7.6) [x86_64-linux]
  - rubocop-rails 2.17.1
@koic koic added the bug Something isn't working label Oct 26, 2022
koic added a commit to koic/rubocop-rails that referenced this issue Oct 28, 2022
Fixes rubocop#838.

This PR fixes an incorrect autocorrect for `Rails/ActionOrder`
when using unconventional order of actions in conditions.
@koic koic closed this as completed in #845 Oct 29, 2022
koic added a commit that referenced this issue Oct 29, 2022
…ils_action_order

[Fix #838] Fix an incorrect autocorrect for `Rails/ActionOrder`
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