A simple eslint config for modern TypeScript projects.
This package configures eslint with:
- Typescript support https://github.com/typescript-eslint/typescript-eslint
- StandardJs rules https://github.com/standard/eslint-config-standard
- Prettier rules https://github.com/prettier/eslint-plugin-prettier
@typescript-eslint/recommended
rules https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin- Requires semicolons (from prettier) for consistancy with types
- Disables some opinionated type check rules
For reference: ./eslint.js.
- 1. Install
- 1.1 Install Peer Dependencies
- 2. Configure
- 3. Bonus configure
- FAQ
- Project future
- Potential issues
Note: For an even "easier" install option, see eslint-config-nfour
yarn add -D eslint-config-standard-typescript-prettier
Install all the peer dependencies listed in this projects package.json into your project.
This should do the trick:
npx install-peerdeps -o --dev --yarn eslint-config-standard-typescript-prettier
Add this to your package.json
:
"eslintConfig": {
"extends": ["standard-typescript-prettier"],
"parserOptions": { "project": "./tsconfig.json" }
},
"prettier": "eslint-config-standard-typescript-prettier/prettier"
For other config recipes, see I want fine grained control
Add the comment below to get type checks on your rules in a .eslintrc.js
/** @ts-check @type import('eslint-config-standard-typescript-prettier/types').TsEslintConfig */
The packages exports a plain object, go nuts!
In an .eslintrc.js
:
const config = require('eslint-config-standard-typescript-prettier');
module.exports = {
...config,
parserOptions: { project: "./tsconfig.json" },
rules: {
...config.rules,
"@typescript-eslint/no-explicit-any": "error",
},
};
Eslint might be changing their config, which is why a
.eslintrc.js
format is recommended.More info: eslint/rfcs#9
In a .prettierrc.js
:
module.exports = {
...require('eslint-config-standard-typescript-prettier/prettier'),
semi: false, // This is how you turn off semicolons, by the way
}
On the CLI, eslint
requires the --ext
flag (currently):
eslint --ext .ts,.tsx .
By default, lint errors can become mixed with TypeScript errors during development.
eslint-plugin-only-warn
is already included in this package, so do this:
{
"plugins": ["only-warn"],
"extends": ["standard-typescript-prettier"],
"parserOptions": { "project": "./tsconfig.json" }
}
Want your lint warnings turned into errors?
yarn eslint --max-warnings 1
Javascript churn is real. This project will be kept up to date only for as long as configuration remains tedious.
The peerDependencies listed are versioned for compatibility. Because you maintain these dependencies in your project, you'll have to keep them all in sync or you could have issues.