Skip to content

Embedding polylint

poly is also a library. polylint-sdk is the supported embedding surface: a small, documented facade over poly-core’s runner, with owned typed inputs and a closed error enum. Everything the facade does not re-export stays free to change.

Linter is Send + Sync and cheap to clone. It owns the cache store, the component host and index, the tool executor and the worker budget; each lint or format call builds a fresh per-run context (ADR 0083), runs on its own worker pool, and forgets the per-run memos afterwards — so sequential and concurrent calls behave like separate poly invocations.

use polylint_sdk::{LintRequest, Linter, TrustMode};
let linter = Linter::builder(TrustMode::Enforce)
.offline(true) // never download a component
.build();
let run = linter.lint(LintRequest::new(["src"]).root("/work/repo").no_cache(true))?;

Requests carry owned inputs, so they outlive the call: root stands in for the process working directory, config names one explicit poly.toml, overrides takes the same KEY=VALUE layering as --set, and control stops the run through a RunControl.

Every failure is a polylint_sdk::Error, with std::error::Error::source where a layer below preserved a cause:

Variant Produced by
InvalidRequest a request that sets both only and skip
Config a config the facade loads (the explicit file, or the one the root resolves) that fails for a non-I/O reason; inside a run, only when the chain carries a TOML error
Paths a named path, or the explicit config file, that does not exist
Component a needed downloadable component that is unavailable
Engine an engine selection nothing answers to
Io a file that cannot be read
Stopped a cancelled run or an exceeded deadline
Run anything else the run failed on before checking a file

A run that checked its files returns Ok however many findings it reports; a file an engine failed on is in LintRun::errors / FormatRun::errors, exactly as the CLI reports it.

FormatRequest::write and LintRequest::fix rewrite each file as it is processed, not after the whole run succeeds. A call that then fails — Error::Component for a component the run needed, Error::Stopped, Error::Run — leaves the files it already processed rewritten, and the error does not name them. Run the dry run first when that matters.

The crate is a workspace member: cargo test -p polylint-sdk. cargo-semver-checks needs a published baseline, so mise run check:semver-sdk refuses to pretend it checked anything until one exists (ADR 0110).