-
Notifications
You must be signed in to change notification settings - Fork 0
fix(template-no-invalid-aria-attributes): absorb allowundefined handling into validateByType #49
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,16 +11,22 @@ function isNumeric(value) { | |
| return !Number.isNaN(Number(value)); | ||
| } | ||
|
|
||
| function isValidAriaValue(attrName, value) { | ||
| const attrDef = aria.get(attrName); | ||
| if (!attrDef) { | ||
| return true; | ||
| } | ||
| // In aria-query 5.3.2, `allowundefined: true` is set only on the four | ||
| // boolean-like ARIA state attributes — `aria-expanded`, `aria-hidden`, | ||
| // `aria-grabbed`, `aria-selected` — whose WAI-ARIA 1.2 value tables list | ||
| // the literal string `"undefined"` as a spec-valid value meaning "state | ||
| // is not applicable" (e.g. https://www.w3.org/TR/wai-aria-1.2/#aria-expanded). | ||
| // The flag is nominally type-agnostic, but in practice this function only | ||
| // green-lights `"undefined"` for that boolean-like subset; no non-boolean | ||
| // ARIA attribute in aria-query currently sets `allowundefined`. | ||
| function allowsUndefinedLiteral(attrDef, value) { | ||
| return value === 'undefined' && Boolean(attrDef.allowundefined); | ||
| } | ||
|
|
||
| if (value === 'undefined') { | ||
| return Boolean(attrDef.allowundefined); | ||
| function validateByType(attrDef, value) { | ||
| if (allowsUndefinedLiteral(attrDef, value)) { | ||
| return true; | ||
| } | ||
|
|
||
| switch (attrDef.type) { | ||
| case 'boolean': { | ||
| return isBoolean(value); | ||
|
|
@@ -45,7 +51,9 @@ function isValidAriaValue(attrName, value) { | |
| return isNumeric(value) && !isBoolean(value); | ||
| } | ||
| case 'token': { | ||
| // aria-query stores boolean values as actual booleans, convert for comparison | ||
| // aria-query stores boolean values as actual booleans; stringify for comparison. | ||
| // The string literal 'undefined' that appears in some values arrays (e.g. | ||
| // aria-orientation) passes through this check naturally — no special-casing. | ||
| const permittedValues = attrDef.values.map((v) => | ||
| typeof v === 'boolean' ? v.toString() : v | ||
| ); | ||
|
|
@@ -60,6 +68,14 @@ function isValidAriaValue(attrName, value) { | |
| } | ||
| } | ||
|
|
||
| function isValidAriaValue(attrName, value) { | ||
| const attrDef = aria.get(attrName); | ||
| if (!attrDef) { | ||
| return true; | ||
| } | ||
| return validateByType(attrDef, value); | ||
| } | ||
|
Comment on lines
+71
to
+77
|
||
|
|
||
| function getExpectedTypeDescription(attrName) { | ||
| const attrDef = aria.get(attrName); | ||
| if (!attrDef) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new block comment ties behavior to an exact aria-query version (5.3.2), but
package.jsondepends onaria-query: ^5.3.2, so consumers may run newer versions whereallowundefinedcoverage changes. To avoid the comment becoming stale/misleading, consider rewording it to be version-agnostic (e.g., "currently in aria-query") or pinning the dependency if the version-specific assertion is important.