Skip to content

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 init

17.4.2. .husky/pre-commit

bash
npx lint-staged

17.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

  1. A developer runs git commit.
  2. husky triggers the pre-commit hook.
  3. lint-staged runs ESLint + Prettier only on staged files.
  4. If lint errors are found, the commit is aborted.
  5. 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=0 or CI=true).
  • In CI, yarn lint and yarn format:check must be run separately to verify code quality.
bash
# CI pipeline script example
yarn lint
yarn format:check  # prettier --check

TIENIPIA QUALIFIED STANDARD