forked from vue-a11y/eslint-plugin-vuejs-accessibility
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathno-static-element-interactions.ts
52 lines (48 loc) · 1.18 KB
/
no-static-element-interactions.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { Rule } from "eslint";
import {
defineTemplateBodyVisitor,
getElementAttributeValue,
hasOnDirectives,
interactiveHandlers,
isCustomComponent,
isHiddenFromScreenReader,
isInteractiveElement,
isInteractiveRole,
isPresentationRole,
makeDocsURL
} from "../utils";
const rule: Rule.RuleModule = {
meta: {
type: "problem",
docs: {
url: makeDocsURL("no-static-element-interactions")
},
messages: {
default:
"Visible, non-interactive elements should not have an interactive handler."
},
schema: []
},
create(context: Rule.RuleContext): Rule.RuleListener {
return defineTemplateBodyVisitor(context, {
VElement(node) {
const role = getElementAttributeValue(node, "role");
if (
isCustomComponent(node) ||
isHiddenFromScreenReader(node) ||
isPresentationRole(node)
) {
return;
}
if (
hasOnDirectives(node, interactiveHandlers) &&
!isInteractiveElement(node) &&
!isInteractiveRole(role)
) {
context.report({ node: node as any, messageId: "default" });
}
}
});
}
};
export default rule;