-
-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathaccessible-emoji.ts
46 lines (42 loc) · 1.12 KB
/
accessible-emoji.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
import type { Rule } from "eslint";
import emojiRegex from "emoji-regex";
import {
defineTemplateBodyVisitor,
getElementAttributeValue,
getElementType,
hasAriaLabel,
isAriaHidden,
makeDocsURL
} from "../utils";
const rule: Rule.RuleModule = {
meta: {
type: "problem",
docs: {
url: makeDocsURL("accessible-emoji")
},
deprecated: true,
messages: {
default: `Emojis should be wrapped in <span>, have role="img", and have an accessible description with aria-label or aria-labelledby.`
},
schema: []
},
create(context) {
return defineTemplateBodyVisitor(context, {
VText(node) {
if (node.value && emojiRegex().test(node.value)) {
const element = node.parent;
if (
element.type === "VElement" &&
!isAriaHidden(element) &&
(!hasAriaLabel(element) ||
getElementType(element) !== "span" ||
getElementAttributeValue(element, "role") !== "img")
) {
context.report({ node: node as any, messageId: "default" });
}
}
}
});
}
};
export default rule;