igmpproxy icon indicating copy to clipboard operation
igmpproxy copied to clipboard

Introduce default format for code base.

Open ViToni opened this issue 8 years ago • 9 comments

The first commit introduces a new goal: make reformat based on clang-reformat (at least version 3.9 should be used). This target is optional.

The second commit contains all changes after the execution of this command.

In the future committers can normalize their code by simply using the make goal.

ViToni avatar May 05 '17 23:05 ViToni

It is a good idea to have just one consistent coding style in whole project, but I dislike your proposed code style where are too many spaces around parenthesis. E.g. spaces around void in static void debugQueue( void );

pali avatar May 06 '17 23:05 pali

Actually I don't mind which formatting style is to be used. For me it's only important that there is one and that formatting is consistent all over the code base.

There are even some defaults styles (LLVM, Google, Chromium, Mozilla, WebKit) which could used: http://releases.llvm.org/3.9.0/tools/clang/docs/ClangFormatStyleOptions.html

Just choose a style and we can stick to it.

ViToni avatar May 07 '17 00:05 ViToni

Try something like this?

BasedOnStyle: LLVM
Language: Cpp
IndentWidth: 4
ColumnLimit: 120
AllowShortFunctionsOnASingleLine: Empty
AlwaysBreakBeforeMultilineStrings: true

pali avatar May 07 '17 08:05 pali

AFAIK AllowShortFunctionsOnASingleLine should be either true or false.

I would suggest having UseTab: Never as one of the mandatory options as the mixture of tabs and whitespaces really messes diffs up.

Having also MaxEmptyLinesToKeep: 1 or MaxEmptyLinesToKeep: 2 might be useful, too.

ViToni avatar May 07 '17 08:05 ViToni

BTW I already pushed another version of reformatted source code settings (based on the initial format settings) when writting https://github.com/pali/igmpproxy/pull/19#issuecomment-299673664 , so you might want to check, if you like it more.

ViToni avatar May 07 '17 08:05 ViToni

AFAIK AllowShortFunctionsOnASingleLine should be either true or false

According to http://releases.llvm.org/3.9.0/tools/clang/docs/ClangFormatStyleOptions.html possible values are: None, Empty, Inline, All

I would suggest having UseTab: Never

Already part of BasedOnStyle: LLVM

Having also MaxEmptyLinesToKeep: 1

Also part of BasedOnStyle: LLVM

or MaxEmptyLinesToKeep: 2 might be useful, too.

BasedOnStyle: LLVM set it to 1, but 2 seems to be better value.

pali avatar May 07 '17 08:05 pali

AFAIK AllowShortFunctionsOnASingleLine should be either true or false

According to http://releases.llvm.org/3.9.0/tools/clang/docs/ClangFormatStyleOptions.html possible values are: None, Empty, Inline, All

You are right. (saw the boolean option here https://clangformat.com/)

I would suggest having UseTab: Never

Already part of BasedOnStyle: LLVM

It was more meant to be explicit.

I update the PR using these settings:

BasedOnStyle: LLVM
Language: Cpp

IndentWidth: 4
ContinuationIndentWidth: 8

ColumnLimit: 120

MaxEmptyLinesToKeep: 2

AllowShortFunctionsOnASingleLine: Empty
AlwaysBreakBeforeMultilineStrings: true

ViToni avatar May 07 '17 12:05 ViToni

Changed the mentioned part manually so that future calls of make reformat should work there nicely.

ViToni avatar May 07 '17 22:05 ViToni

@ViToni seems that auto-reformat by robot/machine for everything does not work as expected. After automatic reformat it needs some manual work to fix some parts. So I do not think that "make reformat" target is a good idea.

But, this is really an improvement for the code... so are you going to fix needed parts manually and finish this work in this pull request?

pali avatar Oct 30 '17 15:10 pali