Skip to content

feat: enforce model conventions in labset-lint-plugin - #2

Merged
viqueen merged 3 commits into
mainfrom
feature/lint-rules
Aug 12, 2026
Merged

feat: enforce model conventions in labset-lint-plugin#2
viqueen merged 3 commits into
mainfrom
feature/lint-rules

Conversation

@viqueen

@viqueen viqueen commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds the first custom lint checks to labset-lint-plugin, enforcing the model conventions for ROLE_ENTITY messages annotated with the labset.plugin.v1.message option. Checks live in a new internal/checks package, one check_<name>.go per check, registered through checks.Spec.

Checks

ID Enforces
MODEL_FILE_STRUCTURE Model messages live in <provider>/<domain>/<version>/models.proto with a package matching the directory path (v1 / v1alpha / v1beta1-style version segment; provider/domain must be proto identifiers).
MODEL_TOP_LEVEL The option may only be applied to top-level messages — nested messages carrying it are flagged.
MODEL_ENTITY_FIELD Field 1 must be labset.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 via Parent(), so they apply uniformly to top-level and nested messages.

Tests

Stock checktest harness — fixtures under internal/checks/golden/<check>/<case>/, labset imports resolved against the real protos dir via DirPaths, 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). A role_unspecified fixture 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:

  • Version regex accepted v1beta1 but rejected v1alpha/v1beta (missing-digit false positive) — fixed.
  • isModel keyed off option presence rather than role == ROLE_ENTITY, mis-firing MODEL_ENTITY_FIELD on non-entity models — now gated on the role.
  • MODEL_TOP_LEVEL hand-rolled descriptor recursion — replaced with the stock checkutil.NewMessageRuleHandler + Parent() check, which also extends the entity-field and file-structure checks to nested models.
  • Package-mismatch message could show a nonsensical expected name for non-identifier path segments — provider/domain segments are now validated as identifiers, yielding a clearer directory violation.

Supporting changes

  • cmd/labset-lint-plugin/main.go: register checks.Spec (was an empty spec).
  • .mise.toml: add a fmt task (golangci-lint fmt), since golines is enforced.
  • CONTRIBUTING.md: document the internal/checks layout and "adding a lint check".

Notes

  • The plugin is not wired into this repo's own buf.yaml — its protos aren't model messages, so the checks are meant to run downstream.

mise run fmt, mise run lint, and mise run test all pass.

🤖 Generated with Claude Code

viqueen and others added 2 commits August 11, 2026 22:51
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>
@github-actions

github-actions Bot commented Aug 11, 2026

Copy link
Copy Markdown

The latest Buf updates on your PR. Results from workflow schema / buf (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedAug 11, 2026, 1:37 PM

- 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>
@viqueen
viqueen merged commit e6cb3b9 into main Aug 12, 2026
2 checks passed
@viqueen
viqueen deleted the feature/lint-rules branch August 12, 2026 07:07
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.

1 participant