Skip to content
12 changes: 10 additions & 2 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,11 +447,19 @@ export type RuleFixer = (
fixer: RuleTextEditor,
) => RuleTextEdit | Iterable<RuleTextEdit> | 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<string, unknown> | undefined;
data?: MessagePlaceholderData | undefined;

/**
* The fix to be applied for the violation.
Expand Down Expand Up @@ -485,7 +493,7 @@ export interface SuggestedEditBase {
/**
* The data to insert into the message.
*/
data?: Record<string, unknown> | undefined;
data?: MessagePlaceholderData | undefined;

/**
* The fix to be applied for the suggestion.
Expand Down
44 changes: 44 additions & 0 deletions packages/core/tests/types/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down