diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 5c55404..a7c21fa 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -187,6 +187,7 @@ export interface RuleContextTypeOptions { Code: SourceCode; RuleOptions: unknown[]; Node: unknown; + MessageIds: string; } /** @@ -195,12 +196,7 @@ export interface RuleContextTypeOptions { * view into the outside world. */ export interface RuleContext< - Options extends RuleContextTypeOptions = { - LangOptions: LanguageOptions; - Code: SourceCode; - RuleOptions: unknown[]; - Node: unknown; - }, + Options extends RuleContextTypeOptions = RuleContextTypeOptions, > { /** * The current working directory for the session. @@ -282,7 +278,9 @@ export interface RuleContext< * The report function that the rule should use to report problems. * @param violation The violation to report. */ - report(violation: ViolationReport): void; + report( + violation: ViolationReport, + ): void; } // #region Rule Fixing @@ -402,11 +400,16 @@ interface ViolationReportBase { suggest?: SuggestedEdit[]; } -type ViolationMessage = { message: string } | { messageId: string }; +type ViolationMessage = + | { message: string } + | { messageId: MessageIds }; type ViolationLocation = { loc: SourceLocation } | { node: Node }; -export type ViolationReport = ViolationReportBase & - ViolationMessage & +export type ViolationReport< + Node = unknown, + MessageIds = string, +> = ViolationReportBase & + ViolationMessage & ViolationLocation; // #region Suggestions @@ -469,6 +472,7 @@ export interface RuleDefinition< Code: Options["Code"]; RuleOptions: Options["RuleOptions"]; Node: Options["Node"]; + MessageIds: Options["MessageIds"]; }>, ): Options["Visitor"]; } diff --git a/packages/core/tests/types/types.test.ts b/packages/core/tests/types/types.test.ts index 5ecc7a3..205a1c6 100644 --- a/packages/core/tests/types/types.test.ts +++ b/packages/core/tests/types/types.test.ts @@ -177,11 +177,14 @@ interface TestRuleVisitor extends RuleVisitor { Node?: (node: TestNode) => void; } +type TestMessageIds = "badFoo" | "wrongBar"; + type TestRuleContext = RuleContext<{ LangOptions: TestLanguageOptions; Code: TestSourceCode; RuleOptions: [{ foo: string; bar: number }]; Node: TestNode; + MessageIds: TestMessageIds; }>; const testRule: RuleDefinition<{