lint-staged icon indicating copy to clipboard operation
lint-staged copied to clipboard

No staged files match any of provided globs

Open kartikpandey2 opened this issue 6 years ago • 23 comments

Description

Folder Structure

folder Structure

Both client and server have package.json with different lint-staged config

client/package.json

"husky": {
    "hooks": {
      "pre-commit": "lint-staged",
      "pre-push": "lint-staged"
    }
  },
  "lint-staged": {
    "*": [
      "prettier --write",
      "eslint",
      "git add"
    ]
  }

server/package.json

"husky": {
    "hooks": {
      "pre-commit": "lint-staged",
      "pre-push": "lint-staged"
    }
  },
  "lint-staged": {
    "*.js": [
      "prettier --write",
      "eslint",
      "git add"
    ]
  }

lint-stage is working on the staged files of the server folder but not working staged files of the client folder instead it complains about No staged files match any of provided globs. But if I run npx lint-staged -d from the client folder using cmd, lint-stage works on staged files of the client folder.

Environment

  • OS: Windows 10
  • Node.js: v10.15.0
  • lint-staged: 9.2.0

kartikpandey2 avatar Aug 05 '19 17:08 kartikpandey2

This seems like a monorepo problem, which we cover in our README.md.

I think the problem boils down to the git directory being different than the working directory (client/server).

iiroj avatar Sep 19 '19 04:09 iiroj

the same problem

guanrongjia avatar Jan 16 '20 10:01 guanrongjia

I am not sure, but

"scripts": {
"lint:ts": "eslint \"packages/**/*.{tsx,ts}\"", // ok =)
"lint:ts": "eslint 'packages/**/*.{tsx,ts}'", // no matches =(
},
  "lint-staged": {
    "packages/**/*.{tsx,ts}": "eslint --cache --fix ", // =(
    "**/*.{tsx,ts}": "eslint --cache --fix ", // =(
    "**/*.{tsx,ts,js}": "eslint --cache --fix ", // files only in one package matched =(
    "packages/**/*.css": "stylelint --fix"  // =(
  }

I have one root git directory. Maybe I'm a fool, but I expected the same with "scripts" result. My repo: https://github.com/NikitaIT/boilerplate/tree/add-eslint last commit: https://github.com/NikitaIT/boilerplate/commit/07952a59fcb1fcb1ae6ddc454d05279fbe608fb7

NikitaIT avatar Jan 30 '20 02:01 NikitaIT

I started getting this issue. I have a normal repo, my config looks like

{
  "scripts": {
	"test": "NODE_ENV=test jest --passWithNoTests",
    "build": "echo 'OK'",
    "prettify": "prettier --write",
    "prettify-all": "prettier --write \"./**/*.{js,scss,json}\"",
    "lint": "eslint",
    "lint-all": "eslint \"**/*.js\""
  },
  "devDependencies": {
    "eslint": "^6.8.0",
    "eslint-config-prettier": "^6.10.0",
    "eslint-loader": "^3.0.3",
    "eslint-plugin-jest": "^23.7.0",
    "eslint-plugin-prettier": "^3.1.2",
    "eslint-plugin-react": "^7.18.3",
    "husky": "^4.2.1",
    "lint-staged": "^10.0.7",
    "prettier": "^1.19.1"
  },
  "lint-staged": {
    "*.{js}": [
      "npm run prettify",
      "npm run lint"
    ],
    "*.{json}": [
      "npm run prettify"
    ]
  },
  "husky": {
    "hooks": {
      "pre-commit": "lint-staged && npm run test && npm run build"
    }
  },
  "dependencies": {}
}

And no tasks are run even though I actually had some JS files staged.

Also, another part of the pre-commit command was failing (the test command was wrong) but it was hidden and non-informative "pre-commit hook failed (add --no-verify to bypass)" message was shown.

emirotin avatar Feb 13 '20 12:02 emirotin

I have the same issue.

Folder structure is the following:

client
  package.json // with local pre-commit rules (src/**/*.{js,jsx})

server
  package.json // with local pre-commit rules (src/**/*.ts)

The one in the 'server' folder works fine, but the one in client just throws: No staged files match any of provided globs

Both husky and lint-staged versions in both directories are the same.

aloeugene avatar Mar 19 '20 16:03 aloeugene

removing the node_modules folder and running npm install solved this for me.

uzikilon avatar Mar 22 '20 10:03 uzikilon

It's going to be a year-old issue soon (or 2+ months old for me personally) and nothing has changed.

I'm currently building a template for the students' projects and if this is not going to work I should look into an alternative.

UPD: I think the issue is when using the {} syntax like *.{js}

emirotin avatar Apr 17 '20 14:04 emirotin

@emirotin if that’s the case, it sounds like an issue with the upstream dependency micromatch.

iiroj avatar Apr 17 '20 16:04 iiroj

Could be, for me it's just that the patch upgrade has broken the existing config

emirotin avatar Apr 17 '20 18:04 emirotin

I’m sorry, but I’ll need those debug logs and configurations to be able to do anything.

iiroj avatar Apr 17 '20 18:04 iiroj

You can find my config in my comment from Feb https://github.com/okonet/lint-staged/issues/682#issuecomment-585729946

emirotin avatar Apr 17 '20 19:04 emirotin

I'm having the same issue, which is indeed fixed by omitting the curly braces {}.

For me *.{sh} did not work, but *.sh works.

OS: Windows 10 Node.js: v12.2.0 lint-staged: 8.1.7

Exact same behaviour for MacOS

OS: MacOS 10.14.5 Node.js: v12.2.0 lint-staged: 8.1.7

webbertakken avatar Apr 20 '20 10:04 webbertakken

As a curiosity, do the curly braces only work when there are multiple items inside it? Maybe this could be reported as a bug to micromatch.

iiroj avatar Apr 20 '20 10:04 iiroj

@emirotin Have you tried configuring lint-staged using the .lintstagedrc.json file instead of package.json? This resolved the issue for me.

mikoz93 avatar May 01 '20 23:05 mikoz93

Didn't try anything new since I figured out the braces issue.

On Sat, May 2, 2020, 02:45 Michal Kozakiewicz [email protected] wrote:

@emirotin https://github.com/emirotin Have you tried configuring lint-staged using the .lintstagedrc.json file instead of package.json? This resolved the issue for me.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/okonet/lint-staged/issues/682#issuecomment-622613035, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEAMCHLM66L75DJ2ZDZZ63RPNNH7ANCNFSM4IJNQIZA .

emirotin avatar May 02 '20 08:05 emirotin

I guess there must be serious technical constraints in order for lint-staged to not work on multi-packages monorepos without Lerna at subrepo level and not root. In our case we cannot have all linters at root level because each subrepo has a different configuration and versioning.

It's a total pity because lint-staged is a must-have package on any npm project.

EDIT: actually I got it working with only one Husky and lint-staged configuration on the root package.json:

// package.json:

  "husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },
  "lint-staged": {
    "project1/**/*.{js,jsx,ts,tsx}": [
      "cd project1",
      "eslint --fix",
      "prettier --write"
    ],
    "project2/**/*.{js,jsx,ts,tsx}": [
      "cd project2",
      "eslint --fix",
      "prettier --write"
    ]
  }

AntonioRedondo avatar Jul 18 '20 21:07 AntonioRedondo

@AntonioRedondo that cd project1 doesn't do anything related to the following commands, especially when you're not using the --shell option. I don't recommend using shell either, since it's potentially unsafe. In your config it will run eslint and prettier from the repo root, but pass different files to each. Maybe combine that with explicit config files like eslint -c project1/.eslintrc.json --version.

iiroj avatar Jul 19 '20 07:07 iiroj

Oops, my example contained a bug, it's eslint --fix, not eslint --version. That --version came from the troubleshooting I did to make linting working.

AntonioRedondo avatar Jul 19 '20 10:07 AntonioRedondo

So what i did was i removed. "husky": { "hooks": { "pre-commit": "lint-staged && npm run precommit" } from package.json and now i can commit my project to bitbucket.

ishtact avatar Aug 20 '20 12:08 ishtact

It worked for me when I downgraded "lint-staged" package from "10.5.1" to "10.2.11" and removed node_modules and reinstalled it.

gandhirahul avatar Feb 04 '21 12:02 gandhirahul

I guess there must be serious technical constraints in order for lint-staged to not work on multi-packages monorepos without Lerna at subrepo level and not root. In our case we cannot have all linters at root level because each subrepo has a different configuration and versioning.

It's a total pity because lint-staged is a must-have package on any npm project.

EDIT: actually I got it working with only one Husky and lint-staged configuration on the root package.json:

// package.json:

  "husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },
  "lint-staged": {
    "project1/**/*.{js,jsx,ts,tsx}": [
      "cd project1",
      "eslint --fix",
      "prettier --write"
    ],
    "project2/**/*.{js,jsx,ts,tsx}": [
      "cd project2",
      "eslint --fix",
      "prettier --write"
    ]
  }

actually assuming your lerna packages are scoped with @AntonioRedondo you can just do this:


  "husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },
  "lint-staged": {
    "project1/**/*.{js,jsx,ts,tsx}": [
      "yarn workspace @AntonioRedondo/project1 lint",
    ],
    "project2/**/*.{js,jsx,ts,tsx}": [
      "yarn workspace @AntonioRedondo/project2 lint",
    ]
  }

then in your project1 and project2 package.json have this script:

"name" "@AntonioRedondo/project2",
...
"scripts": {
  "lint": "npm-run-all lint:eslint lint:prettier",
  "lint:eslint": "eslint --fix",
  "lint:prettier": "prettier --write",
}
...

this doesn't even require that you're using lerna, just yarn workspaces (or both)

airtonix avatar Feb 09 '21 06:02 airtonix

removing the node_modules folder and running npm install solved this for me.

for me, reomve yarn.lock or package.lock file too

YorickLane avatar Feb 27 '21 04:02 YorickLane

I'll +1 @uzikilon's solution. I am in a tradition repo with all code under src/. I'd been playing with .eslintignore files at the root level and subdirectories. Eventually scrubbed that approach and removed all .eslintignores from the repo. At that point I was unable to commit anything. Recreating node_modules fixed it. Using [email protected].

maslade avatar Jul 15 '21 12:07 maslade