Lint rule · ADN0001

adorn/typed-parameters

Every parameter of a contracted method carries a type-bearing decorator.

IdADN0001, the prefix of every message
recommendederror
stricterror
Fixableno
Needs type informationyes: a typed config (parserOptions.projectService)

What it reports

A parameter of a contracted method or constructor with no type-bearing decorator: a constraint such as @NotEmpty(), or @Defined() for a value adorn can't type further. A type declared on a base class's method counts. Also a rest parameter of a contracted method, which collects arguments past the signature.

Why

Every parameter of a contracted method is typed (DEC-119), and a call past the typed signature is refused. The runtime refuses most untyped parameters when the class is installed, but a defaulted or rest parameter does not count in Function.length, so at runtime it gets only the ADN0001 development warning and every call that passes it is refused. The lint sees all of them in the source.

Examples

Reported

reported by adorn/typed-parameters
import { Contract, GreaterThan } from 'adorn';

@Contract()
class Jobs {
    run(@GreaterThan(0) n: number, label: string) {   // 'label' has no type
        return label.repeat(n);
    }
}

Accepted

accepted
import { Contract, Defined, GreaterThan, NotEmpty, Optional } from 'adorn';

@Contract()
class Jobs {
    run(
        @GreaterThan(0) n: number,
        @NotEmpty() label: string,
        @Optional() @Defined() meta?: unknown,
    ) {
        return label.repeat(n);
    }
}

Details

  • Markers state no type: @Optional(), @Default(), @Describe(), @Name(), @Sensitive() and @Telemetry alone leave a position untyped.
  • A method is contracted when an installer reaches it (@Contract() on the class or @Validate() on the method) and it carries a clause or a type-bearing parameter decorator. An undecorated helper on a @Contract() class, and a bare @Validate(), are left alone.
  • A constructor is checked only when it is contracted: a type-bearing parameter decorator, or @Requires/@Ensures on the class. A constructor with no contract imposes no signature.
  • Under extraArgs: 'allow' a rest parameter is not reported (that is its stated fix), but an untyped fixed parameter still is. A TypeScript this parameter is not a position.

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

Messages

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

Message idText
untyped[ADN0001] Parameter '{{name}}' of contracted method '{{method}}' has no type-bearing decorator, so it is past the signature and a call passing it is refused (DEC-119). Type it (a constraint, or @Defined() for any value; with @Optional() if it may be absent).
rest[ADN0001] Rest parameter '{{name}}' of contracted method '{{method}}' collects arguments past the signature, which are refused (DEC-115). Declare the positions it takes, or opt out with extraArgs: 'allow'.

All rules · the adorn/eslint guide