Extract rule: template-no-redundant-fn#2567
Conversation
NullVoxPopuli-ai-agent
left a comment
There was a problem hiding this comment.
Review: template-no-redundant-fn
Compared against the original ember-template-lint rule no-redundant-fn.
What looks good
- Core detection logic faithfully matches the original: checks for
fnhelper with exactly 1 param and no hash pairs. - Covers both
GlimmerSubExpression(e.g.,(fn this.handleClick)) andGlimmerMustacheStatement(e.g.,{{fn this.handleClick}}), matching the original'sSubExpressionandMustacheStatementvisitors. - The error message includes a helpful suggestion showing the direct function reference.
- Test cases match the original's test suite exactly (same valid and invalid cases).
- Both
.gjsand.hbsparsers are tested. originallyFrommetadata is present.
Items worth attention
-
Original restricts to
PathExpressionparams only: The original rule checksparams[0].type !== 'PathExpression'and returns early if the single param is not a path expression. The ESLint implementation does not enforce this restriction. This means it would flag(fn "some-string")or(fn 42)which the original would not. In practice these are unlikely inputs, but it's a behavioral difference. TheparamTextfallback tocontext.sourceCode.getText(param)handles non-path params gracefully. -
Original has autofix support: The original rule supports
fixmode, replacing(fn this.action)withthis.action(for SubExpressions) and{{fn this.action}}with{{this.action}}(for MustacheStatements). The ESLint rule hasfixable: null. Given that the fix is straightforward, this could be a nice enhancement in a follow-up. -
Error message style difference: The original uses a terse message:
`fn` helpers without additional arguments are not allowed. The ESLint version is more verbose but more helpful:"Unnecessary use of (fn) helper. Pass the function directly instead: {{suggestion}}". This is an improvement.
Summary
This is a clean, faithful port. The test coverage matches the original well. The only meaningful behavioral difference is the missing PathExpression type check on params[0], which is very minor in practice. Nice work.
🤖 Automated review comparing with ember-template-lint source
When `fn` is imported from a local module in gjs/gts, it shadows Ember's built-in helper. Use scope analysis to detect this and avoid false positives. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
69f55fb to
9b7e226
Compare
Split from #2371.