Ensures that strict locals comments use the exact locals: ( ... ) syntax so they are properly recognized by Rails and tooling. Also validates that only keyword arguments are used (no positional, block, or splat arguments).
Strict locals comments declare which locals are expected in a template. Misspellings or malformed syntax silently disable the declaration, leading to confusing runtime errors when required locals are missing.
Additionally, Rails only supports keyword arguments in strict locals declarations. Positional, block, and splat arguments will raise an ActionView::Error at render-time.
This rule catches invalid comment forms and argument types early during development.
Linter Rule: Enforce strict locals comment syntax
Rule:
erb-strict-locals-comment-syntaxDescription
Ensures that strict locals comments use the exact
locals: ( ... )syntax so they are properly recognized by Rails and tooling. Also validates that only keyword arguments are used (no positional, block, or splat arguments).Rationale
Strict locals comments declare which locals are expected in a template. Misspellings or malformed syntax silently disable the declaration, leading to confusing runtime errors when required locals are missing.
Additionally, Rails only supports keyword arguments in strict locals declarations. Positional, block, and splat arguments will raise an
ActionView::Errorat render-time.This rule catches invalid comment forms and argument types early during development.
Examples
✅ Good
Required keyword argument:
Keyword argument with default value:
Complex default values:
No locals (empty):
Double-splat for optional keyword arguments:
🚫 Bad
Wrong comment syntax
Missing colon after
locals:Singular
localinstead oflocals:Missing colon before parentheses:
Missing parentheses around parameters:
Empty
locals:without parentheses:Unbalanced parentheses:
Wrong tag type (must use ERB comment tag)
Ruby comment in execution tag:
Unsupported argument types
Positional argument (use
user:instead):Block argument:
Single splat argument:
Note: Double-splat (
**attributes) IS supported for optional keyword arguments.Invalid Ruby syntax
Trailing comma:
Leading comma:
Double comma:
Duplicate declarations
Only one
locals:comment is allowed per partial:References