-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent ClangFormat From Breaking Before Curly Braces
- Loading branch information
1 parent
8653ae9
commit 23b677a
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
c/prevent-clangformat-from-breaking-before-curly-braces.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Prevent ClangFormat From Breaking Before Curly Braces | ||
|
||
For some unfathomable reason, C and C++ developers sometimes put line breaks before curly braces: | ||
|
||
```c | ||
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](https://clang.llvm.org/docs/ClangFormat.html). | ||
|
||
Fortunately, it's configurable by setting the [`BreakBeforeBraces` option](https://clang.llvm.org/docs/ClangFormatStyleOptions.html#breakbeforebraces) to `Attach` in your `.clang-format` file: | ||
|
||
``` | ||
BreakBeforeBraces: Attach | ||
``` | ||
|
||
Much more readable: | ||
|
||
```c | ||
int main() { | ||
for (int i = 0; i < 10; i++) { | ||
printf("%d\n", i); | ||
} | ||
} | ||
``` |