nodeeditor icon indicating copy to clipboard operation
nodeeditor copied to clipboard

Add a .clang-format file

Open Quincunx271 opened this issue 6 years ago • 4 comments

Clang Format is an auto-formatter for C++ source code. As there are a lot of C++ code formatting styles, it lets you customize your formatting with a .clang-format file. I think it would be helpful to add such a file to this repository; that way contributors can autoformat the code they submit to match the style of the repository.

Quincunx271 avatar Mar 13 '18 22:03 Quincunx271

I couldn't tailor the clang-config to reproduce the same formatting as extists.

Particularily, it is not possible to make a line break after :::

ReturnType
ClassName::
memberFunctionName()
{
    //
}

I can add another config for the uncrustify code formatter

paceholder avatar Apr 03 '18 10:04 paceholder

On this branch, I added a .clang-format file that goes most of the way. It changes a bit of the current source here and there, but it's pretty close.

For the specific case you mention, if you write the code in that form, it leaves it like that. If you write it like this:

ReturnType
ClassName::memberFunctionName()

It also leaves it like that. So it doesn't force the linebreak, but it leaves it in. I think that's decent.

The main problem I was unable to solve with that .clang-format file is this:

int
foo() { return 42; }

Is formatted as

int
foo()
{
    return 42;
}

Instead of on one line, as Clang Format doesn't expect return types on separate lines while the function body is on a single line.

I noticed some inconsistencies in the class declarations, where members are sometimes aligned, othertimes unaligned. That .clang-format always aligns variables, whether they are member variables or not (it has no option to specify just member variables)

Quincunx271 avatar Apr 03 '18 18:04 Quincunx271

The main problem I was unable to solve with that .clang-format file is this:

My uncrustify based formatter wasn't perfect. I have nothing against some small differences, the main thing is that the source code is formatted.

I will have a look at your config, thanks!

Dmitry

paceholder avatar Apr 04 '18 09:04 paceholder

Totally agree with @Quincunx271 !

It'd be nice to have a code style defined in a file shipped with sources! But may be, we could stick to some more traditional styles? Google or Mozilla, may be (those are shipped with clang-format already!)

Also, some .editorconfig would be a great plus too! :)

aol-nnov avatar Feb 17 '19 19:02 aol-nnov

I'm using this issue to address what has been talked in #333. This will be the reference for the .clang-format configuration: https://raw.githubusercontent.com/qt-creator/qt-creator/master/.clang-format

I'm going to add to the MR whole coding base already formatted. Just need to have time to access to my Linux device, with Windows it's such a pain.

Daguerreo avatar Dec 05 '22 18:12 Daguerreo