Linter: Add erb-prefer-pluralize-helper rule#1868
Open
joaoGabriel55 wants to merge 2 commits into
Open
Conversation
marcoroth
reviewed
Jul 22, 2026
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.
Overview
Adds a new linter rule,
erb-prefer-pluralize-helper, that flags calls toString#pluralizewith a count argument in ERB templates and recommends theActionView::Helpers::TextHelper#pluralizehelper instead.The helper form (
pluralize("Alias", count)) prepends the count to the output and reads naturally in a template, whereas"Alias".pluralize(count)typically forces the count to be rendered separately — leading to duplicated output like<%= aliases.size %> <%= "Alias".pluralize(aliases.size) %>.The offense message includes a concrete, source-derived suggestion, e.g.:
Related Issue
Closes #1723
Affected Component(s)
Type of Change
Main Technical Changes
erb-prefer-pluralize-helper(javascript/packages/linter/src/rules/erb-prefer-pluralize-helper.ts), modeled on the existing Prism-basederb-no-debug-outputrule:parserOptions: { prism_program: true }and aPrismVisitorto walkCallNodes.pluralize, the receiver is a string literal (StringNode/InterpolatedStringNode), and it has at least one argument (the count). This scoping avoids false positives on non-string receivers (e.g.model.pluralize(count)) and on the argument-less"Alias".pluralize, matching the "for counts" intent of the issue.warning;introducedIn: "unreleased".slice()helper.src/rules.tsand re-exported it fromsrc/rules/index.ts.docs/rules/erb-prefer-pluralize-helper.mdand linked it fromdocs/rules/README.md(required by therule-docscompleteness test).How to Test
The rule test covers valid cases (helper form, argument-less
String#pluralize, non-string receivers, unrelated string methods) and invalid cases (string-literalpluralizewith a count in both<%= %>and<% %>tags).Checklist
bin/integrationlocally (ran the linter package test suite: 2438 passed)Component: Descriptionconvention (Linter: Add \erb-prefer-pluralize-helper` rule`)