diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 971df45ba..a70bbc2b6 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -447,11 +447,19 @@ export type RuleFixer = ( fixer: RuleTextEditor, ) => RuleTextEdit | Iterable | null; +/** + * Data that can be used to fill placeholders in error messages. + */ +export type MessagePlaceholderData = Record< + string, + string | number | boolean | bigint | null | undefined +>; + export interface ViolationReportBase { /** * The data to insert into the message. */ - data?: Record | undefined; + data?: MessagePlaceholderData | undefined; /** * The fix to be applied for the violation. @@ -485,7 +493,7 @@ export interface SuggestedEditBase { /** * The data to insert into the message. */ - data?: Record | undefined; + data?: MessagePlaceholderData | undefined; /** * The fix to be applied for the suggestion. diff --git a/packages/core/tests/types/types.test.ts b/packages/core/tests/types/types.test.ts index 3719a2f64..2861115c1 100644 --- a/packages/core/tests/types/types.test.ts +++ b/packages/core/tests/types/types.test.ts @@ -320,6 +320,28 @@ const testRule: RuleDefinition<{ foo: "foo", bar: 1, baz: true, + qux: false, + a: 1n, + b: null, + c: undefined, + d: void 0, + // @ts-expect-error -- Symbols are not allowed in `data`. + e: Symbol("b"), + // @ts-expect-error -- Objects are not allowed in `data`. + f: { + hi: "hi", + }, + // @ts-expect-error -- Arrays are not allowed in `data`. + g: [1, 2, 3], + // @ts-expect-error -- Sets are not allowed in `data`. + h: new Set([1, 2, 3]), + // @ts-expect-error -- Maps are not allowed in `data`. + i: new Map([ + ["a", 1], + ["b", 2], + ]), + // @ts-expect-error -- Functions are not allowed in `data`. + j: () => {}, }, // @ts-expect-error -- 'fix' is required in suggestion objects fix: null, @@ -336,6 +358,28 @@ const testRule: RuleDefinition<{ foo: "foo", bar: 1, baz: true, + qux: false, + a: 1n, + b: null, + c: undefined, + d: void 0, + // @ts-expect-error -- Symbols are not allowed in `data`. + e: Symbol("b"), + // @ts-expect-error -- Objects are not allowed in `data`. + f: { + hi: "hi", + }, + // @ts-expect-error -- Arrays are not allowed in `data`. + g: [1, 2, 3], + // @ts-expect-error -- Sets are not allowed in `data`. + h: new Set([1, 2, 3]), + // @ts-expect-error -- Maps are not allowed in `data`. + i: new Map([ + ["a", 1], + ["b", 2], + ]), + // @ts-expect-error -- Functions are not allowed in `data`. + j: () => {}, }, fix: null, suggest: null,