forked from zbycz/osmapp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheslint-local-rules.js
More file actions
53 lines (50 loc) · 1.59 KB
/
eslint-local-rules.js
File metadata and controls
53 lines (50 loc) · 1.59 KB
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
module.exports = {
'no-styled-missing-transient-props': {
meta: {
type: 'problem',
docs: {
description:
'Warns when a styled component has custom props but is missing shouldForwardProp.',
category: 'Possible Errors',
recommended: true,
url: '',
},
schema: [],
messages: {
missingShouldForwardProp:
"styled() has custom props, but is missing `shouldForwardProp`. Make sure that your props start with `$` and add `styled(..., { shouldForwardProp: (prop) => !prop.startsWith('$') })`.",
},
},
create(context) {
return {
CallExpression(callExpression) {
if (
callExpression.callee.type === 'Identifier' &&
callExpression.callee.name === 'styled'
) {
let hasCustomProps = false;
let hasShouldForwardProp = false;
const taggedTemplate = callExpression.parent;
if (
taggedTemplate.typeArguments &&
taggedTemplate.typeArguments.type ===
'TSTypeParameterInstantiation' &&
taggedTemplate.typeArguments.params.length > 0
) {
hasCustomProps = true;
}
if (callExpression.arguments.length > 1) {
hasShouldForwardProp = true;
}
if (hasCustomProps && !hasShouldForwardProp) {
context.report({
node: callExpression,
messageId: 'missingShouldForwardProp',
});
}
}
},
};
},
},
};