pre-commit-with-lint

raw JSON →
1.2.5 verified Fri May 01 auth: no javascript deprecated

A fork of the pre-commit package (v1.2.5) that adds selective linting of only changed files in a commit. It integrates with stylelint and eslint by default, linting CSS/SCSS/Less and JS/JSX files respectively, with configurable patterns. Designed to speed up commits by avoiding full-project linting. Release cadence is low (last update 2017), and it's effectively unmaintained. Key differentiator vs original pre-commit: automatic linting of only staged changes. Alternative better-maintained packages exist.

error Cannot find module 'eslint'
cause eslint is not installed but default linting pattern requires it.
fix
Run: npm install eslint --save-dev; or disable eslint in package.json: "eslint": "false"
error Something bad happened with the pre-commit hook. You can force the commit by using --no-verify.
cause Git hook script failed due to a configuration error or missing dependencies.
fix
Check package.json pre-commit configuration, ensure scripts are valid, and reinstall the package.
error fatal: could not open '.git/HEAD': No such file or directory
cause Command run outside a git repository.
fix
Initialize a git repo: git init
deprecated Package is a fork of pre-commit from 2017; no updates since then. Use modern alternatives like husky + lint-staged.
fix Switch to @commitlint/lint-staged or husky + lint-staged.
gotcha If a linter specified in package.json is not installed, the commit will be prevented with an error.
fix Ensure listed linters (eslint, stylelint, tslint, etc.) are installed as devDependencies.
gotcha The default lint patterns are hardcoded and may not match all file types. Misconfigured patterns can cause no linting or broken commits.
fix Set explicit patterns in package.json: { "pre-commit": { "lint": { "eslint": ".jsx?$" } } }
breaking clone: The 'pre-commit' key must be an object for lint config; using an array (original pre-commit style) will be ignored without warning.
fix Use object syntax with 'lint' and 'run' keys, not an array.
gotcha If default linters (stylelint, eslint) are not found in node_modules, a warning is printed but commit proceeds. Non-default linters cause an error.
fix Install default linters or disable them via config: { "pre-commit": { "lint": { "eslint": "false" } } }
npm install pre-commit-with-lint
yarn add pre-commit-with-lint
pnpm add pre-commit-with-lint

Shows full setup: install, configure package.json with selective lint and scripts, then commit. Verifies pre-commit hook runs lint and test before allowing commit.

mkdir test-repo && cd test-repo && npm init -y && npm install pre-commit-with-lint --save-dev && echo '{
  "name": "test",
  "version": "1.0.0",
  "scripts": {
    "test": "echo \"tests pass\" && exit 0",
    "lint": "echo \"linting\" && exit 0"
  },
  "pre-commit": {
    "lint": {
      "eslint": ".js$"
    },
    "run": ["lint", "test"]
  }
}' > package.json && git init && git add . && git commit -m "test commit"