eslint-config-haku
Version:
Custom Eslint config with airbnb
71 lines (54 loc) • 1.57 kB
Markdown
- Install `eslint-config-haku`
```bash
npm i --save-dev eslint-config-haku
yarn add -D eslint-config-haku
pnpm add -D eslint-config-haku
```
- Extend the config in `.eslintrc.js`
```javascript
// Extend the config matching your project
extends: ["haku/react"],
parserOptions: {
// Warn: the location may differ in different project structure
project: "./tsconfig.json",
},
```
- setup to auto fix lint problems on save
```json
{
"editor.codeActionsOnSave": { "source.fixAll": true },
"editor.formatOnSave": false
}
```
- Refer to https://typescript-eslint.io/linting/typed-linting
- Add to `extend`
```javascript
"extends": [
// ...
"haku/react",
"plugin:@typescript-eslint/recommended-type-checked"
],
```
- Refer to https://redux.js.org/usage/usage-with-typescript#define-typed-hooks
- Add rule to restrict using custom `useAppSelector` and `useAppDispatch` for typing
```javascript
"@typescript-eslint/no-restricted-imports": [
"warn",
{
name: "react-redux",
importNames: ["useSelector", "useDispatch"],
message: "Use typed hooks `useAppDispatch` and `useAppSelector` instead.",
},
],
```
- Add [`eslint-import-resolver-typescript`](https://www.npmjs.com/package/eslint-import-resolver-typescript) plugin