Skip to content

Codemod: migrate {{! template-lint-disable }} comments to ESLint-native directives#3

Open
johanrd wants to merge 8 commits into
feat/recommended-template-configfrom
feat/migrate-template-lint-directives-codemod
Open

Codemod: migrate {{! template-lint-disable }} comments to ESLint-native directives#3
johanrd wants to merge 8 commits into
feat/recommended-template-configfrom
feat/migrate-template-lint-directives-codemod

Conversation

@johanrd
Copy link
Copy Markdown
Owner

@johanrd johanrd commented Apr 19, 2026

Note

This is part of a series where Claude has audited eslint-plugin-ember against jsx-a11y, vuejs-accessibility, angular-eslint, lit-a11y and html-validate, ember-template-lint, and the HTML and WCAG specs.

Alternative to ember-cli/eslint-plugin-ember#2627 (and to the follow-up enable-range work that built on top of it on feat/template-lint-enable-range-semantics). Targets the feat/recommended-template-config branch because it completes the ETL-migration story started there.

Cowritten by claude

Why a codemod instead of a processor

PR ember-cli#2627 introduced a runtime processor that parses {{! template-lint-disable }} comments out of template text and filters ESLint messages to match ETL's semantics. The follow-up on feat/template-lint-enable-range-semantics widened that to block scope.

That works, but it reimplements functionality ESLint already provides: {{! eslint-disable rule }}, {{! eslint-disable-next-line rule }}, and {{! eslint-disable rule }}{{! eslint-enable rule }} already work today inside mustache comments in .gjs / .gts / .hbs files (covered by tests added in commits a077ffe7 and 5c433af4 on feat/template-lint-enable-range-semantics). The only thing missing for ETL migrators is the comment name. A codemod fixes that once, at migration time, with zero ongoing plugin code to maintain and no second directive-scope model to keep in sync.

The rule-name mapping is deterministic by convention: every ported template rule lives at lib/rules/template-<etl-name>.js, so ETL's no-foo maps cleanly to this plugin's ember/template-no-foo. Rules that don't follow that convention (if any future port deviates) surface as unknown-rule warnings.

Scope

Grounded in what ETL itself parses today (lib/rules/_base.js:247-337):

  • File types: .hbs, .gjs, .gts.
  • Comment syntax: mustache only ({{! ... }} and {{!-- ... --}}). HTML comments are skipped because ETL doesn't honour directives in them either (_base.js:197-201 registers a CommentStatement visitor but attaches no instruction handler to it; only MustacheCommentStatement gets _processInstructionNode wired in at _base.js:247).
  • Rewritten: template-lint-disable / template-lint-enableeslint-disable / eslint-enable, with rule names remapped.
  • Skipped + warned: template-lint-disable-tree / -enable-tree (ESLint has no tree scope) and template-lint-configure[-tree] (no in-template rule-config equivalent; must move to the flat config file).
  • Unknown rule names (pass validation, don't exist in plugin): still rewritten with a warning. ESLint silently ignores unknown rule IDs in disable comments, so the rewrite is safe and the warning is actionable.
  • Malformed rule lists (trailing prose, /, etc.): comment left unchanged with a warning. Prevents bogus ember/template-extra output when a user writes {{!-- template-lint-disable no-bare-strings extra text --}}.
  • Rule-name parsing closely mirrors ETL's (_base.js:27-39, 515): whitespace-split (not comma), paired quotes stripped via unquote-style regex. Trailing commas are tolerated as a common migration typo.

Example

- {{! template-lint-disable no-bare-strings no-invalid-role }}
+ {{! eslint-disable ember/template-no-bare-strings, ember/template-no-invalid-role }}

- {{!-- template-lint-disable no-bare-strings --}}
+ {{!-- eslint-disable ember/template-no-bare-strings --}}

- {{! template-lint-enable }}
+ {{! eslint-enable }}

template-lint-disable-tree and template-lint-configure are left in place with a warning pointing at the line so users can resolve them manually.

CLI

# Dry run (default).
node scripts/migrate-template-lint-directives.js app/ tests/

# Apply.
node scripts/migrate-template-lint-directives.js --write app/ tests/

Accepts files or directories; directories are walked recursively, filtered to .hbs/.gjs/.gts, excluding node_modules, .git, dist, tmp, .cache. ENOENT / EACCES on inputs produce clean error messages and a non-zero exit code.

Coverage vs feat/template-lint-enable-range-semantics

The processor-branch tests are integration tests (do real lint messages get suppressed?). The codemod tests are transformation tests (does the output text match?). Every processor-branch behavior has a codemod equivalent:

Processor branch test Codemod equivalent
disables all rules on next line (mustache) rewrites a simple mustache disable with no rules
disables all rules on next line (block) rewrites a block mustache disable
disables a specific rule from comment to EOF rewrite covered; EOF behavior is ESLint-native
disables all rules to EOF when no enable same
template-lint-enable closes the disable range rewrite covered; range closing is ESLint-native
enable with specific rules closes matching ranges same
supports multiple rule names joins multiple rule names with commas
multiple disable comments in same file handles multiple simple comments on different lines
native eslint-disable/enable works in gjs foundation the codemod relies on — out of scope
gts + ember/template-no-bare-strings suppression end-to-end; codemod produces the input, ESLint does the suppression

Deliberate divergences

Two processor behaviors the codemod does not match:

  1. Bare JS core rule names in template-lint-disable (e.g. {{! template-lint-disable no-undef }}). The processor's matchesRule() accepted bare rule IDs and suppressed JS core rules. The codemod always prepends ember/template-, so no-undefember/template-no-undef (warns as unknown). This was never real ETL behavior — ETL doesn't touch JS rules — so ETL-alignment is deliberate.
  2. Already-prefixed rule IDs (e.g. {{! template-lint-disable ember/template-no-bare-strings }}). The validator rejects tokens containing / and leaves the comment unchanged with a warning. Rare in real ETL-migrating codebases.

Gap

There is no end-to-end integration test that lints the rewritten output with real ESLint to confirm messages actually get suppressed. Low risk (ESLint's native directives are well-tested), but a real gap in the test pyramid. Happy to add if requested.

Tests

30 vitest tests covering:

  • Simple and block forms, with/without rules
  • Enable path (with rule, bare)
  • Multiple rules, whitespace variants, tab/multi-space, CRLF
  • Single- and double-quoted rule names; mismatched quotes left alone
  • No-space mustache open ({{!template-lint-disable...}}) normalized to {{! ... }}
  • -tree and configure[-tree] skip + warn (one test per code path)
  • Unknown rule: rewritten with warning
  • Malformed rule list (trailing prose): unchanged + warn
  • Trailing comma: stripped
  • template-lint-disable-next-line (not an ETL directive): left alone
  • Nested: mustache directive inside a BLOCK body is not rewritten
  • Context preservation: indentation, mixed forms, multiple same-line directives
  • Warnings carry original-source line numbers even after a preceding BLOCK rewrite collapses lines

All pass.

Smoke-tested on a real file

Dry-run on punch-card.gts in a migrating consumer project cleanly rewrote two {{! template-lint-disable no-nested-interactive }} comments to their ESLint equivalents, zero warnings.

Open questions for review

  1. Distribution. Currently sits in scripts/ as a prototype. Options: (a) keep in scripts/ and document the path in README, (b) add a bin/ entry to package.json so it runs as npx eslint-plugin-ember migrate-template-lint-directives, (c) a separate codemod package.
  2. E2E test. Should the codemod ship with an integration test that runs ESLint on a rewritten file and asserts messages are suppressed? Higher confidence, more setup.
  3. -tree expansion. MVP skips with a warning. AST-based expansion (parse template with @glimmer/syntax, synthesize eslint-enable at parent element close) is possible but feels like a bad trade for rare cases.

Checklist

  • 30 tests pass (pnpm vitest run tests/scripts/)
  • README updated under "Migrating from ember-template-lint"
  • Real-file smoke test on a migrating consumer codebase

Test plan

  • Reviewer: run pnpm vitest run tests/scripts/ locally and confirm green
  • Reviewer: point the CLI at a .gts file with ETL comments in dry-run, then apply, then lint — confirm the resulting {{! eslint-disable ember/template-... }} comments are honoured

johanrd added 5 commits April 14, 2026 01:22
…ecommended

Adds `eslint-plugin-ember/configs/recommended-template` — an opt-in flat
config that enables the same ~94 template rules as ember-template-lint's
recommended preset, making it easy to drop ember-template-lint and keep
equivalent coverage.

The config is intentionally not part of the main `recommended` export.
Template linting is a separate concern and many projects will want to
adopt it incrementally or tune individual rules (e.g. no-bare-strings
allowlists, no-inline-styles) before committing to the full set.

Unlike ember-template-lint's recommended.js, this config carries no
gjs/gts overrides. The original ETL overrides existed because template-
lint has no JS scope tracker and couldn't distinguish `{{foo}}` (a JS
binding) from `{{foo}}` (an implicit-this lookup). The ported rules in
this plugin walk ESLint's scope chain directly, so no-implicit-this and
no-curly-component-invocation already skip JS-scoped identifiers, and
no-builtin-form-components / no-unknown-arguments-for-builtin-components
explicitly check for imports in gjs/gts files. The overrides would only
suppress correct behaviour.
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 19, 2026

🏎️ Benchmark Comparison

Benchmark Control (p50) Experiment (p50) Δ
🟢 js small 14.04 ms 13.39 ms -4.7%
🟢 js medium 6.77 ms 6.51 ms -3.9%
🟢 js large 2.65 ms 2.59 ms -2.3%
gjs small 1.10 ms 1.10 ms -0.4%
gjs medium 551.08 µs 550.61 µs -0.1%
gjs large 218.08 µs 218.14 µs +0.0%
gts small 1.10 ms 1.10 ms +0.4%
gts medium 553.39 µs 553.47 µs +0.0%
gts large 218.98 µs 217.20 µs -0.8%

🟢 faster · 🔴 slower · 🟠 slightly slower · ⚪ within 2%

Full mitata output
clk: ~2.13 GHz
cpu: AMD EPYC 9V74 80-Core Processor
runtime: node 24.14.1 (x64-linux)

benchmark                   avg (min … max) p75 / p99    (min … top 1%)
------------------------------------------- -------------------------------
js small (control)            16.41 ms/iter  17.96 ms █                    
                      (11.29 ms … 29.87 ms)  29.56 ms █ █ ▃         ▃      
                    (  4.15 mb …  10.13 mb)   7.20 mb ███▆█▆▁▆▄▄▁▁▁▁█▁▄▁▁▄▄

js small (experiment)         14.02 ms/iter  14.41 ms    █ ▂               
                      (11.84 ms … 20.62 ms)  17.59 ms  ▅ █ █  ▅▂       ▂   
                    (  6.16 mb …   7.85 mb)   6.83 mb ▇█▄█▄█▇▇██▁▄▇▁▄▁▇█▁▁▄

                             ┌                                            ┐
                             ╷  ┌─────────┬──┐                            ╷
          js small (control) ├──┤         │  ├────────────────────────────┤
                             ╵  └─────────┴──┘                            ╵
                              ╷  ┌──┬┐       ╷
       js small (experiment)  ├──┤  │├───────┤
                              ╵  └──┴┘       ╵
                             └                                            ┘
                             11.29 ms           20.43 ms           29.56 ms

summary
  js small (experiment)
   1.17x faster than js small (control)

------------------------------------------- -------------------------------
js medium (control)            7.47 ms/iter   7.76 ms ▃█                   
                       (6.11 ms … 15.61 ms)  14.44 ms ███                  
                    (  2.71 mb …   4.64 mb)   3.54 mb ███▄▇█▂▄▁▄▃▁▁▁▁▁▂▁▂▁▂

js medium (experiment)         7.19 ms/iter   7.48 ms  █                   
                       (5.96 ms … 12.89 ms)  12.46 ms  █                   
                    (  3.27 mb …   3.96 mb)   3.54 mb ▆██▆▄▄▂▄▃▂▁▂▁▁▂▂▁▂▁▂▂

                             ┌                                            ┐
                              ╷┌─────┬─┐                                  ╷
         js medium (control)  ├┤     │ ├──────────────────────────────────┤
                              ╵└─────┴─┘                                  ╵
                             ╷ ┌────┬┐                          ╷
      js medium (experiment) ├─┤    │├──────────────────────────┤
                             ╵ └────┴┘                          ╵
                             └                                            ┘
                             5.96 ms           10.20 ms            14.44 ms

summary
  js medium (experiment)
   1.04x faster than js medium (control)

------------------------------------------- -------------------------------
js large (control)             3.08 ms/iter   3.05 ms ▃█▃                  
                       (2.21 ms … 11.56 ms)   8.19 ms ███                  
                    (319.84 kb …   3.62 mb)   1.45 mb ███▄▆▄▂▂▁▁▂▂▃▁▂▁▁▁▁▁▁

js large (experiment)          2.83 ms/iter   2.73 ms  █                   
                        (2.37 ms … 8.00 ms)   6.29 ms ▇█                   
                    (636.07 kb …   2.24 mb)   1.43 mb ██▇▂▂▂▃▂▁▂▁▂▁▁▁▁▁▁▁▁▁

                             ┌                                            ┐
                             ╷┌─────┬                                     ╷
          js large (control) ├┤     │─────────────────────────────────────┤
                             ╵└─────┴                                     ╵
                              ╷┌──┬                         ╷
       js large (experiment)  ├┤  │─────────────────────────┤
                              ╵└──┴                         ╵
                             └                                            ┘
                             2.21 ms            5.20 ms             8.19 ms

summary
  js large (experiment)
   1.09x faster than js large (control)

------------------------------------------- -------------------------------
gjs small (control)            1.23 ms/iter   1.13 ms █                    
                        (1.08 ms … 5.98 ms)   5.35 ms █                    
                    (360.05 kb …   1.63 mb)   1.06 mb █▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁

gjs small (experiment)         1.21 ms/iter   1.11 ms █                    
                        (1.07 ms … 6.12 ms)   5.13 ms █                    
                    (244.71 kb …   1.88 mb)   1.06 mb █▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁

                             ┌                                            ┐
                             ┌─┬                                          ╷
         gjs small (control) │ │──────────────────────────────────────────┤
                             └─┴                                          ╵
                             ┌┬                                         ╷
      gjs small (experiment) ││─────────────────────────────────────────┤
                             └┴                                         ╵
                             └                                            ┘
                             1.07 ms            3.21 ms             5.35 ms

summary
  gjs small (experiment)
   1.02x faster than gjs small (control)

------------------------------------------- -------------------------------
gjs medium (control)         600.58 µs/iter 558.38 µs █                    
                      (531.91 µs … 5.24 ms)   3.06 ms █                    
                    ( 72.55 kb …   1.63 mb) 542.44 kb █▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁

gjs medium (experiment)      596.32 µs/iter 558.21 µs █                    
                      (529.86 µs … 5.45 ms)   1.94 ms █                    
                    (504.53 kb …   1.08 mb) 541.91 kb █▃▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁

                             ┌                                            ┐
                             ┌┬                                           ╷
        gjs medium (control) ││───────────────────────────────────────────┤
                             └┴                                           ╵
                             ┌┬                       ╷
     gjs medium (experiment) ││───────────────────────┤
                             └┴                       ╵
                             └                                            ┘
                             529.86 µs           1.80 ms            3.06 ms

summary
  gjs medium (experiment)
   1.01x faster than gjs medium (control)

------------------------------------------- -------------------------------
gjs large (control)          239.05 µs/iter 225.32 µs  █                   
                      (211.61 µs … 4.65 ms) 296.14 µs  █▄                  
                    (130.89 kb … 993.57 kb) 217.33 kb ▂██▄▇▄▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁

gjs large (experiment)       240.04 µs/iter 225.28 µs  █                   
                      (211.71 µs … 4.95 ms) 299.96 µs  █▃                  
                    (170.17 kb … 952.92 kb) 216.82 kb ▃██▄▇▃▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁

                             ┌                                            ┐
                             ╷ ┌───────────┬                            ╷
         gjs large (control) ├─┤           │────────────────────────────┤
                             ╵ └───────────┴                            ╵
                             ╷ ┌───────────┬                              ╷
      gjs large (experiment) ├─┤           │──────────────────────────────┤
                             ╵ └───────────┴                              ╵
                             └                                            ┘
                             211.61 µs         255.78 µs          299.96 µs

summary
  gjs large (control)
   1x faster than gjs large (experiment)

------------------------------------------- -------------------------------
gts small (control)            1.19 ms/iter   1.11 ms █                    
                        (1.08 ms … 5.95 ms)   5.35 ms █                    
                    (222.25 kb …   1.69 mb)   1.06 mb █▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁

gts small (experiment)         1.19 ms/iter   1.11 ms █                    
                        (1.08 ms … 5.77 ms)   5.12 ms █                    
                    (511.08 kb …   1.63 mb)   1.05 mb █▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁

                             ┌                                            ┐
                             ┌┬                                           ╷
         gts small (control) ││───────────────────────────────────────────┤
                             └┴                                           ╵
                             ┌┬                                         ╷
      gts small (experiment) ││─────────────────────────────────────────┤
                             └┴                                         ╵
                             └                                            ┘
                             1.08 ms            3.21 ms             5.35 ms

summary
  gts small (experiment)
   1x faster than gts small (control)

------------------------------------------- -------------------------------
gts medium (control)         594.65 µs/iter 559.78 µs █                    
                      (535.72 µs … 5.11 ms)   1.31 ms ██                   
                    (127.80 kb …   1.25 mb) 540.94 kb ██▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁

gts medium (experiment)      596.58 µs/iter 559.53 µs █                    
                      (533.47 µs … 5.26 ms)   1.97 ms █                    
                    (  5.84 kb …   1.25 mb) 541.13 kb █▃▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁

                             ┌                                            ┐
                             ┌─┬                     ╷
        gts medium (control) │ │─────────────────────┤
                             └─┴                     ╵
                             ┌─┬                                          ╷
     gts medium (experiment) │ │──────────────────────────────────────────┤
                             └─┴                                          ╵
                             └                                            ┘
                             533.47 µs           1.25 ms            1.97 ms

summary
  gts medium (control)
   1x faster than gts medium (experiment)

------------------------------------------- -------------------------------
gts large (control)          239.17 µs/iter 224.79 µs  █                   
                      (211.26 µs … 4.62 ms) 421.34 µs ▇█                   
                    (173.29 kb … 693.23 kb) 216.90 kb ███▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁

gts large (experiment)       236.72 µs/iter 224.21 µs  █                   
                      (211.45 µs … 4.72 ms) 290.26 µs  █▄                  
                    (137.97 kb … 836.18 kb) 216.47 kb ▅██▃▆▅▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁

                             ┌                                            ┐
                             ╷┌────┬                                      ╷
         gts large (control) ├┤    │──────────────────────────────────────┤
                             ╵└────┴                                      ╵
                             ╷┌───┬           ╷
      gts large (experiment) ├┤   │───────────┤
                             ╵└───┴           ╵
                             └                                            ┘
                             211.26 µs         316.30 µs          421.34 µs

summary
  gts large (experiment)
   1.01x faster than gts large (control)

Adds a one-shot codemod that rewrites ember-template-lint comment
directives to ESLint-native equivalents, so projects migrating to
eslint-plugin-ember can keep their in-template suppression comments
working without reimplementing ETL's directive semantics as an ESLint
processor.

Scope is grounded in what ETL itself parses today
(lib/rules/_base.js:247-337):

  - Mustache comments only ({{! ... }} and {{!-- ... --}}); HTML
    comments are skipped because ETL does not honour directives in
    them either.
  - template-lint-disable / template-lint-enable rewrite to
    eslint-disable / eslint-enable with rules remapped from the bare
    ETL name (no-foo) to the plugin rule ID (ember/template-no-foo).
  - template-lint-disable-tree / -enable-tree and
    template-lint-configure[-tree] are left unchanged with a warning;
    they have no ESLint equivalent (tree scope / in-template rule
    config respectively).
  - Unknown rule names are still rewritten so they surface in lint
    output, with a warning.

Includes a CLI entry (dry-run by default, --write to apply) and 26
tests covering simple and block forms, multi-line block comments,
quoted and whitespace-separated rule lists, skip+warn paths, line
numbers in warnings, idempotency, and context preservation.

README gains a "Rewriting {{! template-lint-disable }} comments"
subsection under the ETL migration guide.
@johanrd johanrd force-pushed the feat/migrate-template-lint-directives-codemod branch from ce3b401 to 8d479a5 Compare April 19, 2026 11:45
…RLF)

Layer the rule-name validator: accept a token if the plugin already has a
rule with that name, or if it looks like kebab-case with a hyphen. The
previous hyphen-only check had a false negative for real single-word
rules — specifically `template-quotes` — which would have left user
comments like {{! template-lint-disable quotes }} untransformed. The
layered validator still rejects plain prose (`extra text`) because those
tokens are neither known plugin rules nor hyphenated.

Swap parseRules replace order: strip trailing commas before paired
quotes, so `'foo',` → `foo` instead of `'foo'`. Comment the rationale.

Strengthen the CRLF test to also pressure computeLine across CRLF
line endings, not just preservation.

Document the "continue after input error" CLI choice so a future reader
doesn't mistake it for a missing early-exit.
@johanrd johanrd force-pushed the feat/recommended-template-config branch 4 times, most recently from 37c416d to 7bc1404 Compare April 20, 2026 16:16
Drops the regex comment scanner in favor of
root.find('GlimmerMustacheCommentStatement') + path.replace(), now that
ember-estree 0.4.3 (NullVoxPopuli/ember-estree#31) keeps mustache comment
nodes in the template body with semantic types and a longForm boolean
that drives delimiter re-emission.

Script is now ESM (.mjs) since zmod and zmod-ember are ESM-only.
Test file uses import but keeps the .js extension — vitest handles it.

transform takes a filePath option and routes to { templateOnly: true }
for .hbs vs { filePath } for .gjs/.gts.

Known limitation: for HBS the parser exposes each comment twice (once
in ast.body, once in a parallel comments array). Worked around with
dedupe-by-node.start. Filing upstream.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant