-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
eslint-local-rules.js
38 lines (36 loc) · 1.1 KB
/
eslint-local-rules.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
module.exports = {
'no-class-without-style': {
meta: {
type: 'problem',
docs: {
description: 'Enforce the use of style() function for class attributes',
category: 'Possible Errors',
recommended: false,
},
fixable: null,
schema: [], // no options
},
create: function (context) {
return {
JSXAttribute(node) {
if (node.name && node.name.name === 'class') {
const parentElement = node.parent;
const hasAppearanceKey = parentElement.attributes.some(
(attr) => attr.name && attr.name.name === 'appearanceKey'
);
if (hasAppearanceKey) {
return; // Skip reporting if appearanceKey is present, as it is most likely forwarded.
}
const value = context.getSourceCode().getText(node.value);
if (!value.includes('style(')) {
context.report({
node,
message: 'Class attributes must use the style() function.',
});
}
}
},
};
},
},
};