Add UseRenderModeInsteadOfPrimitives cop - #5
Merged
Conversation
Flags `format_text` calls that pass the external-rendering primitive flags (`static_html: true`, `plain_text: true`, `only_path: false`) instead of the canonical `render_mode:` API or the mailer view helpers `format_mail_html` / `format_mail_text`. The primitive flags are a coupled set whose partial application silently produced numeric work package IDs in watcher notifications (openproject#74762). `render_mode:` documents the intent and bundles the toggles into one canonical surface. The cop fires on both `.rb` and `.erb` sources via OpenProject's erb_lint Rubocop bridge. v1 is flag-only; autocorrect is a follow-up.
This was referenced May 27, 2026
akabiru
marked this pull request as ready for review
June 25, 2026 07:41
oliverguenther
approved these changes
Jun 25, 2026
oliverguenther
left a comment
Member
There was a problem hiding this comment.
Nice, thanks @akabiru 👏
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
https://community.openproject.org/wp/75389
What this cop does
Flags
format_text(...)calls that pass the external-rendering primitive flags —static_html: true,plain_text: true, oronly_path: false— instead of the canonicalrender_mode:API. Suggested fix:render_mode: :external_html/render_mode: :external_text, orformat_mail_html/format_mail_textinside mailer templates.Why now
format_textrenders trusted Markdown for two distinct audiences: in-app HTML and external surfaces (mailer bodies, feeds). External surfaces need absolute URLs and a subset of macros pre-resolved to static HTML / plain text, because the recipient has no JavaScript runtime to hydrate the rest. Expressing that requirement as three loosely coupled toggles makes call sites easy to get partially right and silently wrong.openproject#23337 introduced the
render_mode:API and the mailer view helpers as the structural fix; this cop prevents regression.Scope and behaviour
.rband.erbsources — OpenProject's.erb_lint.ymlinherits.rubocop.yml, so mailer templates are covered automatically.render_mode:as an explicit escape hatch: if the call already passesrender_mode:, the primitive flags are treated as an intentional override and no offense is raised.static_html: true, only_path: falsecollapses to a single kwarg whose source range may not be contiguous.Preview of offenses on opf/openproject
devSmoke-test against a
dev: