Skip to content

Extract rule: template-no-redundant-role#2569

Merged
NullVoxPopuli merged 3 commits intoember-cli:masterfrom
NullVoxPopuli:nvp/template-lint-extract-rule-template-no-redundant-role
Mar 21, 2026
Merged

Extract rule: template-no-redundant-role#2569
NullVoxPopuli merged 3 commits intoember-cli:masterfrom
NullVoxPopuli:nvp/template-lint-extract-rule-template-no-redundant-role

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-redundant-role

Compared with the original ember-template-lint no-redundant-role rule.

What looks good

  • Faithful port of the original rule's logic including the ROLE_TO_ELEMENTS mapping, ALLOWED_ELEMENT_ROLES exceptions, LANDMARK_ROLES set, and checkAllHTMLElements configuration option.
  • Error messages match the original's two-tier approach (landmark-specific message vs. generic message).
  • Autofix implementation correctly removes the role attribute with preceding whitespace.
  • Comprehensive test suite covering both GJS and HBS parsers.
  • Tests cover allowed exceptions (nav+navigation, form+search, input+combobox, ol/ul+list, a+link).
  • Good edge case coverage: dynamic roles, checkAllHTMLElements: false, multiple attributes on element.

Potential issues

  1. context.getSourceCode() is deprecated: The fix function uses context.getSourceCode() which is deprecated in ESLint v9+ in favor of context.sourceCode. Consider using context.sourceCode for forward compatibility (note: PR #2568 already uses context.sourceCode).

  2. Regex escaping in fix: The fix uses replaceAll(/[$()*+.?[\\\]^{|}]/g, '\\$&') to escape the attribute text for regex matching. This is clever but fragile -- if the attribute text contains special characters or the element has complex content, the regex approach could fail. A range-based approach (using fixer.removeRange) as done in PR #2568 would be more robust.

  3. Missing <a role="link"> in allowed list with context: The original allows <a role="link"> (it's in ALLOWED_ELEMENT_ROLES). The PR correctly includes this. However, the valid test '<a role="link" aria-disabled="true">valid</a>' only tests it with aria-disabled. Consider also testing <a role="link"> without additional attributes.

  4. <nav role="navigation"> in HBS valid tests has a typo: In the HBS tests, line '<nav class="navigation" role="navigation></nav>' is missing the closing " after navigation. This should be role="navigation". This would silently pass as valid because the parser may treat the broken attribute differently, masking a real test.

  5. Good parity with original: The test cases match the original ember-template-lint test file closely -- dialog, button, checkbox on input, columnheader on th, listbox on select are all covered.

  6. Schema matches original: The checkAllHTMLElements boolean option correctly mirrors the original rule's configuration.

Overlap note

This rule and PR #2568 (template-no-redundant-landmark-role) overlap significantly. This rule is the comprehensive version and should be the preferred one.

Overall, this is a thorough and well-structured port. The main action item is fixing the HBS test typo.

🤖 Automated review comparing with ember-template-lint source

NullVoxPopuli and others added 2 commits March 21, 2026 12:18
The test string '<nav class="navigation" role="navigation></nav>' was
missing the closing double-quote after "navigation", causing the role
value to not be properly parsed in the test.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@NullVoxPopuli NullVoxPopuli force-pushed the nvp/template-lint-extract-rule-template-no-redundant-role branch from 547e978 to ae24d4c Compare March 21, 2026 16:18
@NullVoxPopuli NullVoxPopuli merged commit 389c10b into ember-cli:master Mar 21, 2026
9 checks passed
@NullVoxPopuli NullVoxPopuli deleted the nvp/template-lint-extract-rule-template-no-redundant-role branch March 21, 2026 16:27
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