Skip to content
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

Update .clang-format import groups order #1254

Merged
merged 1 commit into from
Nov 21, 2024

Conversation

tweksteen
Copy link
Member

Match the import order to the style guide[1]. This is based on art/.clang-format.

[1] https://source.android.com/docs/setup/contribute/code-style#order-import-statements

Test: repo upload .
Change-Id: Ifd5c45fce2e20adf818d1cf03637f07b10786122

@tweksteen tweksteen requested a review from prbprbprb November 5, 2024 00:07
@tweksteen
Copy link
Member Author

We might want to add a step to Gradle to run clang-format as part of CI (I don't think this is done yet, but I might be wrong). One option is to use Spotless with clangFormat(). Let me know if that something you'd consider and I can create a bug to track that. Thanks.

@prbprbprb
Copy link
Collaborator

The problem is that all the old code is formatted to the wrong standard, so if we auto-run clang-format then every time we touch a file, it'll get reformatted and break the git blame history.

@tweksteen
Copy link
Member Author

Spotless has a configuration option ("ratchet") exactly for that purpose: https://github.com/diffplug/spotless/blob/main/plugin-gradle/README.md#how-can-i-enforce-formatting-gradually-aka-ratchet

It will only report a formatting issue on the diff (and nothing else).

@prbprbprb
Copy link
Collaborator

Ah, that sounds promising then!

Match the import order to the style guide[1]. This is based on
art/.clang-format.

[1] https://source.android.com/docs/setup/contribute/code-style#order-import-statements

Test: repo upload .
Change-Id: Ifd5c45fce2e20adf818d1cf03637f07b10786122
@tweksteen tweksteen force-pushed the clang_format_upstream branch from 0469224 to 6ba6ed8 Compare November 21, 2024 00:26
@tweksteen tweksteen merged commit 38498a2 into google:master Nov 21, 2024
37 checks passed
@tweksteen
Copy link
Member Author

Quick update: I spent some time trying to setup spotless. There are a few issues:

  • You need to define the exact clang-format version, including the minor component eg 14.0.6. It is highly unlikely that the different platforms have a specific version in common (eg Debian and Ubuntu don't).
  • The formatting is per-file. So if someone updates only one line, the whole file gets reformatted.

I think a better option will be to use git clang-format (as it's done in AOSP), which only reformat the specific lines from the diff. I'll explore that avenue.

@prbprbprb
Copy link
Collaborator

The formatting is per-file. So if someone updates only one line, the whole file gets reformatted.

Yeah, that was my reading of it which put me off somewhat.

@tweksteen tweksteen deleted the clang_format_upstream branch November 27, 2024 03:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants