-
Notifications
You must be signed in to change notification settings - Fork 30.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
Feature/clang format #3612
Feature/clang format #3612
Conversation
As per @bnoordhuis suggestion, we will probably need to apply this to LTS too, to make patches easier to backport. |
IMHO this (currently) makes the source code less readable. |
I'd like to see the option for overriding download/install by providing your own. |
@jbergstroem what if you have an older clang-format version that does things differently? |
@mscdex clang-format is configurable, what in particular became worse in your opinion? |
I like the formatter idea in general, but the code changes this makes are rather significant. Can we start with something closer to the existing style and adapt to some "better" style incrementally? I'm not a big fan of the havoc this plays on git blame... |
@Qard my guess is that no matter how we tune it we'll end with just as big of a diff because of inconsistencies through the code. In general I think it's best to take the standard style people are used to, so either the clang defaults or perhaps the defaults used by v8 or another project we already rely on. |
@indutny The ones that really bug me right off the bat are the changes in function parameter and macro layouts. IMHO function parameters should either fit all on one line or each parameter each on a new line. As far as macros go, an example is the |
Suggesting we check |
@mscdex the defines are limitation of clang-format, there is no way to configure it right now. Regarding function parameters, this is how they are handled in v8. After contributing several CLs recently, I got convinced that this is actually pretty good way of doing it. Just a matter of getting used to. Anyway, we can do some sort of voting in TSC, and I'm sure that we will account all points of view. |
This is v8's https://chromium.googlesource.com/v8/v8/+/master/.clang-format LMAO that "Google" is a builtin clang style :) |
@mikeal I tried going that way, but ended up in way too many changes. I don't mind doing it, though |
@indutny if we're going to take a big ass diff anyway we might as well get to the ideal style for long-term maintenance. |
I've worked with source that places as many arguments as possible on the same line and IMO it makes quickly scanning through code noticeably more difficult. It's not bad once you are familiar with it, but otherwise it adds a cognitive burden. Though I assume this won't land over the weekend so I'll chime in more on Monday. |
Instead of reformatting the source code, what about requiring that new changes are run through I'm happy that you included reformatted source code in the PR though, as it makes it easy to see what style clang-format would produce. Also, I wonder why |
@trevnorris we can make it put each argument on a newline, but I would like to say that IMO putting each argument on a new line is less readable. However, I think we may go with the way we have things now (each argument on a new line) for now, just to postpone the decision on this to the later time. I think it is still very important to get proper formatting in our C++ code. @piscisaureus this is actually a pretty interesting idea. However it does not help us to enforce a code style over the code base, unless we will use separate tools to verify that the code in commits is properly formatted. Regarding, I don't mind using |
It's actually pretty easy! Just run git clang-format origin/master...HEAD. If the user did run it, clang-format should make no further changes, so we can simply whether the working tree is clean after running it. |
Anyone want to give any arguments for or against @piscisaureus idea? |
I'm no so sure about some of the styles enforced, can we configure that more, ala eslint? |
Can't say I'm a huge fan of this but I don't feel too strongly about it. I agree with @trevnorris and @Fishrock123 on not being happy with the styles enforced. I happen to like all my arguments separated out thank you very much ;-). And if we are doing this, I'd prefer a much more incremental approach on rolling it out as @piscisaureus suggests. Just seems like a huge bit of churn for no obvious benefit... and definitely not convinced it should go into LTS but with this much code touched by the PR I don't think we'd have any choice (which isn't really a good thing) |
I really dislike this enforced formatting, because at more than just a few places in the diff of this PR the reformat just makes scanning the code extremely hard. The most obvious thing that bugs me is the merge of multi-line arguments to methods into a single line whereas the methods that are being called usually have arguments that are not obvious at all; they then require much more of a 'thorough look' in order to be properly understood. e.g. (1) ares_query(env()->cares_channel(),
name,
ns_c_in,
ns_t_txt,
Callback,
GetQueryArg()); becoming (2) ares_query(env()->cares_channel(), name, ns_c_in, ns_t_txt, Callback,
GetQueryArg()); In my opinion, in (1) it is far easier to skip through the code vertically.. which might have something in common with my dislike of unnecessarily long lines. $.02 |
@indutny FWIW I think having linting enabled would be a great thing. Seems the styles themselves just need to be hashed out. I'm alright with the idea of incrementally adding rules that everyone can agree upon. Also with using git clang-format, but make lint will have issues if a rule is introduced that doesn't work with what we have today. Also, I believe the eslint introduction on the JS side has caused a similar number of less than useful code changes than this. |
33a2c05
to
e2c1224
Compare
I have just pushed May I ask everyone to take another look? |
You should not allow control-flow statements without blocks. When adding future lines, which inevitably will happen, one does not get additional noise of adding the now necessary block statements, nor the bugs that always come from forgetting them. |
@kkoopa I don't think that mandatory blocks are in our code-style at the moment, nor I can see this in any of recent C++ changes. |
Now would be a good opportunity to introduce that. Since there will be a bunch of changes due to style either way, the old excuse of "we don't do pure style changes" should not hold. Can anyone list good arguments against said change? |
I don't have any arguments except that this is not a code style that I currently use. I guess the argument for it is that double goto bud in apple's code? |
@Fishrock123 Try it for a while, I'll bet you end up liking it. |
@Fishrock123 yep, it does. That's the idea, we should not really care about it anymore. |
@bnoordhuis all fixed, please take a look. |
CLANG_FORMAT ?= tools/format/clang-format-win.exe | ||
endif | ||
|
||
CLANG_LINT ?= ./tools/format/git-clang-format --binary $(CLANG_FORMAT) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can I suggest calling this GIT_CLANG_FORMAT?
Umm, I'm not sure I understand, could you explain why, if you didn't already? |
Also only linting new changes is confusing and seems even more inconsistent. |
Not too many comments on the PR itself but a few questions about the approach:
|
The first version of this PR linted everything, resulting in a massive diff.
It's mechanizing what we do by hand now: sticking to the style guide. |
Fair enough I suppose. I still think having the linter autocorrect it for you is pretty aggressive and we shouldn't do that though. |
@bnoordhuis i've raised this [download stuff] as well. I'd rather see installing it documented since its pretty easy to install for mac ( |
It does make sense to stick to a single version of clang-format because it has changed dramatically since its introduction in 3.4, it's just that I'm not wild about auto-downloading it. |
@bnoordhuis so you're saying future changes are a problem? I just thought it was a cutoff at 3.5-3.6 (somewhere) where they massively changed it. |
I don't have a llvm/clang source tree checked out on this machine so I can't check but IIRC there were quite a few changes and additions between 3.6 and 3.7 too. I haven't really tracked what's upcoming in 3.8. |
We have an idea of how big the download is? Also, can I just use the included |
f88fe41
to
35ba5ff
Compare
Ok, everyone, pushed update to the makefile. Now downloading @trevnorris here are the forced changes of current |
Add `format-commit` and `install-pre-commit-hook` make targets. First one will format all committed changes against current `.clang-format`. The latter one will execute `make format-commit` on `pre-commit` hook.
35ba5ff
to
02cbc0b
Compare
And updated the gist, I have changed |
Hitting one month on this PR. What is our decision on this? |
-1 if it still autocorrects the linting |
@indutny , I definitely appreciate the work on this but I'm leaning -1 on this. I'm just not seeing the overall value at this point. |
Ok... closing. |
R=@bnoordhuis
cc @nodejs/tsc @nodejs/collaborators and everyone who cares about C++ code style in node.js