-
Notifications
You must be signed in to change notification settings - Fork 22.5k
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
lint-staged: preserve linter fixes after precommit hook fails #28168
Conversation
Thanks Onkar, what are the downsides of this? From the docs:
|
In this repo we are running only linters and an image optimizer. I don't see any case where authors would want their unlinted/unoptimized content back. 😁 To be safe it would be nice if you ping @mdn/core-dev team. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to leave a +1 but it would be great if @hamishwillee can have a try to see if it resolves the issue (I'm not sure if you can reproduce the error).
@OnkarRuikar The formatting was fixed up by the hook, but I still get an error:
|
It is expected. Why do you want to make a commit(empty) that doesn't have any changes?
This will skip all the hooks. If this isn't the case then please provide the file name and the changes you are making. |
I'm an idiot - I was changing a file to see if it would prettify, but not realizing that after prettifying the file would return to its state before committing. I tested this again by copying Looks good to me, but obviously this proves perhaps I'm not the right reviewer :-( |
Still this fix saves us, in this case, from manually reverting the changes after precommit fails. So there is no harm in merging this. |
@LeoMcA could you review and if required merge this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that this is a good idea, here's why:
- In the best case, when lint-staged makes changes, and raises no errors, the behaviour is the same before/after, so that's fine
- In the case when lint-staged makes changes, but also raises an error requiring manual intervention:
- Before: it would revert the changes it made - in a lot of cases this shouldn't matter, whatever change is required should be able to be done in isolation compared to whatever other changes prettier/markdownlint are making, but even if it's not, one can manually run
npx lint-staged --no-stash
oryarn fix:md
or whatever to make the changes again - After: we keep the changes, this is also fine, it saves manually running the linter
- Before: it would revert the changes it made - in a lot of cases this shouldn't matter, whatever change is required should be able to be done in isolation compared to whatever other changes prettier/markdownlint are making, but even if it's not, one can manually run
- In the worst case, where lint-staged fails in a way which is destructive:
- Before: it's all good, it reverts the changes it made, we're back to where we were
- After: uh oh - we've lost content, and it's unlikely to be stored anywhere (
git reflog
won't help if it hasn't been committed), there's no way back to the previous state
Since this change in the best case saves running a command, but in the worst case loses edits, I don't think it's a change we should make.
Happy to be convinced otherwise if I've missed something.
Closing this considering the above comment. |
Seems like the best option. Thanks @LeoMcA for the 2¢ |
Addresses https://github.com/orgs/mdn/discussions/428#discussioncomment-6537591