Lint rule · ADN0010

adorn/shape-fields-typed

A class used as an exact @Shape declares every instance field with a field decorator.

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

What it reports

A class used as an exact shape (@Shape(Dto), Enforce.shape(Dto) or ObjectContracts.Shape(Dto)) with an instance field that has no field decorator, including a field inherited from a base class.

Why

A shape is exact by default: it accepts the keys of the fields that carry a field decorator and refuses every other own key. An undecorated field is therefore refused as an undeclared key, though the class declares it, and a value the class itself would produce fails its own shape.

Examples

Reported

reported by adorn/shape-fields-typed
import { Contract, CreateFieldDecorator, Shape, StringContracts as S } from 'adorn';

class Signup {
    @CreateFieldDecorator(S.Email()) email!: string;
    createdAt!: string;                                  // no field decorator
}

@Contract()
class Accounts {
    register(@Shape(Signup) body: Signup) { return body.email; }
}

Accepted

accepted
import { Contract, CreateFieldDecorator, Shape, StringContracts as S } from 'adorn';

class Signup {
    @CreateFieldDecorator(S.Email()) email!: string;
    @CreateFieldDecorator(S.DateTime()) createdAt!: string;
}

@Contract()
class Accounts {
    register(@Shape(Signup) body: Signup) { return body.email; }
}

Details

Static fields are not instance fields and are ignored. A shape opened with {extra: 'allow'} accepts the extra key and is not reported (that opt-out wants an adorn-allow reason, see justify-opt-out). A field typed on a base class and redeclared on the subclass is typed.

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

Messages

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

Message idText
untypedField[ADN0010] Shape({{cls}}): field '{{field}}'{{via}} has no field decorator, so the exact shape refuses a key the class declares (DEC-116). Decorate it, or pass {extra: 'allow'}.

All rules · the adorn/eslint guide