Lint rule · ADN0506

adorn/contract-coverage

Every exported function and public method of an exported class that takes input has a contract.

IdADN0506, the prefix of every message
recommendedoff
stricterror
Fixableno
Needs type informationno: it also runs in an untyped config

What it reports

An exported function, or a public method of an exported class, that takes input and has no contract. It covers exported function declarations, exported const function literals, export {local} lists and default exports; a contract() or contract.checked() call counts as covered.

Why

At a boundary (an API handler, an LLM tool module) every input should be checked by a contract that also projects to the schema, docs and tests. This rule is the paradigm rather than a bug check, so it is off in recommended and an error in strict. boundary(globs) turns it on for just the files you name.

Examples

Reported

reported by adorn/contract-coverage
export function quote(city: string, days: number) {
    return city + ': ' + days + ' days';
}

Accepted

accepted
import { contract, Contracts } from 'adorn';

export const quote = contract(
    { params: [Contracts.string.notEmpty(), Contracts.number.between(1, 14)] },
    function quote(city: string, days: number) {
        return city + ': ' + days + ' days';
    },
);

Details

Skipped: functions and methods with no parameters, constructors (a constructor contract is optional), accessors, overload signatures, and private, protected or # members. To keep an uncovered export on purpose: // eslint-disable-next-line adorn/contract-coverage -- <why>.

To keep a finding on purpose, disable it with a reason, which justify-opt-out checks: // eslint-disable-next-line adorn/contract-coverage -- <why>.

Messages

The text ESLint prints, read from the rule itself. {{…}} is filled in for each finding.

Message idText
uncoveredFunction[ADN0506] Exported function '{{name}}' takes input but has no contract. Wrap it in contract({params: [...]}, ...), or say why not: // eslint-disable-next-line adorn/contract-coverage -- <why>.
uncoveredMethod[ADN0506] Public method '{{cls}}.{{name}}' of an exported class takes input but has no contract. Type its parameters and add @Contract() to the class (or @Validate() to the method).

All rules · the adorn/eslint guide