import type { Maybe } from '@dereekb/util'; import { type AstNode } from './util'; /** * Name of the `@dereekb/model` helper that expands an arktype definition to `T | null | undefined`. */ export declare const CLEARABLE_FUNCTION_NAME = "clearable"; /** * Module that publishes {@link CLEARABLE_FUNCTION_NAME}. */ export declare const CLEARABLE_IMPORT_MODULE = "@dereekb/model"; /** * Identifier callees whose object-literal argument is an arktype definition (`type({ ... })`, `scope({ ... })`). */ export declare const DEFAULT_ARKTYPE_DEFINITION_CALLEE_NAMES: readonly string[]; /** * Arktype combinator methods that take an object-literal definition (`targetModelParamsType.merge({ ... })`). */ export declare const DEFAULT_ARKTYPE_COMBINATOR_METHOD_NAMES: readonly string[]; /** * Options for the prefer-clearable-arktype rule. */ export interface FirebasePreferClearableArktypeRuleOptions { /** * Name of the clearable helper. Defaults to {@link CLEARABLE_FUNCTION_NAME}. */ readonly clearableFunctionName?: string; /** * Module the helper is auto-imported from. Defaults to {@link CLEARABLE_IMPORT_MODULE}. */ readonly importModule?: string; /** * Whether the fixer may add the helper's import when it is missing. Defaults to `true`. */ readonly autoImport?: boolean; /** * Whether to also report definitions that union only one of `null` / `undefined`. Defaults to * `false`, since a single-nullish definition can be a deliberate narrowing rather than a clearable * field. */ readonly includeSingleNullish?: boolean; /** * Identifier callee names that take an arktype definition. Defaults to {@link DEFAULT_ARKTYPE_DEFINITION_CALLEE_NAMES}. */ readonly definitionCalleeNames?: string[]; /** * Combinator method names that take an arktype definition. Defaults to {@link DEFAULT_ARKTYPE_COMBINATOR_METHOD_NAMES}. */ readonly combinatorMethodNames?: string[]; } /** * ESLint rule definition for prefer-clearable-arktype. */ export interface FirebasePreferClearableArktypeRuleDefinition { readonly meta: { readonly type: 'suggestion'; readonly fixable: 'code'; readonly docs: { readonly description: string; readonly recommended: boolean; }; readonly messages: Readonly>; readonly schema: readonly object[]; }; create(context: { options: FirebasePreferClearableArktypeRuleOptions[]; report: (descriptor: { node: AstNode; messageId: string; data?: Record; fix?: (fixer: AstNode) => Maybe | AstNode[]; }) => void; sourceCode: AstNode; }): Record void>; } /** * ESLint rule that requires arktype model/params definitions to express a clearable field with * `clearable('TYPE')` rather than by unioning the nullish keywords inline * (`'TYPE | null | undefined'`) or by appending them with `.or(...)`. * * `clearable(...)` is the workspace's canonical spelling for the `Maybe` fields on a params * interface: it names the semantic (`null` clears the field, `undefined` leaves it unchanged) * instead of restating the union at every property, and it is what the model-api validator's * `MAYBE_WITHOUT_CLEARABLE` check and the JSON Schema export helper both key off. An inline union * decodes the same way today but drifts from both. * * Only properties of an object literal passed to an arktype definition call (`type({ … })`, * `someType.merge({ … })`, …) are considered, so ordinary object literals — and `clearable`'s own * implementation — are left alone. * * The fix rewrites the property value and, when the helper is not already in scope, adds its import * (once per pass; the remaining properties are rewritten in the same pass alongside it). When no * import can be anchored the violation is reported without a fix rather than emitting a reference to * an unimported helper. * * @example * ```ts * // WARN — preferClearableDefinition * export const updateWidgetParamsType = type({ * 'name?': 'string | null | undefined', * 'tags?': 'string[] | null | undefined' * }); * * // WARN — preferClearableOrChain * export const publishWidgetParamsType = type({ * 'entries?': widgetEntryParamsType.array().or('null | undefined') * }); * * // OK * export const updateWidgetParamsType = type({ * 'name?': clearable('string'), * 'tags?': clearable('string[]') * }); * ``` */ export declare const FIREBASE_PREFER_CLEARABLE_ARKTYPE_RULE: FirebasePreferClearableArktypeRuleDefinition;