-
-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathno-onchange.ts
38 lines (34 loc) · 896 Bytes
/
no-onchange.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
import type { Rule } from "eslint";
import {
defineTemplateBodyVisitor,
getElementType,
hasOnDirective,
makeDocsURL
} from "../utils";
const rule: Rule.RuleModule = {
meta: {
type: "problem",
deprecated: true,
docs: {
url: makeDocsURL("no-onchange")
},
messages: {
default:
"@blur must be used instead of @change, unless absolutely necessary and it causes no negative consequences for keyboard only or screen reader users."
},
schema: []
},
create(context) {
return defineTemplateBodyVisitor(context, {
VElement(node) {
if (!["select", "option"].includes(getElementType(node))) {
return;
}
if (hasOnDirective(node, "change") && !hasOnDirective(node, "blur")) {
context.report({ node: node as any, messageId: "default" });
}
}
});
}
};
export default rule;