Skip to content

linters/eslint-rules/require-plugin-api-contract-schemas

ESLint rule: require-plugin-api-contract-schemas

Reports a method entry of a plugin API contract that lacks an input or an output schema.

A typed PluginApiContract<MyApi> already refuses such an entry at compile time. The untyped default, the structurally typed contracts a provider ships beside its api.d.ts, and every repository still on obsidian-dev-utils get no such check, so a {} entry there compiles, declares only that the method exists, and validates nothing. This rule closes that gap for every contract it can recognize.

An object literal is read as a contract when it is:

  • the initializer of a variable typed PluginApiContract (or TypedPluginApiContract); - the operand of satisfies PluginApiContract or as PluginApiContract; - the value of a contract property of an object literal, as passed to publishPluginApi, watchPluginApi or findPluginApi; - the initializer of a variable named *_API_CONTRACT, optionally followed by a _V<n> version suffix.

Each of its entries is a method entry. An entry, or a contract, written as the name of a const is followed to that constant’s object literal, so a method contract shared by several entries is checked once per entry.

Not attempted: an entry built by a call, read from another module, or carrying a spread cannot be read statically, so it is skipped. The rule under-reports rather than guessing.

Variable Description
MESSAGE_ID Message ID reported for a method entry that lacks a schema.
requirePluginApiContractSchemas ESLint rule requiring both an input and an output schema on every method entry of a plugin API contract.