Skip to content

Commit 90d3362

Browse files
committed
fix: 🐛 update ecosystem-02 eslint config
1 parent cbd78c5 commit 90d3362

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+647
-216
lines changed

challenges/ecosystem/02.md

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,32 +42,40 @@ Prettier is an opinionated code formatter. It enforces a consistent style by par
4242

4343
![Prettier format on save preview on VS Code](https://raw.githubusercontent.com/flexbox/react-native-workshop/main/challenges/ecosystem/format-on-save.png)
4444

45-
### Setup ESLint rules for React Native project
4645

47-
- [ ] Install ESLint as a dev dependency.
46+
### Setup ESLint in your expo project
4847

4948
```console
50-
npm install --dev eslint @typescript-eslint/eslint-plugin @typescript-eslint/parser
51-
# same as `yarn add --dev eslint @typescript-eslint/eslint-plugin @typescript-eslint/parser`
49+
npx expo lint
5250
```
5351

54-
- [ ] Run `npx expo lint` to create a `.eslintrc.js` file at the root of your project.
52+
You can lint your code manually by rerunning `npx expo lint` in your terminal.
53+
54+
- [ ] Setup ESLint in your project.
55+
- [ ] Run `npx expo lint` in your terminal.
5556

57+
### Prettier
58+
59+
For other packages managers
5660
```console
57-
npx expo lint
61+
npx expo install -- --save-dev prettier eslint-config-prettier eslint-plugin-prettier
5862
```
5963

60-
- [ ] Update your `.eslintrc.js` file to add the following rules:
64+
For yarn
65+
```console
66+
yarn add -D prettier eslint-config-prettier eslint-plugin-prettier
67+
```
68+
69+
- [ ] add the dependencies to your project.
70+
71+
- [ ] Update your `eslintrc.js` file to add the following rules:
6172

6273
```javascript
63-
// .eslintrc.js
6474
module.exports = {
65-
extends: ["expo", "react-native-wcandillon"],
66-
plugins: ["@tanstack/query"],
67-
requireConfigFile: false,
75+
extends: ["expo", "prettier"],
76+
plugins: ["prettier"],
6877
rules: {
69-
camelcase: "off",
70-
"import/no-anonymous-default-export": [1, { allowArray: true }],
78+
"prettier/prettier": "warn",
7179
},
7280
};
7381
```
@@ -118,6 +126,9 @@ We are making progress, but we are not done yet. We need to add rules for React
118126
```console
119127
npm install --dev prettier eslint-config-prettier eslint-plugin-prettier eslint-plugin-react eslint-plugin-react-native eslint-plugin-simple-import-sort
120128
```
129+
```console
130+
yarn add -D prettier eslint-config-prettier eslint-plugin-prettier eslint-plugin-react eslint-plugin-react-native eslint-plugin-simple-import-sort
131+
```
121132

122133
- [ ] Update your `.eslintrc.js` file to add the following rules:
123134

@@ -167,7 +178,9 @@ module.exports = {
167178
["^\\./(?=.*/)(?!/?$)", "^\\.(?!/?$)", "^\\./?$"],
168179
]
169180
}
170-
]
181+
],
182+
quotes: ["error", "double"], // enforce double quotes
183+
"react/no-unescaped-entities": "off", // Disable the rule
171184
}
172185
};
173186
```
@@ -188,7 +201,6 @@ module.exports = {
188201
}
189202
```
190203

191-
- [ ] Run `--fix` to automatically fix your errors.
192204
- [ ] if you encounter a difference between errors on your terminal and VSCode, reload VSCode with `⌘ + ⇧ + P` "Developer: Reload Window".
193205

194206
### Updating ESLint rules
@@ -205,7 +217,7 @@ In our case `cargo_capacity`, `cost_in_credits` are not using `camelCase` and we
205217
{
206218
"rules": {
207219
...
208-
"camelcase": "off", // disable camelcase rule
220+
camelcase: "off", // disable camelcase rule
209221
"@typescript-eslint/no-explicit-any": "warn" // detect usage of `any` type
210222
},
211223
}

hackathon/spacecraft/.eslintrc.js

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,52 @@
1-
// https://docs.expo.dev/guides/using-eslint/
21
module.exports = {
3-
extends: 'expo',
4-
};
2+
env: {
3+
node: true,
4+
},
5+
parser: "@typescript-eslint/parser", // Specifies the ESLint parser
6+
root: true, // make sure eslint picks up the config at the root of the directory
7+
extends: [
8+
"expo",
9+
"eslint:recommended", // ESLint rules
10+
"plugin:@typescript-eslint/recommended", // TypeScript rules
11+
"plugin:react/recommended", // React rules
12+
"plugin:react/jsx-runtime", // support for React 17 JSX
13+
"plugin:prettier/recommended", // Prettier recommended rules
14+
],
15+
plugins: ["react", "react-native", "simple-import-sort"], // add React and React Native plugins
16+
rules: {
17+
camelcase: "off", // disable camelcase rule
18+
"@typescript-eslint/no-explicit-any": "warn", // detect usage of `any` type
19+
"prettier/prettier": [
20+
// Prettier rules
21+
"warn",
22+
{
23+
usePrettierrc: true,
24+
},
25+
],
26+
"react-native/no-color-literals": 2, // enforce color literals are not used
27+
"react-native/no-unused-styles": 2, // detect unused StyleSheet rules
28+
"react-native/no-raw-text": 0, // detect raw text outside of Text component
29+
"react-native/sort-styles": 2, // enforce style definitions are sorted
30+
"@typescript-eslint/no-unused-vars": "warn", // detect unused variables
31+
"simple-import-sort/exports": "warn", // enforce sorting exports within module
32+
"simple-import-sort/imports": [
33+
"warn",
34+
{
35+
groups: [
36+
// Side effect imports.
37+
["^\\u0000"],
38+
// Packages `react` related packages come first.
39+
["^react", "^@?\\w"],
40+
// Environment variables
41+
["^(@env)(/.*|$)"],
42+
// Parent imports. Put `..` last.
43+
["^\\.\\.(?!/?$)", "^\\.\\./?$"],
44+
// Other relative imports. Put same-folder imports and `.` last.
45+
["^\\./(?=.*/)(?!/?$)", "^\\.(?!/?$)", "^\\./?$"],
46+
],
47+
},
48+
],
49+
quotes: ["error", "double"], // enforce double quotes
50+
"react/no-unescaped-entities": "off", // Disable the rule
51+
},
52+
};

hackathon/spacecraft/.prettierrc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
{
2+
"$schema": "http://json.schemastore.org/prettierrc",
23
"semi": true,
4+
"singleAttributePerLine": true,
5+
"trailingComma": "all",
6+
"tabWidth": 2,
37
"singleQuote": false
4-
}
8+
}

hackathon/spacecraft/App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
2-
import Constants from "expo-constants";
31
import React from "react";
42
import { NetworkProvider } from "react-native-offline";
53
import { Provider as PaperProvider } from "react-native-paper";
4+
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
5+
import Constants from "expo-constants";
66

77
import { AuthenticationProvider } from "~/context/Authentication";
88
import { useAppearanceTheme } from "~/hooks/useAppearanceTheme";

hackathon/spacecraft/package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,26 @@
8080
"@types/jest": "^29.5.4",
8181
"@types/react": "~18.2.79",
8282
"@types/react-dom": "~18.2.25",
83+
"@typescript-eslint/eslint-plugin": "^7.11.0",
84+
"@typescript-eslint/parser": "^7.11.0",
8385
"app-icon-badge": "^0.0.15",
8486
"babel-loader": "^9.1.3",
8587
"babel-plugin-module-resolver": "^5.0.0",
8688
"babel-plugin-root-import": "^6.6.0",
8789
"babel-plugin-transform-remove-console": "^6.9.4",
8890
"eslint": "^8.56.0",
8991
"eslint-config-expo": "^7.0.0",
92+
"eslint-config-prettier": "^9.1.0",
9093
"eslint-config-react-native-wcandillon": "^3.9.0",
9194
"eslint-import-resolver-babel-plugin-root-import": "^1.1.1",
9295
"eslint-plugin-import": "^2.29.1",
96+
"eslint-plugin-prettier": "^5.1.3",
97+
"eslint-plugin-react": "^7.34.2",
98+
"eslint-plugin-react-native": "^4.1.0",
99+
"eslint-plugin-simple-import-sort": "^12.1.0",
93100
"jest": "^29.6.4",
94101
"jest-expo": "~51.0.2",
102+
"prettier": "^3.2.5",
95103
"typescript": "~5.3.3"
96104
}
97105
}

hackathon/spacecraft/src/components/Button.stories.tsx

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,41 @@ export default {
77

88
export const _Button = () => (
99
<View style={{ flex: 1, justifyContent: "space-around", padding: 16 }}>
10-
<Button onPress={() => Alert.alert("Pressed!")} mode="contained">
10+
<Button
11+
onPress={() => Alert.alert("Pressed!")}
12+
mode="contained"
13+
>
1114
contained
1215
</Button>
13-
<Button onPress={() => Alert.alert("Pressed!")} mode="contained-tonal">
16+
<Button
17+
onPress={() => Alert.alert("Pressed!")}
18+
mode="contained-tonal"
19+
>
1420
contained-tonal
1521
</Button>
16-
<Button onPress={() => Alert.alert("Pressed!")} mode="elevated">
22+
<Button
23+
onPress={() => Alert.alert("Pressed!")}
24+
mode="elevated"
25+
>
1726
elevated
1827
</Button>
19-
<Button onPress={() => Alert.alert("Pressed!")} mode="outlined">
28+
<Button
29+
onPress={() => Alert.alert("Pressed!")}
30+
mode="outlined"
31+
>
2032
outlined
2133
</Button>
22-
<Button onPress={() => Alert.alert("Pressed!")} mode="text">
34+
<Button
35+
onPress={() => Alert.alert("Pressed!")}
36+
mode="text"
37+
>
2338
text
2439
</Button>
25-
<Button onPress={() => Alert.alert("Pressed!")} mode="text" icon="camera">
40+
<Button
41+
onPress={() => Alert.alert("Pressed!")}
42+
mode="text"
43+
icon="camera"
44+
>
2645
<ActivityIndicator />
2746
text
2847
</Button>
@@ -53,7 +72,10 @@ export const _Button = () => (
5372
export const _ButtonSizes = () => (
5473
<View style={{ flex: 1, justifyContent: "space-around", padding: 16 }}>
5574
<Button onPress={() => Alert.alert("Pressed!")}>small</Button>
56-
<Button onPress={() => Alert.alert("Pressed!")} compact={true}>
75+
<Button
76+
onPress={() => Alert.alert("Pressed!")}
77+
compact={true}
78+
>
5779
medium
5880
</Button>
5981
</View>

hackathon/spacecraft/src/components/ButtonSupport.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@ interface Props {
99
export const ButtonSupport = ({ mode = "contained" }: Props) => {
1010
const handleOpenGitHub = async () => {
1111
await WebBrowser.openBrowserAsync(
12-
"https://github.com/flexbox/react-native-bootcamp/issues"
12+
"https://github.com/flexbox/react-native-bootcamp/issues",
1313
);
1414
};
1515

1616
return (
17-
<Button onPress={handleOpenGitHub} mode={mode} style={{ marginBottom: 12 }}>
17+
<Button
18+
onPress={handleOpenGitHub}
19+
mode={mode}
20+
style={{ marginBottom: 12 }}
21+
>
1822
Give my opinion
1923
</Button>
2024
);

hackathon/spacecraft/src/components/Card.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { NavigationContainer } from "@react-navigation/native";
2-
32
import type { StarshipProps } from "api/types";
3+
44
import { StarshipCard } from "~/components/StarshipCard";
55

66
const shipFixture = {

hackathon/spacecraft/src/components/FromInput.test.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ import { FormInput } from "~/components/FromInput";
66
describe("FormInput", () => {
77
const mock = jest.fn();
88
it("renders correctly", () => {
9-
render(<FormInput label="your-car" value="tesla" onChangeText={mock} />);
9+
render(
10+
<FormInput
11+
label="your-car"
12+
value="tesla"
13+
onChangeText={mock}
14+
/>,
15+
);
1016
screen.getAllByText("your-car");
1117
fireEvent.changeText(screen.getAllByText("your-car")[0], "tesla");
1218
expect(mock).toHaveBeenCalled();

hackathon/spacecraft/src/components/Header.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { render, screen } from "@testing-library/react-native";
21
import React from "react";
2+
import { render, screen } from "@testing-library/react-native";
33

44
import { Header } from "./Header";
55

hackathon/spacecraft/src/components/Header.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { View, StyleSheet } from "react-native";
21
import React from "react";
2+
import { StyleSheet, View } from "react-native";
33
import { Text, useTheme } from "react-native-paper";
44
import Constants from "expo-constants";
55

@@ -24,10 +24,10 @@ export const Header = ({ title }: HeaderProps) => {
2424

2525
const styles = StyleSheet.create({
2626
container: {
27-
paddingTop: Constants.statusBarHeight,
2827
alignItems: "center",
29-
justifyContent: "center",
3028
height: 256,
29+
justifyContent: "center",
30+
paddingTop: Constants.statusBarHeight,
3131
},
3232
headerText: {
3333
fontWeight: "800",

hackathon/spacecraft/src/components/Image.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import React from "react";
22
// import type { ImageProps } from "expo-image";
33
import type { ImageProps } from "react-native";
44
import { Image as RNImage } from "react-native";
5-
import { Image as ExpoImage } from "expo-image";
65
import type { AnimatedProps } from "react-native-reanimated";
76
import Animated from "react-native-reanimated";
7+
import { Image as ExpoImage } from "expo-image";
88

99
const AnimatedImage = Animated.createAnimatedComponent(RNImage);
1010

hackathon/spacecraft/src/components/Offline.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from "react";
2-
import { StyleSheet, View, Text } from "react-native";
3-
import { ActivityIndicator } from "react-native-paper";
2+
import { StyleSheet, Text, View } from "react-native";
43
import { useIsConnected } from "react-native-offline";
4+
import { ActivityIndicator } from "react-native-paper";
55

66
export const Offline = () => {
77
const isConnected = useIsConnected();
@@ -20,16 +20,16 @@ export const Offline = () => {
2020

2121
const styles = StyleSheet.create({
2222
container: {
23-
padding: 20,
23+
alignItems: "center",
24+
backgroundColor: "#FEE2E2",
25+
borderRadius: 10,
26+
flexDirection: "row",
27+
justifyContent: "space-between",
2428
marginHorizontal: 20,
29+
padding: 20,
2530
position: "absolute",
2631
top: 55,
2732
width: "90%",
28-
borderRadius: 10,
29-
backgroundColor: "#FEE2E2",
30-
flexDirection: "row",
31-
justifyContent: "space-between",
32-
alignItems: "center",
3333
},
3434
message: {
3535
color: "#991B1B",

0 commit comments

Comments
 (0)