This is a company-wide coding style-guide using eslint
, @stylistic/eslint-plugin
as formatter and optional linting for TailwindCSS using eslint-plugin-tailwindcss
.
It should be applied to all JS/TS projects to unify the company coding-styles.
-
Install packages:
npm i -D eslint @cewald/eslint-config
-
Add
eslint.config.mjs
to root directory:import config from '@cewald/eslint-config' export default [ ...config() ]
-
For autoformat on save in VSCode, add VSCode settings to workspace settings in
.vscode/settings.json
:{ "editor.formatOnSave": false, "editor.codeActionsOnSave": { "source.fixAll.eslint": "always" } }
-
Add linting commands to
package.json
:"scripts": { "lint": "eslint", "lint:fix": "eslint --fix", }
-
Remove unnecessary packages
With this configured changed files will automatically be formatted and linted on commit.
-
Install deps:
npm i -D husky lint-staged
-
Create hook for
husky
in.husky/pre-commit
:npx lint-staged
-
Add
lint-staged
config topackage.json
:"lint-staged": { "*": [ "npm run lint:fix" ] }
- Simply run
npm run dev
- You can use
npm link
to use a local version in your local repos
In case you have to debug rules or how they are applied, there is a whole guide for it here:
https://eslint.org/docs/latest/use/configure/debug
Anyway the config-inspector
is the best tool:
https://eslint.org/docs/latest/use/configure/debug#use-the-config-inspector
Just run npx eslint --inspect-config
from the root folder and you can see which rules are applied in a nice and conveniant interface.