eslint-config-triple-node v0.1.9
eslint-config-triple
Unified ESlint config for Triple Node.js projects
This config is an effort to reduce duplicated configuration across projects. The goal is not to prescribe a fixed set of linting rules. This config should be considered a starting point which can be tweaked to the project needs.
- Prettier (Use prettier formatting as base)
- Unicorn (For remaining formatting + coding practises)
- Typescript recommendations (Typescript coding practises)
The rules where the config deviates from these presets are documented in eslint-config-triple source files.
When you agree with the rule in general but not for a specific scenario use comments like:
/* eslint-disable-next-line rulename */
(Tip: Press cmd + .
or click the lightbulb in VSCode)
Installation
npm install --save-dev \
concurrently \
eslint \
typescript \
prettier \
@typescript-eslint/eslint-plugin \
@typescript-eslint/parser \
eslint-plugin-unicorn \
eslint-plugin-only-warn \
eslint-plugin-import \
eslint-import-resolver-typescript \
eslint-config-triple-node
Usage
The config uses the prettier integration, therefore certain config files heavily impact the formatting:
Important!
Remove existing .prettierrc
and .editorconfig
files from the project and modify the package.json
to include:
"prettier": "eslint-config-triple-node/.prettierrc"
ESLint
Create a .eslintrc
with:
{
"extends": ["triple-node"],
"env": {
"browser": false,
"node": true
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json"
}
}
Trouble with linting js files?
Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser. The file does not match your project config:
Change "project": "./tsconfig.json"
to "project": "./tsconfig.eslint.json"
Create the tsconfig.eslint.json
and add additional include paths:
{
"extends": "./tsconfig.json",
"include": [
"src/**/*.d.ts",
"src/**/*.js",
"src/**/*.ts",
".*.js",
"**/*.js",
"**/*.jsx",
".*.cjs",
"**/*.cjs",
"./*.config.ts"
]
}
Automation
package.json scripts
"scripts": {
"lint": "concurrently --kill-others-on-fail \"npm:lint:*\"",
"lint:prettier": "prettier --check --loglevel=warn src",
"lint:tsc": "tsc --noEmit",
"lint:eslint": "eslint --ext=js,jsx,ts,tsx --max-warnings=0 src",
"format": "prettier --write src && eslint --ext=js,jsx,ts,tsx --fix src",
This adds npm run lint
to validate and npm run format
to autofix where possible.
Husky & Lint-staged
It's recommended to add husky and lint-staged which will verify the code in a git pre-commit hook. This helps fixing linting issues before the npm run lint
is run on CI.
npm install --save-dev husky lint-staged
npm pkg set scripts.prepare="husky install" scripts.precommit="lint-staged"
npm run prepare
npx husky add .husky/pre-commit "npm run precommit"
Add to package.json:
"lint-staged": {
"*.ts": [
"eslint --max-warnings 0 --no-ignore",
"sh -c 'tsc -p tsconfig.json --noEmit'"
],
"*.(js|cjs|mjs)": [
"eslint --max-warnings 0 --no-ignore"
],
"*.(json|md)": [
"prettier --check --loglevel=warn"
]
}