Skip to content

Latest commit

 

History

History
31 lines (24 loc) · 700 Bytes

prevent-clangformat-from-breaking-before-curly-braces.md

File metadata and controls

31 lines (24 loc) · 700 Bytes

Prevent ClangFormat from breaking before curly braces

For some unfathomable reason, C and C++ developers sometimes put line breaks before curly braces:

int main()
{
  for (int i = 0; i < 10; i++)
  {
    printf("%d\n", i);
  }
}

It's also the default formatting style in the code formatter ClangFormat.

Fortunately, it's configurable by setting the BreakBeforeBraces option to Attach in your .clang-format file:

BreakBeforeBraces: Attach

Much more readable:

int main() {
  for (int i = 0; i < 10; i++) {
    printf("%d\n", i);
  }
}