Skip to content

Commit 83f4040

Browse files
committed
update
1 parent b60f85e commit 83f4040

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

packages/eslint-config/react-native.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,78 @@ import reactNative from "eslint-plugin-react-native";
33
import reanimated from "eslint-plugin-reanimated";
44
import reactRules from "magic-eslint-config/react";
55

6+
const restrictedImports = [
7+
{
8+
name: "react-native",
9+
importNames: [
10+
"TouchableOpacity",
11+
"TouchableHighlight",
12+
"TouchableNativeFeedback",
13+
],
14+
message:
15+
"Please do not import Touchables from react-native. Use `import { PressableArea } from @/components/PressableArea` instead.",
16+
},
17+
{
18+
name: "react-native",
19+
importNames: ["TouchableOpacityProps"],
20+
message:
21+
"Please do not import Touchables from react-native. Use `import { PressableAreaProps } from @/components/PressableArea` instead.",
22+
},
23+
{
24+
name: "react-native",
25+
importNames: ["Image"],
26+
message:
27+
"Please do not import Image from react-native. Use `import { Image } from @/components/Image` instead.",
28+
},
29+
{
30+
name: "react-native",
31+
importNames: ["ImageBackground"],
32+
message:
33+
"Please do not import ImageBackground from react-native. Use `import { ImageBackground } from @/components/ImageBackground` instead.",
34+
},
35+
{
36+
name: "react-native",
37+
importNames: ["TouchableWithoutFeedback"],
38+
message:
39+
"Please do not import TouchableWithoutFeedback. Use `import { Pressable } from react-native` instead.",
40+
},
41+
{
42+
name: "react-native-gesture-handler",
43+
importNames: [
44+
"TouchableWithoutFeedback",
45+
"TouchableOpacity",
46+
"TouchableHighlight",
47+
"TouchableNativeFeedback",
48+
],
49+
message:
50+
"Please do not import Touchables from react-native-gesture-handler. Use `import { PressableArea } from @/components/PressableArea` instead.",
51+
},
52+
{
53+
name: "react-native-gesture-handler",
54+
importNames: ["TouchableWithoutFeedback"],
55+
message:
56+
"Please do not import TouchableWithoutFeedback from react-native-gesture-handler. Use `import { Pressable } from react-native` instead.",
57+
},
58+
{
59+
name: "react-native-gesture-handler",
60+
message:
61+
"Please do not import ScrollView from react-native-gesture-handler. Import from react-native instead.",
62+
importNames: ["ScrollView", "FlatList", "SectionList"],
63+
},
64+
];
65+
66+
/** no-restricted-imports can't support different messages for the same package */
67+
const restrictedImportsRules = restrictedImports.map((restrictedImport) => {
68+
const importNames = restrictedImport.importNames.map((importName) => {
69+
return `ImportDeclaration[source.value='${restrictedImport.name}'] > ImportSpecifier[imported.name='${importName}']`;
70+
});
71+
72+
return {
73+
selector: importNames.join(", "),
74+
message: restrictedImport.message,
75+
};
76+
});
77+
678
/** @type {Awaited<import('typescript-eslint').Config>} */
779
export default [
880
...reactRules,
@@ -17,6 +89,13 @@ export default [
1789
"react-native/no-inline-styles": 1,
1890
"react-native/no-color-literals": 2,
1991
"react-native/no-single-element-style-arrays": 2,
92+
"no-restricted-syntax": [
93+
"error",
94+
"ForInStatement",
95+
"LabeledStatement",
96+
"WithStatement",
97+
...restrictedImportsRules,
98+
],
2099
},
21100
},
22101
];

0 commit comments

Comments
 (0)