newlinestatic-analysisclang-format

ClangFormat style to handle non-idiomatic whitespace?


Are there any ClangFormat styles (or other tools) which will handle excessive newlines? With two or more newlines after the function parameter parentheses, as in the example below, none of the styles I tried (LLVM, Google, Chromium, Mozilla, WebKit, Microsoft, GNU) remove the extra line break.

void test()

{
  return 0;
}

Solution

  • Maybe this?

    # FILE: abc.clang-format21
    MaxEmptyLinesToKeep: 0
    AllowShortFunctionsOnASingleLine: false
    

    Output:

    clang-format-21 --style=file:abc.clang-format21 source.c
    
    void test() {
      return 0;
    }