-
-
Notifications
You must be signed in to change notification settings - Fork 699
Enforce code consistency with clang-format #3125
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
Conversation
This is a good idea, and I like clang-format. Having manual fixups after an automatic process is not good though :( Perhaps we should just adopt one of the more standard K&R-derived layouts? Would just getting rid of the spaces inside parenthesis be enough? |
Indeed, I don't like manual fixes either. Getting rid of the spaces inside parenthesis might help, see the subsequent commits. Line wrapping and adding comments in code regions we want to exclude is still necessary, but that's all. Diff is best viewed with GitHub's "Hide whitespace" option: |
8df8c5c
to
c2a037b
Compare
I was thinking, perhaps we should run clang-format only on new files (or files we touch)? I'm not sure if we should run clang-format over all files at once (since line wrapping still has to be done manually after that). |
c2a037b
to
1bd4481
Compare
Let's clang-format everything in one huge commit. Moving to automatic formatting in a series of steps will cause even more disruption. We could automatically format on push, or maybe just add a format check to the test suite. Any preference? |
4a79508
to
6efac0e
Compare
I agree. Let's clang-format everything in one go.
I added CI integration with commit 6efac0e and deliberately triggered a formatting error with the (temporary) commit However, it does not seem to detect all the files in CI (probably because this patch is huge). For example: Returns only the modified |
19b1199
to
0fff6c6
Compare
.clang-format
configuration file
Clarified the PR description and title. I confirm that re-running clang-format on all files does not change anything. TODO:
|
I reported this issue at llvm/llvm-project#59188. |
Shall we delay 8.14 for this PR? It looks like it could take a while to finish up. |
Alternatively, I'm fine with deferring this to the 8.15 cycle, hopefully the above clang-format issue will be addressed in LLVM 16 (which would avoid the need to rename all those |
OK, let's do 8.14 alpha then. |
Ooop, once #3164 is merged, I mean. |
😅 Leaving out the whitespace changes results in:
Ah, I had excluded those sources within commit 219afdb, but I accidentally touched FWIW, the bundled files are also ignored in the CI lint configuration: libvips/.github/workflows/lint.yml Lines 17 to 18 in d93ee2c
I wasn't sure how to approach this correctly, but this is indeed not the right solution. I'll change all
Good idea! I'll add some instructions for this. |
Oh duh, sorry, you talk about this right at the top, forget that comment about nsgif. I ran it like this, for reference:
And indeed it all seems to work well, though it's a bit slow. And having to use |
d93ee2c
to
e7163ba
Compare
Oh, I tested pytest, made a few formatting errors, tried a release build, tried a gtk-doc build, it all seems good and worked as expected. I suppose one thing is the 4-space tabs we set now. All line breaks are currently set for 8-space tabs, so there's quite a bit of "prettyfying" we could do. But I think this is probably better left to happen piecewise as we work on the various files. Summary: LGTM! Nice work on this, Kleis. |
Indeed, we may have to (re-)adjust some code to the 80-column limit. I'll do another careful review tomorrow. :) |
d123fca
to
1009689
Compare
I reported this issue at llvm/llvm-project#60357, see e.g. commit 7a09a5a for a possible workaround. |
I made a branch here that fixes the merge conflicts https://github.com/libvips/libvips/tree/kleisauke-clang-format Perhaps we should merge this PR now? It seems good to me. |
I held back this PR for a while because it could make backporting commits to the 8.14 branch difficult (as a different code style is used there). I suppose there won't be any backports to 8.14 now, so let me rebase and merge this. |
\o/, PR #3566 will hide this landed commit from git blame. |
Hooray! This is a very good thing. |
This PR adds a
.clang-format
configuration file (commit 149ca43) which I have been using to ensure consistent formatting.With commit 6149b40, I applied this configuration to the entire project with (using clang-format 16.0.5):
Though, it still required some manual edits after that:
or
variables (commit 5fedbc1);.clang-format
style;doc/
directory (commit 03ca653);.clang-format
style;profiles.c
(commit 5316e69);*.in
files (commit 33033d0).While we're here, commit 7450863 updates
.editorconfig
to reflect the clang-format changes and commit c322194 add some usage instructions for this.Last but not least, commit c31cdbe adds CI integration for this.