Skip to content

Commit 03c0239

Browse files
committed
Add eslint-plugin-compat
1 parent 43eb486 commit 03c0239

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

tutorial/02-babel-es6-eslint-flow-jest-husky.md

+34-2
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,36 @@ I recommend reading the [ESLint documentation about semicolons](http://eslint.or
152152

153153
I am aware that some of you will want to keep using semicolons, which will make the code provided in this tutorial inconvenient. If you are using this tutorial just for learning, I'm sure it will remain bearable to learn without semicolons, until going back to using them on your real projects. If you want to use the code provided in this tutorial as a boilerplate though, it will require a bit of rewriting, which should be pretty quick with ESLint set to enforce semicolons to guide you through the process. I apologize if you're in such case.
154154

155+
### Compat
156+
157+
[Compat](https://github.com/amilajack/eslint-plugin-compat) is a neat ESLint plugin that warns you if you use some JavaScript APIs that are not available in the browsers you need to support. It uses [Browserslist](https://github.com/ai/browserslist), which relies on [Can I Use](http://caniuse.com/).
158+
159+
- Run `yarn add --dev eslint-plugin-compat`
160+
161+
- Add the following to your `package.json`, to indicate that we want to support browsers that have more than 1% market share:
162+
163+
```json
164+
"browserslist": ["> 1%"],
165+
```
166+
167+
- Edit your `.eslintrc.json` file like so:
168+
169+
```json
170+
{
171+
"extends": "airbnb",
172+
"plugins": [
173+
"compat"
174+
],
175+
"rules": {
176+
"semi": [2, "never"],
177+
"no-unexpected-multiline": 2,
178+
"compat/compat": 2
179+
}
180+
}
181+
```
182+
183+
You can try the plugin by using `navigator.serviceWorker` or `fetch` in your code for instance, which should raise an ESLint warning.
184+
155185
### ESLint in your editor
156186

157187
This chapter set you up with ESLint in the terminal, which is great for catching errors at build time / before pushing, but you also probably want it integrated to your IDE for immediate feedback. Do NOT use your IDE's native ES6 linting. Configure it so the binary it uses for linting is the one in your `node_modules` folder instead. This way it can use all of your project's config, the Airbnb preset, etc. Otherwise you will just get some generic ES6 linting.
@@ -186,11 +216,13 @@ Right now, our JavaScript code is valid ES6 code. Flow can analyze plain JavaScr
186216
"plugin:flowtype/recommended"
187217
],
188218
"plugins": [
189-
"flowtype"
219+
"flowtype",
220+
"compat"
190221
],
191222
"rules": {
192223
"semi": [2, "never"],
193-
"no-unexpected-multiline": 2
224+
"no-unexpected-multiline": 2,
225+
"compat/compat": 2
194226
}
195227
}
196228
```

tutorial/05-redux-immutable-fetch.md

+10
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,16 @@ We are going to use `fetch` to make calls to the server from the client. `fetch`
361361
362362
- Run `yarn add isomorphic-fetch`
363363
364+
Since we're using `eslint-plugin-compat`, we need to indicate that we are using a polyfill for `fetch` to not get warnings from using it.
365+
366+
- Add the following to your `.eslintrc.json` file:
367+
368+
```json
369+
"settings": {
370+
"polyfills": ["fetch"]
371+
},
372+
```
373+
364374
### 3 asynchronous actions
365375
366376
`sayHelloAsync` is not going to be a regular action. Asynchronous actions are usually split into 3 actions, which trigger 3 different states: a *request* action (or "loading"), a *success* action, and a *failure* action.

0 commit comments

Comments
 (0)