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

Clang tools testing #5948

Closed
wants to merge 10 commits into from

Conversation

JohannesLorenz
Copy link
Contributor

@JohannesLorenz JohannesLorenz commented Mar 13, 2021

This is not intended to be merged (I'll do a new branch for the official). The intention is to

  1. See if you're happy with clang's changes (comment the code/conversation if unsatisfied, please)
  2. Find out how difficult it gets to rebase other branches on this branch

Rebasing your branch on this might work like this for single-commit branches:

  1. clang-format -style=file -i $(git ls-files '*.cpp' '*.h')
  2. git commit -am 'fixup'
  3. git rebase -i HEAD~2, Chooese f for the second commit, accept.
  4. git rebase clang-formatted

This is a testing brach for #4690 .

@LmmsBot
Copy link

LmmsBot commented Mar 13, 2021

🤖 Hey, I'm @LmmsBot from github.com/lmms/bot and I made downloads for this pull request, click me to make them magically appear! 🎩

Windows

Linux

macOS

🤖
{"platform_name_to_artifacts": {"Windows": [{"artifact": {"title": {"title": "32-bit", "platform_name": "Windows"}, "link": {"link": "https://14454-15778896-gh.circle-artifacts.com/0/lmms-1.3.0-alpha.1.82%2Bga6a09454f-mingw-win32.exe"}}, "build_link": "https://circleci.com/gh/LMMS/lmms/14454?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link"}, {"artifact": {"title": {"title": "64-bit", "platform_name": "Windows"}, "link": {"link": "https://14452-15778896-gh.circle-artifacts.com/0/lmms-1.3.0-alpha.1.82%2Bga6a09454f-mingw-win64.exe"}}, "build_link": "https://circleci.com/gh/LMMS/lmms/14452?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link"}], "Linux": [{"artifact": {"title": {"title": "(AppImage)", "platform_name": "Linux"}, "link": {"link": "https://14453-15778896-gh.circle-artifacts.com/0/lmms-1.3.0-alpha.1.82%2Bga6a0945-linux-x86_64.AppImage"}}, "build_link": "https://circleci.com/gh/LMMS/lmms/14453?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link"}], "macOS": [{"artifact": {"title": {"title": "", "platform_name": "macOS"}, "link": {"link": "https://14456-15778896-gh.circle-artifacts.com/0/lmms-1.3.0-alpha.1.82%2Bga6a09454f-mac10.14.dmg"}}, "build_link": "https://circleci.com/gh/LMMS/lmms/14456?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link"}]}, "commit_sha": "c7424137f6f6d25aab1b7f905f9d20c44df62abf"}

Copy link
Contributor

@Veratil Veratil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some glances around and comments on format

.clang-format Outdated Show resolved Hide resolved
src/gui/editors/PianoRoll.cpp Outdated Show resolved Hide resolved
src/gui/editors/PianoRoll.cpp Outdated Show resolved Hide resolved
src/gui/editors/PianoRoll.cpp Outdated Show resolved Hide resolved
src/gui/editors/PianoRoll.cpp Outdated Show resolved Hide resolved
src/gui/editors/PianoRoll.cpp Outdated Show resolved Hide resolved
src/gui/editors/PianoRoll.cpp Outdated Show resolved Hide resolved
src/gui/editors/PianoRoll.cpp Outdated Show resolved Hide resolved
src/gui/editors/PianoRoll.cpp Outdated Show resolved Hide resolved
src/gui/editors/PianoRoll.cpp Outdated Show resolved Hide resolved
@IanCaio
Copy link
Contributor

IanCaio commented Mar 14, 2021

Is it easy to change the clang format to use Type* foo; instead of Type *foo;? I'm personally fine with either, but I think most people voted on the former at Discord and we were trying to use it lately. If it's not an easy change I'm for just using Type *foo; to make things easier!

Preparation for clang-format. It will shuffle the includes, and this
preparation will prevent errors from that step.
This enables files for checking against the
[LMMS coding conventions](https://github.com/LMMS/lmms/wiki/Coding-conventions).

There is no strategy for automatic testing yet.
This commit was created by solely running

```
clang-format -style=file -i $(git ls-files '*.cpp' '*.h')
git commit -a
```

No functional changes.
@JohannesLorenz
Copy link
Contributor Author

JohannesLorenz commented Apr 3, 2021

No matter what I configure (different break styles, different columnlimit), I always get

        auto controllerType = m_controllerConnection
-                       ? m_controllerConnection->getController()->type()
-                       : Controller::DummyController;
-       bool skipMidiController = Engine::getSong()->isSavingProject()
-                                                         && Engine::getSong()->getSaveOptions().discardMIDIConnections.value();
-       if (m_controllerConnection && controllerType != Controller::DummyController
-               && !(skipMidiController && controllerType == Controller::MidiController))
+               ? m_controllerConnection->getController()->type()
+               : Controller::DummyController;
+       bool skipMidiController = Engine::getSong()->isSavingProject() && Engine::getSong()->getSaveOptions().discardMIDIConnections.value();
+       if (m_controllerConnection && controllerType != Controller::DummyController && !(skipMidiController && controllerType == Controller::MidiController))
        {

That's really bad. I'm clueless how to fix this. fixed

@Veratil
Copy link
Contributor

Veratil commented Apr 18, 2021

To fix the bool and if statements we can try:

BreakBeforeBinaryOperators: NonAssignment

For the ternary operator:

BreakBeforeTernaryOperators: true

@JohannesLorenz
Copy link
Contributor Author

@Veratil Thanks for the hint! That worked in some lines, but not in the marked line.

Copy link
Contributor

@sziegler103 sziegler103 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just scrolled to a random spot to have a look. Looks a lot cleaner from the little I saw.

#include "gui_templates.h"

#define makeknob( name, x, y, model, label, hint, unit ) \
Knob * name = new Knob( knobBright_26, this); \
Copy link
Contributor

@sziegler103 sziegler103 Jun 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a heads up, any tabs formatting line-continuation characters in multi-line #define's to be in a single "column" are reduced to being only a single space after the line. I'm ambivalent to either style but wanted to bring it up.

plugins/DualFilter/DualFilterControls.cpp Show resolved Hide resolved
src/gui/PianoView.cpp Outdated Show resolved Hide resolved
src/gui/PianoView.cpp Outdated Show resolved Hide resolved
@Spekular
Copy link
Member

Have we ever done a poll on bracket style? I feel like it would make sense to include that in this if it's going to be changed.

I think this covers the common styles, correct me if something's missing:

// Heart
if (gum)
{
    chew(gum);
}
else
{
    doTheOtherThing();
}

// Rocket
if (gum) {
    chew(gum);
}
else {
    doTheOtherThing();
}

// Eye
if (gum) {
    chew(gum);
} else {
    doTheOtherThing();
}

@JohannesLorenz
Copy link
Contributor Author

Looks like 👁️ is preferred.

@Spekular can you please fill out

BraceWrapping:
  AfterClass: true
  AfterControlStatement: true
  AfterEnum: true
  AfterFunction: true
  AfterNamespace: true
  AfterStruct: true
  AfterUnion: true
  AfterExternBlock: true
  BeforeCatch: true
  BeforeElse: true
  IndentBraces: false
  SplitEmptyFunction: true
  SplitEmptyRecord: true
  SplitEmptyNamespace: true

And reply how you think it should be, in your opinion?

@JohannesLorenz
Copy link
Contributor Author

First of all, many thanks for the feedback on the PR.

Many of the comments can be resolved by using ColumnLimit: 120. So I will change that and append a commit with the changes, unless anyone says "no" in the next days. This will also make our CTORs look like

classname::classname()
    : obj1(x1)
    , obj2(x2)
    , obj3(x3)

which has been accepted (4 times) on Discord.

If they are smaller than ColumnLimit (120), it is packed into one line.
If not, it remains unchanged.
@Spekular
Copy link
Member

Looks like 👁️ is preferred.

@Spekular can you please fill out [...] And reply how you think it should be, in your opinion?

BraceWrapping:
AfterClass: true // why is this inverted to the rest?
AfterControlStatement: Never
AfterEnum: false
AfterFunction: false
AfterNamespace: false // unsure here, example shows no indentation in which case wrap may be good for visibility
AfterStruct: false
AfterUnion: false
AfterExternBlock: false // again, example shows no indentation here when false is set...
BeforeCatch: false
BeforeElse: false // to match vote above, I prefer true
IndentBraces: false
SplitEmptyFunction: true // shouldn't apply if AfterFunction is false
SplitEmptyRecord: true // see above
SplitEmptyNamespace: true // see above
// Additionally:
BeforeWhile: false
BeforeLambdaBody: false

My only concern with these settings is that in some of the examples disabling wrapping seems to disable indentation inside the brackets, or there's no indent in the first place. I'm using https://clang.llvm.org/docs/ClangFormatStyleOptions.html for reference.

AfterExternBlock:

true:
extern "C"
{
  int foo();
}

false:
extern "C" {
int foo();
}

AfterNamespace

true:
namespace
{
int foo();
int bar();
}

false:
namespace {
int foo();
int bar();
}

If these examples are the only options I would say true (wrapping the braces) is the least bad choice, assuming there's no way to get unwrapped braces with indent.

@JohannesLorenz
Copy link
Contributor Author

JohannesLorenz commented Jul 24, 2021

AfterClass: true // why is this inverted to the rest?

Agreed, I set this to false, too. It looks strange to me if class braces are not wrapped, but enum braces are.

If these examples are the only options

That seems true for extern, and not for namespace, I can confirm that.

I would say true (wrapping the braces) is the least bad choice, assuming there's no way to get unwrapped braces with indent

In many cases, namespace and extern wrap the whole file. In this case, I think indent is overkill. Do you really want to indent the whole file (except license) for every class (namespace) and every plugin (extern) (extern is not wrapped around the whole plugin, only around the descriptor)? Which means I would use false in these 2 cases, too. git grep -A 5 extern on the current code also shows that most extern code is not indented. I hope setting them to false (like you filled it out) is OK for everyone.

SplitEmptyFunction: true // shouldn't apply if AfterFunction is false
SplitEmptyRecord: true // see above
SplitEmptyNamespace: true // see above

Yes, tested, this has no effect on the whole source.

Summary: I take it like you filled it out, except that I set it to false for classes, too.

@JohannesLorenz
Copy link
Contributor Author

Note: I only ran clang-format for the first pass. I'll run clang-tidy if the changes here are accepted by everyone.

Note to self: You need to run clang-tidy -fix -config-file=.clang-tidy <FILENAME> -- -Iinclude -Igcc/{src,} -I/usr/include/qt/{QtCore,QtWidgets,QtGui,QtXml,}, followed by a further clang-format run.

@Spekular
Copy link
Member

AfterClass: true // why is this inverted to the rest?

Agreed, I set this to false, too. It looks strange to me if class braces are not wrapped, but enum braces are.

What I mean is, in the documentation it looks like "true" provides unwrapped braces and "false" provides wrapped ones, as opposed to all other settings. I still want classes to look like this:

class a {
    // content
}

As for namespace and extern, I'll trust your judgement on those.

@JohannesLorenz
Copy link
Contributor Author

What I mean is, in the documentation it looks like "true" provides unwrapped braces and "false" provides wrapped ones, as opposed to all other settings.

Oh, that's a documentation error at their example for AfterClass (the other examples are correct). I just tried both bool values, and it's exactly the opposite of their example. So I'll leave it as false.

@JohannesLorenz
Copy link
Contributor Author

JohannesLorenz commented Jul 25, 2021

All comments that marked negative aspects of clang-format are now resolved. I'd like to invite everyone to check if you are now OK with the code and vote:

  • 🚀 I have no remarks, we should take it
  • 👀 I have remarks, but if they are fixed we can take it
  • ❤️ We should not take clang-format at all, it does too many things that we don't like, it's too much automation

I'm not sad if anyone votes for ❤️ . Please simply vote what you think applies most.


if (!chunky) delete[] data;
delete[](sBank*) pBank;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grepping our whole code base, it's only 6 occurrences in the mentioned file, so I think we can do this inconsistent for now and possibly fix it after reorg.

@JohannesLorenz
Copy link
Contributor Author

Deprecated by #6323 (and merged there).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

10 participants