Skip to content

Fix false positive for Rails/LexicallyScopedActionFilter when action methods are delegated #1450

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

Merged

Conversation

vlad-pisanov
Copy link
Contributor

Fixes: #1447

Currently, Rails/LexicallyScopedActionFilter only looks for explicitly defined (def) action methods, and aliased action methods (alias, alias_method), but not action methods defined via delegation delegate :my_action, to: ...

This PR fixes that.


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.
  • If this is a new cop, consider making a corresponding update to the Rails Style Guide.

@vlad-pisanov vlad-pisanov force-pushed the vp_fix_lexically_scoped_action_filter_2 branch from 7d3c4ed to 957ab12 Compare February 18, 2025 08:21
@vlad-pisanov vlad-pisanov changed the title Fix false negative for Rails/LexicallyScopedActionFilter when action methods are delegated Fix false positive for Rails/LexicallyScopedActionFilter when action methods are delegated Feb 18, 2025
…nFilter` when action methods are delegated
@vlad-pisanov vlad-pisanov force-pushed the vp_fix_lexically_scoped_action_filter_2 branch from 957ab12 to 7b92670 Compare February 18, 2025 08:24
@Earlopain
Copy link
Contributor

Getting into this situation in the first place seems wrong to me, I don't think I would enjoy using delegation for controller actions. But, this is a fix regardless of that.

In my opinion Rails/Delegate should have special handling for controllers. What do you think?

@vlad-pisanov
Copy link
Contributor Author

@Earlopain I'm down with disabling Rails/Delegate on the controller directories by default. Delegated actions can be useful but I wouldn't want to be forced into using them.

@koic koic merged commit 04529cf into rubocop:master Feb 20, 2025
16 checks passed
@koic
Copy link
Member

koic commented Feb 20, 2025

Thanks!

@koic
Copy link
Member

koic commented Feb 20, 2025

I'm down with disabling Rails/Delegate on the controller directories by default.

I agree.

Earlopain added a commit to Earlopain/rubocop-rails that referenced this pull request Feb 27, 2025
@Earlopain
Copy link
Contributor

#1454

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

Successfully merging this pull request may close these issues.

False positive / conflicting cops: Rails/Delegate and Rails/LexicallyScopedActionFilter?
3 participants