- follow this guide/video:
- install prettier extension in vscode and setup as default formatter
- create node project
npm init -y
pnpm i -D eslint
(use exact version)
npx eslint --init
[it will install few deps]
pnpx install-peerdeps --dev eslint-config-airbnb-base
[ for react: eslint-config-airbnb ]
- for node
pnpm install eslint-config-airbnb-base@15.0.0 eslint@^8.2.0 eslint-plugin-import@^2.25.2 --save-dev
- for react:
pnpm install eslint-config-airbnb@19.0.4 eslint@^8.2.0 eslint-plugin-import@^2.25.3 eslint-plugin-jsx-a11y@^6.5.1 eslint-plugin-react@^7.28.0 eslint-plugin-react-hooks@^4.3.0 --save-dev
- make the extends array like this:
extends: ["airbnb-base", "plugin:@typescript-eslint/recommended"],
or for react extends: ["airbnb", "plugin:react/recommended","plugin:@typescript-eslint/recommended"]
- we need another plugin for typescript : eslint-config-airbnb-typescript
pnpm i -D eslint-config-airbnb-typescript
- update it extends:
extends: ["airbnb-base", "airbnb-typescript/base", "plugin:@typescript-eslint/recommended",]
- for react
extends: ["airbnb", "airbnb-typescript", "plugin:react/recommended", "plugin:@typescript-eslint/recommended",]
- add parser option
parserOptions: {
ecmaVersion: "latest",
sourceType: "module",
+ project: "./tsconfig.json",
},
- tell tsconfig.json about eslint
"include": [".eslintrc.js", "src"]
- install deps:
pnpm i -D prettier eslint-config-prettier eslint-plugin-prettier
- add .prettierrc.js
// prettier.config.js or .prettierrc.js or .prettierrc.cjs
module.exports = {
trailingComma: 'es5',
tabWidth: 4,
semi: false,
singleQuote: true,
}
// if you change any rule then reload the window
- update extends in eslint config
extends: [
...,
'airbnb-base',
'airbnb-typescript/base',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
- update plugin
plugins: ['@typescript-eslint', 'prettier'],
- disable few rule in eslint
rules: {
'prettier/prettier': [
'warn',
{
endOfLine: 'auto',
},
],
'no-console': 'off',
'linebreak-style': 'off',
}
- add script for eslint
"lint": "npx eslint . --fix",
"lint:check": "npx eslint ."