question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't find staged files matching glob, but does find when not on pre-commit

See original GitHub issue

Description

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).

Steps to reproduce

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"
      ]
    }
  }
}

Debug Logs

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:

expand to view
14:55 $ ./node_modules/.bin/lint-staged --debug
  lint-staged:bin Running `lint-staged@8.1.7` +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 `lint-staged@8.1.7` +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)

Environment

  • OS: macOS 10.14.5
  • Node.js: 10.15.3
  • lint-staged: 8.1.7

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
dialexcommented, Jun 2, 2019
2reactions
okonetcommented, May 27, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Lint-staged can't find staged files matching glob - Stack Overflow
I'm working with NodeJS Typescript and I wanted to set lint-staged to validate my files before commit but it is not working.
Read more >
lint-staged - npm
Linter commands work on a subset of all staged files, defined by a glob pattern. lint-staged uses micromatch for matching files with the ......
Read more >
pre-commit: Various Ways to Run Hooks - Adam Johnson
You can run a single hook by specifying its ID: $ pre-commit run trailing-whitespace [WARNING] Unstaged files detected. [INFO] Stashing unstaged ...
Read more >
Frontend Handbook | Code Quality / Tools - Infinum
No matter which code quality tools we use, git hooks are a great way to ... What lint-staged does is it matches files...
Read more >
Linting Staged Git Files with lint-staged -- newline - Fullstack.io
You can configure lint-staged to run a specific linter command against files that match a glob pattern. For JavaScript files ( *.js ) ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found