Skip to content

tooling: add pre-commit hook for Prettier format-check on staged files #758

Description

@fpigeonjr

Problem

Prettier formatting drift on staged files goes undetected locally and only surfaces in the CI Format-Check step. This causes avoidable CI failures on otherwise-correct commits (most recently #755).

Proposed solution

Add a pre-commit hook that runs Prettier only on staged files using lint-staged + Husky.

This keeps the hook fast (ms per file, not seconds across the whole repo) and catches format issues before they ever reach CI.

Suggested implementation

npm install --save-dev husky lint-staged
npx husky init

.husky/pre-commit

npx lint-staged

package.json addition:

"lint-staged": {
  "**/*.{scss,css,js,json,md}": "prettier --check"
}

Scope

  • In scope: Prettier format-check on staged files only
  • Out of scope: Running full npm run lint (stylelint across all SCSS) or build:storybook in the pre-commit hook — both are too slow for interactive use

Acceptance criteria

  • husky and lint-staged added as devDependencies
  • npx husky init sets up .husky/pre-commit
  • lint-staged config in package.json runs prettier --check on staged .scss, .css, .js, .json, and .md files
  • Committing a Prettier-dirty file is blocked with a clear error message
  • npm run lint and npm run compile:check still pass
  • prepare script added so npm install auto-installs the hook for new contributors

Related

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buildchoretoolingDeveloper tooling, pre-commit hooks, scripts

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions