I stage JavaScript files that match my lint-staged glob with git add. When I git commit I expect prettier and eslint to run. Instead I get the "No staged files match any of provided globs" message.
However if I run lint-staged directly from node-modules, without triggering a precommit, then prettier and eslint execute and find issues (as expected).
package.json
{
...
"scripts": {
...
"lint": "eslint '**/*.js'",
"lint:fix": "eslint '**/*.js' --fix",
"pretty": "prettier --check '**/*.{js,json}'",
"pretty:fix": "prettier --write '**/*.{js,json}'",
"precommit": "lint-staged",
"postcommit": "git update-index --again"
},
"dependencies": {
...
},
"devDependencies": {
"husky": "^2.3.0",
"lint-staged": "^8.1.7"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"linters": {
"**/*.{js,json}": [
"prettier --write",
"git add"
],
"**/*.js": [
"eslint",
"git add"
]
}
}
}
When running on precommit:
14:43 $ git add .; git commit -m "some message"
husky > pre-commit (node v10.15.3)
No staged files match any of provided globs.
[feature/automate-lint-format 254e671] format and lint
2 files changed, 40 insertions(+), 38 deletions(-)
rewrite etl/test/integration/mycomponent.test.js (72%) # the file was not changed tho π€
When running directly:
14:55 $ ./node_modules/.bin/lint-staged --debug
lint-staged:bin Running `[email protected]` +0ms
lint-staged:find-bin Loaded package.json using `process.cwd()` +0ms
lint-staged Loading config using `cosmiconfig` +0ms
lint-staged Successfully loaded config from `/Users/dnunes/Git/.../etl/package.json`:
lint-staged { linters:
lint-staged { '**/*.{js,json}': [ 'prettier --write', 'git add' ],
lint-staged '**/*.js': [ 'eslint', 'git add' ] } } +8ms
lint-staged:cfg Normalizing config +0ms
lint-staged:cfg Validating config +1ms
Running lint-staged with the following config:
{
linters: {
'**/*.{js,json}': [
'prettier --write',
'git add'
],
'**/*.js': [
'eslint',
'git add'
]
},
concurrent: true,
chunkSize: 9007199254740991,
globOptions: {
matchBase: true,
dot: true
},
ignore: [],
subTaskConcurrency: 1,
renderer: 'verbose',
relative: false
}
lint-staged:run Running all linter scripts +0ms
lint-staged:run Resolved git directory to be `/Users/dnunes/Git/.../myproject/` +0ms
lint-staged:run Loaded list of staged files in git:
lint-staged:run [] +19ms
lint-staged:gen-tasks Generating linter tasks +0ms
lint-staged:cfg Normalizing config +28ms
lint-staged:gen-tasks Generated task:
lint-staged:gen-tasks { pattern: '**/*.{js,json}',
lint-staged:gen-tasks commands: [ 'prettier --write', 'git add' ],
lint-staged:gen-tasks fileList: [] } +0ms
lint-staged:gen-tasks Generated task:
lint-staged:gen-tasks { pattern: '**/*.js',
lint-staged:gen-tasks commands: [ 'eslint', 'git add' ],
lint-staged:gen-tasks fileList: [] } +1ms
No staged files match any of provided globs.
lint-staged linters were executed successfully! +33ms
β ~/Git/.../etl [feature/automate-lint-format βΒ·11|β 2]
14:56 $ git add .
β ~/Git/.../etl [feature/automate-lint-format βΒ·11|β1β 1]
14:56 $ ./node_modules/.bin/lint-staged --debug
lint-staged:bin Running `[email protected]` +0ms
lint-staged:find-bin Loaded package.json using `process.cwd()` +0ms
lint-staged Loading config using `cosmiconfig` +0ms
lint-staged Successfully loaded config from `/Users/dnunes/Git/.../etl/package.json`:
lint-staged { linters:
lint-staged { '**/*.{js,json}': [ 'prettier --write', 'git add' ],
lint-staged '**/*.js': [ 'eslint', 'git add' ] } } +8ms
lint-staged:cfg Normalizing config +0ms
lint-staged:cfg Validating config +1ms
Running lint-staged with the following config:
{
linters: {
'**/*.{js,json}': [
'prettier --write',
'git add'
],
'**/*.js': [
'eslint',
'git add'
]
},
concurrent: true,
chunkSize: 9007199254740991,
globOptions: {
matchBase: true,
dot: true
},
ignore: [],
subTaskConcurrency: 1,
renderer: 'verbose',
relative: false
}
lint-staged:run Running all linter scripts +0ms
lint-staged:run Resolved git directory to be `/Users/dnunes/Git/.../` +0ms
lint-staged:run Loaded list of staged files in git:
lint-staged:run [ 'etl/src/services/common.service.js' ] +20ms
lint-staged:gen-tasks Generating linter tasks +0ms
lint-staged:cfg Normalizing config +28ms
lint-staged:gen-tasks Generated task:
lint-staged:gen-tasks { pattern: '**/*.{js,json}',
lint-staged:gen-tasks commands: [ 'prettier --write', 'git add' ],
lint-staged:gen-tasks fileList:
lint-staged:gen-tasks [ '/Users/dnunes/Git/.../etl/src/services/common.service.js' ] } +17ms
lint-staged:gen-tasks Generated task:
lint-staged:gen-tasks { pattern: '**/*.js',
lint-staged:gen-tasks commands: [ 'eslint', 'git add' ],
lint-staged:gen-tasks fileList:
lint-staged:gen-tasks [ '/Users/dnunes/Git/.../etl/src/services/common.service.js' ] } +2ms
Stashing changes... [started]
Stashing changes... [skipped]
β No partially staged files found...
Running linters... [started]
Running tasks for **/*.{js,json} [started]
Running tasks for **/*.js [started]
lint-staged:make-cmd-tasks Creating listr tasks for commands [ 'prettier --write', 'git add' ] +0ms
lint-staged:find-bin Resolving binary for command `prettier --write` +176ms
lint-staged:find-bin Binary for `prettier --write` resolved to `/Users/dnunes/Git/.../etl/node_modules/.bin/prettier` +3ms
lint-staged:task β OS: darwin; File path chunking unnecessary +0ms
lint-staged:find-bin Resolving binary for command `git add` +0ms
lint-staged:find-bin Binary for `git add` resolved to `/usr/local/bin/git` +1ms
lint-staged:task β OS: darwin; File path chunking unnecessary +2ms
lint-staged:make-cmd-tasks Creating listr tasks for commands [ 'eslint', 'git add' ] +6ms
lint-staged:find-bin Resolving binary for command `eslint` +1ms
lint-staged:find-bin Binary for `eslint` resolved to `/Users/dnunes/Git/.../etl/node_modules/.bin/eslint` +1ms
lint-staged:task β OS: darwin; File path chunking unnecessary +1ms
lint-staged:find-bin Resolving binary for command `git add` +0ms
lint-staged:find-bin Resolving binary for `git` from cache +0ms
lint-staged:task β OS: darwin; File path chunking unnecessary +0ms
prettier --write [started]
eslint [started]
lint-staged:task bin: /Users/dnunes/Git/.../etl/node_modules/.bin/prettier +0ms
lint-staged:task args: [ '--write',
lint-staged:task '/Users/dnunes/Git/.../etl/src/services/common.service.js' ] +0ms
lint-staged:task opts: { reject: false } +6ms
lint-staged:task bin: /Users/dnunes/Git/.../etl/node_modules/.bin/eslint +9ms
lint-staged:task args: [ '/Users/dnunes/Git/.../etl/src/services/common.service.js' ] +0ms
lint-staged:task opts: { reject: false } +0ms
prettier --write [completed]
git add [started]
lint-staged:task bin: /usr/local/bin/git +296ms
lint-staged:task args: [ 'add',
lint-staged:task '/Users/dnunes/Git/.../etl/src/services/common.service.js' ] +0ms
lint-staged:task opts: { reject: false, cwd: '/Users/dnunes/Git/.../' } +0ms
git add [completed]
Running tasks for **/*.{js,json} [completed]
eslint [failed]
β
Running tasks for **/*.js [failed]
β
Running linters... [failed]
β eslint found some errors. Please fix them and try committing again.
/Users/dnunes/Git/.../etl/src/services/common.service.js
10:3 error 'dasddasdas' is not defined no-undef
13:3 error 'dadsaad' is not defined no-undef
β 2 problems (2 errors, 0 warnings)
lint-staged: 8.1.7Try removing **/ from your globs since youβre running in the same directory. There is note about this in the readme.
I also tried that (and it didn't work):
"lint-staged": {
"linters": {
"*.{js,json}": [
"prettier --write",
"git add"
],
"*.js": [
"eslint",
"git add"
]
}
}
This is really weird because I have the same config on another project/repo, in the same machine, and it works fine.
Please find the difference between 2 projects
I've compared both project's package.json and the lint-staged config is the same and there are no major differences in the rest of the file. Is the problem the glob?
I have a monorepo, with a folder for each component with their own package.json. Below is the folder structure of the project that doesn't work:
.
βββ README.md
βββ backend
βΒ Β βββ package.json <--- I'm here
βΒ Β βββ src
βΒ Β βΒ Β βββ *.js
βΒ Β βββ test
βΒ Β βΒ Β βββ integration
βΒ Β βΒ Β βΒ Β βββ *.test.js
βΒ Β βΒ Β βββ sanity
βΒ Β βΒ Β βββ *.test.js
βββ frontend
βΒ Β βββ package.json <--- another lint-staged config will be here
βΒ Β βββ src
βΒ Β βΒ Β βββ *.js
βΒ Β βββ ...
βββ .gitignore
βββ .gitlab-ci.yml
I'm staging and committing files inside the backend folder. Am I using the right glob **/*.{js,json}? I tried etl/**/*.{js,json} but failed as well.
Have you read https://github.com/okonet/lint-staged/blob/master/README.md#filtering-files? It says globs should be relative to package.json. If this isnβt working when Iβd need help resolving this. There is also an issue reported recently that might affect you about absolute paths but it doesnβt look like it.
I ended up using this: https://github.com/sudo-suhas/lint-staged-multi-pkg
Most helpful comment
I ended up using this: https://github.com/sudo-suhas/lint-staged-multi-pkg