-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
[WIP] tools: use clang-format to format C++ code #16122
Conversation
Should this be applied to |
Yes, and test/addons and test/addons-napi as well. The problem of course is that it results in humongous diffs. It:
That might be a good solution, because
|
641f51b
to
6969062
Compare
@danbev @bnoordhuis Just noticed I have missed
I think we can try to relax the rules a bit and make them more about capturing what we have right now, then tighten the rules one by one later, so there will be less conflicts to start with. Basically by doing
That I've described in the OP. I will try to tweak with it a bit, maybe after #16090 lands.
Yeah the npm module does keep track of the revision of its binaries. Also we can do something like what |
Did a bit of archaeology and found #1539 , let's see if clang-format is flexible enough to do this kind of stuff again |
#16090 has already landed. Will try to tweak the .clang-format over the weekend. |
From an LTS/backporting perspective if we're going to do this I'd rather do it all at once, and backport it ASAP, rather than the "death by a thousand cuts" style of making changes. I assume that's better for open Pull Requests too. |
@gibfahn hmm now come to think of it, I think this one can be backported by running the final clang-format on all branches instead of manually backporting them? Also for conflicts in other PRs we can do that as well, so it might not be that hard... I will give this another try over the weekend |
- Initializes .clang-format - Add `make format` to Makefile
6969062
to
ab13553
Compare
BTW: I am still pursuing this. One outstanding issue is when is appropriate for this to land, if it ever gets landed. Any patches to C++ code landed prior to this patch would not land cleanly anymore, even when this patch is backported to different release lines asap, and the conflict would look pretty scary. To land those C++ changes one has to manually recreate the commits by copying files via |
@joyeecheung http://clang.llvm.org/docs/ClangFormat.html#script-for-patch-reformatting - can be used to reformat commits when applying them. The CI can probably be made to do it automatically when rebasing onto the target branch. |
@bnoordhuis Ooh, that looks pretty nice! Thanks for discovering that. I'll see if I can integrate it somehow. |
@joyeecheung is this something you still work on? I believe it would still be great to have something like this. |
FWIW, I still think it's a good idea and the practical issues are tractable. |
@BridgeAR I have not forgotten about this, just need to find some time to tweak this again... |
If I'm not mistaken, |
Closed in favor of #21997 |
I think we have discussed briefly about this during the collaboration summit @BridgeAR @Fishrock123 This is just an attempt to see how everybody feels about using an automatic formatting tool to reduce style inconsistencies and nits in PRs. We use
clang-format
in llnode and v8 uses it as well so this sounds like a good candidate..clang-format
file based on Google styles (since previously we usecpplint.py
that lints C++ code using the Google style guide). We have our own "extensions" to the style guide (e.g. the ones being added in doc: add basic C++ style guide #16090) so we need to work out more rules in the.clang-format
based on our needs.clang-format -style=google -dump-config > .clang-format
and start from that as well..cc
undersrc
with the initalized.clang-format
(clang-format -style=file -i src/**/*.cc
)clang-format
can be obtained by compiling from the clang source code as well. Also you can get a python wrapper if you happen to havedepot_tools
and a V8/Chromium checkout on your machine. I am not sure whether we should bundle it in the codebase like what we do with eslint, but definitely doesn't hurt to add some commands to the Makefile (maybe along witheslint --fix
).Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
src, tools