Skip to content

Commit 26e6a50

Browse files
authored
fix: make data property stricter (#327)
1 parent d180dce commit 26e6a50

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

packages/core/src/types.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,11 +447,19 @@ export type RuleFixer = (
447447
fixer: RuleTextEditor,
448448
) => RuleTextEdit | Iterable<RuleTextEdit> | null;
449449

450+
/**
451+
* Data that can be used to fill placeholders in error messages.
452+
*/
453+
export type MessagePlaceholderData = Record<
454+
string,
455+
string | number | boolean | bigint | null | undefined
456+
>;
457+
450458
export interface ViolationReportBase {
451459
/**
452460
* The data to insert into the message.
453461
*/
454-
data?: Record<string, unknown> | undefined;
462+
data?: MessagePlaceholderData | undefined;
455463

456464
/**
457465
* The fix to be applied for the violation.
@@ -485,7 +493,7 @@ export interface SuggestedEditBase {
485493
/**
486494
* The data to insert into the message.
487495
*/
488-
data?: Record<string, unknown> | undefined;
496+
data?: MessagePlaceholderData | undefined;
489497

490498
/**
491499
* The fix to be applied for the suggestion.

packages/core/tests/types/types.test.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,28 @@ const testRule: RuleDefinition<{
320320
foo: "foo",
321321
bar: 1,
322322
baz: true,
323+
qux: false,
324+
a: 1n,
325+
b: null,
326+
c: undefined,
327+
d: void 0,
328+
// @ts-expect-error -- Symbols are not allowed in `data`.
329+
e: Symbol("b"),
330+
// @ts-expect-error -- Objects are not allowed in `data`.
331+
f: {
332+
hi: "hi",
333+
},
334+
// @ts-expect-error -- Arrays are not allowed in `data`.
335+
g: [1, 2, 3],
336+
// @ts-expect-error -- Sets are not allowed in `data`.
337+
h: new Set([1, 2, 3]),
338+
// @ts-expect-error -- Maps are not allowed in `data`.
339+
i: new Map([
340+
["a", 1],
341+
["b", 2],
342+
]),
343+
// @ts-expect-error -- Functions are not allowed in `data`.
344+
j: () => {},
323345
},
324346
// @ts-expect-error -- 'fix' is required in suggestion objects
325347
fix: null,
@@ -336,6 +358,28 @@ const testRule: RuleDefinition<{
336358
foo: "foo",
337359
bar: 1,
338360
baz: true,
361+
qux: false,
362+
a: 1n,
363+
b: null,
364+
c: undefined,
365+
d: void 0,
366+
// @ts-expect-error -- Symbols are not allowed in `data`.
367+
e: Symbol("b"),
368+
// @ts-expect-error -- Objects are not allowed in `data`.
369+
f: {
370+
hi: "hi",
371+
},
372+
// @ts-expect-error -- Arrays are not allowed in `data`.
373+
g: [1, 2, 3],
374+
// @ts-expect-error -- Sets are not allowed in `data`.
375+
h: new Set([1, 2, 3]),
376+
// @ts-expect-error -- Maps are not allowed in `data`.
377+
i: new Map([
378+
["a", 1],
379+
["b", 2],
380+
]),
381+
// @ts-expect-error -- Functions are not allowed in `data`.
382+
j: () => {},
339383
},
340384
fix: null,
341385
suggest: null,

0 commit comments

Comments
 (0)