Skip to content

Commit 4b14364

Browse files
authored
Update 02.md
1 parent d997985 commit 4b14364

File tree

1 file changed

+67
-50
lines changed
  • challenges/ecosystem

1 file changed

+67
-50
lines changed

challenges/ecosystem/02.md

Lines changed: 67 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ npx expo lint
5555
- [ ] Answer **yes** to the following question:
5656

5757
```console
58-
✔ No ESLint config found. Install and configure ESLint in this project?
58+
✔ No ESLint config found. Install and configure ESLint in this project?
5959
```
6060

61-
You will have a `.eslintrc.js` file created at the root of your project.
61+
You will have a `eslint.config.js` file created at the root of your project.
6262

6363
### Run ESLint from the terminal
6464

@@ -69,7 +69,7 @@ You will have a `.eslintrc.js` file created at the root of your project.
6969

7070
"scripts": {
7171
...
72-
"lint": "eslint --ignore-path .gitignore --ext .js,.ts,.tsx .",
72+
"lint": "eslint --ignore-path .gitignore --ext .js,.ts,.tsx ."
7373
...
7474
}
7575
```
@@ -110,10 +110,11 @@ npm install --save-dev prettier eslint-config-prettier eslint-plugin-prettier
110110
yarn add --dev prettier eslint-config-prettier eslint-plugin-prettier
111111
```
112112

113-
- [ ] Update your `eslintrc.js` file to add the following rules:
113+
- [ ] Update your `eslint.config.js` file to add the following rules:
114114

115115
```javascript
116-
// https://docs.expo.dev/guides/using-eslint/
116+
// eslint.config.js
117+
117118
const { defineConfig } = require("eslint/config");
118119
const expoConfig = require("eslint-config-expo/flat");
119120
const prettier = require("eslint-plugin-prettier");
@@ -131,7 +132,6 @@ module.exports = defineConfig([
131132
},
132133
},
133134
]);
134-
135135
```
136136

137137
### ESLint and prettier rules for React Native
@@ -141,40 +141,45 @@ We are making progress, but we are not done yet. We need to add rules for React
141141
- [ ] Install the following plugins
142142

143143
```console
144-
npm install --dev prettier eslint-config-prettier eslint-plugin-prettier eslint-plugin-react
144+
npm install --save-dev eslint-plugin-react @typescript-eslint/parser
145145
# or
146-
yarn add --dev prettier eslint-config-prettier eslint-plugin-prettier eslint-plugin-react
146+
yarn add --dev eslint-plugin-react @typescript-eslint/parser
147147
```
148148

149-
- [ ] Update your `.eslintrc.js` file to add the following rules:
149+
- [ ] Update your `eslint.config.js` file to add the following rules:
150150

151151
```javascript
152-
// .eslintrc.js
152+
// eslint.config.js
153+
154+
const { defineConfig } = require("eslint/config");
155+
const expoConfig = require("eslint-config-expo/flat");
156+
const prettier = require("eslint-plugin-prettier");
157+
const prettierConfig = require("eslint-config-prettier");
158+
const reactPlugin = require("eslint-plugin-react");
159+
const typescriptParser = require("@typescript-eslint/parser");
153160

154-
module.exports = {
155-
env: {
156-
node: true
161+
module.exports = defineConfig([
162+
expoConfig,
163+
prettierConfig,
164+
{
165+
languageOptions: {
166+
parser: typescriptParser, // Specifies the ESLint parser
167+
},
168+
plugins: {
169+
prettier,
170+
react: reactPlugin, // add React plugin
171+
},
172+
rules: {
173+
"prettier/prettier": [ // Prettier rules
174+
"warn",
175+
{
176+
usePrettierrc: true,
177+
},
178+
],
179+
"@typescript-eslint/no-unused-vars": "warn", // detect unused variables
180+
},
157181
},
158-
parser: "@typescript-eslint/parser", // Specifies the ESLint parser
159-
root: true, // make sure eslint picks up the config at the root of the directory
160-
extends: [
161-
"eslint:recommended", // ESLint rules
162-
"plugin:@typescript-eslint/recommended", // TypeScript rules
163-
"plugin:react/recommended", // React rules
164-
"plugin:react/jsx-runtime", // support for React 17 JSX
165-
"plugin:prettier/recommended" // Prettier recommended rules
166-
],
167-
plugins: ["react"], // add React and React Native plugins
168-
rules: {
169-
"prettier/prettier": [ // Prettier rules
170-
"warn",
171-
{
172-
usePrettierrc: true
173-
}
174-
],
175-
"@typescript-eslint/no-unused-vars": "warn", // detect unused variables
176-
}
177-
};
182+
]);
178183
```
179184

180185
- [ ] Create a `.prettierrc` file at the root of your project with the following content:
@@ -187,7 +192,7 @@ module.exports = {
187192
"semi": true,
188193
"singleAttributePerLine": true,
189194
"trailingComma": "all",
190-
"tabWidth": 2,
195+
"tabWidth": 2,
191196
"singleQuote": false,
192197
"endOfLine": "crlf" // for windows users only
193198
}
@@ -198,19 +203,25 @@ module.exports = {
198203
We want to add some rules to our ESLint configuration.
199204

200205
```console
201-
npm install --dev eslint-plugin-react-native
206+
npm install --save-dev eslint-plugin-react-native
202207
# or
203208
yarn add --dev eslint-plugin-react-native
204209
```
205210

206-
- [ ] Update your `.eslintrc.js` file to add the following react-native rules:
211+
- [ ] Update your `eslint.config.js` file to add the following react-native rules:
207212

208213
```javascript
209-
// .eslintrc.js
214+
// eslint.config.js
215+
216+
const reactNativePlugin = require("eslint-plugin-react-native");
210217

218+
// Add to plugins:
211219
{
212-
plugins: ["react", "react-native"],
213-
"rules": {
220+
plugins: {
221+
...
222+
"react-native": reactNativePlugin,
223+
},
224+
rules: {
214225
...
215226
"react-native/no-color-literals": 2, // enforce color literals are not used
216227
"react-native/no-unused-styles": 2, // detect unused StyleSheet rules
@@ -225,19 +236,25 @@ yarn add --dev eslint-plugin-react-native
225236
We now want to sort our imports automatically. We can use the `simple-import-sort` plugin.
226237

227238
```console
228-
npm install --dev eslint-plugin-simple-import-sort
239+
npm install --save-dev eslint-plugin-simple-import-sort
229240
# or
230241
yarn add --dev eslint-plugin-simple-import-sort
231242
```
232243

233-
- [ ] Update your `.eslintrc.js` file to add the following import rules:
244+
- [ ] Update your `eslint.config.js` file to add the following import rules:
234245

235246
```javascript
236-
// .eslintrc.js
247+
// eslint.config.js
248+
249+
const simpleImportSort = require("eslint-plugin-simple-import-sort");
237250

251+
// Add to plugins:
238252
{
239-
"rules": {
240-
plugins: ["react", "react-native", "eslint-plugin-simple-import-sort"],
253+
plugins: {
254+
...
255+
"simple-import-sort": simpleImportSort,
256+
},
257+
rules: {
241258
...
242259
"simple-import-sort/exports": "warn", // enforce sorting exports within module
243260
"simple-import-sort/imports": [
@@ -254,8 +271,8 @@ yarn add --dev eslint-plugin-simple-import-sort
254271
["^\\.\\.(?!/?$)", "^\\.\\./?$"],
255272
// Other relative imports. Put same-folder imports and `.` last.
256273
["^\\./(?=.*/)(?!/?$)", "^\\.(?!/?$)", "^\\./?$"],
257-
]
258-
}
274+
],
275+
},
259276
],
260277
},
261278
}
@@ -267,16 +284,16 @@ We have no control on the api data we are pulling from SWAPI. Sometimes we want
267284

268285
In our case `cargo_capacity`, `cost_in_credits` are not using `camelCase` and we want to disable this rule.
269286

270-
- [ ] Update your `.eslintrc.js` file to add the following rules:
287+
- [ ] Update your `eslint.config.js` file to add the following rules:
271288

272289
```javascript
273-
// .eslintrc.js
290+
// eslint.config.js
274291

275292
{
276-
"rules": {
293+
rules: {
277294
...
278295
camelcase: "off", // disable camelcase rule
279-
"@typescript-eslint/no-explicit-any": "warn" // detect usage of `any` type
296+
"@typescript-eslint/no-explicit-any": "warn", // detect usage of `any` type
280297
},
281298
}
282299
```

0 commit comments

Comments
 (0)