Problems with Open-Source Downloads read https://www.qt.io/blog/problem-with-open-source-downloads and https://forum.qt.io/post/638946

Clang tidy help



  • Hi!

    I am a complete beginner and wanted to learn more about Code Beautifier and clang tidy. I have never done this before and need your help. :)
    I have a list of formatting rules that I would like to work through with clang tidy.
    I have thought of 15 formatting rules that I want to follow:
    not use /.../ style comments
    make labels easy to see
    ensure consistens line endings
    Layout boolean expression neatly
    balance space around binary operators
    no space after non-word prefix operators
    no space before postfix operators
    avoid more than 60 lines in a block
    no more than 60 characters on a comment line
    avoid more than 500 to 1000 lines per file
    avoid more than 140 character per line
    start each statement or declaration on a new line
    prefer break, continue, and return to deeper nesting
    ident to reflect nesting and continuation of statements and declarations
    avoid more than three levels of nesting
    balance space around braced, bracketed and parenthesized areas

    How are these things possible with clang tidy?
    And is it possible to process multiple files or whole directories at once. For example, is it possible to process all *.c files from a given directory with one command?

    Can you help me please?
    Thanks a lot in advance!

    Best regards
    Shirl



  • And you did research and read up on this before asking someone to show you how, right?

    https://clang.llvm.org/extra/clang-tidy/



  • Hi @shirl
    I think that what you need is a clang-format, not clang-tidy. clang-tidy is a linter, it doesn't format code.
    Useful documentation on clang-format: https://clang.llvm.org/docs/ClangFormat.html
    Here https://www.clangformat.com/ you can try different styles and see how they affect your code.
    And this part:
    avoid more than 60 lines in a block
    no more than 60 characters on a comment line
    avoid more than 500 to 1000 lines per file
    prefer break, continue, and return to deeper nesting

    How do you want to enforce it? Line breaks, whitespace can be added, but what do you want to do here?