Skip to content

Commit

Permalink
refactor: use to axe-cre 3.4 SerialVirtualNode format
Browse files Browse the repository at this point in the history
  • Loading branch information
WilcoFiers committed Nov 6, 2019
1 parent 3519c7b commit 8703840
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"aria-query": "^3.0.0",
"array-includes": "^3.0.3",
"ast-types-flow": "^0.0.7",
"axe-core": "^3.3.0",
"axe-core": "^3.4.0",
"axobject-query": "^2.0.2",
"damerau-levenshtein": "^1.0.4",
"emoji-regex": "^7.0.2",
Expand Down
31 changes: 16 additions & 15 deletions src/rules/autocomplete-valid.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,28 @@ module.exports = {

create: context => ({
JSXOpeningElement: (node) => {
// Determine if ignoreNonDOM is set to true
// If true, then do not run rule.
const options = context.options[0] || {};
const ignoreNonDOM = !!options.ignoreNonDOM;

const autocomplete = getLiteralPropValue(getProp(node.attributes, 'autocomplete'));
const elType = elementType(node);
const isDOMNode = dom.get(elType);
if (ignoreNonDOM && !isDOMNode) {
const isNativeDOMNode = !!dom.get(elType);

if (typeof autocomplete !== 'string'
|| (isNativeDOMNode && elType !== 'input')
|| (!isNativeDOMNode && ignoreNonDOM)
) {
return;
}

const attr = (attrName) => {
const value = getLiteralPropValue(getProp(node.attributes, attrName));
return (typeof value === 'string' ? value : null);
};
const props = {
nodeName: isDOMNode ? elType : 'input',
nodeType: 1,
};
const hasAttr = attrName => attr(attrName) !== null;

const { violations } = runVirtualRule('autocomplete-valid', { attr, props, hasAttr });
const { violations } = runVirtualRule('autocomplete-valid', {
nodeName: 'input',
attributes: {
autocomplete,
// Which autocomplete is valid depends on the input type
type: getLiteralPropValue(getProp(node.attributes, 'type')),
},
});

if (violations.length === 0) {
return;
Expand Down

0 comments on commit 8703840

Please sign in to comment.