API ContractsAPI contracts
api-contracts/no-ambiguous-failure-contracts
Directly exported functions should not mix nullable or sentinel results with thrown errors unless each failure representation has a visibly distinct role.
01 Examples
TypeScript
export function findUser(id: string) { if (!id) throw new Error("missing"); return db.find(id) ?? null; }Finding
Disallow overlapping public failure channels.
02 Enable it
Setup
Install the package, register its plugin factory, then enable the rule.
Install the package
pnpm add -D @scruple/api-contractsRegister the plugin
In scruple.config.ts, register the factory under the api-contracts namespace used by the rule ID.
import { apiContracts } from "@scruple/api-contracts";
plugins: {
"api-contracts": apiContracts(),
},Enable the rule
"api-contracts/no-ambiguous-failure-contracts": "warn"- Package
@scruple/api-contracts- Default threshold
- 0.8
- Minimum confidence
- 0.7