forked from ember-cli/eslint-plugin-ember
-
Notifications
You must be signed in to change notification settings - Fork 0
BUGFIX: template-no-empty-headings — recognize boolean aria-hidden #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
2529828
fix(template-no-empty-headings): recognize boolean aria-hidden as hidden
johanrd 4544f39
fix(template-no-empty-headings): treat aria-hidden values case-insens…
johanrd 872190f
test(template-no-empty-headings): pin falsy mustache aria-hidden cases
johanrd e713bdd
fix(template-no-empty-headings): align aria-hidden handling with WAI-…
johanrd f1a7b30
fix(template-no-empty-headings): lean toward fewer positives on value…
johanrd 16ca450
docs: document deliberate spec deviation on valueless aria-hidden
johanrd a02b3e9
fix(template-no-empty-headings): recognize quoted-mustache aria-hidden
johanrd 343869d
Update tests/lib/rules/template-no-empty-headings.js
johanrd 28373ea
Update docs/rules/template-no-empty-headings.md
johanrd fbf4c1b
Update lib/rules/template-no-empty-headings.js
johanrd 00a5c40
fix: normalize role/aria-hidden values — trim + lowercase (Copilot re…
johanrd 9dd106d
fix(#48): address round-2 Copilot review (doc + test polish)
johanrd ceaf0cf
fix(template-no-empty-headings): align aria-hidden with WAI-ARIA spec…
johanrd 7911cf5
docs(template-no-empty-headings): correct WAI-ARIA section reference
johanrd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| 'use strict'; | ||
|
|
||
| /** | ||
| * Return the statically-known string value of a Glimmer attribute value node, | ||
| * or `undefined` when the value is dynamic (cannot be resolved at lint time). | ||
| * | ||
| * Unwraps: | ||
| * - GlimmerTextNode → chars | ||
| * - GlimmerMustacheStatement with a literal path (boolean/string/number) → stringified value | ||
| * - GlimmerConcatStatement whose parts are all statically resolvable → joined string | ||
| * | ||
| * A missing/undefined value (valueless attribute, e.g. `<input disabled>`) | ||
| * returns the empty string. Pass `attr.value` — not the attribute itself. | ||
| */ | ||
| function getStaticAttrValue(value) { | ||
| if (value === null || value === undefined) { | ||
| return ''; | ||
| } | ||
| if (value.type === 'GlimmerTextNode') { | ||
| return value.chars; | ||
| } | ||
| if (value.type === 'GlimmerMustacheStatement') { | ||
| return extractLiteral(value.path); | ||
| } | ||
| if (value.type === 'GlimmerConcatStatement') { | ||
| const parts = value.parts || []; | ||
| let out = ''; | ||
| for (const part of parts) { | ||
| if (part.type === 'GlimmerTextNode') { | ||
| out += part.chars; | ||
| continue; | ||
| } | ||
| if (part.type === 'GlimmerMustacheStatement') { | ||
| const literal = extractLiteral(part.path); | ||
| if (literal === undefined) { | ||
| return undefined; | ||
| } | ||
| out += literal; | ||
| continue; | ||
| } | ||
| return undefined; | ||
| } | ||
| return out; | ||
| } | ||
| return undefined; | ||
| } | ||
|
|
||
| function extractLiteral(path) { | ||
| if (!path) { | ||
| return undefined; | ||
| } | ||
| if (path.type === 'GlimmerBooleanLiteral') { | ||
| return path.value ? 'true' : 'false'; | ||
| } | ||
| if (path.type === 'GlimmerStringLiteral') { | ||
| return path.value; | ||
| } | ||
| if (path.type === 'GlimmerNumberLiteral') { | ||
| return String(path.value); | ||
| } | ||
| return undefined; | ||
| } | ||
|
|
||
| module.exports = { getStaticAttrValue }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| 'use strict'; | ||
|
|
||
| const { getStaticAttrValue } = require('../../../lib/utils/static-attr-value'); | ||
|
|
||
| describe('getStaticAttrValue', () => { | ||
| it('returns empty string for null/undefined (valueless attribute)', () => { | ||
| expect(getStaticAttrValue(null)).toBe(''); | ||
| expect(getStaticAttrValue(undefined)).toBe(''); | ||
| }); | ||
|
|
||
| it('returns chars for GlimmerTextNode', () => { | ||
| expect(getStaticAttrValue({ type: 'GlimmerTextNode', chars: 'hello' })).toBe('hello'); | ||
| expect(getStaticAttrValue({ type: 'GlimmerTextNode', chars: '' })).toBe(''); | ||
| }); | ||
|
|
||
| it('unwraps GlimmerMustacheStatement with BooleanLiteral', () => { | ||
| expect( | ||
| getStaticAttrValue({ | ||
| type: 'GlimmerMustacheStatement', | ||
| path: { type: 'GlimmerBooleanLiteral', value: true }, | ||
| }) | ||
| ).toBe('true'); | ||
| expect( | ||
| getStaticAttrValue({ | ||
| type: 'GlimmerMustacheStatement', | ||
| path: { type: 'GlimmerBooleanLiteral', value: false }, | ||
| }) | ||
| ).toBe('false'); | ||
| }); | ||
|
|
||
| it('unwraps GlimmerMustacheStatement with StringLiteral', () => { | ||
| expect( | ||
| getStaticAttrValue({ | ||
| type: 'GlimmerMustacheStatement', | ||
| path: { type: 'GlimmerStringLiteral', value: 'foo' }, | ||
| }) | ||
| ).toBe('foo'); | ||
| expect( | ||
| getStaticAttrValue({ | ||
| type: 'GlimmerMustacheStatement', | ||
| path: { type: 'GlimmerStringLiteral', value: '' }, | ||
| }) | ||
| ).toBe(''); | ||
| }); | ||
|
|
||
| it('unwraps GlimmerMustacheStatement with NumberLiteral', () => { | ||
| expect( | ||
| getStaticAttrValue({ | ||
| type: 'GlimmerMustacheStatement', | ||
| path: { type: 'GlimmerNumberLiteral', value: -1 }, | ||
| }) | ||
| ).toBe('-1'); | ||
| expect( | ||
| getStaticAttrValue({ | ||
| type: 'GlimmerMustacheStatement', | ||
| path: { type: 'GlimmerNumberLiteral', value: 0 }, | ||
| }) | ||
| ).toBe('0'); | ||
| }); | ||
|
|
||
| it('returns undefined for GlimmerMustacheStatement with a dynamic PathExpression', () => { | ||
| expect( | ||
| getStaticAttrValue({ | ||
| type: 'GlimmerMustacheStatement', | ||
| path: { type: 'GlimmerPathExpression', original: 'this.foo' }, | ||
| }) | ||
| ).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('joins GlimmerConcatStatement with only static parts', () => { | ||
| expect( | ||
| getStaticAttrValue({ | ||
| type: 'GlimmerConcatStatement', | ||
| parts: [ | ||
| { type: 'GlimmerTextNode', chars: 'prefix-' }, | ||
| { | ||
| type: 'GlimmerMustacheStatement', | ||
| path: { type: 'GlimmerStringLiteral', value: 'mid' }, | ||
| }, | ||
| { type: 'GlimmerTextNode', chars: '-suffix' }, | ||
| ], | ||
| }) | ||
| ).toBe('prefix-mid-suffix'); | ||
| }); | ||
|
|
||
| it('joins concat with boolean and number literal parts', () => { | ||
| expect( | ||
| getStaticAttrValue({ | ||
| type: 'GlimmerConcatStatement', | ||
| parts: [ | ||
| { | ||
| type: 'GlimmerMustacheStatement', | ||
| path: { type: 'GlimmerBooleanLiteral', value: true }, | ||
| }, | ||
| ], | ||
| }) | ||
| ).toBe('true'); | ||
| expect( | ||
| getStaticAttrValue({ | ||
| type: 'GlimmerConcatStatement', | ||
| parts: [ | ||
| { | ||
| type: 'GlimmerMustacheStatement', | ||
| path: { type: 'GlimmerNumberLiteral', value: -1 }, | ||
| }, | ||
| ], | ||
| }) | ||
| ).toBe('-1'); | ||
| }); | ||
|
|
||
| it('returns undefined for GlimmerConcatStatement with a dynamic part', () => { | ||
| expect( | ||
| getStaticAttrValue({ | ||
| type: 'GlimmerConcatStatement', | ||
| parts: [ | ||
| { type: 'GlimmerTextNode', chars: 'x-' }, | ||
| { | ||
| type: 'GlimmerMustacheStatement', | ||
| path: { type: 'GlimmerPathExpression', original: 'this.foo' }, | ||
| }, | ||
| ], | ||
| }) | ||
| ).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('returns undefined for an unknown node type', () => { | ||
| expect(getStaticAttrValue({ type: 'GlimmerSubExpression' })).toBeUndefined(); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.