Prevent lint-staged from running in all packages (monorepo)

See original GitHub issue

Description

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 packageA is found and has configuration for lint-staged, scripts specified are run
      • package.json in packageB is also found, since it seems to search for package.json’s in the whole project
  • Changes are detected in packageB
    • cd packageB && yarn lint-staged
      • package.json in packageB is found and has configuration for lint-staged, scripts specified are run
      • package.json in packageA is also found, since it seems to search for package.json’s in the whole project

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:closed
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
iirojcommented, Mar 2, 2022

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!

0reactions
iirojcommented, Mar 5, 2022

Version 12.3.5 is now released.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Running multiple instances of lint-staged in a monorepo leads ...
Either switch to sequential or avoid lint-staged (lint the whole codebase, not only a portion of files intended for a new commit).
Read more >
How to use lint-staged in a lerna monorepo to run the same ...
The solution involves using git commands in the package.json to stash files that are untracked and not staged, perform the test, and then...
Read more >
Setup lint-staged on a Monorepo | Horacio Herrera
lint -staged will run the root's lint script, and Yarn workspaces will run each package lint script using the yarn workspaces run lint...
Read more >
lint-staged - npm
The concept of lint-staged is to run configured linter tasks (or other tasks) on files that are staged in git. lint-staged will always...
Read more >
Turborepo Tutorial | Part 1 - Typescript, Eslint, Tailwind, Husky ...
... use our different workspace packages within our different applications. ... configs 48:00 shared tailwind ui 56:00 husky and lint staged ...
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