Prevent lint-staged from running in all packages (monorepo)
See original GitHub issueDescription
Currently working on a monorepo project that has the following structure:
├── ...
├── .husky
│ └── pre-commit.sh
├── packageA
│ ├── src
│ ├── package.json
│ └── ...
├── packageB
│ ├── src
│ ├── package.json
│ └── ...
├── ...
Both packages have lint-staged installed. I do not have a package.json at root level.
In the pre-commit hook i’m determining whether changes occur in packageA or packageB. Ideally i’d like to run lint-staged only on files in packageA if there are changes in packageA and only in packageB if there are changes packageB.
What happens is if both packages have changes:
- Changes are detected in
packageA- cd packageA && yarn lint-staged
- package.json in
packageAis found and has configuration for lint-staged, scripts specified are run - package.json in
packageBis also found, since it seems to search for package.json’s in the whole project
- package.json in
- cd packageA && yarn lint-staged
- Changes are detected in
packageB- cd packageB && yarn lint-staged
- package.json in
packageBis found and has configuration for lint-staged, scripts specified are run - package.json in
packageAis also found, since it seems to search for package.json’s in the whole project
- package.json in
- cd packageB && yarn lint-staged
This results in staged files of both packages being linted twice. Ideally i would lint-staged to only run on the closest package.json. This isn’t really too much of an issue, since i can simply run lint-staged on any of the packages and the other changes are detected as well, but im quite curious if there’s a better way to achieve this or if there’s an argument i can pass to lint-staged.
cheers
Issue Analytics
- State:
- Created 2 years ago
- Comments:5
Top Related StackOverflow Question
Lint-staged will automatically find the configurations inside your project. It’s just that there’s a bug in the current implementation, keep track of that PR for it to get fixed!
Version 12.3.5 is now released.