Skip to content

Extract rule: template-no-unnecessary-component-helper#2584

Merged
NullVoxPopuli merged 2 commits intoember-cli:masterfrom
NullVoxPopuli:nvp/template-lint-extract-rule-template-no-unnecessary-component-helper
Mar 21, 2026
Merged

Extract rule: template-no-unnecessary-component-helper#2584
NullVoxPopuli merged 2 commits intoember-cli:masterfrom
NullVoxPopuli:nvp/template-lint-extract-rule-template-no-unnecessary-component-helper

Conversation

@NullVoxPopuli
Copy link
Copy Markdown
Contributor

Split from #2371.

Copy link
Copy Markdown

@NullVoxPopuli-ai-agent NullVoxPopuli-ai-agent left a comment

Choose a reason for hiding this comment

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

Review: template-no-unnecessary-component-helper (comparing with ember-template-lint no-unnecessary-component-helper)

Coverage

Good migration that covers the key behavior of the original rule.

What's done well

  • Correct detection logic: isComponentWithStringLiteral checks the same conditions as the original -- path.original === 'component', first param is a StringLiteral, and the string doesn't contain @ (addon-scoped names).
  • Attribute-safe namespace tracking: The inAttribute counter correctly mirrors the original's inSafeNamespace pattern (using AttrNode enter/exit), ensuring that {{component "name"}} inside attribute values is not flagged. This is a key behavior of the original.
  • Auto-fix for MustacheStatement and SubExpression: Fixes correctly reconstruct the invocation by stripping the component helper and using the component name directly.
  • No fix for BlockStatement: Correctly does not attempt to fix block invocations (matching the original's more complex block fix that may not translate cleanly).
  • Comprehensive tests: Good coverage of valid/invalid cases in both gjs and hbs modes.

Items needing attention

  1. SubExpression handling is an addition: The original only handles MustacheStatement and BlockStatement visitors. This PR adds GlimmerSubExpression handling. While this is arguably a useful extension, it goes beyond the original rule's scope. The original explicitly only visits AttrNode, BlockStatement, and MustacheStatement. In practice, a sub-expression like (component "foo") in a non-attribute context is unusual, so this may be fine, but it's worth flagging as a divergence.

  2. (component "my-component") in HBS valid tests: The HBS valid test includes '(component "my-component")' as valid. This is correct because in HBS mode, a bare sub-expression at the top level is unusual, but more importantly, the rule correctly exempts sub-expressions in attribute contexts. However, the gjs tests don't test this case explicitly.

  3. Error message difference: Original says "Invoke component directly instead of using \component` helper", while the PR says "Unnecessary use of (component) helper. Use the component name directly."`. The PR message is arguably clearer and more actionable.

Verdict

Solid migration. The SubExpression addition is a minor divergence worth documenting but is a reasonable enhancement. Test coverage is good.


🤖 Automated review comparing with ember-template-lint source

@NullVoxPopuli NullVoxPopuli force-pushed the nvp/template-lint-extract-rule-template-no-unnecessary-component-helper branch from 92470cb to d25c2d3 Compare March 21, 2026 03:33
@NullVoxPopuli NullVoxPopuli merged commit 707cf7b into ember-cli:master Mar 21, 2026
9 checks passed
@NullVoxPopuli NullVoxPopuli deleted the nvp/template-lint-extract-rule-template-no-unnecessary-component-helper branch March 21, 2026 03:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants