typescript-eslint-prettier-config
v1.3.11
Published
Minimal Typescript, ESLint and Prettier configuration.
Downloads
102
Maintainers
Readme
typescript-eslint-prettier-config
Minimal Typescript, ESLint and Prettier configuration.
ESLint and Prettier configurations are pretty standard in Javascript world. The intention of this package is to create a minimal setup with recommendations for eslint and prettier from the authors. According to them, we don't even need advance plugins that tries to get the best of both the worlds. Typescript config is cherry on top and gels easily with them.
Installation
To install:
npm i -D typescript eslint prettier typescript-eslint-prettier-config
or
yarn add -D typescript eslint prettier typescript-eslint-prettier-config
How to use this package
- To extend your existing Typescript configuration
**/tsconfig.json
{
"extends": "**/node_modules/typescript-eslint-prettier-config/tsconfig.json",
"compilerOptions": {
...
},
"exclude": ["**/node_modules/**", "build/**", "dist/**"],
"include": ["src"] // include your src folder or use default
}
- To extend your existing ESLint configuration
**/.eslintrc
{
"root": true,
"extends": "**/node_modules/typescript-eslint-prettier-config/.eslintrc",
"parserOptions": {
"project": ["./tsconfig.json"] // this is your typescript configuration that you extended in the previous step
}
}
- To extend your existing Prettier configuration
**/.prettierrc.ts
module.exports = {
...require('**/node_modules/typescript-eslint-prettier-config/prettier.config'),
};
Further ideas to use the setup optimally
VSCode
eslint --fix
can be configured in the settings.json file in VSCode to automatically fix the linting errors. Also, adding formatOnSave
runs Prettier every time you save.
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true,
"source.organizeImports": true
},
"editor.formatOnSave": true
}
Lint staging
lint-staged
in combination with husky
can be used in package.json to avoid accidentally committing non-linted files on github.
{
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.{js,jsx,ts,tsx}": [
"eslint --fix"
],
"*.{js,jsx,ts,tsx,json,yml,yaml,css,html}": [
"prettier --write"
]
}
}