nx: affected:lint with lint-staged hangs in nx monorepo
I am using affected:lint with lint-staged and noticed it hangs forever when I run npx lint-staged.
wonder if I am doing something wrong.
The command npm run affected:lint -- --uncommitted --fix --parallel itself runs fine.
"lint-staged": {
"{apps,libs}/**/*.{ts,json,md,scss}": [
"npm run affected:lint -- --uncommitted --fix --parallel",
"npm run format:write -- --uncommitted",
"git add"
]
},
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 6
- Comments: 25 (12 by maintainers)
Thanks @meeroslav for confirming the = is not necessary. To amend the previous solution there is no need to use the lint-staged js configuration the following should work, and long list of files that exceed the command length max will be chunked correctly
.husky/pre-commit.lintstagedrc.jsonThe above is not working for me I get the following error:
EDIT: Updated solution here https://github.com/nrwl/nx/issues/869#issuecomment-1022345603
If anyone ends up here again lint-staged is using the full file name not the relative file name. Adding
--relativehttps://github.com/okonet/lint-staged#command-line-flags when invoking lint-staged and using js config to concatenate the file names solve the issue for me.husky/pre-commitlint-staged.config.jsI am a little concerned about the length of the command when making large changes, but this has worked for me a few times
If you want to try to figure out what is going on lint-staged has a
--debugflag, from what I see when using the standard json config it is not sending the files foraffected:lintbut it is forformat:write@sourcier this happens if you omit the
--relativeflag?@JoA-MoS, the signature
--files= somethingis incorrect as variable value needs to follow equals sign if one is added. So this is not an issue in Nx. I’m wondering howformat:writeworks though.These are correct:
The approach with concatenation or using function as mentioned by @iiroj should be a way to go.
I ended up back here and thought I would post an update. Adding a lint-staged config with these settings seems to work
here is how I think i solved this if anyone is interested
lint-staged.config.js