Skip to content

Commit 664740a

Browse files
nzakasfasttime
andauthored
fix: Types to align with older ESLint types (#155)
Co-authored-by: Francesco Trotta <github@fasttime.org>
1 parent d4a04b9 commit 664740a

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

packages/core/src/types.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,15 @@ export interface RuleTextEdit {
459459

460460
// #endregion
461461

462+
/**
463+
* Fixes a violation.
464+
* @param fixer The text editor to apply the fix.
465+
* @returns The fix(es) for the violation.
466+
*/
467+
type RuleFixer = (
468+
fixer: RuleTextEditor,
469+
) => RuleTextEdit | Iterable<RuleTextEdit> | null;
470+
462471
interface ViolationReportBase {
463472
/**
464473
* The type of node that the violation is for.
@@ -473,22 +482,22 @@ interface ViolationReportBase {
473482

474483
/**
475484
* The fix to be applied for the violation.
476-
* @param fixer The text editor to apply the fix.
477-
* @returns The fix(es) for the violation.
478485
*/
479-
fix?(fixer: RuleTextEditor): RuleTextEdit | Iterable<RuleTextEdit> | null;
486+
fix?: RuleFixer | null | undefined;
480487

481488
/**
482489
* An array of suggested fixes for the problem. These fixes may change the
483490
* behavior of the code, so they are not applied automatically.
484491
*/
485-
suggest?: SuggestedEdit[];
492+
suggest?: SuggestedEdit[] | null | undefined;
486493
}
487494

488495
type ViolationMessage<MessageIds = string> =
489496
| { message: string }
490497
| { messageId: MessageIds };
491-
type ViolationLocation<Node> = { loc: SourceLocation } | { node: Node };
498+
type ViolationLocation<Node> =
499+
| { loc: SourceLocation | Position }
500+
| { node: Node };
492501

493502
export type ViolationReport<
494503
Node = unknown,
@@ -507,10 +516,8 @@ interface SuggestedEditBase {
507516

508517
/**
509518
* The fix to be applied for the suggestion.
510-
* @param fixer The text editor to apply the fix.
511-
* @returns The fix for the suggestion.
512519
*/
513-
fix?(fixer: RuleTextEditor): RuleTextEdit | Iterable<RuleTextEdit> | null;
520+
fix?: RuleFixer | null | undefined;
514521
}
515522

516523
type SuggestionMessage = { desc: string } | { messageId: string };

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ const testRule: RuleDefinition<{
257257
: "👎",
258258
);
259259
},
260+
suggest: undefined,
260261
});
261262
}
262263
},
@@ -268,10 +269,20 @@ const testRule: RuleDefinition<{
268269
suggest: [
269270
{
270271
messageId: "Bar",
272+
fix: null,
271273
},
272274
],
273275
});
274276
},
277+
Baz(node: TestNode) {
278+
// node.type === "Baz"
279+
context.report({
280+
message: "This baz is foobar",
281+
loc: { line: node.start, column: 1 },
282+
fix: null,
283+
suggest: null,
284+
});
285+
},
275286
};
276287
},
277288
};

0 commit comments

Comments
 (0)