Skip to content

Post-merge-review: Fix template-no-attrs-in-components: align detection with upstream#2688

Merged
NullVoxPopuli merged 7 commits intoember-cli:masterfrom
johanrd:day_fix/template-no-attrs-in-components
Apr 15, 2026
Merged

Post-merge-review: Fix template-no-attrs-in-components: align detection with upstream#2688
NullVoxPopuli merged 7 commits intoember-cli:masterfrom
johanrd:day_fix/template-no-attrs-in-components

Conversation

@johanrd
Copy link
Copy Markdown
Contributor

@johanrd johanrd commented Apr 13, 2026

Summary

  • Adds file-path gate: only runs in component template paths (matching upstream's heuristic)
  • Flags both attrs.* and this.attrs.* — both are pre-Octane args-leakage patterns from @ember/component
  • Adds templateMode: 'loose' and originallyFrom metadata

Test plan

  • {{attrs.foo}} in component template path → flagged
  • {{this.attrs.foo}} in component template path → flagged
  • {{attrs.foo}} in non-component template path → not flagged (path gate)
  • {{this.attrs.foo}} in non-component template path → not flagged (path gate)

johanrd added 3 commits April 13, 2026 14:44
The port flagged this.attrs.* (which is not a real Ember API) and ran
on all templates. Upstream gates on file path (templates/components/,
components/*/template, ui/components/, -components/) and flags bare
attrs.* — the pre-Octane args-leakage pattern. Restore upstream's
behavior.
@johanrd johanrd marked this pull request as ready for review April 13, 2026 17:20
@johanrd johanrd force-pushed the day_fix/template-no-attrs-in-components branch from 1577807 to 11afc7a Compare April 13, 2026 17:38
@johanrd johanrd changed the title Fix template-no-attrs-in-components: align detection with upstream Post-merge-review: Fix template-no-attrs-in-components: align detection with upstream Apr 13, 2026
},
// `this.attrs.*` is not a real Ember API, but it is NOT what this rule
// targets — only bare `attrs.*` is flagged. So outside of a component
// template, `this.attrs.*` should not be flagged.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should be flagged, unless there is another lint rule that would cover it.

This is from @ember/component components.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, should be fixed now. The PR was using original.startsWith('attrs.') which misses it. In the Glimmer AST, this.attrs.foo has parts[0] === 'attrs' (this is the receiver, not a part), so switching to parts[0] === 'attrs' catches both forms.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't see any tests with this.attrs -- did I miss them?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

johanrd added 2 commits April 14, 2026 20:48
In the Glimmer AST, `this.attrs.foo` has parts[0] === 'attrs' (this is
the receiver, not a part), so switching from original.startsWith('attrs.')
to parts[0] === 'attrs' matches upstream and correctly flags both bare
attrs.* and this.attrs.* — both are pre-Octane @ember/component patterns.
…roaden test coverage

Add /components/ to the path gate regex to catch Octane co-located
templates (app/components/foo.hbs) which the previous pattern missed
(cf. ember-template-lint#1445).

Add invalid test cases for attrs in attribute value, block helper, and
hash pair positions, and for the co-located path pattern.
@@ -1,5 +1,7 @@
# ember/template-no-attrs-in-components

> **HBS Only**: This rule applies to classic `.hbs` template files only (loose mode). It is not relevant for `gjs`/`gts` files (strict mode), where these patterns cannot occur.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not hbs only

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, fixed

…both'

  The rule applies in both HBS and GJS/GTS — classic @ember/component
  components can be authored in strict mode too, and their templates can
  still leak `this.attrs.*`. Regenerated docs to drop the incorrect
  "HBS Only" note.
@NullVoxPopuli NullVoxPopuli merged commit dcd8c51 into ember-cli:master Apr 15, 2026
10 checks passed
@github-actions github-actions bot mentioned this pull request Apr 15, 2026
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.

2 participants