Skip to content

Commit 3aea217

Browse files
committed
chore: replace ignoreNonDOM with inputComponents
1 parent 1848d00 commit 3aea217

File tree

3 files changed

+12
-23
lines changed

3 files changed

+12
-23
lines changed

__tests__/src/rules/autocomplete-valid-test.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ const inappropriateAutocomplete = [{
2929
type: 'JSXOpeningElement',
3030
}];
3131

32-
const ignoreNonDOMSchema = [{
33-
ignoreNonDOM: true,
34-
}];
35-
3632
ruleTester.run('autocomplete-valid', rule, {
3733
valid: [
3834
// INAPPLICABLE
@@ -49,20 +45,20 @@ ruleTester.run('autocomplete-valid', rule, {
4945
{ code: '<input type="text" autocomplete={autocompl} />;' },
5046
{ code: '<input type="text" autocomplete={autocompl || "name"} />;' },
5147
{ code: '<input type="text" autocomplete={autocompl || "foo"} />;' },
52-
{ code: '<Foo autocomplete="bar"></Foo>;', options: ignoreNonDOMSchema },
48+
{ code: '<Foo autocomplete="bar"></Foo>;' },
5349
].map(parserOptionsMapper),
5450
invalid: [
5551
// FAILED "autocomplete-valid"
5652
{ code: '<input type="text" autocomplete="foo" />;', errors: invalidAutocomplete },
5753
{ code: '<input type="text" autocomplete="name invalid" />;', errors: invalidAutocomplete },
5854
{ code: '<input type="text" autocomplete="invalid name" />;', errors: invalidAutocomplete },
5955
{ code: '<input type="text" autocomplete="home url" />;', errors: invalidAutocomplete },
60-
{ code: '<Bar autocomplete="baz"></Bar>;', errors: invalidAutocomplete },
56+
{ code: '<Bar autocomplete="baz"></Bar>;', errors: invalidAutocomplete, options: [{ inputComponents: ['Bar'] }] },
6157

6258
// FAILED "autocomplete-appropriate"
6359
{ code: '<input type="date" autocomplete="email" />;', errors: inappropriateAutocomplete },
6460
{ code: '<input type="number" autocomplete="url" />;', errors: inappropriateAutocomplete },
6561
{ code: '<input type="month" autocomplete="tel" />;', errors: inappropriateAutocomplete },
66-
{ code: '<Foo type="month" autocomplete="tel"></Foo>;', errors: inappropriateAutocomplete },
62+
{ code: '<Foo type="month" autocomplete="tel"></Foo>;', errors: inappropriateAutocomplete, options: [{ inputComponents: ['Foo'] }] },
6763
].map(parserOptionsMapper),
6864
});

docs/rules/autocomplete-valid.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ This rule takes one optional object argument of type object:
1414
{
1515
"rules": {
1616
"jsx-a11y/autocomplete-valid": [ 2, {
17-
"ignoreNonDOM": true
17+
"inputComponents": ["Input", "FormField"]
1818
}],
1919
}
2020
}
@@ -25,7 +25,7 @@ This rule takes one optional object argument of type object:
2525
<!-- Good: the autocomplete attribute is used according to the HTML specification -->
2626
<input type="text" autocomplete="name" />
2727

28-
<!-- Good: ignoreNonDOM is set to true -->
28+
<!-- Good: MyInput is not listed in inputComponents -->
2929
<MyInput autocomplete="incorrect" />
3030
```
3131

@@ -37,6 +37,6 @@ This rule takes one optional object argument of type object:
3737
<!-- Bad: the autocomplete attribute is on an inappropriate input element -->
3838
<input type="email" autocomplete="url" />
3939

40-
<!-- Bad: ignoreNonDOM is undefined or set to false -->
40+
<!-- Bad: MyInput is listed in inputComponents -->
4141
<MyInput autocomplete="incorrect" />
4242
```

src/rules/autocomplete-valid.js

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,12 @@
66
// ----------------------------------------------------------------------------
77
// Rule Definition
88
// ----------------------------------------------------------------------------
9-
import { dom } from 'aria-query';
109
import { runVirtualRule } from 'axe-core';
1110
import { elementType, getLiteralPropValue, getProp } from 'jsx-ast-utils';
12-
import { generateObjSchema } from '../util/schemas';
11+
import { generateObjSchema, arraySchema } from '../util/schemas';
1312

1413
const schema = generateObjSchema({
15-
ignoreNonDOM: {
16-
type: 'boolean',
17-
default: false,
18-
},
14+
inputComponents: arraySchema,
1915
});
2016

2117
module.exports = {
@@ -29,16 +25,13 @@ module.exports = {
2925
create: context => ({
3026
JSXOpeningElement: (node) => {
3127
const options = context.options[0] || {};
32-
const ignoreNonDOM = !!options.ignoreNonDOM;
28+
const { inputComponents = [] } = options;
29+
const inputTypes = ['input', ...inputComponents];
3330

34-
const autocomplete = getLiteralPropValue(getProp(node.attributes, 'autocomplete'));
3531
const elType = elementType(node);
36-
const isNativeDOMNode = !!dom.get(elType);
32+
const autocomplete = getLiteralPropValue(getProp(node.attributes, 'autocomplete'));
3733

38-
if (typeof autocomplete !== 'string'
39-
|| (isNativeDOMNode && elType !== 'input')
40-
|| (!isNativeDOMNode && ignoreNonDOM)
41-
) {
34+
if (typeof autocomplete !== 'string' || !inputTypes.includes(elType)) {
4235
return;
4336
}
4437

0 commit comments

Comments
 (0)