Skip to content

Commit 926e43b

Browse files
authored
Merge pull request #253 from flexbox/feat/perfectionnist
feat: 🎸 add perfectionnist to eslint config
2 parents fcf5e85 + c96c91e commit 926e43b

Some content is hidden

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

63 files changed

+1151
-458
lines changed

.markdownlint.jsonc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"MD013": false, // https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md
3+
"MD033": {
4+
"allowed_elements": ["img", "table"]
5+
}
6+
}

challenges/ecosystem/01.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Example:
5959
... paste an example result here
6060
```
6161

62-
Feel free to copy/paste some [React Native snippets from this list](https://davidl.fr/pattern).
62+
Feel free to copy/paste some [React Native snippets from this list](https://davidl.fr/snippets).
6363

6464
### React Native Snippets
6565

@@ -69,7 +69,7 @@ Feel free to copy/paste some [React Native snippets from this list](https://davi
6969
code --install-extension dsznajder.es7-react-js-snippets
7070
```
7171

72-
- [ ] On your new `cheatcodes.md` write down [React Native components shortcuts](https://github.com/dsznajder/vs code-es7-javascript-react-snippets#react-native-components) you prefer (_Are you a `const` or a `function` person?_)
72+
- [ ] On your new `cheatcodes.md` write down [React Native components shortcuts](https://github.com/r5n-dev/vscode-react-javascript-snippets/blob/master/docs/Snippets.md#react-native-components) you prefer (_Are you a `const` or a `function` person?_).
7373

7474
**🔭 Hint:** Using `ts` before `rn**` wil automatically add typescript definitions 🚀
7575

@@ -81,9 +81,9 @@ code --install-extension dsznajder.es7-react-js-snippets
8181
code --install-extension nathanchapman.javascriptsnippets
8282
```
8383

84-
- [ ] add 3 [JavaScripts Snippets](https://github.com/nathanchapman/vs code-javascript-snippets) to your `cheatcodes.md`.
84+
- [ ] add 3 [JavaScripts Snippets](https://github.com/nathanchapman/vscode-javascript-snippets) to your `cheatcodes.md`.
8585

86-
**🔭 Hint:** I use `map⇥` and `filter⇥` all the time.
86+
**🔭 Hint:** I use `fn⇥`, `map⇥` and `filter⇥` all the time.
8787

8888
### Turbo `console.log()`
8989

@@ -134,7 +134,7 @@ In your `settings.json`:
134134

135135
<img src="https://raw.githubusercontent.com/flexbox/react-native-bootcamp/main/challenges/ecosystem/autoDetectColorScheme.png" alt="VS Code theme for light and dark mode" />
136136

137-
I use the theme [Night Owl](https://github.com/sdras/night-owl-vs code-theme)
137+
I use the theme [Night Owl](https://github.com/sdras/night-owl-vscode-theme)
138138

139139
```console
140140
code --install-extension sdras.night-owl

challenges/ecosystem/02.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
- [ ] ❗ Commit your work if it's not already done.
1414
- [ ] Push your code to GitHub.
1515

16+
You are going to create a `.eslintrc.js` file, here is a [preview of the one used on the spacecraft codebase](https://raw.githubusercontent.com/flexbox/react-native-bootcamp/main/hackathon/spacecraft/.eslintrc.js). We will create more or less the same with small steps.
17+
1618
## 👨‍🚀 Exercise 2
1719

1820
### [ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) and [Prettier](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) extensions
@@ -42,7 +44,7 @@ Prettier is an opinionated code formatter. It enforces a consistent style by par
4244

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

45-
### Setup ESLint
47+
### Setup ESLint
4648

4749
- [ ] Setup ESLint in your project with the following command:
4850

@@ -177,7 +179,7 @@ module.exports = {
177179
"trailingComma": "all",
178180
"tabWidth": 2,
179181
"singleQuote": false,
180-
"endOfLine": "CRLF" // for windows users only
182+
"endOfLine": "crlf" // for windows users only
181183
}
182184
```
183185

@@ -273,10 +275,6 @@ In our case `cargo_capacity`, `cost_in_credits` are not using `camelCase` and we
273275

274276
## 👽 Bonus
275277

276-
### Avoid data layer issues
277-
278-
- [ ] Install [TanStack Query ESLint plugin](https://tanstack.com/query/latest/docs/eslint/eslint-plugin-query).
279-
280278
### Share your settings with your team
281279

282280
You can share your VSCode settings with your team by adding a `.vscode` folder at the root of your project with the following content.
@@ -296,3 +294,7 @@ This will make sure everyone in your team is using the same settings.
296294
- [ ] create a `.vscode` folder.
297295
- [ ] create a `settings.json` file.
298296
- [ ] Add the content above.
297+
298+
### Avoid data layer issues
299+
300+
- [ ] Install [TanStack Query ESLint plugin](https://tanstack.com/query/latest/docs/eslint/eslint-plugin-query).

challenges/ecosystem/05.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,10 @@ Now you can run `npm run test:watch` to watch your files and run tests automatic
216216
- https://reactnativetesting.io/
217217
- https://github.com/vanGalilea/react-native-testing?tab=readme-ov-file#covered-examples-
218218

219-
220219
### 👽 Bonus
221220

222-
- [ ] Check the [React Native Testing Library Cookbook](https://callstack.github.io/react-native-testing-library/cookbook/index) and add a new test to your component.
221+
- [ ] Check the [React Native Testing Library Cookbook](https://callstack.github.io/react-native-testing-library/cookbook/index) and add a new test to your component.
222+
223+
### Improve your ESLint setup
224+
225+
- [ ] Install [eslint-plugin-testing-library](https://callstack.github.io/react-native-testing-library/docs/start/quick-start#eslint-plugin)

challenges/foundation/04.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ We will use `JSON.stringify()` here to render a `string` version of the data.
7070
function App() {
7171
return (
7272
// <LoginScreen />
73-
<TermsScreen />
73+
<StarshipFeedScreen />
74+
// <TermsScreen />
7475
);
7576
};
7677
```

hackathon/spacecraft/.eslintrc.js

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,58 @@ module.exports = {
22
env: {
33
node: true,
44
},
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
75
extends: [
86
"expo",
97
"eslint:recommended", // ESLint rules
108
"plugin:@typescript-eslint/recommended", // TypeScript rules
119
"plugin:react/recommended", // React rules
12-
"plugin:react/jsx-runtime", // support for React 17 JSX
10+
"plugin:react/jsx-runtime", // Support for React 17 JSX
1311
"plugin:prettier/recommended", // Prettier recommended rules
12+
"plugin:perfectionist/recommended-natural-legacy",
13+
],
14+
overrides: [
15+
{
16+
// Test files only
17+
extends: ["plugin:testing-library/react"],
18+
files: ["**/__tests__/**/*.[jt]s?(x)", "**/?(*.)+(spec|test).[jt]s?(x)"],
19+
},
1420
],
15-
plugins: ["react", "react-native", "simple-import-sort"], // add React and React Native plugins
21+
parser: "@typescript-eslint/parser", // Specifies the ESLint parser
22+
plugins: [
23+
"react",
24+
"react-native",
25+
"perfectionist", // Keep only 'perfectionist'
26+
],
27+
root: true, // Make sure eslint picks up the config at the root of the directory
1628
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",
29+
"@typescript-eslint/no-explicit-any": "warn", // Detect usage of `any` type
30+
"@typescript-eslint/no-unused-vars": "warn", // Detect unused variables
31+
camelcase: "off", // Disable camelcase rule
32+
"perfectionist/sort-imports": "error", // Perfectionist import sorting https://perfectionist.dev/guide/introduction
33+
"perfectionist/sort-interfaces": ["error"], // Perfectionist interfaces sorting
34+
"perfectionist/sort-objects": [
35+
"error",
2236
{
23-
usePrettierrc: true,
37+
ignorePattern: ["useQuery*", "queries*", "useMutation*", "mutations*"],
38+
type: "natural",
2439
},
2540
],
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": [
41+
"prettier/prettier": [
3342
"warn",
3443
{
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-
],
44+
usePrettierrc: true,
4745
},
4846
],
47+
"react/no-unescaped-entities": "off",
48+
"react-native/no-color-literals": 2, // Enforce color literals are not used
49+
"react-native/no-raw-text": 0, // Detect raw text outside of Text component
50+
"react-native/no-unused-styles": 2, // Detect unused StyleSheet rules
51+
"react-native/sort-styles": 2, // Enforce style definitions are sorted
52+
},
53+
settings: {
54+
perfectionist: {
55+
partitionByComment: true,
56+
type: "line-length",
57+
},
4958
},
5059
};

hackathon/spacecraft/App.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import React from "react";
2-
import { Provider as PaperProvider } from "react-native-paper";
31
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
42
import Constants from "expo-constants";
3+
import { Provider as PaperProvider } from "react-native-paper";
54

65
import { AuthenticationProvider } from "~/context/Authentication";
76
import { NetworkProvider } from "~/context/Network";

hackathon/spacecraft/api/types.d.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export interface StarshipProps {
2-
MGLT?: string;
32
cargo_capacity?: string;
43
consumables?: string;
54
cost_in_credits?: string;
@@ -11,6 +10,7 @@ export interface StarshipProps {
1110
length?: string;
1211
manufacturer?: string;
1312
max_atmosphering_speed?: string;
13+
MGLT?: string;
1414
model: string;
1515
name: string;
1616
passengers?: string;
@@ -20,20 +20,20 @@ export interface StarshipProps {
2020
}
2121

2222
interface PeopleProps {
23-
name: string;
24-
height: string;
25-
mass: string;
26-
hair_color: string;
27-
skin_color: string;
28-
eye_color: string;
2923
birth_year: string;
24+
created: string;
25+
edited: string;
26+
eye_color: string;
27+
films: string[];
3028
gender: string;
29+
hair_color: string;
30+
height: string;
3131
homeworld: string;
32-
films: string[];
32+
mass: string;
33+
name: string;
34+
skin_color: string;
3335
species: string[];
34-
vehicles: string[];
3536
starships: string[];
36-
created: string;
37-
edited: string;
3837
url: string;
38+
vehicles: string[];
3939
}

hackathon/spacecraft/app.config.js

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,64 @@
11
module.exports = {
2-
name: "spacecraft",
3-
description: "Learning materials for the `react-native-bootcamp` repository.",
4-
slug: "spacecraft",
5-
owner: "weshipit",
6-
version: "1.0.2",
7-
orientation: "portrait",
8-
icon: "./assets/icon.png",
9-
splash: {
10-
image: "./assets/splash.png",
11-
resizeMode: "contain",
12-
backgroundColor: "#ffffff",
13-
},
14-
updates: {
15-
fallbackToCacheTimeout: 0,
16-
url: "https://u.expo.dev/012accc3-4ce5-4bae-9f4d-2f842489f07a",
17-
},
18-
assetBundlePatterns: ["**/*"],
19-
ios: {
20-
supportsTablet: true,
21-
bundleIdentifier: "weshipit.today.spacecraft",
22-
appStoreUrl:
23-
"https://apps.apple.com/fr/app/retail-shake-scanner/id1234567890",
24-
},
252
android: {
263
adaptiveIcon: {
27-
foregroundImage: "./assets/adaptive-icon.png",
284
backgroundColor: "#FFFFFF",
5+
foregroundImage: "./assets/adaptive-icon.png",
296
},
307
package: "weshipit.today.spacecraft",
318
playStoreUrl:
329
"https://play.google.com/store/apps/details?id=weshipit.today.spacecraft",
3310
},
34-
web: {
35-
favicon: "./assets/favicon.png",
36-
},
11+
assetBundlePatterns: ["**/*"],
12+
description: "Learning materials for the `react-native-bootcamp` repository.",
3713
extra: {
38-
storybookEnabled: process.env.STORYBOOK_ENABLED,
3914
eas: {
4015
projectId: "012accc3-4ce5-4bae-9f4d-2f842489f07a",
4116
},
17+
storybookEnabled: process.env.STORYBOOK_ENABLED,
18+
},
19+
icon: "./assets/icon.png",
20+
ios: {
21+
appStoreUrl:
22+
"https://apps.apple.com/fr/app/retail-shake-scanner/id1234567890",
23+
bundleIdentifier: "weshipit.today.spacecraft",
24+
supportsTablet: true,
4225
},
26+
name: "spacecraft",
27+
orientation: "portrait",
28+
owner: "weshipit",
4329
plugins: [
4430
[
4531
"app-icon-badge",
4632
{
4733
// enable/ disable the plugin based on the environment (usually disabled for production builds)
48-
enabled: process.env.ENVIRONMENT === "production" ? false : true,
4934
badges: [
5035
{
36+
background: "#FF0000", // by default it will be black and we are only supporting hex format for colors
37+
color: "white", // by default it will be white and the only color supported for now is white and black
5138
text: process.env.ENVIRONMENT || "unkown", // banner text
5239
type: "banner", // banner or ribbon
53-
color: "white", // by default it will be white and the only color supported for now is white and black
54-
background: "#FF0000", // by default it will be black and we are only supporting hex format for colors
5540
},
5641
{
5742
text: process.env.version,
5843
type: "ribbon",
5944
},
6045
],
46+
enabled: process.env.ENVIRONMENT === "production" ? false : true,
6147
},
6248
],
6349
],
50+
slug: "spacecraft",
51+
splash: {
52+
backgroundColor: "#ffffff",
53+
image: "./assets/splash.png",
54+
resizeMode: "contain",
55+
},
56+
updates: {
57+
fallbackToCacheTimeout: 0,
58+
url: "https://u.expo.dev/012accc3-4ce5-4bae-9f4d-2f842489f07a",
59+
},
60+
version: "1.0.2",
61+
web: {
62+
favicon: "./assets/favicon.png",
63+
},
6464
};

hackathon/spacecraft/babel.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module.exports = function (api) {
22
api.cache(true);
33
return {
4-
presets: ["babel-preset-expo"],
54
env: {
65
production: {
76
plugins: ["transform-remove-console", "react-native-paper/babel"],
@@ -10,5 +9,6 @@ module.exports = function (api) {
109
plugins: [
1110
"react-native-reanimated/plugin", // order matters
1211
],
12+
presets: ["babel-preset-expo"],
1313
};
1414
};

hackathon/spacecraft/metro.config.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// metro.config.js
2-
const path = require("path");
3-
4-
const { getDefaultConfig } = require("expo/metro-config");
52
const { generate } = require("@storybook/react-native/scripts/generate");
3+
const { getDefaultConfig } = require("expo/metro-config");
4+
const path = require("path");
65

76
generate({
87
configPath: path.resolve(__dirname, "./.storybook"),

0 commit comments

Comments
 (0)