forked from vue-a11y/eslint-plugin-vuejs-accessibility
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathno-role-presentation-on-focusable.ts
35 lines (32 loc) · 1.1 KB
/
no-role-presentation-on-focusable.ts
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
import type { Rule } from "eslint";
// import type { AST } from "vue-eslint-parser";
import { defineTemplateBodyVisitor, getElementAttributeValue, makeDocsURL } from "../utils";
import hasFocusableElements from "../utils/hasFocusableElement";
const rule: Rule.RuleModule = {
meta: {
type: "problem",
docs: {
url: makeDocsURL("no-role-presentation-on-focusable")
},
messages: {
default: "Focusable/Interactive elements must not have a presentation role attribute."
},
schema: []
},
create(context) {
return defineTemplateBodyVisitor(context, {
VElement(node) {
const hasRolePresentation = getElementAttributeValue(node, 'role') === 'presentation';
if (hasRolePresentation) {
if (hasFocusableElements(node)) {
context.report({
node: node as any,
messageId: 'default',
});
}
}
},
});
}
}
export default rule;