Skip to content

Commit 8703840

Browse files
committed
refactor: use to axe-cre 3.4 SerialVirtualNode format
1 parent 3519c7b commit 8703840

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"aria-query": "^3.0.0",
6363
"array-includes": "^3.0.3",
6464
"ast-types-flow": "^0.0.7",
65-
"axe-core": "^3.3.0",
65+
"axe-core": "^3.4.0",
6666
"axobject-query": "^2.0.2",
6767
"damerau-levenshtein": "^1.0.4",
6868
"emoji-regex": "^7.0.2",

src/rules/autocomplete-valid.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,28 @@ module.exports = {
2828

2929
create: context => ({
3030
JSXOpeningElement: (node) => {
31-
// Determine if ignoreNonDOM is set to true
32-
// If true, then do not run rule.
3331
const options = context.options[0] || {};
3432
const ignoreNonDOM = !!options.ignoreNonDOM;
33+
34+
const autocomplete = getLiteralPropValue(getProp(node.attributes, 'autocomplete'));
3535
const elType = elementType(node);
36-
const isDOMNode = dom.get(elType);
37-
if (ignoreNonDOM && !isDOMNode) {
36+
const isNativeDOMNode = !!dom.get(elType);
37+
38+
if (typeof autocomplete !== 'string'
39+
|| (isNativeDOMNode && elType !== 'input')
40+
|| (!isNativeDOMNode && ignoreNonDOM)
41+
) {
3842
return;
3943
}
4044

41-
const attr = (attrName) => {
42-
const value = getLiteralPropValue(getProp(node.attributes, attrName));
43-
return (typeof value === 'string' ? value : null);
44-
};
45-
const props = {
46-
nodeName: isDOMNode ? elType : 'input',
47-
nodeType: 1,
48-
};
49-
const hasAttr = attrName => attr(attrName) !== null;
50-
51-
const { violations } = runVirtualRule('autocomplete-valid', { attr, props, hasAttr });
45+
const { violations } = runVirtualRule('autocomplete-valid', {
46+
nodeName: 'input',
47+
attributes: {
48+
autocomplete,
49+
// Which autocomplete is valid depends on the input type
50+
type: getLiteralPropValue(getProp(node.attributes, 'type')),
51+
},
52+
});
5253

5354
if (violations.length === 0) {
5455
return;

0 commit comments

Comments
 (0)