1 import { AST_NODE_TYPES, AST_TOKEN_TYPES } from '../ts-estree';
2 import { ParserOptions } from './ParserOptions';
3 import { RuleModule } from './Rule';
4 interface ValidTestCase<TOptions extends Readonly<unknown[]>> {
6 * Code for the test case.
10 * Environments for the test case.
12 readonly env?: Readonly<Record<string, boolean>>;
14 * The fake filename for the test case. Useful for rules that make assertion about filenames.
16 readonly filename?: string;
18 * The additional global variables.
20 readonly globals?: Record<string, 'readonly' | 'writable' | 'off'>;
22 * Options for the test case.
24 readonly options?: Readonly<TOptions>;
26 * The absolute path for the parser.
28 readonly parser?: string;
30 * Options for the parser.
32 readonly parserOptions?: Readonly<ParserOptions>;
34 * Settings for the test case.
36 readonly settings?: Readonly<Record<string, unknown>>;
38 interface SuggestionOutput<TMessageIds extends string> {
40 * Reported message ID.
42 readonly messageId: TMessageIds;
44 * The data used to fill the message template.
46 readonly data?: Readonly<Record<string, unknown>>;
48 * NOTE: Suggestions will be applied as a stand-alone change, without triggering multi-pass fixes.
49 * Each individual error has its own suggestion, so you have to show the correct, _isolated_ output for each suggestion.
51 readonly output: string;
53 interface InvalidTestCase<TMessageIds extends string, TOptions extends Readonly<unknown[]>> extends ValidTestCase<TOptions> {
57 readonly errors: TestCaseError<TMessageIds>[];
59 * The expected code after autofixes are applied. If set to `null`, the test runner will assert that no autofix is suggested.
61 readonly output?: string | null;
63 interface TestCaseError<TMessageIds extends string> {
65 * The 1-based column number of the reported start location.
67 readonly column?: number;
69 * The data used to fill the message template.
71 readonly data?: Readonly<Record<string, unknown>>;
73 * The 1-based column number of the reported end location.
75 readonly endColumn?: number;
77 * The 1-based line number of the reported end location.
79 readonly endLine?: number;
81 * The 1-based line number of the reported start location.
83 readonly line?: number;
85 * Reported message ID.
87 readonly messageId: TMessageIds;
89 * Reported suggestions.
91 readonly suggestions?: SuggestionOutput<TMessageIds>[] | null;
93 * The type of the reported AST node.
95 readonly type?: AST_NODE_TYPES | AST_TOKEN_TYPES;
97 interface RunTests<TMessageIds extends string, TOptions extends Readonly<unknown[]>> {
98 readonly valid: (ValidTestCase<TOptions> | string)[];
99 readonly invalid: InvalidTestCase<TMessageIds, TOptions>[];
101 interface RuleTesterConfig {
102 readonly parser: string;
103 readonly parserOptions?: Readonly<ParserOptions>;
105 declare class RuleTesterBase {
107 * Creates a new instance of RuleTester.
108 * @param testerConfig extra configuration for the tester
110 constructor(testerConfig?: RuleTesterConfig);
112 * Adds a new rule test to execute.
113 * @param ruleName The name of the rule to run.
114 * @param rule The rule to test.
115 * @param test The collection of tests to run.
117 run<TMessageIds extends string, TOptions extends Readonly<unknown[]>>(ruleName: string, rule: RuleModule<TMessageIds, TOptions>, tests: RunTests<TMessageIds, TOptions>): void;
119 * If you supply a value to this property, the rule tester will call this instead of using the version defined on
120 * the global namespace.
121 * @param text a string describing the rule
122 * @param callback the test callback
124 static describe?: (text: string, callback: () => void) => void;
126 * If you supply a value to this property, the rule tester will call this instead of using the version defined on
127 * the global namespace.
128 * @param text a string describing the test case
129 * @param callback the test callback
131 static it?: (text: string, callback: () => void) => void;
133 declare const RuleTester_base: typeof RuleTesterBase;
134 declare class RuleTester extends RuleTester_base {
136 export { InvalidTestCase, SuggestionOutput, RuleTester, RuleTesterConfig, RunTests, TestCaseError, ValidTestCase, };
137 //# sourceMappingURL=RuleTester.d.ts.map