Check plugins cannot detect builtin rules that conflict with their own rules

オープン
#4,722 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
12/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
go, grpc
領域
cli, devtools

調査の方向性

Start with multi_client.go, where CheckRequest.rule_ids is filtered per plugin, and with the rule.proto and check_service.proto definitions in bufbuild/bufplugin. The issue offers two designs (an enabled_rule_ids field, or conflicting_rule_ids on Rule) and no decision has been made, so the first step is a maintainer-agreed protocol design. Done means an agreed proto change plus enforcement at configuration time in buf.

索引モデルが issue の本文から書いたものです。

説明

Feature

I maintain a lint check plugin, buf-lint-extra, whose rules replace or contradict builtin rules:

  • PACKAGE_DIRECTORY_MATCH_EXTRA and DIRECTORY_SAME_PACKAGE_EXTRA are variants of PACKAGE_DIRECTORY_MATCH and DIRECTORY_SAME_PACKAGE with extra options. Running both the builtin and the plugin rule reports the same files with different expectations.
  • FILE_LOWER_KEBAB_CASE contradicts FILE_LOWER_SNAKE_CASE, PACKAGE_CAMEL_CASE contradicts PACKAGE_LOWER_SNAKE_CASE, and ENUM_DEDICATED_PACKAGE (last package component is the enum name) contradicts PACKAGE_VERSION_SUFFIX. With both sides enabled, every file fails one of the two.

All of these builtin rules are part of STANDARD, so anyone who adds the plugin to a STANDARD config hits the conflict. Today the only thing a plugin can do is document a lint.except list in its README and hope users copy it.

The plugin cannot detect the situation itself:

  • CheckRequest.rule_ids is filtered per client in multi_client.go, so a plugin only ever sees its own rule IDs. The field's contract in check_service.proto says all IDs must be IDs returned by ListRules, so builtin IDs cannot be passed there without changing its meaning.
  • Nothing else in the request describes the lint configuration: there is no path to buf.yaml, and a Wasm plugin has no filesystem or environment at all. A native plugin could walk up from the working directory looking for buf.yaml, but that breaks with --config, with workspaces where each module has its own lint section, and would mean reimplementing category expansion and except handling, and it still would not work for Wasm and BSR plugins.

Two ways to solve this, either one would be enough:

  1. Tell plugins what else is enabled. A new field on CheckRequest, say repeated string enabled_rule_ids, with every rule ID buf runs in this check across the builtin rules and all plugins, while rule_ids keeps its current meaning. A plugin could then report or error out when it sees PACKAGE_DIRECTORY_MATCH next to PACKAGE_DIRECTORY_MATCH_EXTRA, and could also adapt its behaviour to other rules. My PACKAGE_DIRECTORY_MATCH_EXTRA already changes its default depending on whether ENUM_DEDICATED_PACKAGE is in rule_ids, which only works because both rules live in the same plugin.

  2. Let plugins declare conflicts and have buf enforce them. A new field on Rule in rule.proto, say repeated string conflicting_rule_ids: IDs of rules, builtin or from other plugins, that must not be enabled together with this one. buf already checks rule and category ID uniqueness across plugins and has replacement_ids for deprecated rules, so this would be one more declarative relation of the same kind. After resolving use and except, buf would fail (or warn) once, at configuration time, with a message pointing to lint.except, instead of users getting contradicting annotations on every file. This also covers conflicts between two unrelated plugins.

Option 2 is the better user experience, option 1 is more general. The protocol change belongs in bufbuild/bufplugin, but the enforcement and the request population are in buf, so filing here.

Seen with buf v1.73.0 and bufplugin-go v0.11.1.

主要言語
Go
スター
11.5k
フォーク
376
平均マージ
2日 3時間
マージ済み PR(30日)
21

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

bufbuild/buf のほかの issue

bufbuild/buf の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。