Skip to content

Add new Rails/IncludeViewHelper cop#1609

Open
mathieugoedhart96 wants to merge 1 commit intorubocop:masterfrom
mathieugoedhart96:rails-include-view-helper-cop
Open

Add new Rails/IncludeViewHelper cop#1609
mathieugoedhart96 wants to merge 1 commit intorubocop:masterfrom
mathieugoedhart96:rails-include-view-helper-cop

Conversation

@mathieugoedhart96
Copy link
Copy Markdown

@mathieugoedhart96 mathieugoedhart96 commented Apr 23, 2026

Summary

Add a new Rails/IncludeViewHelper cop that disallows including view helper modules outside of view contexts.

View helpers (modules in the ActionView::Helpers namespace or following the *Helper naming convention) depend on the view context. Including them in controllers, models, jobs, etc. may cause methods to fail silently or raise errors because the view context is not present.

Modules in app/helpers are automatically included into all views by Rails. If shared behaviour is needed across multiple classes, it should be extracted into a concern under app/concerns instead. In controllers, the helpers proxy can be used to call helper methods.


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.

@mathieugoedhart96 mathieugoedhart96 marked this pull request as draft April 23, 2026 13:46
…r modules (modules in the `ActionView::Helpers` namespace or following the `*Helper` naming convention) outside of view contexts.
@mathieugoedhart96 mathieugoedhart96 force-pushed the rails-include-view-helper-cop branch from cdcd018 to 55f79df Compare April 23, 2026 13:55
@mathieugoedhart96 mathieugoedhart96 marked this pull request as ready for review April 23, 2026 13:57
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.

1 participant