husky + lint-staged
17.4.1. Installation and Configuration
Lint and formatting are automatically verified before each commit.
bash
yarn add -D husky lint-staged
npx husky init17.4.2. .husky/pre-commit
bash
npx lint-staged17.4.3. lint-staged Configuration
The following must be added to package.json.
json
{
"lint-staged": {
"*.{ts,vue}": [
"eslint --fix",
"prettier --write"
],
"*.{json,md,yml,yaml}": [
"prettier --write"
]
}
}17.4.4. Workflow
- A developer runs
git commit. - husky triggers the pre-commit hook.
- lint-staged runs ESLint + Prettier only on staged files.
- If lint errors are found, the commit is aborted.
- Auto-fixed files are re-added to the staging area.
Mandatory
The husky + lint-staged configuration is mandatory for all projects. TQS certification cannot be achieved without this configuration.
17.4.5. CI Environment Considerations
- In CI environments, husky is automatically disabled (
HUSKY=0orCI=true). - In CI,
yarn lintandyarn format:checkmust be run separately to verify code quality.
bash
# CI pipeline script example
yarn lint
yarn format:check # prettier --check