question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

feature request: mode to exit 0 if only autofixes were triggered

See original GitHub issue

i did a quick search on existing issues but didn’t find one that matched what I want. apologies if this is a duplicate.


sometimes i find myself running pre-commit run -a twice, usually in a script. this most recently happened when i needed to run all my linters as a part of a script. (exact details are described in this issue https://github.com/lerna/lerna/issues/1415#issuecomment-455790478 ; basically, using lerna to publish a package to npm involves editing a json file and committing the change, and i need to configure a script to run prettier via pre-commit before this commit happens.)

my first try was to run pre-commit run -a && ... && git add .... it did reformat the json file as I wanted, but then the script invocation failed because the call to pre-commit exited with a non-zero code. the fix was to change the script invocation to pre-commit run -a; pre-commit run -a && ... && git add .... this makes it to where the first invocation of pre-commit can return any code; assuming that only autofixes were applied, the second invocation should succeed.

i think that when running pre-commit as a generalized lint-runner, the desired behavior changes to the following:

  • if everything is green, exit 0
  • if things were autofixed, but otherwise everything is ok, still exit 0
  • if something is broken and/or not autofix-able, exit nonzero

my feature request is for pre-commit to provide this behavior as a flag, perhaps as a part of the run command.


anecdotally, i separately remember seeing @mxr 's dotfile, and his alias for git commit -m "$msg" was actually something like git commit -m "$msg" || git commit -m "$msg" for a similar reason- he basically just wanted to take all pre-commit autofixes as a part of his commit, but still fail the commit if pre-commit didn’t pass beyond those autofixes.


@asottile i’d like to hear whether this is something you’d be open to having in your project. and if you’re open to it, i volunteer @mxr to write the feature

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
mxrcommented, Feb 9, 2022

Yeah it’s a deliberate design decision that any hook changes require user confirmation, since hooks may not be trustworthy. There are closed issues about this already (I volunteer @ryanrhee to go find them)

This is my alias if you decide to trust your hooks 🤷

1reaction
asottilecommented, Feb 9, 2022

pre-commit doesn’t have enough information to satisfy this – and commonly tools exit nonzero when making changes so even if it were possible to have the information the two states would be indistinguishable (a tool “successfully” making changes vs. a tool making some changes and erroring). my recommendation is to pre-commit run --all-files || pre-commit run --all-files and is typically what I do

Read more comments on GitHub >

github_iconTop Results From Across the Web

pre-commit
We built pre-commit to solve our hook issues. It is a multi-language package manager for pre-commit hooks. You specify a list of hooks...
Read more >
Troubleshoot Linux VM boot issues due to fstab errors
This article discusses multiple conditions where a wrong fstab configuration can lead to boot issue and provides troubleshooting guidance. Few ...
Read more >
Command Line Interface - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
Error Codes | Yarn - Package Manager
This error is triggered when Git conflict tokens are found within the yarn.lock file while Yarn is executing under the immutable mode (...
Read more >
Toggle between feature request modes - ArcGIS Developers
Use the latest version of ArcGIS Runtime for iOS to build powerful mobile apps that incorporate capabilities such as mapping, geocoding, routing, ...
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