-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
55 lines (53 loc) · 1.87 KB
/
index.js
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
53
54
55
module.exports = {
rules: {
"onclick-requires-data-client-id": {
meta: {
docs: {
description:
"Elements that have an onClick must also have a data-client-id, data-client-type, or clientId.",
},
messages: {
missingId:
"Elements that have an onClick must also have a data-client-id, data-client-type, or clientId.",
missingDatadog:
"Interactable elements need a data-dd-action-name to prevent logging private user data.",
},
},
create: function (context) {
return {
JSXOpeningElement: function (node) {
if (node.attributes.length > 0) {
const hasOnClick = node.attributes.some(
(attribute) =>
attribute &&
attribute.name &&
attribute.name.name === "onClick"
);
const hasDataClientId = node.attributes.some(
(attribute) =>
attribute &&
attribute.name &&
(attribute.name.name === "data-client-id" ||
attribute.name.name === "data-client-type" ||
attribute.name.name === "clientId") &&
attribute.value.value !== ""
);
const hasDataDogActionName = node.attributes.some(
(attribute) =>
attribute &&
attribute.name &&
attribute.name.name === "data-dd-action-name"
);
if (hasDataClientId && !hasDataDogActionName) {
context.report({ node, messageId: "missingDatadog" });
}
if (hasOnClick && !hasDataClientId) {
context.report({ node, messageId: "missingId" });
}
}
},
};
},
},
},
};