eslint-plugin-lit-a11y
Advanced tools
Comparing version 3.0.0 to 4.0.0
# Change Log | ||
## 4.0.0 | ||
### Major Changes | ||
- 14e4270a: feat: new a11y rules | ||
## 3.0.0 | ||
@@ -4,0 +10,0 @@ |
@@ -19,2 +19,3 @@ # alt-text | ||
<div role="img"></div> | ||
<input type="image" /> | ||
`; | ||
@@ -29,2 +30,4 @@ ``` | ||
<input type="image" alt="" /> | ||
<img src="${src}" aria-hidden="true" /> | ||
@@ -31,0 +34,0 @@ |
@@ -24,4 +24,4 @@ /** | ||
'lit-a11y/accessible-emoji': 'off', | ||
'lit-a11y/accessible-name': 'error', | ||
'lit-a11y/alt-text': 'error', | ||
'lit-a11y/anchor-has-content': 'error', | ||
'lit-a11y/anchor-is-valid': 'error', | ||
@@ -35,5 +35,7 @@ 'lit-a11y/aria-activedescendant-has-tabindex': 'error', | ||
'lit-a11y/click-events-have-key-events': 'error', | ||
'lit-a11y/heading-has-content': 'error', | ||
'lit-a11y/definition-list': 'error', | ||
'lit-a11y/heading-hidden': 'error', | ||
'lit-a11y/iframe-title': 'error', | ||
'lit-a11y/img-redundant-alt': 'error', | ||
'lit-a11y/list': 'error', | ||
'lit-a11y/mouse-events-have-key-events': 'error', | ||
@@ -45,2 +47,3 @@ 'lit-a11y/no-access-key': 'error', | ||
'lit-a11y/no-redundant-role': 'error', | ||
'lit-a11y/obj-alt': 'error', | ||
'lit-a11y/role-has-required-aria-attrs': 'error', | ||
@@ -47,0 +50,0 @@ 'lit-a11y/role-supports-aria-attr': 'error', |
@@ -29,3 +29,3 @@ /** | ||
roleImgAttrs: "elements with role '{{role}}' must have an {{attrs}} attribute.", | ||
imgAttrs: '<img> elements must have an alt attribute.', | ||
imgAttrs: '{{role}} elements must have an alt attribute.', | ||
}, | ||
@@ -58,2 +58,17 @@ fixable: null, | ||
/** | ||
* Is the element an `<input type="image">` with no `alt` attribute? | ||
* @param {import('parse5-htmlparser2-tree-adapter').Element} element | ||
* @return {boolean} | ||
*/ | ||
function isUnlabeledInputImg(element) { | ||
return ( | ||
element.name === 'input' && | ||
element.attribs.type === 'image' && | ||
element.attribs.role !== 'presentation' && | ||
!isHiddenFromScreenReader(element) && | ||
!elementHasAttribute(element, 'alt') | ||
); | ||
} | ||
/** | ||
* Does the element an `img` role with no label? | ||
@@ -94,3 +109,9 @@ * @param {import('parse5-htmlparser2-tree-adapter').Element} element | ||
if (isUnlabeledAOMImg(element)) { | ||
context.report({ loc, messageId: 'imgAttrs' }); | ||
context.report({ loc, messageId: 'imgAttrs', data: { role: '<img>' } }); | ||
} else if (isUnlabeledInputImg(element)) { | ||
context.report({ | ||
loc, | ||
messageId: 'imgAttrs', | ||
data: { role: '<input type="image">' }, | ||
}); | ||
} else if (isUnlabeledImgRole(element)) { | ||
@@ -97,0 +118,0 @@ context.report({ |
{ | ||
"name": "eslint-plugin-lit-a11y", | ||
"version": "3.0.0", | ||
"version": "4.0.0", | ||
"description": "linting plugin for lit-a11y", | ||
@@ -18,3 +18,3 @@ "license": "ISC", | ||
"test:node": "mocha tests --recursive", | ||
"test:single": "mocha tests/lib/rules/role-has-required-aria-attrs.js --watch" | ||
"test:single": "mocha tests/lib/rules/obj-alt.js --watch" | ||
}, | ||
@@ -21,0 +21,0 @@ "keywords": [ |
@@ -83,26 +83,26 @@ # Linting >> EsLint Plugin Lit A11y >> Overview || -5 | ||
- [lit-a11y/accessible-emoji](https://github.com/open-wc/open-wc/blob/57ddb3ccfff6b00468d3a7ebabbc15cfe966f7a9/docs/docs/linting/eslint-plugin-lit-a11y/rules/accessible-emoji.md) | ||
- [lit-a11y/alt-text](https://github.com/open-wc/open-wc/blob/57ddb3ccfff6b00468d3a7ebabbc15cfe966f7a9/docs/docs/linting/eslint-plugin-lit-a11y/rules/alt-text.md) | ||
- [lit-a11y/anchor-has-content](https://github.com/open-wc/open-wc/blob/57ddb3ccfff6b00468d3a7ebabbc15cfe966f7a9/docs/docs/linting/eslint-plugin-lit-a11y/rules/anchor-has-content.md) | ||
- [lit-a11y/anchor-is-valid](https://github.com/open-wc/open-wc/blob/57ddb3ccfff6b00468d3a7ebabbc15cfe966f7a9/docs/docs/linting/eslint-plugin-lit-a11y/rules/anchor-is-valid.md) | ||
- [lit-a11y/aria-activedescendant-has-tabindex](https://github.com/open-wc/open-wc/blob/57ddb3ccfff6b00468d3a7ebabbc15cfe966f7a9/docs/docs/linting/eslint-plugin-lit-a11y/rules/aria-activedescendant-has-tabindex.md) | ||
- [lit-a11y/aria-attr-valid-value](https://github.com/open-wc/open-wc/blob/57ddb3ccfff6b00468d3a7ebabbc15cfe966f7a9/docs/docs/linting/eslint-plugin-lit-a11y/rules/aria-attr-valid-value.md) | ||
- [lit-a11y/aria-attrs](https://github.com/open-wc/open-wc/blob/57ddb3ccfff6b00468d3a7ebabbc15cfe966f7a9/docs/docs/linting/eslint-plugin-lit-a11y/rules/aria-attrs.md) | ||
- [lit-a11y/aria-role](https://github.com/open-wc/open-wc/blob/57ddb3ccfff6b00468d3a7ebabbc15cfe966f7a9/docs/docs/linting/eslint-plugin-lit-a11y/rules/aria-role.md) | ||
- [lit-a11y/aria-unsupported-elements](https://github.com/open-wc/open-wc/blob/57ddb3ccfff6b00468d3a7ebabbc15cfe966f7a9/docs/docs/linting/eslint-plugin-lit-a11y/rules/aria-unsupported-elements.md) | ||
- [lit-a11y/autocomplete-valid](https://github.com/open-wc/open-wc/blob/57ddb3ccfff6b00468d3a7ebabbc15cfe966f7a9/docs/docs/linting/eslint-plugin-lit-a11y/rules/autocomplete-valid.md) | ||
- [lit-a11y/click-events-have-key-events](https://github.com/open-wc/open-wc/blob/57ddb3ccfff6b00468d3a7ebabbc15cfe966f7a9/docs/docs/linting/eslint-plugin-lit-a11y/rules/click-events-have-key-events.md) | ||
- [lit-a11y/heading-has-content](https://github.com/open-wc/open-wc/blob/57ddb3ccfff6b00468d3a7ebabbc15cfe966f7a9/docs/docs/linting/eslint-plugin-lit-a11y/rules/heading-has-content.md) | ||
- [lit-a11y/iframe-title](https://github.com/open-wc/open-wc/blob/57ddb3ccfff6b00468d3a7ebabbc15cfe966f7a9/docs/docs/linting/eslint-plugin-lit-a11y/rules/iframe-title.md) | ||
- [lit-a11y/img-redundant-alt](https://github.com/open-wc/open-wc/blob/57ddb3ccfff6b00468d3a7ebabbc15cfe966f7a9/docs/docs/linting/eslint-plugin-lit-a11y/rules/img-redundant-alt.md) | ||
- [lit-a11y/mouse-events-have-key-events](https://github.com/open-wc/open-wc/blob/57ddb3ccfff6b00468d3a7ebabbc15cfe966f7a9/docs/docs/linting/eslint-plugin-lit-a11y/rules/mouse-events-have-key-events.md) | ||
- [lit-a11y/no-access-key](https://github.com/open-wc/open-wc/blob/57ddb3ccfff6b00468d3a7ebabbc15cfe966f7a9/docs/docs/linting/eslint-plugin-lit-a11y/rules/no-access-key.md) | ||
- [lit-a11y/no-autofocus](https://github.com/open-wc/open-wc/blob/57ddb3ccfff6b00468d3a7ebabbc15cfe966f7a9/docs/docs/linting/eslint-plugin-lit-a11y/rules/no-autofocus.md) | ||
- [lit-a11y/no-distracting-elements](https://github.com/open-wc/open-wc/blob/57ddb3ccfff6b00468d3a7ebabbc15cfe966f7a9/docs/docs/linting/eslint-plugin-lit-a11y/rules/no-distracting-elements.md) | ||
- [lit-a11y/no-invalid-change-handler](https://github.com/open-wc/open-wc/blob/57ddb3ccfff6b00468d3a7ebabbc15cfe966f7a9/docs/docs/linting/eslint-plugin-lit-a11y/rules/no-invalid-change-handler.md) | ||
- [lit-a11y/no-redundant-role](https://github.com/open-wc/open-wc/blob/57ddb3ccfff6b00468d3a7ebabbc15cfe966f7a9/docs/docs/linting/eslint-plugin-lit-a11y/rules/no-redundant-role.md) | ||
- [lit-a11y/role-has-required-aria-attrs](https://github.com/open-wc/open-wc/blob/57ddb3ccfff6b00468d3a7ebabbc15cfe966f7a9/docs/docs/linting/eslint-plugin-lit-a11y/rules/role-has-required-aria-attrs.md) | ||
- [lit-a11y/role-supports-aria-attr](https://github.com/open-wc/open-wc/blob/57ddb3ccfff6b00468d3a7ebabbc15cfe966f7a9/docs/docs/linting/eslint-plugin-lit-a11y/rules/role-supports-aria-attr.md) | ||
- [lit-a11y/scope](https://github.com/open-wc/open-wc/blob/57ddb3ccfff6b00468d3a7ebabbc15cfe966f7a9/docs/docs/linting/eslint-plugin-lit-a11y/rules/scope.md) | ||
- [lit-a11y/tabindex-no-positive](https://github.com/open-wc/open-wc/blob/57ddb3ccfff6b00468d3a7ebabbc15cfe966f7a9/docs/docs/linting/eslint-plugin-lit-a11y/rules/tabindex-no-positive.md) | ||
- [lit-a11y/valid-lang](https://github.com/open-wc/open-wc/blob/57ddb3ccfff6b00468d3a7ebabbc15cfe966f7a9/docs/docs/linting/eslint-plugin-lit-a11y/rules/valid-lang.md) | ||
- [lit-a11y/accessible-emoji](https://github.com/open-wc/open-wc/blob/3dbda1e265c460defdaec5226bad45a3a9acf259/docs/docs/linting/eslint-plugin-lit-a11y/rules/accessible-emoji.md) | ||
- [lit-a11y/alt-text](https://github.com/open-wc/open-wc/blob/3dbda1e265c460defdaec5226bad45a3a9acf259/docs/docs/linting/eslint-plugin-lit-a11y/rules/alt-text.md) | ||
- [lit-a11y/anchor-has-content](https://github.com/open-wc/open-wc/blob/3dbda1e265c460defdaec5226bad45a3a9acf259/docs/docs/linting/eslint-plugin-lit-a11y/rules/anchor-has-content.md) | ||
- [lit-a11y/anchor-is-valid](https://github.com/open-wc/open-wc/blob/3dbda1e265c460defdaec5226bad45a3a9acf259/docs/docs/linting/eslint-plugin-lit-a11y/rules/anchor-is-valid.md) | ||
- [lit-a11y/aria-activedescendant-has-tabindex](https://github.com/open-wc/open-wc/blob/3dbda1e265c460defdaec5226bad45a3a9acf259/docs/docs/linting/eslint-plugin-lit-a11y/rules/aria-activedescendant-has-tabindex.md) | ||
- [lit-a11y/aria-attr-valid-value](https://github.com/open-wc/open-wc/blob/3dbda1e265c460defdaec5226bad45a3a9acf259/docs/docs/linting/eslint-plugin-lit-a11y/rules/aria-attr-valid-value.md) | ||
- [lit-a11y/aria-attrs](https://github.com/open-wc/open-wc/blob/3dbda1e265c460defdaec5226bad45a3a9acf259/docs/docs/linting/eslint-plugin-lit-a11y/rules/aria-attrs.md) | ||
- [lit-a11y/aria-role](https://github.com/open-wc/open-wc/blob/3dbda1e265c460defdaec5226bad45a3a9acf259/docs/docs/linting/eslint-plugin-lit-a11y/rules/aria-role.md) | ||
- [lit-a11y/aria-unsupported-elements](https://github.com/open-wc/open-wc/blob/3dbda1e265c460defdaec5226bad45a3a9acf259/docs/docs/linting/eslint-plugin-lit-a11y/rules/aria-unsupported-elements.md) | ||
- [lit-a11y/autocomplete-valid](https://github.com/open-wc/open-wc/blob/3dbda1e265c460defdaec5226bad45a3a9acf259/docs/docs/linting/eslint-plugin-lit-a11y/rules/autocomplete-valid.md) | ||
- [lit-a11y/click-events-have-key-events](https://github.com/open-wc/open-wc/blob/3dbda1e265c460defdaec5226bad45a3a9acf259/docs/docs/linting/eslint-plugin-lit-a11y/rules/click-events-have-key-events.md) | ||
- [lit-a11y/heading-has-content](https://github.com/open-wc/open-wc/blob/3dbda1e265c460defdaec5226bad45a3a9acf259/docs/docs/linting/eslint-plugin-lit-a11y/rules/heading-has-content.md) | ||
- [lit-a11y/iframe-title](https://github.com/open-wc/open-wc/blob/3dbda1e265c460defdaec5226bad45a3a9acf259/docs/docs/linting/eslint-plugin-lit-a11y/rules/iframe-title.md) | ||
- [lit-a11y/img-redundant-alt](https://github.com/open-wc/open-wc/blob/3dbda1e265c460defdaec5226bad45a3a9acf259/docs/docs/linting/eslint-plugin-lit-a11y/rules/img-redundant-alt.md) | ||
- [lit-a11y/mouse-events-have-key-events](https://github.com/open-wc/open-wc/blob/3dbda1e265c460defdaec5226bad45a3a9acf259/docs/docs/linting/eslint-plugin-lit-a11y/rules/mouse-events-have-key-events.md) | ||
- [lit-a11y/no-access-key](https://github.com/open-wc/open-wc/blob/3dbda1e265c460defdaec5226bad45a3a9acf259/docs/docs/linting/eslint-plugin-lit-a11y/rules/no-access-key.md) | ||
- [lit-a11y/no-autofocus](https://github.com/open-wc/open-wc/blob/3dbda1e265c460defdaec5226bad45a3a9acf259/docs/docs/linting/eslint-plugin-lit-a11y/rules/no-autofocus.md) | ||
- [lit-a11y/no-distracting-elements](https://github.com/open-wc/open-wc/blob/3dbda1e265c460defdaec5226bad45a3a9acf259/docs/docs/linting/eslint-plugin-lit-a11y/rules/no-distracting-elements.md) | ||
- [lit-a11y/no-invalid-change-handler](https://github.com/open-wc/open-wc/blob/3dbda1e265c460defdaec5226bad45a3a9acf259/docs/docs/linting/eslint-plugin-lit-a11y/rules/no-invalid-change-handler.md) | ||
- [lit-a11y/no-redundant-role](https://github.com/open-wc/open-wc/blob/3dbda1e265c460defdaec5226bad45a3a9acf259/docs/docs/linting/eslint-plugin-lit-a11y/rules/no-redundant-role.md) | ||
- [lit-a11y/role-has-required-aria-attrs](https://github.com/open-wc/open-wc/blob/3dbda1e265c460defdaec5226bad45a3a9acf259/docs/docs/linting/eslint-plugin-lit-a11y/rules/role-has-required-aria-attrs.md) | ||
- [lit-a11y/role-supports-aria-attr](https://github.com/open-wc/open-wc/blob/3dbda1e265c460defdaec5226bad45a3a9acf259/docs/docs/linting/eslint-plugin-lit-a11y/rules/role-supports-aria-attr.md) | ||
- [lit-a11y/scope](https://github.com/open-wc/open-wc/blob/3dbda1e265c460defdaec5226bad45a3a9acf259/docs/docs/linting/eslint-plugin-lit-a11y/rules/scope.md) | ||
- [lit-a11y/tabindex-no-positive](https://github.com/open-wc/open-wc/blob/3dbda1e265c460defdaec5226bad45a3a9acf259/docs/docs/linting/eslint-plugin-lit-a11y/rules/tabindex-no-positive.md) | ||
- [lit-a11y/valid-lang](https://github.com/open-wc/open-wc/blob/3dbda1e265c460defdaec5226bad45a3a9acf259/docs/docs/linting/eslint-plugin-lit-a11y/rules/valid-lang.md) |
@@ -29,2 +29,4 @@ /** | ||
valid: [ | ||
{ code: "html`<input type='image' alt=''/>`" }, | ||
{ code: "html`<input type='image' alt='hello'/>`" }, | ||
{ code: "html`<img alt=''/>`" }, | ||
@@ -42,2 +44,10 @@ { code: 'html`<img aria-hidden="true"/>`' }, | ||
{ | ||
code: "html`<input type='image'/>`", | ||
errors: [ | ||
{ | ||
messageId: 'imgAttrs', | ||
}, | ||
], | ||
}, | ||
{ | ||
code: "html`<img src='./myimg.png'/>`", | ||
@@ -44,0 +54,0 @@ errors: [ |
@@ -32,3 +32,3 @@ /** | ||
{ code: 'html`<span role="row"></span>`' }, | ||
{ code: 'html`<input type="checkbox" role="switch">`' }, | ||
{ code: 'html`<input type="checkbox" aria-checked="true" role="switch">`' }, | ||
{ code: 'html`<div role="combobox" aria-controls="foo" aria-expanded="foo"></div>`' }, | ||
@@ -49,11 +49,2 @@ { | ||
{ | ||
code: "html`<input role='switch' aria-checked='true'>`", | ||
errors: [ | ||
{ | ||
message: | ||
'The "switch" role on an input[type=checkbox] cannot use the attribute "aria-checked".', | ||
}, | ||
], | ||
}, | ||
{ | ||
code: "html`<div role='combobox'></div>`", | ||
@@ -60,0 +51,0 @@ errors: [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
272562
109
6238