Skip to content

Commit 6b2b27b

Browse files
committed
fix: 🐛 eslint setup
1 parent 90d3362 commit 6b2b27b

File tree

2 files changed

+73
-25
lines changed

2 files changed

+73
-25
lines changed

challenges/ecosystem/02.md

Lines changed: 73 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,10 @@ We are making progress, but we are not done yet. We need to add rules for React
124124
- [ ] Install the following plugins
125125

126126
```console
127-
npm install --dev prettier eslint-config-prettier eslint-plugin-prettier eslint-plugin-react eslint-plugin-react-native eslint-plugin-simple-import-sort
127+
npm install --dev prettier eslint-config-prettier eslint-plugin-prettier eslint-plugin-react
128128
```
129129
```console
130-
yarn add -D prettier eslint-config-prettier eslint-plugin-prettier eslint-plugin-react eslint-plugin-react-native eslint-plugin-simple-import-sort
130+
yarn add -D prettier eslint-config-prettier eslint-plugin-prettier eslint-plugin-react
131131
```
132132

133133
- [ ] Update your `.eslintrc.js` file to add the following rules:
@@ -148,7 +148,7 @@ module.exports = {
148148
"plugin:react/jsx-runtime", // support for React 17 JSX
149149
"plugin:prettier/recommended" // Prettier recommended rules
150150
],
151-
plugins: ["react", "react-native", "simple-import-sort"], // add React and React Native plugins
151+
plugins: ["react", "simple-import-sort"], // add React and React Native plugins
152152
rules: {
153153
"prettier/prettier": [ // Prettier rules
154154
"warn",
@@ -161,26 +161,6 @@ module.exports = {
161161
"react-native/no-raw-text": 0, // detect raw text outside of Text component
162162
"react-native/sort-styles": 2, // enforce style definitions are sorted
163163
"@typescript-eslint/no-unused-vars": "warn", // detect unused variables
164-
"simple-import-sort/exports": "warn", // enforce sorting exports within module
165-
"simple-import-sort/imports": [
166-
"warn",
167-
{
168-
groups: [
169-
// Side effect imports.
170-
["^\\u0000"],
171-
// Packages `react` related packages come first.
172-
["^react", "^@?\\w"],
173-
// Environment variables
174-
["^(@env)(/.*|$)"],
175-
// Parent imports. Put `..` last.
176-
["^\\.\\.(?!/?$)", "^\\.\\./?$"],
177-
// Other relative imports. Put same-folder imports and `.` last.
178-
["^\\./(?=.*/)(?!/?$)", "^\\.(?!/?$)", "^\\./?$"],
179-
]
180-
}
181-
],
182-
quotes: ["error", "double"], // enforce double quotes
183-
"react/no-unescaped-entities": "off", // Disable the rule
184164
}
185165
};
186166
```
@@ -205,6 +185,74 @@ module.exports = {
205185

206186
### Updating ESLint rules
207187

188+
We want to add some rules to our ESLint configuration.
189+
190+
```console
191+
npm install --dev eslint-plugin-react-native
192+
```
193+
```console
194+
yarn add -D eslint-plugin-react-native
195+
```
196+
197+
- [ ] Update your `.eslintrc.js` file to add the following react-native rules:
198+
199+
```json
200+
// .eslintrc.js
201+
202+
{
203+
"rules": {
204+
...
205+
"react-native/no-color-literals": 2, // enforce color literals are not used
206+
"react-native/no-unused-styles": 2, // detect unused StyleSheet rules
207+
"react-native/no-raw-text": 0, // detect raw text outside of Text component
208+
"react-native/sort-styles": 2, // enforce style definitions are sorted
209+
},
210+
}
211+
```
212+
213+
- [ ] Lint your code and push your changes to GitHub.
214+
215+
We now want to sort our imports automatically. We can use the `simple-import-sort` plugin.
216+
217+
```console
218+
npm install --dev eslint-plugin-simple-import-sort
219+
```
220+
```console
221+
yarn add -D eslint-plugin-simple-import-sort
222+
```
223+
224+
- [ ] Update your `.eslintrc.js` file to add the following import rules:
225+
226+
```json
227+
// .eslintrc.js
228+
229+
{
230+
"rules": {
231+
...
232+
"simple-import-sort/exports": "warn", // enforce sorting exports within module
233+
"simple-import-sort/imports": [
234+
"warn",
235+
{
236+
groups: [
237+
// Side effect imports.
238+
["^\\u0000"],
239+
// Packages `react` related packages come first.
240+
["^react", "^@?\\w"],
241+
// Environment variables
242+
["^(@env)(/.*|$)"],
243+
// Parent imports. Put `..` last.
244+
["^\\.\\.(?!/?$)", "^\\.\\./?$"],
245+
// Other relative imports. Put same-folder imports and `.` last.
246+
["^\\./(?=.*/)(?!/?$)", "^\\.(?!/?$)", "^\\./?$"],
247+
]
248+
}
249+
],
250+
},
251+
}
252+
```
253+
254+
- [ ] Lint your code and push your changes to GitHub.
255+
208256
We have no control on the api data we are pulling from SWAPI. Sometimes we want to update our rules to reflect differences.
209257

210258
In our case `cargo_capacity`, `cost_in_credits` are not using `camelCase` and we want to disable this rule.
@@ -223,6 +271,8 @@ In our case `cargo_capacity`, `cost_in_credits` are not using `camelCase` and we
223271
}
224272
```
225273

274+
- [ ] Lint your code and push your changes to GitHub.
275+
226276
## 👽 Bonus
227277

228278
You can share your VSCode settings with your team by adding a `.vscode` folder at the root of your project with the following content:

hackathon/spacecraft/.eslintrc.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,5 @@ module.exports = {
4646
],
4747
},
4848
],
49-
quotes: ["error", "double"], // enforce double quotes
50-
"react/no-unescaped-entities": "off", // Disable the rule
5149
},
5250
};

0 commit comments

Comments
 (0)