Skip to content

Format .proto files with spotlessApply #13

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ricekot
Copy link
Contributor

@ricekot ricekot commented Jan 7, 2025

  • Use the buf-gradle-plugin to download the correct buf binary automatically and configure spotless to use it
  • Update spotless plugin to 7.0.0 (released today)
  • Use spotless to format files in this repo

- Use the buf-gradle-plugin to download the correct buf binary automatically
  and configure spotless to use it
- Update spotless plugin to `7.0.0`
- Use spotless to format files in this repo

Signed-off-by: Akshath Kothari <[email protected]>
@ricekot ricekot requested a review from a team as a code owner January 7, 2025 05:06
build.gradle.kts Outdated
@@ -6,6 +6,7 @@ plugins {
id("org.hypertrace.ci-utils-plugin") version "0.3.0"
id("org.hypertrace.publish-plugin") version "1.0.4"
id("org.owasp.dependencycheck") version "8.4.0"
id("com.diffplug.spotless") version "7.0.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than using spotless directly you could just use the last version of this plugin to have been published to dogfood it a bit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to use the current version and settled on this, but that's a good idea to use the last version.

project
.getConfigurations()
.getByName(BufSupportKt.BUF_BINARY_CONFIGURATION_NAME)
.getSingleFile();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't typically want to do something like this since it forces the buf binary to be resolved whether the user is formatting or not. If the buf plugin is responsible for downloading it, are they not already making it executable? Can you use a provider instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're not making it executable. They do the same in their exec task: https://github.com/bufbuild/buf-gradle-plugin/blob/f03bbc1e5cf902eaf9c505d0b43d603aee6f5a85/src/main/kotlin/build/buf/gradle/BufSupport.kt#L74-L76
I can switch to a provider.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to use a provider, let me know if that was what you were expecting.

Signed-off-by: Akshath Kothari <[email protected]>
build.gradle.kts Outdated
@@ -4,6 +4,7 @@ plugins {
`java-gradle-plugin`
id("org.hypertrace.repository-plugin") version "0.4.0"
id("org.hypertrace.ci-utils-plugin") version "0.3.0"
id("org.hypertrace.code-style-plugin") version "latest.release"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We always want versions pinned. By latest version, I meant the actual version that was most recent :) Otherwise a breaking change could break the build.

format ->
format
.buf(bufExtension.getToolVersion())
.pathToExe(bufBinaryProvider.get().getAbsolutePath()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so the provider part is right, but if pathToExe doesn't accept a provider we don't get the benefit we're looking for - we want gradle to be resolving the provider JIT so .get() is usually a red flag.

This actually is a closure already (the lambda from 67) it's just one that likely evaluates during config time rather than execution. So moving the resolution inside here appears to be the best we can do. Given that, we have the option of either removing the explicit provider and moving that code inside this lambda or leaving it as is. They should be equivalent, so up to you which you feel is more readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, I see what you mean now. I believe the spotless gradle plugin supports lazy configuration, so it shouldn't try to configure the protobuf plugin if the user is not formatting files. I'll revert my last commit that moved the resolution from this lambda to a provider.

@ricekot ricekot marked this pull request as draft January 13, 2025 11:39
@ricekot
Copy link
Contributor Author

ricekot commented Jan 13, 2025

Spotted a few issues with this - bufLint runs automatically and fails for subprojects which don't have any proto files. The buf.yaml file is also ignored which should probably be fine but we should probably delete it if it's not used.

Converted to draft for now, will revisit this in a while.

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