Skip to content

Extract rule: template-simple-unless#2619

Open
NullVoxPopuli wants to merge 1 commit intoember-cli:masterfrom
NullVoxPopuli:nvp/template-lint-extract-rule-template-simple-unless
Open

Extract rule: template-simple-unless#2619
NullVoxPopuli wants to merge 1 commit intoember-cli:masterfrom
NullVoxPopuli:nvp/template-lint-extract-rule-template-simple-unless

Conversation

@NullVoxPopuli
Copy link
Contributor

Split from #2371.

Copy link

@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-simple-unless

Compared against ember-template-lint simple-unless.js.

General Correctness

  1. Missing inline unless with helper detection (default maxHelpers=1): In the original ETL rule, inline {{unless}} mustache statements with a sub-expression first param are checked via _withHelper. In the ESLint port, the GlimmerMustacheStatement handler checks node.params?.[0]?.path, but this condition is only true when the first param is a sub-expression with its own .path. This appears correct for the intended use case -- good.

  2. Missing valid cases for inline unless in gjs tests: The gjs valid tests are missing several cases that the hbs tests include, such as {{unless foo bar}}, {{unless (eq foo bar) baz}}, {{unless (and isBad isAwful) "notBadAndAwful"}}, and the allowlist/maxHelpers combination tests. These should be added for completeness.

  3. Missing invalid cases for inline unless in gjs tests: Several inline {{unless}} invalid cases are only tested in hbs mode but not in gjs mode (e.g., {{unless (if (or true)) 'Please no'}} with default maxHelpers). Consider adding them.

  4. else unless detection using sourceCode.getText(): The isElseUnlessBlock function uses sourceCode.getText(node) and checks text.startsWith('{{else '). This is a reasonable approach for ESLint since there's no sourceForNode equivalent, but it's worth noting this may be fragile if the parser represents {{else unless}} blocks differently than expected. Worth verifying this works correctly with the actual parser output.

  5. Original ETL has autofix support: The original rule supports fix mode (converting unless to if (not ...) and swapping else blocks). The ESLint port does not implement fixable. This is noted for awareness -- it's fine to skip for an initial port, but the isFixable metadata in the ETL messages suggests this was an important feature.

  6. Message interpolation via withHelper messageId: The withHelper message template is '{{message}}', which works but is unusual. Typically ESLint rules use data for specific interpolation fields rather than passing the entire message string. Consider using separate messageIds for the different withHelper sub-cases (maxHelpers exceeded, allowlist violation, denylist violation).

Scope Analysis (gjs/gts)

This rule checks node.path.original === 'unless' and node.path.original === 'if'. These are Ember/Handlebars built-in control flow keywords. In gjs/gts, unless is not a JavaScript keyword and would be very unusual to shadow as a local variable. Similarly for if. No scope analysis needed -- these are structural/syntactic checks on Handlebars control flow constructs.


🤖 Automated review comparing with ember-template-lint source

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