Code Monkey home page Code Monkey logo

Comments (6)

MarkKoz avatar MarkKoz commented on August 25, 2024

Actually, it only seems to exit with code 1 through pre-commit. If I invoke clang-tidy directly, it shows the warnings were suppressed but exits with code 0.

$ clang-tidy --fix -p cmake-build-debug src/main.c
2816 warnings generated.
Suppressed 2816 warnings (2816 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
$ echo $?
0
clang-tidy...............................................................Failed
- hook id: clang-tidy
- exit code: 1

2816 warnings generated.
Suppressed 2816 warnings (2816 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
repos:
    - repo: https://github.com/pocc/pre-commit-hooks
      rev: v1.3.3
      hooks:
          - id: clang-format
            args: [-i, --style=file]
          - id: clang-tidy
            args: [--fix, -p=cmake-build-debug]

My solution for now is to use a local hook:

repos:
    - repo: local
      hooks:
          - id: clang-tidy
            name: clang-tidy
            description: Statically analyse files with clang-tidy.
            entry: clang-tidy --fix -p=cmake-build-debug
            language: system
            types: [c]

Frankly, I don't really see what the clang-tidy hook here has to offer over the above.

from pre-commit-hooks.

pocc avatar pocc commented on August 25, 2024

What version of llvm are you using? What OS are you on? The test ok file uses <stdio.h> and the test passes. I'll take a look at it.

from pre-commit-hooks.

pocc avatar pocc commented on August 25, 2024

Can you provide your src/main.c as well (or a link to the repo that has it)? I'm not able to replicate this on Linux or Macos.

from pre-commit-hooks.

pocc avatar pocc commented on August 25, 2024

Adding some tests for double-dash arguments -- --std=c++20, I got a test that failed (try using -- args with your local hook). I'm guessing the default language target on your system is higher than mine?

Most recent commit is 661e54b - can you set rev to that and see if you still have issues?

from pre-commit-hooks.

MarkKoz avatar MarkKoz commented on August 25, 2024

Sorry for a late response. I did get together a minimal reproducible example, but I tried that new ref, and it indeed fixes the issue. I was going to point out that clang-tidy was outputting to stderr and the hook always failed if it saw anything in stderr, but you caught onto that already.

For posterity, I suppose I'll attach the example anyway since I already made it. It can be reproduced through Docker.

test.zip

I'm guessing the default language target on your system is higher than mine?

I don't know; I specify it through CMake. I thought clang-tidy somehow determines the language target by reading compile_commands.json.

from pre-commit-hooks.

pocc avatar pocc commented on August 25, 2024

Looks like your language target is C 99. I added this as a test in tests/test_iss36.py.

Thanks for providing your example files.

from pre-commit-hooks.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.