GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [WIP] tools: use clang-format to format C++ code by joyeecheung · Pull Request #16122 · nodejs/node

Conversation

@joyeecheung

@joyeecheung joyeecheung commented Oct 10, 2017 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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.

  • The first commit just initializes the.clang-format file based on Google styles (since previously we use cpplint.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.
    • If we want more granular control over the rules we can do a clang-format -style=google -dump-config > .clang-format and start from that as well.
    • This PR is first about seeing if there are any concerns on the idea of using a auto-formatting tool at all. And the rules will kinda depend on what doc: add basic C++ style guide #16090 comes down to.
  • The second commit formats every .cc under src with the initalized .clang-format (clang-format -style=file -i src/**/*.cc)
  • I am using the clang-format npm module with pre-built binaries maintained by the Angular team, though 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 have depot_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 with eslint --fix).
Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines
Affected core subsystem(s)

src, tools

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bricss and gengjiawen reacted with thumbs up emoji
All reactions
  • 👍 2 reactions
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs involving general changes in the lib/ or src/ directories. labels Oct 10, 2017
@joyeecheung

joyeecheung commented Oct 10, 2017

Copy link
Copy Markdown
Member Author

cc @addaleax @TimothyGu @bnoordhuis

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@danbev

danbev commented Oct 10, 2017

Copy link
Copy Markdown
Contributor

Should this be applied to test/cctest as well perhaps?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bnoordhuis

bnoordhuis commented Oct 10, 2017

Copy link
Copy Markdown
Member

Yes, and test/addons and test/addons-napi as well.

The problem of course is that it results in humongous diffs. It:

  1. creates merge conflicts with just about every open pull request that touches C++ code, and
  2. makes back-porting hard unless it's merged simultaneously in all branches;

I am using the clang-format npm module with pre-built binaries maintained by the Angular team

That might be a good solution, because

  1. the problem with just any clang-format is that different versions behave differently.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@joyeecheung
joyeecheung force-pushed the clang-format branch from 641f51b to 6969062 Compare October 10, 2017 11:16
@joyeecheung

joyeecheung commented Oct 10, 2017

Copy link
Copy Markdown
Member Author

@danbev @bnoordhuis Just noticed I have missed src/**/*.h as well. Added to the commits.

  1. creates merge conflicts with just about every open pull request that touches C++ code, and
  2. makes back-porting hard unless it's merged simultaneously in all branches;

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

If we want more granular control over the rules we can do a clang-format -style=google -dump-config > .clang-format and start from that as well.

That I've described in the OP. I will try to tweak with it a bit, maybe after #16090 lands.

  1. the problem with just any clang-format is that different versions behave differently.

Yeah the npm module does keep track of the revision of its binaries. Also we can do something like what make coverage does, use the bundled npm and install it in the project directory.

danbev, TimothyGu, and BridgeAR reacted with thumbs up emoji
All reactions
  • 👍 3 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@joyeecheung

joyeecheung commented Oct 10, 2017

Copy link
Copy Markdown
Member Author

Did a bit of archaeology and found #1539 , let's see if clang-format is flexible enough to do this kind of stuff again

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@joyeecheung

joyeecheung commented Oct 20, 2017

Copy link
Copy Markdown
Member Author

#16090 has already landed. Will try to tweak the .clang-format over the weekend.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@gibfahn

gibfahn commented Oct 25, 2017

Copy link
Copy Markdown
Member

The problem of course is that it results in humongous diffs. It:

  • creates merge conflicts with just about every open pull request that touches C++ code, and
  • makes back-porting hard unless it's merged simultaneously in all branches;

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

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@joyeecheung

joyeecheung commented Oct 26, 2017 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

@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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@joyeecheung joyeecheung mentioned this pull request Oct 26, 2017
Why do we include both *-inl.h and *.h in the same .cc file? #16519
Closed
joyeecheung added 2 commits October 27, 2017 14:48
@joyeecheung
tools: initialize .clang-format with Google styles
86d2d6d
- Initializes .clang-format
- Add `make format` to Makefile
@joyeecheung
src: don't format certs
ab13553
@joyeecheung
joyeecheung force-pushed the clang-format branch from 6969062 to ab13553 Compare October 27, 2017 06:49
@joyeecheung joyeecheung mentioned this pull request Oct 31, 2017
src: fix etw provider include on Windows #16639
Closed
1 of 4 tasks
@joyeecheung joyeecheung mentioned this pull request Nov 15, 2017
doc: mention smart pointers in Cpp style guide #17055
Closed
2 tasks done
@mmarchini mmarchini mentioned this pull request Dec 7, 2017
src, test: node internals' postmortem metadata #14901
Closed
2 tasks done
@MylesBorins
MylesBorins force-pushed the master branch from b7405ab to 7f086dd Compare December 8, 2017 16:37
@joyeecheung

joyeecheung commented Jan 11, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

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 git checkout, do a make format, and commit again, instead of cherry-picking the commits. So it's best to land this when a minor release on all release lines is out and the number of C++ commits on master that have not been backported is minimum.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bnoordhuis

bnoordhuis commented Jan 15, 2018

Copy link
Copy Markdown
Member

@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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@joyeecheung

joyeecheung commented Jan 15, 2018

Copy link
Copy Markdown
Member Author

@bnoordhuis Ooh, that looks pretty nice! Thanks for discovering that. I'll see if I can integrate it somehow.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@joyeecheung joyeecheung added the wip Issues and PRs that are still a work in progress. label Jan 21, 2018
@maclover7
maclover7 force-pushed the master branch from bb5575a to 993b716 Compare January 26, 2018 22:02
@cjihrig
cjihrig force-pushed the master branch from 993b716 to 082f952 Compare January 26, 2018 22:36
@BridgeAR
BridgeAR self-requested a review March 2, 2018 03:44
@BridgeAR

BridgeAR commented Apr 22, 2018

Copy link
Copy Markdown
Member

@joyeecheung is this something you still work on? I believe it would still be great to have something like this.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bnoordhuis

bnoordhuis commented Apr 24, 2018

Copy link
Copy Markdown
Member

FWIW, I still think it's a good idea and the practical issues are tractable.

gibfahn and mmarchini reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@joyeecheung

joyeecheung commented Apr 24, 2018

Copy link
Copy Markdown
Member Author

@BridgeAR I have not forgotten about this, just need to find some time to tweak this again...

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mmarchini

mmarchini commented May 1, 2018

Copy link
Copy Markdown
Contributor

If I'm not mistaken, git cl format on v8 will only format modified files (not sure how they determine "modified" though). Maybe we could use a similar approach to minimize breakage among PRs and backports?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@joyeecheung joyeecheung mentioned this pull request Jul 27, 2018
tools: add make format-cpp to run clang-format on C++ diffs #21997
Closed
2 tasks done
@joyeecheung

joyeecheung commented Jul 27, 2018

Copy link
Copy Markdown
Member Author

Closed in favor of #21997

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@joyeecheung joyeecheung closed this Jul 27, 2018
@joyeecheung joyeecheung mentioned this pull request Feb 6, 2019
[Internal] clang-format the whole repo #25955
Closed
@RaisinTen RaisinTen mentioned this pull request Apr 11, 2022
build: run clang-format on CI #42681
Merged
@bnoordhuis bnoordhuis mentioned this pull request Dec 21, 2022
src: formatting of C++ files #45933
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@BridgeAR BridgeAR Awaiting requested review from BridgeAR

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs involving general changes in the lib/ or src/ directories. wip Issues and PRs that are still a work in progress.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

7 participants

@joyeecheung @danbev @bnoordhuis @gibfahn @BridgeAR @mmarchini @nodejs-github-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.