Lint rule · ADN0099

adorn/justify-opt-out

An opt-out of a strict default carries an adorn-allow: <reason> comment.

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

What it reports

An opt-out of a strict default with no reason: {extra: 'allow'} passed to Fields, Shape or Contracts.object; extraArgs: 'allow' on contract(), @Contract() or @Validate(); and disableGuardEnforcement(). Also an eslint-disable comment naming an adorn/ rule with no -- <reason>.

Why

adorn is strict by default with explicit opt-outs, and an opt-out with no reason is indistinguishable from a mistake. The reason is a comment, // adorn-allow: <reason>, on the opt-out's own lines, the line directly above it, or the line directly above the statement that holds it. The runtime never reads it and the contract never stores it, so it changes no snapshot or diff.

Examples

Reported

reported by adorn/justify-opt-out
import { ObjectContracts, StringContracts } from 'adorn';

const payload = ObjectContracts.Fields({ id: StringContracts.NotEmpty() }, { extra: 'allow' });

Accepted

accepted
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' });

Details

Only an options object passed straight to an adorn call is an opt-out, so an unrelated {extra: 'allow'} is never reported. An empty adorn-allow: is reported. adorn-allow justifies an opt-out written in data; it does not suppress other findings. To keep a finding on purpose, use ESLint's own description: // eslint-disable-next-line adorn/installer-present -- <why>.

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

Messages

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

Message idText
unjustified[ADN0099] {{what}} opts out of a strict default without a reason. Add a comment on the line or the line above: // adorn-allow: <why>.
commentedNoMarker[ADN0099] {{what}} opts out of a strict default; the comment next to it has no 'adorn-allow: <why>' reason marker.
emptyReason[ADN0099] 'adorn-allow:' needs a reason after the colon.
disableWithoutReason[ADN0099] This eslint-disable of {{rules}} has no reason. Add one after the rule list: -- <why>.

All rules · the adorn/eslint guide