Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Style: Remove new line at block start, enforce line between functions, enforce braces in if and loop blocks #38738

Merged

Conversation

akien-mga
Copy link
Member

@akien-mga akien-mga commented May 14, 2020

You got that Allman spacey look in your files
And I got that screen tight, braceless if that you like
Yet when we go crashing down, we run hooks every time
'Cause we never go out of style, we never go out of style
You've got those long pedantic clang-tidy checks
And I got that perl-fu to fix what tools don't get
And when we go crashing down, we run hooks every time
'Cause we never go out of style, with the One True Brace Style


Part of #33027.

Which means that reduz' beloved style which we all became used to
will now be changed automatically to remove the first empty line.

This makes us lean closer to 1TBS (the one true brace style) instead
of hybridating it with some Allman-inspired spacing.

There's still the case of braces around single-statement blocks that
needs to be addressed (but clang-format can't help with that, but
clang-tidy may if we agree about it).

Part of godotengine#33027.
I couldn't find a tool that enforces it, so I went the manual route:
```
find -name "thirdparty" -prune \
  -o -name "*.cpp" -o -name "*.h" -o -name "*.m" -o -name "*.mm" \
  -o -name "*.glsl" > files
perl -0777 -pi -e 's/\n}\n([^#])/\n}\n\n\1/g' $(cat files)
misc/scripts/fix_style.sh -c
```

This adds a newline after all `}` on the first column, unless they
are followed by `#` (typically `#endif`). This leads to having lots
of places with two lines between function/class definitions, but
clang-format then fixes it as we enforce max one line of separation.

This doesn't fix potential occurrences of function definitions which
are indented (e.g. for a helper class defined in a .cpp), but it's
better than nothing. Also can't be made to run easily on CI/hooks so
we'll have to be careful with new code.

Part of godotengine#33027.
@akien-mga
Copy link
Member Author

akien-mga commented May 14, 2020

Duh! Here be bugs, I spent over 2 hours fixing breakage introduced by https://clang.llvm.org/extra/clang-tidy/checks/readability-braces-around-statements.html in that last commit... there might be more that I didn't catch while compiling and reviewing the diff.

@groud
Copy link
Member

groud commented May 14, 2020

Nice poem :D

@akien-mga akien-mga force-pushed the cause-we-never-go-out-of-style branch from 77fb6b8 to 0ee0fa4 Compare May 14, 2020 19:58
@akien-mga akien-mga merged commit 00949f0 into godotengine:master May 14, 2020
@akien-mga akien-mga deleted the cause-we-never-go-out-of-style branch May 14, 2020 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants