Skip to content
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

clang-format stops working when using --version #44

Open
mintar opened this issue Apr 6, 2022 · 5 comments
Open

clang-format stops working when using --version #44

mintar opened this issue Apr 6, 2022 · 5 comments

Comments

@mintar
Copy link

mintar commented Apr 6, 2022

With the default test repo (pre-commit-hooks/tests/test_repo) and the following config...

fail_fast: false
repos:
  - repo: https://github.com/pocc/pre-commit-hooks
    rev: v1.3.5
    hooks:
      - id: clang-format
        args: [--version=10.0.0, --style=Google]

... the following happens (incorrectly, it should detect the incorrect formatting):

$ pre-commit run -a
clang-format.............................................................Passed

But when I remove --version=10.0.0, it's working:

$ pre-commit run -a
clang-format.............................................................Failed
- hook id: clang-format
- exit code: 1

err.cpp
====================
--- original

+++ formatted

@@ -1,2 +1,5 @@

 #include <string>
-int main(){int i;return;}
+int main() {
+  int i;
+  return;
+}
err.c
====================
--- original

+++ formatted

@@ -1,2 +1,5 @@

 #include <stdio.h>
-int main(){int i;return;}
+int main() {
+  int i;
+  return;
+}
@pocc pocc changed the title clang-tidy stops working when using --version clang-format stops working when using --version Apr 13, 2022
@pocc
Copy link
Owner

pocc commented Apr 13, 2022

Thank you for the feedback. I see this is an issue, and I'm investigating it.

@nielskm
Copy link

nielskm commented Sep 23, 2022

This is the case for clang-tidy as well. Any ideas on how to fix this?

@nielskm
Copy link

nielskm commented Sep 23, 2022

Isn't the problem simply that you don't remove the --version argument from args in Command.parse_args.

@ypearson
Copy link

ypearson commented Nov 23, 2022

I get the same error, specifying the version "fixes" it

@ascended121
Copy link

It seems likely that the problem is with assert_version(). That method exits with a success code if the correct version of the executable is found, which pre-commit interprets as the hook running successfully.

That means that execution never continues once assert_version()... either an exception is raised if the wrong version is found or the program exits successfully if the right version is found.

It seems like maybe the successful exit line should be removed so that the hook can actually run after the version is confirmed.

If that looks like the right fix, I'm happy to submit a PR if that's welcome @pocc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants