-
Notifications
You must be signed in to change notification settings - Fork 592
Expand file tree
/
Copy patheslint-local-rules.js
More file actions
157 lines (148 loc) · 5.06 KB
/
Copy patheslint-local-rules.js
File metadata and controls
157 lines (148 loc) · 5.06 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
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)
},
},
],
})
}
}
}
}
},
}
},
},
"no-status-bar-style-in-navigation-options": {
meta: {
type: "problem",
docs: {
description:
"Disallow statusBarStyle in navigation options (screenOptions or options props)",
},
messages: {
noStatusBarStyleInNavigationOptions:
"Please do not use 'statusBarStyle' in navigation options. Using it will cause an crash in iOS with UIViewControllerBasedStatusBarAppearance, please use react-native StatusBar instead.",
},
schema: [],
},
create(context) {
const checkForStatusBarStyle = (objectExpression) => {
if (!objectExpression || objectExpression.type !== "ObjectExpression") {
return
}
for (const property of objectExpression.properties) {
if (
property.type === "Property" &&
property.key.type === "Identifier" &&
property.key.name === "statusBarStyle"
) {
context.report({
node: property,
messageId: "noStatusBarStyleInNavigationOptions",
})
}
}
}
return {
JSXElement(node) {
const elementName = node.openingElement.name
// Check for Stack.Navigator or StackNavigator.Navigator (screenOptions)
const isNavigator =
elementName.type === "JSXMemberExpression" &&
elementName.property.type === "JSXIdentifier" &&
elementName.property.name === "Navigator"
// Check for Stack.Screen or StackNavigator.Screen (options)
const isScreen =
elementName.type === "JSXMemberExpression" &&
elementName.property.type === "JSXIdentifier" &&
elementName.property.name === "Screen"
if (!isNavigator && !isScreen) {
return
}
// Find the relevant prop (screenOptions for Navigator, options for Screen)
const propName = isNavigator ? "screenOptions" : "options"
const targetProp = node.openingElement.attributes.find(
(attr) => attr.type === "JSXAttribute" && attr.name.name === propName
)
if (!targetProp || !targetProp.value) {
return
}
// Handle JSXExpressionContainer (e.g., screenOptions={{...}})
if (targetProp.value.type === "JSXExpressionContainer") {
const expression = targetProp.value.expression
checkForStatusBarStyle(expression, targetProp)
}
},
}
},
},
}