@@ -124,10 +124,10 @@ We are making progress, but we are not done yet. We need to add rules for React
124
124
- [ ] Install the following plugins
125
125
126
126
``` 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
128
128
```
129
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
130
+ yarn add -D prettier eslint-config-prettier eslint-plugin-prettier eslint-plugin-react
131
131
```
132
132
133
133
- [ ] Update your ` .eslintrc.js ` file to add the following rules:
@@ -148,7 +148,7 @@ module.exports = {
148
148
" plugin:react/jsx-runtime" , // support for React 17 JSX
149
149
" plugin:prettier/recommended" // Prettier recommended rules
150
150
],
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
152
152
rules: {
153
153
" prettier/prettier" : [ // Prettier rules
154
154
" warn" ,
@@ -161,26 +161,6 @@ module.exports = {
161
161
" react-native/no-raw-text" : 0 , // detect raw text outside of Text component
162
162
" react-native/sort-styles" : 2 , // enforce style definitions are sorted
163
163
" @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
184
164
}
185
165
};
186
166
```
@@ -205,6 +185,74 @@ module.exports = {
205
185
206
186
### Updating ESLint rules
207
187
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
+
208
256
We have no control on the api data we are pulling from SWAPI. Sometimes we want to update our rules to reflect differences.
209
257
210
258
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
223
271
}
224
272
```
225
273
274
+ - [ ] Lint your code and push your changes to GitHub.
275
+
226
276
## 👽 Bonus
227
277
228
278
You can share your VSCode settings with your team by adding a ` .vscode ` folder at the root of your project with the following content:
0 commit comments