Skip to content

Linter Rule: erb-hash-shorthand-syntax #2041

Description

@marcoroth

Rule: erb-hash-shorthand-syntax

Description

Enforce a consistent style for Ruby's hash value omission (shorthand hash syntax, Ruby >= 3.1) inside ERB tags, most visibly in render calls with a locals: hash.

The rule should be configurable through an enforcedStyle option:

  • always (proposed default)
  • never

Examples

With enforcedStyle: "always":

✅ Good
<%= render partial: "users/featured_talk", locals: { featured: } %>
<%= render partial: "users/featured_talk", locals: { featured:, speaker: } %>
<%= render partial: "users/featured_talk", locals: { featured: @featured } %>
<%= render partial: "users/featured_talk", locals: { talk: featured } %>
🚫 Bad
<%= render partial: "users/featured_talk", locals: { featured: featured } %>
<%= render partial: "users/featured_talk", locals: { featured: featured, speaker: speaker } %>

With enforcedStyle: "never":

✅ Good
<%= render partial: "users/featured_talk", locals: { featured: featured } %>
<%= render partial: "users/featured_talk", locals: { featured: featured, speaker: speaker } %>

🚫 Bad

<%= render partial: "users/featured_talk", locals: { featured: } %>
<%= render partial: "users/featured_talk", locals: { featured:, speaker: } %>

Notes

Depends on #1204

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    linter@herb-tools/linter for HTML+ERB templateslinter-ruleIndividual linter rules and their documentation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions