@dialpad/eslint-plugin-dialtone 1.12.0-next.2 → 1.12.0-next.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Warns when v-dt-focusgroup is used without an accessible label on the same element.
|
|
3
|
+
* @author Dialtone
|
|
4
|
+
*/
|
|
5
|
+
'use strict';
|
|
6
|
+
|
|
7
|
+
module.exports = {
|
|
8
|
+
meta: {
|
|
9
|
+
type: 'suggestion',
|
|
10
|
+
docs: {
|
|
11
|
+
description:
|
|
12
|
+
'Warns when v-dt-focusgroup is used on an element without aria-label or aria-labelledby. ' +
|
|
13
|
+
'Screen readers need an accessible name to identify the widget.',
|
|
14
|
+
recommended: false,
|
|
15
|
+
url: 'https://github.com/dialpad/dialtone/blob/staging/packages/eslint-plugin-dialtone/docs/rules/focusgroup-requires-label.md',
|
|
16
|
+
},
|
|
17
|
+
fixable: null,
|
|
18
|
+
schema: [],
|
|
19
|
+
messages: {
|
|
20
|
+
missingLabel:
|
|
21
|
+
'v-dt-focusgroup requires an accessible name via "aria-label" or "aria-labelledby" ' +
|
|
22
|
+
'so screen readers can identify the widget.',
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
create (context) {
|
|
27
|
+
const sourceCode = context.sourceCode ?? context.getSourceCode();
|
|
28
|
+
return sourceCode.parserServices.defineTemplateBodyVisitor({
|
|
29
|
+
VAttribute (node) {
|
|
30
|
+
if (!node.directive) return;
|
|
31
|
+
if (node.key.name.name !== 'dt-focusgroup') return;
|
|
32
|
+
|
|
33
|
+
const element = node.parent;
|
|
34
|
+
const hasLabel = element.attributes.some(
|
|
35
|
+
attr =>
|
|
36
|
+
(!attr.directive && (
|
|
37
|
+
attr.key.name === 'aria-label' ||
|
|
38
|
+
attr.key.name === 'aria-labelledby'
|
|
39
|
+
)) ||
|
|
40
|
+
(attr.directive && attr.key.name.name === 'bind' && (
|
|
41
|
+
attr.key.argument?.name === 'aria-label' ||
|
|
42
|
+
attr.key.argument?.name === 'aria-labelledby'
|
|
43
|
+
)),
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
if (!hasLabel) {
|
|
47
|
+
context.report({ node, messageId: 'missingLabel' });
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
},
|
|
52
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Warns when v-dt-focusgroup is used without a role attribute on the same element.
|
|
3
|
+
* @author Dialtone
|
|
4
|
+
*/
|
|
5
|
+
'use strict';
|
|
6
|
+
|
|
7
|
+
module.exports = {
|
|
8
|
+
meta: {
|
|
9
|
+
type: 'suggestion',
|
|
10
|
+
docs: {
|
|
11
|
+
description:
|
|
12
|
+
'Warns when v-dt-focusgroup is used on an element without a role attribute. ' +
|
|
13
|
+
'Screen readers need a role to announce the widget correctly.',
|
|
14
|
+
recommended: false,
|
|
15
|
+
url: 'https://github.com/dialpad/dialtone/blob/staging/packages/eslint-plugin-dialtone/docs/rules/focusgroup-requires-role.md',
|
|
16
|
+
},
|
|
17
|
+
fixable: null,
|
|
18
|
+
schema: [],
|
|
19
|
+
messages: {
|
|
20
|
+
missingRole:
|
|
21
|
+
'v-dt-focusgroup requires a "role" attribute (e.g. toolbar, tablist, listbox, radiogroup, menu) ' +
|
|
22
|
+
'so screen readers can announce the widget correctly.',
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
create (context) {
|
|
27
|
+
const sourceCode = context.sourceCode ?? context.getSourceCode();
|
|
28
|
+
return sourceCode.parserServices.defineTemplateBodyVisitor({
|
|
29
|
+
VAttribute (node) {
|
|
30
|
+
if (!node.directive) return;
|
|
31
|
+
if (node.key.name.name !== 'dt-focusgroup') return;
|
|
32
|
+
|
|
33
|
+
const element = node.parent;
|
|
34
|
+
const hasRole = element.attributes.some(
|
|
35
|
+
attr =>
|
|
36
|
+
(!attr.directive && attr.key.name === 'role') ||
|
|
37
|
+
(attr.directive && attr.key.name.name === 'bind' && attr.key.argument?.name === 'role'),
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
if (!hasRole) {
|
|
41
|
+
context.report({ node, messageId: 'missingRole' });
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
},
|
|
46
|
+
};
|