-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
affected:lint with lint-staged hangs in nx monorepo #869
Comments
Hey guys in my case I have the following settings. .huskyrc.json {
"hooks": {
"pre-commit": "yarn lint-staged -c lint-staged.config.js --debug",
"commit-msg": "yarn commitlint -E HUSKY_GIT_PARAMS",
"pre-push": "yarn run lint && yarn run test && yarn run e2e"
}
} lint-staged.config.js module.exports = {
'*.ts': ['sh ./scripts/lint.sh 1', 'git add'],
'*.{js,json,scss,css,md,html}': ['sh ./scripts/lint.sh 0', 'git add']
}; #!/usr/bin/env bash
SHOULD_LINT=$1
shift
SOURCES=$@
DESTINATIONS=""
DELIMITER=""
FIRST=1
set -e
for src in $SOURCES; do
if [ "${FIRST}" -eq "1" ]; then
DELIMITER=""
FIRST=0
else
DELIMITER=","
fi
DESTINATIONS="$DESTINATIONS$DELIMITER${src}"
done
echo "$DESTINATIONS"
yarn run format:write --files="$DESTINATIONS"
if [ "${SHOULD_LINT}" -eq "1" ]; then
yarn run affected:lint --fix --maxParallel=1 --parallel=false --files="$DESTINATIONS";
fi
exit;
Create this script to be able to format the files that really had been changed according to git, since with the flag of "--uncommitted" all will be formatted with prettier, but that could interfere with the rules of tslint, that is why it required that they will pass the files that have changed according to the lint-staged filters. However, it does not work either since the process never ends, although I think that it would be the fault of the commando's parallelism, but it still does not work, I hope this will also help to solve the solution. |
here is how I think i solved this if anyone is interested lint-staged.config.js module.exports = {
'*': (files) => [`nx format:write --files=${files.join(',')}`, `git add ${files.join(' ')}`],
}; |
@JoA-MoS, I had tried that too, but it didn't work, I will try again to try |
Hi, sorry about this. This was mislabeled as stale. We are testing ways to mark not reproducible issues as stale so that we can focus on actionable items but our initial experiment was too broad and unintentionally labeled this issue as stale. |
Folks, could you provide a repo with a repro using the latest version of Nx? Thank you! |
This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. |
I ended up back here and thought I would post an update. Adding a lint-staged config with these settings seems to work
|
Hi @JoA-MoS I'd love to know how you got this working because with this exact config I always encounter an error:
|
Sorry, I forgot that this was posted. I ended up just using eslint that command for lint didn't work the prettier command does. So just running https://github.com/semantic-release-plus/semantic-release-plus/blob/alpha/.lintstagedrc.json It might actually be a bug that lint affected doesn't work the same format |
Yep. Indeed |
The same goes for |
What is the solution? 👀 |
The only way I got it working was using this (default branch name is
but why do I need to specify the branch name here? if in
Am I missing some configuration in |
@fs-innonova can you provide minimal reproduction? The passing of the On the other point, unless you provide By running
inside the nx repo having these two files changed I can see the affected command properly picking them up and finding all their dependents. Also, have in mind that lint-staged is intended to only lint staged files, ignoring possible lint issues in the rest of the application. Nx will always run on the entire project, even if just one file was changed. |
EDIT: Updated solution here #869 (comment)If anyone ends up here again lint-staged is using the full file name not the relative file name. Adding
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npx lint-staged --relative
module.exports = {
'*': (filesArray) => {
const files = filesArray.join();
return [
`nx affected:lint --fix --files=${files}`,
`nx format:write --files=${files}`,
];
},
}; I 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 |
@meeroslav I found the cause of the issue of why lint-staged works with It seems This can be reproduced by running nx commands in the same way This command works
This command does not
Should I create a new issue for NX for this? |
As an FYI, I chatted with lint-staged author and line length could become an issue especially on windows lint-staged/lint-staged#1097 but using a function as shown in my previous comment is a good approach #869 (comment) |
@JoA-MoS, the signature These are correct: # with equals
--files=first,second,third
# without equals
--files first second third The approach with concatenation or using function as mentioned by @iiroj should be a way to go. |
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
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npx lint-staged --relative
{
"*": ["nx affected:lint --fix --files", "nx format:write --files"]
} |
The above is not working for me I get the following error:
|
@sourcier this happens if you omit the |
I added the exact configuration and my commits are not going through. I had the impression that it was working for some time, but suddenly it doesn't work anymore. Although a |
@DaSchTour, I don't have much experience with |
const workspace = require('./workspace.json');
module.exports = {
'*': ['nx format:write --files'],
'**/src/**/*.{js,jsx,ts,tsx}': allStagedFiles => {
const filesProjectMap = new Map(
Object.keys(workspace.projects)
.map(projectName => [
projectName,
allStagedFiles.filter(fileName => fileName.includes(`/${projectName}/`))
])
);
return [...filesProjectMap]
.filter(([project, files]) => files.length)
.map(([projectName, files]) => `nx lint ${projectName} --lintFilePatterns=${files.join(',')}`);
}
}; |
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context. |
I am using
affected:lint
withlint-staged
and noticed it hangs forever when I runnpx lint-staged
.wonder if I am doing something wrong.
The command
npm run affected:lint -- --uncommitted --fix --parallel
itself runs fine.Ref:
lint-staged/lint-staged#522
The text was updated successfully, but these errors were encountered: