feat: enforce model conventions in labset-lint-plugin - #2
Merged
Conversation
Add three lint checks for messages carrying the labset.plugin.v1.message option, in a new internal/checks package (one check_<name>.go per check): - MODEL_FILE_STRUCTURE: model lives in <provider>/<domain>/<version>/models.proto with a package that matches the directory path. - MODEL_TOP_LEVEL: the option may only be applied to top-level messages. - MODEL_ENTITY_FIELD: field 1 must be labset.data.v1.Entity. Register checks.Spec in labset-lint-plugin and cover each check with the stock checktest harness plus a pure-function table test for the file-structure logic. Add a mise fmt task and allow the bufplugin descriptor import in depguard. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
The latest Buf updates on your PR. Results from workflow schema / buf (pull_request).
|
- Gate isModel on role == ROLE_ENTITY so non-entity annotations no longer trip MODEL_ENTITY_FIELD (with a role-unspecified fixture to prove it). - Accept buf version dirs without a trailing digit (v1alpha, v1beta) and validate provider/domain segments are proto identifiers. - Drive all three checks off checkutil.NewMessageRuleHandler, detecting nesting via Parent(); this drops the hand-rolled recursion and extends the entity-field and file-structure checks to nested models. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds the first custom lint checks to
labset-lint-plugin, enforcing the model conventions forROLE_ENTITYmessages annotated with thelabset.plugin.v1.messageoption. Checks live in a newinternal/checkspackage, onecheck_<name>.goper check, registered throughchecks.Spec.Checks
MODEL_FILE_STRUCTURE<provider>/<domain>/<version>/models.protowith a package matching the directory path (v1/v1alpha/v1beta1-style version segment; provider/domain must be proto identifiers).MODEL_TOP_LEVELMODEL_ENTITY_FIELDlabset.data.v1.Entity.A message counts as a model only when the option sets
role == ROLE_ENTITY; a role-unspecified annotation is silently ignored (buf lint plugins have no "warning" severity, so the choice is error-or-silent — silent is intentional here).All three checks run off
checkutil.NewMessageRuleHandler, detecting nesting viaParent(), so they apply uniformly to top-level and nested messages.Tests
Stock
checktestharness — fixtures underinternal/checks/golden/<check>/<case>/, labset imports resolved against the realprotosdir viaDirPaths, table tests keyed by name. The file-structure logic also has a pure-function table test covering every branch (version suffixes, non-identifier segments, package mismatch). Arole_unspecifiedfixture proves a non-entity annotation is not treated as a model. Assertions use testify consistently.Review
High-effort multi-agent review ran over the diff; all surfaced findings were addressed:
v1beta1but rejectedv1alpha/v1beta(missing-digit false positive) — fixed.isModelkeyed off option presence rather thanrole == ROLE_ENTITY, mis-firingMODEL_ENTITY_FIELDon non-entity models — now gated on the role.MODEL_TOP_LEVELhand-rolled descriptor recursion — replaced with the stockcheckutil.NewMessageRuleHandler+Parent()check, which also extends the entity-field and file-structure checks to nested models.Supporting changes
cmd/labset-lint-plugin/main.go: registerchecks.Spec(was an empty spec)..mise.toml: add afmttask (golangci-lint fmt), since golines is enforced.CONTRIBUTING.md: document theinternal/checkslayout and "adding a lint check".Notes
buf.yaml— its protos aren't model messages, so the checks are meant to run downstream.mise run fmt,mise run lint, andmise run testall pass.🤖 Generated with Claude Code