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

Supporting buf format #1207

Closed
andrewparmet opened this issue May 12, 2022 · 1 comment · Fixed by #1208
Closed

Supporting buf format #1207

andrewparmet opened this issue May 12, 2022 · 1 comment · Fixed by #1208

Comments

@andrewparmet
Copy link
Contributor

andrewparmet commented May 12, 2022

The Buf tool for protobuf recently added the buf format command. Buf is currently published with a download link on their GitHub release page and to DockerHub. They have an open issue to publish binaries to Maven Central.

Is there any precedent for adding a binary tool like this as a formatter? It could be supported with a custom Ivy repository (for Gradle, at least) if that's something you'd be willing to incorporate.

@nedtwigg
Copy link
Member

Yes, we have support for two binary tools in Spotless right now, happy to add another one.

String exeAbsPath = ForeignExe.nameAndVersion("black", version)
.pathToExe(pathToExe)
.versionRegex(Pattern.compile("(?:black, version|black,|version) (\\S*)"))
.fixCantFind("Try running {@code pip install black=={version}}, or else tell Spotless where it is with {@code black().pathToExe('path/to/executable')}" + trackingIssue)
.fixWrongVersion("Try running {@code pip install --force-reinstall black=={version}}, or else specify {@code black('{versionFound}')} to Spotless" + trackingIssue)
.confirmVersionAndGetAbsolutePath();

String howToInstall = "" +
"You can download clang-format from https://releases.llvm.org and " +
"then point Spotless to it with {@code pathToExe('/path/to/clang-format')} " +
"or you can use your platform's package manager:" +
"\n win: choco install llvm --version {version} (try dropping version if it fails)" +
"\n mac: brew install clang-format (TODO: how to specify version?)" +
"\n linux: apt install clang-format (try clang-format-{version} with dropped minor versions)" +
"\n github issue to handle this better: https://github.com/diffplug/spotless/issues/673";
String exeAbsPath = ForeignExe.nameAndVersion("clang-format", version)
.pathToExe(pathToExe)
.fixCantFind(howToInstall)
.fixWrongVersion(
"You can tell Spotless to use the version you already have with {@code clangFormat('{versionFound}')}" +
"or you can download the currently specified version, {version}.\n" + howToInstall)
.confirmVersionAndGetAbsolutePath();

I'm fine with making installation of the buf tool a problem for the user (that's how we handle black and clang currently), or it can be automatic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants