lintkit

package module
v0.2.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 2, 2026 License: MIT Imports: 0 Imported by: 0

README

lintkit

lintkit is a shared integration toolkit for modular lint systems.

It lets downstream libraries define diagnostics once and expose rules through stable contracts, while upstream tools run all rules in one policy-driven runtime.

This repository covers three concerns:

  • downstream contracts and provider registration;
  • upstream runtime, registry, policy, and execution;
  • deterministic snapshot and documentation generation for CI.

Terms

downstream module means a library that owns domain parsing and diagnostics.

upstream application means a tool that imports many modules, applies one policy, and produces one combined lint result.

Repository layout

  • lint contains downstream contracts and catalog helpers.
  • linting contains upstream runtime and policy logic.
  • cmd/lintkit is snapshot/doc/schema CLI tooling.
  • registry is in-process snapshot assembly API.
  • linttest contains downstream contract test helpers.

End-to-end example

Two downstream modules define local code catalogs:

// module_a
var catalogA, _ = lint.NewCodeCatalog(lint.CodeCatalogConfig{
  Module:            "modulea",
  CodePrefix:        "MODA",
  ModuleName:        "Module A",
  ModuleDescription: "Rules for module_a parser.",
  ScopeDescriptions: map[lint.Stage]string{
    "parse": "Parser diagnostics.",
  },
}, []lint.CodeSpec{
  lint.WarningCodeSpec(1001, "parse", "empty block"),
})

// module_b
var catalogB, _ = lint.NewCodeCatalog(lint.CodeCatalogConfig{
  Module:            "moduleb",
  CodePrefix:        "MODB",
  ModuleName:        "Module B",
  ModuleDescription: "Rules for module_b binary decoder.",
  ScopeDescriptions: map[lint.Stage]string{
    "decode": "Binary decode diagnostics.",
  },
}, []lint.CodeSpec{
  lint.ErrorCodeSpec(2001, "decode", "invalid header signature"),
})

An upstream app registers providers once:

engine, err := linting.NewEngineWithProviders(
  modulea.LintRulesProvider{},
  moduleb.LintRulesProvider{},
)
if err != nil {
  return err
}

Then it applies one policy to both modules:

cfg := linting.RunPolicyConfig{
  Exclude: []string{"**/vendor/**"},
  FailOn:  lint.SeverityError,
  Rules: []linting.RunPolicyRuleConfig{
    {
      Rule: "*",
      Severity: lint.SeverityWarning
    },
    {
      Rule: "MODB2001", 
      Enabled: linting.BoolPtr(false)
    },
    {
      Rule:    "modulea.parse.*",
      Exclude: []string{"**/generated/**"},
      Severity: lint.SeverityNotice,
    },
  },
}

Canonical runtime path is:

  • build effective profile via linting.BuildRunProfile(...);
  • execute rules via engine.RunWithProfile(...);
  • evaluate exit condition via profile.ShouldFail(result).

RunPolicyConfig.Rules is ordered. Later matching entries override earlier entries. cfg.ShouldFail(result) evaluates final exit condition for this config and always treats runtime rule errors as critical.

Path matching

linting is matcher-agnostic. Runtime uses PathMatcher, while PathRulesCompiler(...) compiles declarative glob patterns (*, **, ?) into runtime matchers.

Where to continue

Start with lint, then move to linting. For CI snapshot and docs generation use cmd/lintkit.

Documentation

Overview

Package lintkit is a shared integration layer for modular lint systems.

Import subpackages directly:

  • lintkit/lint defines downstream contracts and catalog helpers.
  • lintkit/linting provides upstream runtime, registry, and policy.
  • lintkit/registry assembles deterministic snapshots in-process.
  • lintkit/linttest provides contract checks for downstream module tests.

The root package intentionally exposes no runtime API.

Directories

Path Synopsis
cmd
lintkit command
Package main implements lintkit CLI for lint registry rendering.
Package main implements lintkit CLI for lint registry rendering.
lintkit/internal/app
Package app implements lintkit CLI command execution logic.
Package app implements lintkit CLI command execution logic.
lintkit/internal/collector
Package collector discovers and collects lint rule providers from Go packages using go toolchain.
Package collector discovers and collects lint rule providers from Go packages using go toolchain.
lintkit/internal/registryio
Package registryio provides snapshot IO helpers for lintkit CLI internals.
Package registryio provides snapshot IO helpers for lintkit CLI internals.
lintkit/internal/render
Package render renders lint registry documentation outputs.
Package render renders lint registry documentation outputs.
lintkit/internal/yamlutil
Package yamlutil provides YAML encoding helpers for lintkit CLI.
Package yamlutil provides YAML encoding helpers for lintkit CLI.
Package lint provides downstream lint contracts and helper primitives.
Package lint provides downstream lint contracts and helper primitives.
Package linting provides upstream lint runtime primitives.
Package linting provides upstream lint runtime primitives.
Package linttest provides downstream catalog contract checks for tests.
Package linttest provides downstream catalog contract checks for tests.
Package registry provides in-process registry snapshot assembly helpers.
Package registry provides in-process registry snapshot assembly helpers.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL