lint-staged ignores tsconfig.json when it called through husky hooks
See original GitHub issueDescription
lint-staged ignores tsconfig.json when it called through husky hooks (see “Steps to reproduce”)
Steps to reproduce
Create these files (test.js, tsconfig, package.json):
test.ts
export class Test {
static get observedAttributes() {
return ['foo'];
}
}
tsconfig.json
{
"compilerOptions": {
"target": "ESNEXT"
}
}
package.json
{
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.{js,ts}": [
"tsc --noEmit"
]
}
}
Then on command line write:
// everything works fine (it uses tsconfig.json)!
tsc --noEmit
// throw an error because it ignores tsconfig.json
git commit
// error TS1056: Accessors are only available when targeting ECMAScript 5 and higher
Environment
- OS: macOS Catalina
- Node.js: v13
lint-staged
: v10.1.0
Issue Analytics
- State:
- Created 3 years ago
- Reactions:12
- Comments:21
Top Results From Across the Web
Run a TypeScript type check in your pre-commit hook using ...
Run a TypeScript type check in your pre-commit hook using lint-staged + husky ... A great way to prevent TypeScript compilation errors from ......
Read more >Husky/lint-staged is it possible to exclude/ignore file?
While configuring lint-staged in package.json or If you're using any other IDE, in order to ignore/exclude files by lint-Staged and husky ...
Read more >Lint on Commit | David Valles
The issue resides in how lint-staged calls tsc . It passes git staged files to tsc via the command line, which means tsc...
Read more >Husky + Lint-Staged on a React TypeScript Project
To trigger some action before committing, we will use the Git Hook called “pre-commit”. Let's now create an action to execute our 'test'...
Read more >lint-staged - npm
The concept of lint-staged is to run configured linter tasks (or other tasks) on files that are staged in git. lint-staged will always...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Similar issue with
tsc
. Passing files AND project config is not possible.When invoked from husky, it does not find the project folder or configuration 😒 When invoked from bash, it finds the project folder… but the config prevents passing files as args.
Here’s my setup. It works as long as all changes are staged 😛
It’s because you get the filenames passed as an argument. Try using the function syntax. This is what I use: