intellij-buf icon indicating copy to clipboard operation
intellij-buf copied to clipboard

Allow custom buf.yaml file for linting

Open apodznoev opened this issue 1 year ago • 4 comments

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),
                    )

apodznoev avatar Jul 16 '24 08:07 apodznoev

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.

pkwarren avatar Jul 22 '24 16:07 pkwarren

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.

apodznoev avatar Jul 22 '24 19:07 apodznoev

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:

  • Disabling 'Continuous background linting' under Tools/Buf. Since linting is enforced elsewhere with a custom CLI, this will disable running it in the Buf plugin. You could investigate the File Watcher plugin or Tools->External Tools to run your bespoke CLI.
  • There is already an option in the plugin to specify custom arguments for buf breaking - we could support this for buf lint too. This way you could pass a --config <path/to/buf.yaml> argument with the custom lint config.

pkwarren avatar Jul 22 '24 20:07 pkwarren

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?

apodznoev avatar Jul 23 '24 07:07 apodznoev