Skip to content

Commit b0902f8

Browse files
committed
eslint 🌹
1 parent 0c75c55 commit b0902f8

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
* [Tools](docs/tools/intro.md)
7979
* [Prettier](docs/tools/prettier.md)
8080
* [Husky](docs/tools/husky.md)
81+
* [ESLint](docs/tools/eslint.md)
8182
* [Changelog](docs/tools/changelog.md)
8283
* [TIPs](docs/tips/main.md)
8384
* [String Based Enums](docs/tips/stringEnums.md)

docs/tools/eslint.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# ESLint
2+
3+
ESLint existed to lint JavaScript, but no it is also becoming the defacto linter for [TypeScript](https://github.com/Microsoft/TypeScript/issues/29288), thanks to the [collaboration](https://eslint.org/blog/2019/01/future-typescript-eslint) between the two teams.
4+
5+
## Install
6+
7+
To setup ESLint for TypeScript you need the following packages:
8+
9+
```sh
10+
npm i eslint eslint-plugin-react @typescript-eslint/parser @typescript-eslint/eslint-plugin
11+
```
12+
13+
> TIP: eslint calls packages that contain lint rules as "plugin"
14+
15+
* eslint : Core eslint
16+
* eslint-plugin-react : For react rules provided by eslint. [Supported rules list](https://github.com/yannickcr/eslint-plugin-react#list-of-supported-rules)
17+
* @typescript-eslint/parse : To allow eslint to understand ts / tsx files
18+
* @typescript-eslint/eslint-plugin : For TypeScript rules. [Supported rules list](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin#supported-rules)
19+
20+
> As you can see there are two eslint packages (for use with js or ts) and two @typescript-eslint packages (for use with ts). So the overhead for TypeScript is not *that much*.
21+
22+
## Configure
23+
Create `.eslintrc.js`:
24+
25+
```js
26+
module.exports = {
27+
parser: '@typescript-eslint/parser',
28+
parserOptions: {
29+
project: './tsconfig.json',
30+
},
31+
plugins: ['@typescript-eslint'],
32+
extends: [
33+
'plugin:react/recommended',
34+
'plugin:@typescript-eslint/recommended',
35+
],
36+
rules: {
37+
// Overwrite rules specified from the extended configs e.g.
38+
// "@typescript-eslint/explicit-function-return-type": "off",
39+
}
40+
}
41+
```
42+
43+
## Configure VSCode
44+
45+
* Install extension https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint
46+
* Add to `settings.json`:
47+
```js
48+
"eslint.validate": [
49+
"javascript",
50+
"javascriptreact",
51+
{"language": "typescript", "autoFix": true },
52+
{"language": "typescriptreact", "autoFix": true }
53+
],
54+
```

0 commit comments

Comments
 (0)