-
Notifications
You must be signed in to change notification settings - Fork 25
Add ERB Lint to lint templates (RuboCop only covers .rb) #1988
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
maebeale
wants to merge
9
commits into
main
Choose a base branch
from
maebeale/erb-lint
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
76804b0
Add ERB Lint to fill the gap RuboCop leaves on templates
maebeale 0010ba7
Apply ERB Lint autocorrect sweep across templates
maebeale 81e8330
Document ERB Lint enforcement in AI instruction files
maebeale 333eca7
Fix ERB Lint ruleset to match omakase and cover more documented rules
maebeale 456808c
Re-run ERB Lint autocorrect sweep with the corrected ruleset
maebeale 185e7b6
Exclude vendor/node_modules/tmp from ERB Lint
maebeale 7d7cb54
Rework ERB Lint config to the gem's recommended setup
maebeale 8f34bae
Fix invalid smart quotes in webfonts script (surfaced by AllowedScripβ¦
maebeale 9c0137a
Re-sweep templates under the recommended ERB Lint config
maebeale File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| --- | ||
| # ERB Lint β fills the gap RuboCop leaves: RuboCop only parses .rb, so nothing | ||
| # checked the Ruby inside <% %> tags or our ERB/HTML conventions. Follows the | ||
| # gem's recommended setup (https://github.com/Shopify/erb_lint): default linters | ||
| # stay on, and the Rubocop linter inherits our .rubocop.yml so the Ruby in tags | ||
| # is held to the same omakase style as our .rb files β no rules duplicated here. | ||
| EnableDefaultLinters: true | ||
| # --lint-all globs every *.html.erb under the repo. In CI, `bundler-cache` | ||
| # installs gems into vendor/bundle, so without this exclude erb_lint would lint | ||
| # third-party gem templates. (RuboCop excludes vendor by default; erb_lint does | ||
| # not.) Paths are matched from the repo root. | ||
| exclude: | ||
| - vendor/**/* | ||
| - node_modules/**/* | ||
| - tmp/**/* | ||
| linters: | ||
| # Adding an autocomplete token to each input is a per-field autofill/UX | ||
| # decision, not a mechanical fix, so enforcing it across the existing forms is | ||
| # out of scope here. Left off deliberately; could be revisited on its own. | ||
| RequireInputAutocomplete: | ||
| enabled: false | ||
| # <script type="module"> is legitimate ESM (e.g. the mermaid import on the flow | ||
| # diagram); allow it alongside the default text/javascript. | ||
| AllowedScriptType: | ||
| allowed_types: | ||
| - text/javascript | ||
| - module | ||
| Rubocop: | ||
| enabled: true | ||
| rubocop_config: | ||
| inherit_from: | ||
| - .rubocop.yml | ||
| # Cops that don't make sense against the Ruby extracted from an ERB tag β | ||
| # erb_lint hands RuboCop each tag's Ruby without its surrounding HTML | ||
| # indent context, so file-level layout/naming cops misfire. This is the | ||
| # gem README's recommended disable list. | ||
| Layout/InitialIndentation: | ||
| Enabled: false | ||
| # Block/indentation alignment cops need the whole method body, but a | ||
| # multi-line if/case/block is split across separate <% %> tags with the | ||
| # HTML stripped out, so RuboCop sees misaligned fragments β all false | ||
| # positives in ERB. | ||
| Layout/IndentationWidth: | ||
| Enabled: false | ||
| Layout/IndentationConsistency: | ||
| Enabled: false | ||
| Layout/ElseAlignment: | ||
| Enabled: false | ||
| Layout/EndAlignment: | ||
| Enabled: false | ||
| Layout/CaseIndentation: | ||
| Enabled: false | ||
| Layout/BeginEndAlignment: | ||
| Enabled: false | ||
| Layout/LineLength: | ||
| Enabled: false | ||
| Layout/TrailingEmptyLines: | ||
| Enabled: false | ||
| Layout/TrailingWhitespace: | ||
| Enabled: false | ||
| Naming/FileName: | ||
| Enabled: false | ||
| Style/FrozenStringLiteralComment: | ||
| Enabled: false | ||
| Lint/UselessAssignment: | ||
| Enabled: false | ||
| Rails/OutputSafety: | ||
| Enabled: false | ||
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,17 @@ | ||
| #!/usr/bin/env bash | ||
| # Lint Ruby files with Rubocop. Use --fix to auto-correct. | ||
| set -euo pipefail | ||
| # Lint Ruby with RuboCop and ERB templates with ERB Lint. Use --fix to | ||
| # auto-correct both. File args are passed to RuboCop; ERB Lint always runs | ||
| # across all ERB files. | ||
| set -uo pipefail | ||
| source "$(dirname "$0")/.ruby-env" | ||
|
|
||
| status=0 | ||
| if [[ "${1:-}" == "--fix" ]]; then | ||
| shift | ||
| bundle exec rubocop -a "$@" | ||
| bundle exec rubocop -a "$@" || status=$? | ||
| bundle exec erb_lint --lint-all --autocorrect || status=$? | ||
| else | ||
| bundle exec rubocop "$@" | ||
| bundle exec rubocop "$@" || status=$? | ||
| bundle exec erb_lint --lint-all || status=$? | ||
| fi | ||
| exit $status |
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
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
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
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why duplicate everything in our rubocop.yml ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π€ From Claude: Done β the Rubocop linter now
inherit_from: .rubocop.yml, so nothing is duplicated. The only cops set here are the ones that can't work on the Ruby extracted from a single tag: the README's recommended list plus the block/indentation-alignment family (a multi-lineif/caseis split across separate<% %>tags, so RuboCop sees misaligned fragments). Net effect: it also surfaced more real style issues (space after colon/comma) than my earlier hand-picked subset.