-
-
Notifications
You must be signed in to change notification settings - Fork 307
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
contributing: Add .clang-format #2272
Conversation
+1 given the advantages of clang-format over GNU Indent (also considering we may want to indent modern C++). My experience is that clang-format is not stable in between versions, so to check with exact version in the CI, we need to use DoozyX/clang-format-lint-action. We will also need to update it time to time like we did with Black before it was stable (and still will have to update but with less changes in the source code). BTW, the actual formatting (formatting only) changes should go to |
ddbb123
to
7447d4c
Compare
Just updated the I also limited the number of formatted example files, for better and quicker overview online.
Yes, I'm aware of this circumstances with ClangFormat versions, but I think the advantages compared to GNU indent are worth it. You're right, Black is a good parallel. |
41b797a
to
7800e48
Compare
Fixed some more settings to get even closer to present "GRASS" style and updated the demo files accordingly. GRASS style's Mozilla: class UntypedStream
{
...
} else { Stroustrup: enum rule_type {
...
struct Cell_head {
...
typedef union _dglHeapData {
...
extern "C" {
Linux: enum AMI_stream_type {
...
struct Cell_head {
...
union {
...
class AMI_STREAM : public UntypedStream
{
...
} else {
...
extern "C" {
WebKit: enum AMI_stream_type {
...
struct Cell_head {
...
union {
...
} else {
...
extern "C" {
Even though I'm perfectly ok with present GRASS style, I must say I personally prefer to convert to Stroustrup brace breaking style. |
@nilason would you mind to redo the reformatting afresh on top of the current state of "main"? |
Certainly! Hopefully this crazy busy summer will soon reach the end. I look forward to return to a more active contribution. :-) |
aa2fc21
to
640de4e
Compare
Just updated the formatted examples on current main. |
640de4e
to
97d4987
Compare
97d4987
to
aff3792
Compare
This is a suggestion to replace GNU indent with clang-format.
Attempting to bulk process the code base with
util/grass_indent_ALL.sh
as reported in #1630 (and noticed in #2270) a number of problem occurs. This is caused by limited functionality and lack of active development on GNU indent.However, bulk processing with clang-format causes no error, thanks to the fact that it is backed by a full C and (!) C++ code parser.
Replacing the GRASS formatting tool to clang-format may be the better bet for the future.
Initially I put this up as a draft, for testing and discussion. I tried to get the settings as close as the present style guide, the one notable deviation (I could discover so far) is with alignment of trailing comments.
The
.clang-format
file is created with clang-format version 13.Note: only the addition of the
.clang-format
is the ultimate goal for this PR. The added commit with all the formatted source files are for illustration only.To test this locally:
find -E . -regex '.*\.(cpp|hpp|c|h)' -exec clang-format -style=file -i {} \;
for testing alternative settings see https://clang.llvm.org/docs/ClangFormatStyleOptions.html
For reference, description of the settings in
util/grass_indent.sh
: