Lint-staged: add option to stop passing paths to the linters

Created on 18 Mar 2018  ·  3Comments  ·  Source: okonet/lint-staged

Description

We want to do a full TypeScript type check of the project before any .tsx? files is committed, typically we use tsc -p . --noEmit.

However if we integrate this command into lint-staged like this:

{
  "lint-staged": {
     "*.{ts,tsx}": "tsc -p . --noEmit"
  }
}

we got an error from tsc:

git commit
husky > npm run -s precommit (node v8.9.4)

 ❯ Running tasks for *.{ts,tsx}
   ✖ tsc -p . --noEmit
     → error TS5042: Option 'project' cannot be mixed with source files on a command line.
✖ tsc -p . --noEmit found some errors. Please fix them and try committing again.
error TS5042: Option 'project' cannot be mixed with source files on a command line.

husky > pre-commit hook failed (add --no-verify to bypass)

Environment

  • OS: macOS High Sierra
  • Node.js: v8.9.4
  • lint-staged: v6.0.0
duplicate question

All 3 comments

lint-staged adds staged files as argument to your command, so there is a conflict of . and how lint-staged works. This is why you see this error. You should either do -p . and run it on precommit without lint-staged, or remove -p option.

Regarding the feature request. There is a duplicate issues #138 and #404 so I'm closing this one.

For those that have arrived here in search of type-check TypeScript files on pre-commit hooks, see the gist below.

https://gist.github.com/dcurletti/89edd6a5b329fa01faf39148ffafa71a

Was this page helpful?
0 / 5 - 0 ratings

Related issues

okonet picture okonet  ·  5Comments

acusti picture acusti  ·  6Comments

hadrienl picture hadrienl  ·  8Comments

oliverzy picture oliverzy  ·  4Comments

benjamincharity picture benjamincharity  ·  4Comments