Setup
npm i -D eslint typescript-eslint
import tseslint from 'typescript-eslint';
import adorn from 'adorn/eslint';
export default tseslint.config(
...tseslint.configs.recommended,
{ languageOptions: { parserOptions: { projectService: true, tsconfigRootDir: import.meta.dirname } } },
adorn.configs.recommended, // or adorn.configs.strict, or ...adorn.boundary(['src/api/**', 'src/tools/**'])
);
Several rules read the type checker, so the config must be typed (projectService or project). A rule decides what is adorn's from adorn's own declared types and exported names, resolved through the checker, so an import alias still counts and a local function that happens to be called Contract does not. eslint and @typescript-eslint/utils are optional peers: only this subpath loads them, and import 'adorn' never does.
Presets
| Preset | What it is for |
|---|---|
configs.recommended | Code that is wrong whatever your style: each rule moves a runtime refusal, or a contract that would silently go unenforced, to build time. The opt-out reason and @Optional() on a TypeScript-required parameter warn; contract coverage is off. |
configs.strict | recommended plus the paradigm: every rule is an error, a TypeScript default must be published with @Default(), and every export that takes input has a contract. adorn's own examples and tests pass it in CI. |
boundary(globs) | recommended everywhere and strict on the files you name, such as API handlers and LLM tool modules. Spread it: ...adorn.boundary(['src/api/**']). |
Rules
Each rule has its own page. Levels, fixes and descriptions are read from the plugin.
| Rule | Id | recommended | strict | Fix | Checks that |
|---|---|---|---|---|---|
typed-parameters | ADN0001 | error | error | Every parameter of a contracted method carries a type-bearing decorator. | |
relation-in-signature | ADN0005 | error | error | Arg(i, ...path) names a parameter of the signature and a property its type has. | |
optional-matches-ts | ADN0008 | error, {defaults: false} | error, {defaults: true} | A contracted method's optional parameters are optional to both TypeScript and adorn. | |
no-optional-on-required | ADN0008 | warn | error | yes | @Optional()/@Default() sits on a parameter TypeScript also lets a caller omit. |
shape-fields-typed | ADN0010 | error | error | A class used as an exact @Shape declares every instance field with a field decorator. | |
justify-opt-out | ADN0099 | warn | error | An opt-out of a strict default carries an adorn-allow: <reason> comment. | |
clause-below-validate | ADN0501 | error | error | yes | A clause decorator above @Validate() records after the install and is never enforced. |
contract-spec-shape | ADN0502 | error | error | contract() params are typed slots matching the function. | |
installer-present | ADN0503 | error | error | Parameter constraints and clauses sit on a class with @Contract() or a method with @Validate(). | |
no-sensitive-to-adorn-sink | ADN0505 | error | error | Report where a @Sensitive value reaches one of adorn's own emitters (@Log, a violation-message parameter). Report-only: adorn secures its own emissions, not a raw console.log. | |
contract-coverage | ADN0506 | off | error | Every exported function and public method of an exported class that takes input has a contract. |
Opt-outs say why
adorn is strict by default, with explicit opt-outs: {extra: 'allow'} on an object, extraArgs: 'allow' on a signature, and disableGuardEnforcement(). Each one carries its reason in an adorn-allow comment, on the opt-out's own lines or the line above it. The lint checks it; the runtime never reads it, and the contract never stores it, so a reason changes no snapshot or diff.
import { ObjectContracts, StringContracts } from 'adorn';
// adorn-allow: the upstream webhook adds fields we do not read
const payload = ObjectContracts.Fields({ id: StringContracts.NotEmpty() }, { extra: 'allow' });
A finding you keep on purpose is disabled with ESLint's own description, which the same rule checks: // eslint-disable-next-line adorn/installer-present -- <why>. See justify-opt-out.
Runtime diagnostic codes
In development, adorn reports problems it can only see at runtime through setContractDiagnosticsSink. Each diagnostic carries a stable code as data, beside the unchanged message: setContractDiagnosticsSink((message, { code }) => …). Where a lint rule finds the same problem, it carries the same id.
| Code | Problem | Lint rule |
|---|---|---|
ADN0001 | An untyped defaulted or rest parameter past the signature of a contracted method. | typed-parameters |
ADN0002 | An unsatisfiable constraint stack, on the installer and on toolSchemaFrom. | runtime only |
ADN0502 | A contract() required slot a default can never reach. | contract-spec-shape |
ADN0503 | Constraints that nothing installs: no @Contract(), no @Validate(). | installer-present |
ADN0507 | A @Telemetry opt-in vetoed by @Sensitive. | runtime only |
ADN0508 | A parameter decorator on a rest parameter, which types only the first argument it collects. | runtime only |
ADN0509 | A field contract on a class no construction wrapper covers, whose field is defined with [[Define]] semantics (useDefineForClassFields), so assignments skip the contract. | runtime only |
ADN0510 | An instance of the class held by one of its own static data properties (directly or in an array): a static initialiser or static {} block constructed it before @Contract() wrapped the class, so it was not checked. | runtime only |