Skip to content

Add documentation link to check annotation - #15

Open
ckohnert wants to merge 2 commits into
bufbuild:mainfrom
ckohnert:main
Open

ckohnert wants to merge 2 commits into
bufbuild:mainfrom
ckohnert:main

Conversation

@ckohnert

@ckohnert ckohnert commented Apr 5, 2026 •

Copy link
Copy Markdown

Adding the ability to add a documentation link to annotations (fixes #10, and precursor to fixing bufbuild/buf#4422).

I've also added a general-purpose qualifier field to facilitate rule-refinement in some way. I anticipate using this to capture api-linter's rules, but it would also be useful if checking against external systems that require extra context as to the reason of a failure and want to carry that through to the user.

@ckohnert
ckohnert requested a review from bufdev as a code owner April 5, 2026 19:39
@CLAassistant

CLAassistant commented Apr 5, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@ckohnert

ckohnert commented Oct 7, 2026

Copy link
Copy Markdown
Author

Hi @pkwarren, I saw you are recently active in this project. I don't suppose you could take a look at this PR? I'd love to link to custom rules from buf check plugins!

// A URL that provides more human-readable information about the rule in question.
//
// Optional.
string documentation_link = 5;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this belong on Rule instead of an annotation? Also if we intend to show the field to users we should add some constraints on the link format, for example:

string documentation_url = 5 [
  (buf.validate.field).ignore = IGNORE_IF_ZERO_VALUE,
  (buf.validate.field).string.uri = true,
  (buf.validate.field).string.max_len = 256,
  (buf.validate.field).cel = {
    id: "documentation_url_http_scheme"
    message: "documentation_url must use the https or http scheme"
    expression: "this.startsWith('https://') || this.startsWith('http://')"
  }
];

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some rules have "sub-rules" or specific sub-sections that are applicable and the current formulation of Rules within the Buf ecosystem is not granular enough, so this needs to be per-annotation, because the nature of the violation may need to point to a specific part of a rule or hint. For example https://example.com/rules/1234#dependencies.

Also, while my use case currently would be leveraging http for links, I'm not sure it's worth being quite so opinionated on the validation front. You could just as easily want to reference a URN or custom URL scheme other than http(s).

// Simple rules will probably not require this level of detail because it is obvious, but
// for more complex logic (such as checks involving external systems), it can be helpful to
// provide an identifier that narrows down why the rule failed.
string failure_code = 6;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have an example of how this will be used? If not I'd suggest leaving it off until we have a concrete use case and a way to surface this information to users.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use cases for this would be typically associated with invoking some other tool or encoding a specific manner of failure. Some examples:

  • A Visual Studio warning/error code: C4819
  • A cli exit code: 1 = lint error, 2 = configuration issue
  • A remote invocation against a service: 500 Internal Error

We could certainly skip this as it's not blocking me, but it seemed useful to be able to convey additional context on the nature of failures in a semi-generic way without pulling in some more sophisticated structured error reporting.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support some sort of "more info" link in annotations

3 participants