-
Notifications
You must be signed in to change notification settings - Fork 591
Expand file tree
/
Copy patheslint-local-rules.js
More file actions
85 lines (84 loc) · 2.58 KB
/
eslint-local-rules.js
File metadata and controls
85 lines (84 loc) · 2.58 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
module.exports = {
"no-palette-icon-imports": {
meta: {
type: "problem",
docs: {
description: "Disallow importing Icon components from @artsy/palette-mobile",
},
messages: {
useIconsInstead:
"Do not import '{{name}}' from @artsy/palette-mobile. Import it from @artsy/icons/native instead.",
},
schema: [],
},
create(context) {
return {
ImportDeclaration(node) {
if (node.source.value === "@artsy/palette-mobile") {
for (const specifier of node.specifiers) {
if (
specifier.type === "ImportSpecifier" &&
specifier.imported.name.endsWith("Icon")
) {
context.report({
node: specifier,
messageId: "useIconsInstead",
data: { name: specifier.imported.name },
})
}
}
}
},
}
},
},
"no-onpress-in-routerlink": {
meta: {
type: "problem",
docs: {
description: "Disallow onPress prop on components wrapped with RouterLink",
},
messages: {
noOnPressInRouterLink:
"Do not use onPress prop on components wrapped with RouterLink. Pass `onPress` to `RouterLink` instead and use the 'to' prop for navigation.",
},
schema: [],
hasSuggestions: true,
},
create(context) {
return {
JSXElement(node) {
// Check if this is a RouterLink element
if (
node.openingElement.name.type === "JSXIdentifier" &&
node.openingElement.name.name === "RouterLink"
) {
// Find child elements that have onPress prop
const children = node.children || []
for (const child of children) {
if (child.type === "JSXElement") {
const onPressProp = child.openingElement.attributes.find(
(attr) => attr.type === "JSXAttribute" && attr.name.name === "onPress"
)
if (onPressProp) {
context.report({
node: onPressProp,
messageId: "noOnPressInRouterLink",
suggest: [
{
desc: "Remove the onPress prop",
fix: (fixer) => {
return fixer.remove(onPressProp)
},
},
],
})
}
}
}
}
},
}
},
},
}