Skip to content

Supporting buf format #1207

Description

@andrewparmet

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.

Activity

  1. nedtwigg commented on May 12, 2022

    @nedtwigg
    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions