LinuxCommandLibrary

lint-staged

TLDR

Run on staged files

$ npx lint-staged
copy
Run with config file
$ npx lint-staged --config [.lintstagedrc.json]
copy
Run in debug mode
$ npx lint-staged --debug
copy
Dry run (no changes)
$ npx lint-staged --dry-run
copy
Run on specific files
$ npx lint-staged --diff="[branch]"
copy

SYNOPSIS

lint-staged [options]

DESCRIPTION

lint-staged runs linters on git staged files. It's typically used with husky or lefthook to ensure code quality before commits by running formatters and linters only on changed files.
This makes pre-commit hooks fast by avoiding linting the entire codebase.

PARAMETERS

--config file

Path to config file.
--debug
Enable debug mode.
--dry-run
Show what would run.
--diff ref
Compare against reference.
--no-stash
Disable git stash.
--quiet
Suppress output.
--relative
Use relative paths.

CONFIGURATION

$ // package.json
{
  "lint-staged": {
    "*.js": ["eslint --fix", "prettier --write"],
    "*.css": "stylelint --fix"
  }
}
copy

CAVEATS

Requires git repository. Stashes unstaged changes during run. May conflict with partial staging. Works best with auto-fixing linters.

HISTORY

lint-staged was created by Andrey Okonetchnikov in 2016 to solve the problem of slow pre-commit hooks by targeting only staged files.

SEE ALSO

husky(1), eslint(1), prettier(1), lefthook(1)

Copied to clipboard