eslint-config-kit v5.0.0
ESLint Config Kit is a collection of useful ESLint configs for much more convenient project developing.
It uses only the necessary rules to provide error checking and readability improving. Nothing extra included.
Configs divided into base and technology-specific parts, which can be used in "modular" style.
It doesn't enforce any doubtful rules, like
prefer-default-exportinairbnbconfig.It helps you to write a more readable code.
Any use of implicit language mechanic will be warned.It's designed to be a conflict-free.
For example,@typescript/eslint:recommendedconfig does not resolve conflicts withimportplugin, butkit/typescriptdoes.The main goal is to create a zero-override config, which can be used almost in any project.
Here is the example for TypeScript React project:
{
"extends": [
"kit/base",
"kit/packs/react-typescript"
]
}Overview
- Installation using ESLint Kit CLI
- Manual installation
- Configs
- Config packs
- Integrating ESLint with IDEs/editors
- Advanced Usage
- Troubleshooting
Installation using ESLint Kit CLI
Install ESLint Kit CLI:
npm i -g @eslint-kit/cliRun it:
eslint-kit
Learn more on @eslint-kit/cli page.
Manual installation
Install the base dependencies:
npm i -D eslint eslint-config-kit eslint-plugin-importCreate
.eslintrcfile in the root of your project.Extend from
baseconfig:{ "extends": ["kit/base"] }(optional) Integrate ESLint into your IDE/editor here.
Configs
Note: Base config does not include any formatting rules. It is strongly recommended to use
prettierconfig for this purposes. Just openPrettiersection right below.
This config just enables the prettier plugin and adds prettier/prettier rule.
Installation:
Install dependencies:
npm i -D prettier eslint-plugin-prettierExtend from
prettierconfig:{ "extends": [ "kit/base", + "kit/prettier" ] }Create
.prettierrcfile in the root of your project add specify your formatting settings.(optional) Use the recommended settings:
{ "semi": false, "singleQuote": true, "tabWidth": 2, "quoteProps": "consistent", "trailingComma": "es5", "endOfLine": "lf" }
Installation:
Install dependencies:
npm i -D babel-eslint eslint-plugin-react eslint-plugin-react-hooksNote:
babel-eslintrequiresbabel/core@>=7.2.0and a valid Babel configuration file to run. If you do not have this already set up, please see the Babel Usage Guide.Extend from
reactconfig and specify a parser:{ + "parser": "babel-eslint", "extends": [ "kit/base", + "kit/react" ] }
This config just enables the node env, it doesn't add any rules.
Installation:
Extend from
nodeconfig:{ "extends": [ "kit/base", + "kit/node" ] }
Installation:
Install dependencies:
npm i -D @typescript-eslint/parser @typescript-eslint/eslint-pluginExtend from
typescriptconfig and specify a parser:{ + "parser": "@typescript-eslint/parser", "extends": [ "kit/base", + "kit/typescript" ] }
Config packs
Config packs are just shortcuts for the most used config combinations.
Includes:
reacttypescript
Installation:
Install dependencies:
npm i -D eslint-plugin-react eslint-plugin-react-hooks @typescript-eslint/parser @typescript-eslint/eslint-pluginExtend from
packs/react-typescriptconfig and specify a parser:{ + "parser": "@typescript-eslint/parser", "extends": [ "kit/base", + "kit/packs/react-typescript" ] }
Integrating ESLint with IDEs/editors
Install ESLint plugin
Choose any option you like:
Fix on save.
Add the following to your VSCodesettings.json:"editor.codeActionsOnSave": { "source.fixAll.eslint": true }Fix on keyboard shortcut.
Add the following to your VSCodekeybindings.json:{ "key": "alt+f", // or any other keys "command": "eslint.executeAutofix" }
Advanced Usage
Install dependencies:
npm i -D eslint-import-resolver-aliasUpdate
.eslintrcwith your aliases:{ "settings": { "import/resolver": { "alias": { "map": [ ["@folder-alias", "./src"], ["@file-alias", "./src/App.js"] ], "extensions": [".js", ".jsx", ".json"] } } }, "rules": { "import/order": [ "warn", { "groups": [ "builtin", "external", "internal", "parent", "sibling", "index" ], "pathGroups": [ { "pattern": "@folder-alias/**", "group": "internal", "position": "before" }, { "pattern": "@file-alias", "group": "internal", "position": "before" } ] } ] } }
Install dependencies:
npm i -D eslint-import-resolver-typescriptUpdate
.eslintrc:{ "settings": { "import/parsers": { "@typescript-eslint/parser": [".ts", ".tsx"] }, "import/resolver": { "typescript": { "alwaysTryTypes": true } } }, "rules": { "import/order": [ "warn", { "groups": [ "builtin", "external", "internal", "parent", "sibling", "index" ], "pathGroups": [ { "pattern": "@folder-alias/**", "group": "internal", "position": "before" }, { "pattern": "@file-alias", "group": "internal", "position": "before" } ] } ] } }Note: See eslint-import-resolver-typescript README for the details.
Troubleshooting
Issue:
You have used a rule which requires parserServices to be generated. You must therefore provide a value for the "parserOptions.project" property for @typescript-eslint/parser.
Solution:
You should specify your tsconfig location manually in parserOptions:
{
"parser": "@typescript-eslint/parser",
+ "parserOptions": {
+ "project": "./tsconfig.json"
+ },
"extends": [
"kit/base",
"kit/typescript"
]
}If it doesn't work, try to rename eslint config file to .eslintrc.js and resolve tsconfig.json path:
const path = require('path')
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: path.resolve(__dirname, './tsconfig.json') // or your tsconfig location
},
extends: [
'kit/base',
'kit/typescript'
]
}