-
Notifications
You must be signed in to change notification settings - Fork 303
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
Use clang-format to sort includes #2725
Conversation
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.
LOVE IT ⭐
LGTM so long as tests are passing of course.
I'm gonna add a requires-internal-pr just in case
Are we doing to do the same thing with the internal repository? |
I definitely think we should but the 2 don't need to be done together. we can do the internal change at a later time. |
Agreed that they don't need to be done together. I just hope we'll also get these nice things in the internal repo too! |
Internal PR passes |
Before landing this, I think we should make sure that we are all using the same exact clang-format-18 version. Different clang-format versions (even if they're under the same exact major/minor version) might and will introduce breaking changes. For example, I have 18.1.3, and whenever I format, it formats every single file and makes changes right now. |
I think the correct version would be debian llvm deb most updated clang-format-18. |
@danlapid My clang-format version makes the following change for all files. I think we should assert that in the repository, before making this change. We might have more conflicting differences.
|
Yeah I'm in favor of asserting major,minor,patch clang-format versions then if we're seeing such differences even on patch releases. |
Yeah I'm a bit surprised by the differences. We know the version in CI produces the same results as on my Mac. |
I noticed this type of change when trying to update the internal repo from using a tagged commit to 18.1.8 – I ultimately couldn't figure out what caused the change but there doesn't seem to be a flag to control it. It's unfortunate that clang-format's behavior is not really stable. Agree that we should enforce a major/minor version – 18.1.8 should be our best bet but apparently Ubuntu is still on 18.1.3 which lines up with Yagiz' comment https://packages.ubuntu.com/search?keywords=clang-format&searchon=names&suite=noble§ion=all |
@fhanau Do you think we should try to vendor clang-format in workerd? |
Did some digging with Yagiz, seems like SpaceBeforeCpp11BracedList is the flag that controls that but for some reason with older and newer clang versions it is not enforced if not set to true or false but with 18.1.3 it is enforces as false if not set. We could just set it to true then both versions would emit the same result supposedly, even though it would mean another small formatting chage. |
While fixing this issue, can we make sure we are on the same clang-format version via the format.py file? Ubuntu default clang-format might change at any time (or not). |
I think we should make sure everyone is using apt.llvm.org - we've had some problems when people don't use it. |
I don't want to bikeshed too much here – I think this is best addressed in a follow-up PR to sorting the includes. |
If we're in favour, I'll rewrite the commits with |
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.
I don't agree with some of the spacing decisions clang-format makes here (perhaps newlines are not needed between all groups), but also don't care enough to figure out how to do it differently.
4926675
to
d5abf3c
Compare
d5abf3c
to
62c9ca6
Compare
I actually ended up setting |
@npaun @danlapid The problem still exists. We should have set
|
Can you try to push a PR with those changes and see if it passes lint? |
In my experience, a consistent include order is very beneficial. It saves time during PR reviews, avoiding comments when a dev has inserted an include in the wrong place, or has slightly different IDE settings than another.
It's been a month since we've had clang-format on, and things have been stable, so let's bring back @danlapid's include order config (#2505 (comment)) and apply it.
As last time, two manual adjustments were required:
jsg.h
jsg.h
and not its internal implementation headers likejsg/function.h