bufbuild / intellij-buf

IntelliJ plugin for Buf
https://plugins.jetbrains.com/plugin/19147-buf-for-protocol-buffers
Apache License 2.0
17 stars 2 forks source link

Allow custom buf.yaml file for linting #243

Open apodznoev opened 1 month ago

apodznoev commented 1 month ago

Currently, the plugin performs linting like:

 runBufCommand(
                        project,
                        owner,
                        workingDirectory,
                        listOf("lint", "--error-format=json"),
                        expectedExitCodes = setOf(0, BUF_EXIT_CODE_FILE_ANNOTATION),
                    )

using default Buf settings.

In case the project follows a different configuration - e.g. uses buf.yaml with except block:

version: v1
deps:
- buf.build/googleapis/googleapis
breaking:
  ignore_unstable_packages: true
  use:
  - FILE
lint:
  allow_comment_ignores: true
  use:
  - COMMENTS
  - DEFAULT
  - PACKAGE_NO_IMPORT_CYCLE
  - UNARY_RPC
  except:
  - RPC_RESPONSE_STANDARD_NAME
  - RPC_REQUEST_RESPONSE_UNIQUE

The plugin reports a warning with a suggestion to apply a fix, which contradicts the project's configuration.

A solution would be to provide a setting with path to buf.yaml to be used for lining.

E.g.

configFileContent = readFrom(project.bufSettings.state.bufConfigPath)
 runBufCommand(
                        project,
                        owner,
                        workingDirectory,
                        listOf("lint", "--error-format=json", "--config="+configFileContent),
                        expectedExitCodes = setOf(0, BUF_EXIT_CODE_FILE_ANNOTATION),
                    )
pkwarren commented 1 month ago

Can you provide a sample project or describe the layout of your project? Where is the buf.yaml located relative to the project root and the .proto files?

You may also be interested in https://buf.build/docs/migration-guides/migrate-v2-config-files. In v2 configs, you can easily add a buf.yaml at the root of the project and point to modules which are stored in subdirectories.

apodznoev commented 1 month ago

Thank you for your response highly appreciated! And for the link, in particular, I missed the migration.

Our layout is a bit sophisticated, so I try first to describe it and provide a project if needed.

We have a project with proto files, which are there for self-service for all teams (to create/update/retire services and their protos). We also provide a bespoke CLI for running various linting rules which are made as a combination of internal requirements and most of Buf rules - but not all (a few got disabled in favor of custom ones).

Updating the CLI and its rules happens in the background for users without any actions required from their side. Some portion (or even the majority) of users have the buf-plugin (with default Buf rules) installed, and it provides false-positive warnings for disabled rules in CLI, which we cannot control.

So we have only an option to force users to delete the plugin (maybe by writing our own one).

Alternatively, we could release the actual effective buf.yaml configuration along with the CLI update and use it in the plugin - provided there will be such an option in the plugin itself.

Similar to what IntelliJ provides for JSON schemas - it can pick them from the URL directly or load them from the filesystem, relative or absolute to the project.

Hope it explains a bit about the problem.

pkwarren commented 1 month ago

We have a project with proto files, which are there for self-service for all teams (to create/update/retire services and their protos).

Would it be possible to include a buf.yaml file with the buf lint config rules you wish to enforce in this proto project, or is the desire to keep it entirely behind the bespoke CLI?

Alternatively, we could release the actual effective buf.yaml configuration along with the CLI update and use it in the plugin - provided there will be such an option in the plugin itself.

There are two options I could think of:

apodznoev commented 1 month ago

We could include with CLI updates the buf.yaml in the project with protos, although it's not as convenient as pointing to a static URL with the latest version of the configuration.

As far, as I've gathered, IntelliJ also doesn't provide an option to check in the default plugin configuration (e.g. disable continuous linting or change custom arguments for buf breaking for all users) in the project files, only a list of them?