-
-
Notifications
You must be signed in to change notification settings - Fork 636
/
Copy pathno-disabled.js
64 lines (56 loc) · 1.52 KB
/
no-disabled.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* @fileoverview Rule to flag 'disabled' prop
* @author Courtney Nguyen <@courtyenn>
*/
// ----------------------------------------------------------------------------
// Rule Definition
// ----------------------------------------------------------------------------
import { propName, elementType } from 'jsx-ast-utils';
import {
enumArraySchema,
generateObjSchema,
} from '../util/schemas';
const warningMessage = 'The disabled prop removes the element from being detected by screen readers.';
const DEFAULT_ELEMENTS = [
'button',
'command',
'fieldset',
'keygen',
'optgroup',
'option',
'select',
'textarea',
'input',
];
const schema = generateObjSchema({
disabable: enumArraySchema(DEFAULT_ELEMENTS)
.filter((name) => DEFAULT_ELEMENTS.includes(name)),
});
export default {
meta: {
type: 'suggestion',
docs: {
recommended: false,
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/no-disabled.md',
},
schema: [schema],
},
create: (context) => ({
JSXAttribute: (attribute) => {
const disabable = (
context.options && context.options[0] && context.options[0].disabable
) || DEFAULT_ELEMENTS;
// Only monitor eligible elements for "disabled".
const type = elementType(attribute.parent);
if (!disabable.includes(type)) {
return;
}
if (propName(attribute) === 'disabled') {
context.report({
node: attribute,
message: warningMessage,
});
}
},
}),
};