import type { TSESLint, TSESTree } from "@typescript-eslint/utils"; import type { Rule as ESLintRule } from "eslint"; /** Maps a message, or part of one, to the message to show instead. */ export type CustomMessages = Readonly>; /** * A rule that withCustomMessages() can wrap: ESLint's `Rule.RuleModule`, * typescript-eslint's `RuleModule`, or any other `{ meta, create }` object. */ export interface WrappableRule { meta?: object | undefined; create(context: never): object; } /** What a wrapped rule passes to `context.report()`. */ export interface WrappedReport { message?: unknown; messageId?: unknown; data?: Record; node?: TSESTree.Node; loc?: TSESTree.SourceLocation | TSESTree.Position; fix?: TSESLint.ReportFixFunction | null; suggest?: unknown; } export declare function isRecord(value: unknown): value is Record; /** * Why `messages` is not a map of messages to the messages to show instead, * or undefined when it is one: a plain object whose values are strings. */ export declare function messagesProblem(messages: unknown): string | undefined; /** The message, or suggestion description, a report shows. */ export declare function messageOf(report: { message?: unknown; desc?: unknown; messageId?: unknown; data?: Record; }, messages: Record | undefined): string | undefined; /** * The custom message for a report: the value of the first key of `custom` that * the report's message equals or contains, or `undefined` if none does. */ export declare function customMessageFor(report: WrappedReport, ruleMessages: Record | undefined, custom: CustomMessages): string | undefined; /** * A rule context with `overrides` in place of those properties of `context`. * Everything else, such as `sourceCode`, `settings` or `id`, is read from * `context` itself, through the prototype, the way ESLint itself extends the * context it shares between rules. */ export declare function contextWith(context: Context, overrides: Record): Context; /** * What withCustomMessages() adds to the type of the rule it returns, so that a * typescript-eslint rule fits the plugin rule type of the installed ESLint (a * peer dependency): a `create()` that takes any context, as typescript-eslint's * `LooseRuleDefinition` does, for ESLint 9.20 and later, whose context type * typescript-eslint's `create()` does not accept; and ESLint's own `meta`, for * ESLint 9.19, whose `meta.docs.recommended` is a boolean where * typescript-eslint's is a string. */ interface LooseCreate { create(context: unknown): any; meta?: ESLintRule.RuleModule["meta"]; } /** * Returns `rule` with some of its messages replaced, for registering in a * plugin of your own: * * ```js * plugins: { custom: { rules: { "some-rule": obsidianmd.withCustomMessages(somePlugin.rules["some-rule"], { "Original message": "New message" }) } } }, * rules: { "custom/some-rule": ["error", { ... }] }, * ``` * * A report whose message equals or contains a key of `messages` shows that * key's value instead, the first matching key winning, as in * `obsidianmd/rule-custom-message`. The message matched is the one ESLint shows, * placeholders filled in. The new message can use the report's placeholders, * such as `{{name}}`. Every other report is the rule's own, and so are the * fixes and suggestions. * * The result has `rule`'s `meta`, so ESLint checks its options against `rule`'s * schema, fills in `rule`'s defaults and accepts its fixes and suggestions. * * Its type is `rule`'s, with a `create()` and `meta` that also fit the * installed ESLint's own types, so a typescript-eslint rule fits ESLint's * `defineConfig()` and `Linter.Config`. */ export declare function withCustomMessages(rule: Rule, messages: CustomMessages): Rule & LooseCreate; export {};