Questions tagged [lint-staged]
98 questions
133
votes
29 answers
lint-staged not running on precommit
prettier is not running on precommit. This worked with the same configuration in other projects, so I'm baffled why it's not working this time.
This is the relevant section of my package.json file:
"scripts": {
"precommit": "lint-staged"
…

Andrew Horn
- 2,291
- 2
- 16
- 26
94
votes
3 answers
Error while loading rule '@typescript-eslint/dot-notation'
Today I run eslint,two script
"lint-staged": "lint-staged",
"eslint": "eslint --ext .tsx,.ts --fix ./src -c .eslintrc.js",
When I run npm run eslint // it's ok
When I run npm run lint-staged // it's wrong
lint-staged's result ;
> lint-staged
❯…

leofu
- 941
- 1
- 6
- 6
41
votes
10 answers
VSCODE & GitHub Desktop pre-commit hook: npx: command not found
I am starting a new repo, thinking I should use the most recent Huksy v6 which is installed from LintStaged using their setup guide:
npx mrm lint-staged
// package.json updated with:
"husky": ">=6",
"lint-staged": ">=10",
This adds necessary…

Phil Lucks
- 2,704
- 6
- 31
- 57
24
votes
5 answers
How do I get lint-staged working with Husky version 6
I try to use Husky's pre-commit and lint-staged.
Those are installed:
"husky": "^5.1.3",
"lint-staged": "^10.5.4",
In package.json I have:
"scripts": {
"build": "gatsby build",
"develop": "gatsby develop",
"format": "prettier --write…

meez
- 3,783
- 5
- 37
- 91
23
votes
5 answers
Run eslint "ONLY" on the staged files
I am trying to use a pre-commit hook to detect eslint errors before commit happens. I am using husky and lint-staged. But it runs the lint command for all the files in src and not on staged files only. Here is my package.json file.
"scripts": {
…

Prateek
- 335
- 1
- 2
- 9
23
votes
6 answers
Husky/lint-staged is it possible to exclude/ignore file?
Is it possible to exclude/ignore a file when using Husky/lint-staged hooks?
Looking through the docs atm but not having any luck finding anything on this.
Was hoping there was something like an
/*ignore*/
tag that I could add.
To make lint-staged…

uidevthing
- 1,781
- 2
- 12
- 24
18
votes
2 answers
Why are my changes gone after a cancelled git commit and how do I recover them?
Here's what I did:
Coded 8 hours worth of changes.
git status displays all my changes.
git add -A
git commit -m "Foo". A pre-commit git hook fires with husky and lint-staged.
I remember that there's a TypeScript typing error I failed to fix, so I…

Andrey Mikhaylov - lolmaus
- 23,107
- 6
- 84
- 133
17
votes
2 answers
How to lint for Typescript compilation issues?
Take the following Typescript arrow function:
/**
* Returns a probably unique component name.
*
* @param baseName a suggested name to make unique.
* @returns a probably unique name.
*/
export const getUniqueComponentName = (
baseName
):…

Tom
- 8,536
- 31
- 133
- 232
16
votes
5 answers
Is this a right way to use husky + lint-staged?
I found numerous blogs (including the lint-staged doc) introducing such a way to use husky+ lint-staged as the following code defined in the package.json:
{
"scripts": {
"precommit": "lint-staged"
},
"lint-staged": {
"src/**/*.js":…

Shawn Chen
- 1,017
- 2
- 13
- 24
14
votes
2 answers
lint-staged: what the purpose of 'git add' command
Recently I started to introduce lint-staged into my Frontend build tool chain. And when I checked the document about it, I always find it works as following:
"husky": {
"hooks": {
"pre-commit": "lint-staged"
},
"lint-staged": {
…

Chris Bao
- 2,418
- 8
- 35
- 62
13
votes
1 answer
How do I solve this empty git commit warning?
After pushing my code to the remote branch and creating a PR. I wanted to make some more changes to my code and then commit to the remote branch again
First, I started these steps:
git add .
git commit -m "Remove semicolons, change to multi line…

KYin
- 439
- 1
- 5
- 21
13
votes
2 answers
Prettier: Run for only the changed lines of the file
I have a legacy codebase without eslint/prettier. I want to introduce formatting on pre-commit hooks. Lint staged will let you run prettier for only changed files. Is it possible to only run the prettier just for changed lines? Like IntelliJ's…

sreejith
- 213
- 2
- 8
10
votes
2 answers
How to use lint-staged with jest --collectCoverageFrom
I'm using lint-staged with Jest testing framework to test only changed files from last commit as described in this blog.
My configuration is as below:
"src/**/*.{ts}": [
"prettier --write",
"tslint --fix --project .",
"jest --bail…

özüm
- 1,166
- 11
- 23
9
votes
1 answer
Multiple run lint-staged when use with husky
When I use npx lint-staged in the terminal everything looks ok.
For example:
PS E:\Projects\sample-project> git status
On branch main
Your branch is up to date with 'origin/main'.
Changes to be committed:
(use "git restore --staged ..." to…

Kordrad
- 1,154
- 7
- 18
9
votes
1 answer
npx mrm lint-staged erroring out with 'Preset "default" not found."
Example of the issue:
❯ npx mrm lint-staged
npx: installed 298 in 9.141s
Preset “default” not found.
We’ve tried to load “mrm-preset-default” and “default” npm packages.
Can't run this command and I don't know why!

mishchief
- 412
- 3
- 13