UNPKG

@typespec/compiler

Version:

TypeSpec compiler and standard library

46 lines 2.13 kB
import { DiagnosticMessages, Entity, LinterRuleDefinition } from "../core/types.js"; import { DiagnosticMatch } from "./expect.js"; import { GetMarkedEntities, TemplateWithMarkers } from "./marked-template.js"; import { BasicTestRunner, TestCompileResult, TesterInstance } from "./types.js"; export interface LinterRuleTester { expect<T extends string | TemplateWithMarkers<any> | Record<string, string | TemplateWithMarkers<any>>>(code: T): LinterRuleTestExpect<GetMarkedEntities<T>>; } export interface LinterRuleTestExpect<T extends Record<string, Entity> = any> { toBeValid(): Promise<void>; toEmitDiagnostics(diagnostics: DiagnosticMatch | DiagnosticMatch[] | ((res: TestCompileResult<T>) => DiagnosticMatch | DiagnosticMatch[])): Promise<void>; applyCodeFix(codeFixId: string): ApplyCodeFixExpect; } export interface ApplyCodeFixExpect { /** * Assert the content of the file(s) after the code fix is applied. * @param code Expected content. Pass a `string` for single-file assertions (main.tsp), * or a `Record<string, string>` to assert on specific files (partial match — only the * specified files are checked). * * @example Single file * * ```ts * await ruleTester * .expect(`model Foo { name: string; }`) * .applyCodeFix("rename-model") * .toEqual(`model Bar { name: string; }`); * ``` * * @example Multiple files (e.g. code fix writes augment decorators to a separate file) * * ```ts * await ruleTester * .expect({ * "main.tsp": `import "./client.tsp";\nmodel Foo { name: string; }`, * "client.tsp": ``, * }) * .applyCodeFix("add-client-override") * .toEqual({ * "client.tsp": `@@override(Foo.name, "clientName");\n`, * }); * ``` */ toEqual(code: string | Record<string, string>): Promise<void>; } export declare function createLinterRuleTester(runner: BasicTestRunner | TesterInstance, ruleDef: LinterRuleDefinition<string, DiagnosticMessages>, libraryName: string): LinterRuleTester; //# sourceMappingURL=rule-tester.d.ts.map