-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Add .clang-format and .clang-tidy #4690
Conversation
Per 0b5a7d8, function call arguments are now not separated by newlines, so e.g. calls to |
Explanation about the constructor lists: As you can see, now multiple initializers from the CTOR initializer list are put into one line. I find that ugly, but it looks like clang-format does not provide any workaround here. |
A few more examples: JohannesLorenz/lmms@bdde4e3 shows code-reading rework I did automized, and JohannesLorenz/lmms@1e091ea shows rework that remained to do by hand. As one can see, types are corrected automatically, while variables can currently not being checked (due to clang-format which can not differ between |
Side note: The tab width (4 or 8) is not clearly defined within the project. We need to find that out. |
#4810 states that we should change to spaces (4) instead of tabs. clang-format could save me a lot of time instead of trying to guess every project's code style (and then force-push style changes). Also, clang-tidy could help us to modernize the codebase (e.g. foreach instead of the old "iterator for", |
Looks to me like tabs of length four have most votes in each poll, am I
missing somewhere where spaces are decided on?
…On Mon, May 27, 2019, 21:02 Shmuel H. ***@***.***> wrote:
#4810 <#4810> states that we should
change to spaces (4) instead of tabs. clang-format could save me a lot of
time instead of trying to guess every project's code style (and then
force-push style changes). Also, clang-tidy could help us to modernize the
codebase (e.g. foreach instead of the old "iterator for", auto in casts,
and more)
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#4690?email_source=notifications&email_token=ACEBLGSFUKQAZFCA35VOLFDPXQV6HA5CNFSM4GAZG6C2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWKLY5Q#issuecomment-496286838>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACEBLGWMEGGHBJZJSXICM6DPXQV6HANCNFSM4GAZG6CQ>
.
|
Im sorry. I got confused between the emojis. |
0b5a7d8
to
94b48d5
Compare
Tab width fixed to |
Maybe we should just use Qt's code style with 4-width tabs? It will be a
lot easier to set up with qtcreator and clang-format. Also, it takes me so
much time and frustration to manually format my code every time.
…On Thu, 30 May 2019, 22:30 Johannes Lorenz, ***@***.***> wrote:
Tab width fixed to 4.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#4690?email_source=notifications&email_token=AFOMGKASTPUSF6PXQUCI5WDPYATOJA5CNFSM4GAZG6C2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWTJCVA#issuecomment-497455444>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AFOMGKAG4LJTE5ZIA5PJVLTPYATOJANCNFSM4GAZG6CQ>
.
|
Some more additional info:
|
Setting up a coding style once for QtCreator is no big deal. Just create an XML file and you can always re-use this file. Setting it up for clang-format won't be easier: With this PR, we already have a setup for clang-format. I'm not sure if Qt's code style will match ours. At least for some variable names, this is true, but every derivation will cause more changes in our code base, which is why I was for defining our own code style. |
I find it problematic that this PR is almost ignored. If properly set up, it can increase PR review time a lot, but the points that need to be discussed (as mentioned in the first post) are not discussed at all. The example images/outputs have also not been discussed. 1 or 2 persons can't decide anything that will have significant influence for all active coders. So I'm going to tag everyone to find a consent. Please read the posts carefully, check the examples, make proposals, and if in doubt, try it out on your machine. |
@JohannesLorenz I agree with you on increasing the column limit to 100. |
Why? Because you picked 100? Just get rid of it. |
At the very least 120 imo, otherwise the increase is marginal.
…On Sun, Jun 23, 2019, 18:18 Tres Finocchiaro ***@***.***> wrote:
column limit to 100 instead of 80? Why? Because you picked 100? Just get
rid of it.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#4690?email_source=notifications&email_token=ACEBLGWKSFUN74FMKX4NA5DP36O4RA5CNFSM4GAZG6C2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODYLB6LQ#issuecomment-504766254>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACEBLGU5UMNT7FWEBIA34H3P36O4RANCNFSM4GAZG6CQ>
.
|
Line width is not only about editor for me. E.g. take this line:
Do you really want to read that? You could make this more readable by using:
|
... but it's misplaced to use arbitrary values to fix unreadable code. It's an anecdotal fix. Code reviews will still be required for human readibility. A computer can't automate all human tasks. |
Also, some of the advanced editors can help simplify and clean code using hints. JetBrains has excellent code helpers for this stuff. |
I'm not sure if clang-format works sane without any line length limit (or a limit of, say 200). I guess it would concatenate almost every multi-liner into a very very long line... Maybe this must be tested. Btw, @douglasdgi Sorry, I forgot you in the list of "active coders" |
Open question from the OP:
What's your opinion? |
Automation is usually the easiest route. We'd need to make it clear that it's running so anyone doesn't wonder why their code (possibly) changed from what they originally wrote though. To be clear I'm saying it should auto-run at some step. Maybe a git hook? |
Having a In CI, I assume it would do scan-only (by utilizing the I can't really comment on the "export-only" variant since I don't quite understand what it means (but it seems like a complication compared to a standard |
FWIR, we agreed (in discord) on not modifying anything in the PR. Personally, I think it would be OK if the bot creates a branch like "-bot" (and removes that branch after the merge). This allows the user to fetch the bot changes if they want, but it does not modify the PR. What about that? |
I would probably not like that too much. Changing the
The idea is that
Agreed. That's probably why I suggested in the previous post to let the CI do all and just pull it: The CI will not update their clang-format version (as long as we don't want that). |
I'd rather not pollute the branches (we can't create them for forks and this could quickly pollute our own). If possible, scripting code change recommendations is best, then they can just accept or ignore the recommendation, but without any intermediary branches. |
We could simply create a separate LMMS fork, like "LMMS/bot-suggestions". Then our "LMMS/lmms" fork will not be polluted, and like I mentioned, I'd let the bot remove its branches after the original branches have been merged anyways. So I don't think this would end up in pollution. |
How much extra time it takes, roughly? Although I agree that doing repeatedly something that needs to be run only once before the final submission may not be very efficient use of CPU cycles regardless.
The export-only option could be OK as well in that case, if it just saves data for a subsequent manual clang-tidy run. Either way seems better to me than making and managing a bunch of new branches "in the cloud" for something that could be easily done locally. The cloud solution could also make |
I think the question is how it looks on master. Either the whole branch is a "feature; fix; fix; fix", in which case you just squash into one commit, which you author (most cases in LMMS). Or, the branch commit history is good enough for not being squashed - in this case, I'd expect the developer to not keep "fixed format" commits on the branch, but squash them into the commits where they really belong (e.g. using |
If a developer changes a line, that's the diff they expect to see. Changing what they changed again sounds like a cat chasing its tail. Code formatting can be yelled at by the CI without adding pandemonium to an otherwise predictable coding workflow. |
Correcting my own statement:
Those 9 seconds were for clang-format. For clang-tidy, it is still very slow (~ as slow as for a normal compile, so it doubles compiling time). So IMO a flag to activate it would be not so good. |
Sorry, I can't follow what you mean. Of course, if they submit changes that are against our coding conventions, the bot must submit changes to their changes. |
Don't touch other's code without their approval (or abandonment). Ever. It's a mistake.
The bot MUST do no such thing. Good code is more important than formatted code. The CI can yell at them and they can fix it manually. If you get creative, make code recommendations using GitHub comments. Anything that changes a PR without permission is a mistake. Creating rogue branches is a mistake. Don't make code formatting more important than the code itself (pretty please). ❤️ |
You mean the CI gives the author hints, and they can fix it, but are not forced to take it? Do you propose that the reviewer would still check that the relevant bot hints were used (which means manual review again, which we wanted to avoid?). Or should the reviewer then just say "Author, I trust you did the formatting well"? Another problem with this is: If you do changes A, B and C, deny clang-format's changes and bring it on master. Then the next coder who wants to do change D will be confronted with issues from A, B, C and D. In the end, the whole file will be marked with errors from Summing it up, I'm for either use |
From my point of view, there are two key "big picture" requirements that out
Going deeper into 2): For me, the "cloud bot approach" (create a branch with suggested changes that the PR author can use) seems complicated and messy, but for some devs it may be preferred. Others like me could prefer an option that lets me easily run Both "cloud" and "local" solutions may be still kind of difficult for some people, though: one requires relatively advanced git knowledge (I did not even know the "interactive rebase" existed before Johannes told me last year), the other requires extra tools that Windows users may need to set up. |
This is not true. Automating the "sorry your code doesn't pass our style guidelines" DOES help the user. Otherwise they're waiting for days, weeks or months for a human to do it. This notion that early users can't fix formatting or that it's a detriment to notify them by bot is ludicrous. Our job is NOT to write other people's code and the more we conflate the workflow and take the responsibility off of the coder, the less we expect of our coders. I'll keep using Homebrew as an example here because they merge hundreds and hundreds of PRs every week and they do NOT make changes for people. Homebrew is a Ruby project, so we're talking about a lower barrier to entry. I don't think we should do anything automatically that touches other people's code unless they explicitly request it. Once code is compiling well, I think developers will be happy to fix formatting errors to get it merged.
Preferred by whom? I've contributed to several dozen projects, none do code formatting forking nonsense. I really don't understand any use-case where creating forks for formatting is warranted. Forks should be used for code divergence, not for making sure there's a newline and no spaces after a
Homebrew's errors just cite the rule and I believe sometimes links to examples.
Yes.
If your workflow requires a passing codestyle, you block merging until it passes. There should always be a manual override though.
Ideally, we'd only run checks on stuff that's changed. We need not make the style check more important than the code itself, no?
That's the same for any code that's changed and was previously under review. If a developer chooses to ignore the formatting errors and change lines again, the old code comments should naturally become outdated and collapse by default. |
I don't think there's anything "easy" about auto-formatting code unless the IDE's doing it as you type. Any solution that happens after the code is written (in my opinion) should require human intervention. This doesn't mean the local scripts wont help, they absolutely will (and the CI can offer some guidance here). This becomes increasingly helpful for PRs that becomes stale and only formatting it preventing it from being merged. Any developer can run the format on the code locally and bump the PR with the formatting changes.
For command-line stuff, Windows may be the oddball out here, but from what I'm reading the tidy tasks are supported, at least in the IDEs and will pick up the tidy files automatically. |
I am not saying otherwise. As I explained in the post, I agree that having a CI job that rejects non-compliant code is useful, since it saves time of our reviewers. That CI job is not a new obstacle, it just changes who deals with it. By "adding obstacles" I mean making
I don't know, I can't speak for others. I do not like it either, but Johannes seemed to prefer it (unless he was just further explaining what the process could look like and I mistakenly understood it as a preference).
And I agree (and the human should be the PR author, not the reviewer). By "being easy to use" I mean not forcing the user into a specific way to fix the code (which could require complex setup or advanced knowledge), but simply telling them in the CI log what is wrong and how it can be fixed manually, so that literally anyone could do it, even if they just barely managed to even compile LMMS for the first time and fixed a simple bug. I think we actually agree on that point (and most others) and just describe it differently. |
Me
Can we talk less destructive? IDEs will help, and IMO we should do checks prior to merging (I think we agreed until here). And if everyone can easily apply
All in all, I still expect regular situations where users tried to submit code and the CI rejects them. I expect this not just 1%, but rather something like 10% or 20%. I think if it can happen regularly, we should be prepared for it. So I, personally, don't want to look at a 100 lines diff, fixing each single indentation issue with my own hands. So you may say that the CI could just put the resulting files zipped somewhere. Now compare: Hitting the download button in your browser for the zip, then unzipping it, carefully copying over all the files into you own git tree, typing a git commit, possibly removing the zip and the folder. Compare this with a simple Am I too pessimistic about all |
I think it is a valid concern, but we would likely not be the only ones hit with such issues, so I doubt that there will be many breaking changes in behavior across versions and platforms that couldn't be fixed by a new config option or something. Big organizations using these tools would probably not be happy if each new version reformatted their whole code-base with not workaround available. As I noted on Discord, we started using I don't see any harm in having a bot-fork based option for those who want to use it (currently 33 % of participants in this discussion :)) ), but I would definitely like to see a fully supported option to run |
CRLF is handled by Git. We can turn that off project-side using
Rash perhaps, but destructive? I don't understand what's so confusing about having a CI tell someone to fix their code. These talks of automating this with branches is -- in my opinion -- destructive in a literal sense because it will pollutes and conflate. Downstream, we lack sufficient access to fork, upstream we'll be making forks for formatting? I find it a bit hypocritical to think that formatting code is too complex for someone to grasp while merging in an upstream fork is not complex. One is a matter of following rules, the other requires two remotes and hand-merging or pull requests against forks, neither of which I find to be intuitive to a newcomer. Sorry if that comes off as "destructive", I just find the workflow to be all around messy.
I think this is more pragmatically good.
OpenJDK (especially the CPP-side) does some pretty creative bot stuff for merging PRs, but it's mostly for project integration, I guess for stale branches this might help, I just think it'll cause more PRs in the end. If we have access to push to a stale PR, that's likely the cleaner solution, but I won't fight the bot conversation any longer, I've shared my opinions on it. 🍻
Thanks for sharing. These are the types of exception scenarios I was trying to discuss on Discord. |
For local support, going through the above options:
So I think (1) is not possible, because we will want to do checks at CI side to forbid ill-formed code. (3) and (4) seem to make it impossible to run CMake only on the changed files. However, imagine changing only a header which is included by 100 cpp files. Then there's no way around re-compiling those 100 cpp files with clang-titdy, too (because the definitions may have changed, resulting in different clang-tidy-fixes)? So is this really a problem? (2) seems nice because you can restrict clang-tidy on the files you really changed, but isn't this exactly the danger with the header that requires re-compiling 100 files? All in all, I think we can even offer 2, 3 and 4 in parallel. We'll probably see what is best in practice and the CI will save us or errors anyways... |
This commit was created by solely running ``` clang-format -style=file -i $(git ls-files '*.cpp' '*.h') git commit -a ``` No functional changes.
isn't this done, why not close it? |
Correct. Deprecated by #6323 (and merged there). |
Don't merge yet, needs discussion, see below.
The following patch provides style files for ~2/3 of the LMMS coding conventions (~4/5 if clang-tidy will accept a PR I'll need to create).
clang-format and clang-tidy provide functionality to find style issues (the former for whitespace, the latter for code) and to fix them automatically.
The following works as an example (assuming you're in the main LMMS folder and use a build dir
build
). For best results, use whatmake VERBOSE=1
spits out.QtCreator:
Full support for clang-format and clang-tidy 😄
clang-format output for Mixer.cpp:
click here for examples.
clang-tidy output for Mixer.cpp:
Things to discuss:
otherwise they have to run clang-tidy manually, passing command line args to it
With 80, many
QObject::connect
calls are broken into 4 lines.For the future, I hope we can fix the complete LMMS sources after stable-1.2 is being merged.