Skip to content

Commit f7751cc

Browse files
committed
fix(linter/plugins): fix TS types for RuleTester (#16546)
Fix TS types for `RuleTester`. Merging the `RuleTester` class and namespace was working OK within the repo, but not in the built bundle. Fix that by defining the namespace in same file as the class.
1 parent 6d33320 commit f7751cc

File tree

2 files changed

+26
-29
lines changed

2 files changed

+26
-29
lines changed

apps/oxlint/src-js/index.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,3 @@ export type {
6060
Visitor,
6161
VisitorWithHooks,
6262
} from "./plugins/types.ts";
63-
64-
// Rule tester types.
65-
// Export as namespace to avoid lengthy type names.
66-
import type {
67-
Config as _Config,
68-
DescribeFn as _DescribeFn,
69-
ItFn as _ItFn,
70-
ValidTestCase as _ValidTestCase,
71-
InvalidTestCase as _InvalidTestCase,
72-
TestCases as _TestCases,
73-
Error as _Error,
74-
} from "./package/rule_tester.ts";
75-
76-
export namespace RuleTester {
77-
export type Config = _Config;
78-
export type DescribeFn = _DescribeFn;
79-
export type ItFn = _ItFn;
80-
export type ValidTestCase = _ValidTestCase;
81-
export type InvalidTestCase = _InvalidTestCase;
82-
export type TestCases = _TestCases;
83-
export type Error = _Error;
84-
}

apps/oxlint/src-js/package/rule_tester.ts

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ const { hasOwn } = Object,
3535
// `describe` and `it` functions
3636
// ------------------------------------------------------------------------------
3737

38-
export type DescribeFn = (text: string, fn: () => void) => void;
39-
export type ItFn = ((text: string, fn: () => void) => void) & { only?: ItFn };
38+
type DescribeFn = (text: string, fn: () => void) => void;
39+
type ItFn = ((text: string, fn: () => void) => void) & { only?: ItFn };
4040

4141
/**
4242
* Default `describe` function, if `describe` doesn't exist as a global.
@@ -111,7 +111,7 @@ function getItOnly(): ItFn {
111111
/**
112112
* Configuration for `RuleTester`.
113113
*/
114-
export interface Config {
114+
interface Config {
115115
/**
116116
* ESLint compatibility mode.
117117
* If `true`, column offsets in diagnostics are incremented by 1, to match ESLint's behavior.
@@ -154,12 +154,12 @@ interface TestCase {
154154
/**
155155
* Test case for valid code.
156156
*/
157-
export interface ValidTestCase extends TestCase {}
157+
interface ValidTestCase extends TestCase {}
158158

159159
/**
160160
* Test case for invalid code.
161161
*/
162-
export interface InvalidTestCase extends TestCase {
162+
interface InvalidTestCase extends TestCase {
163163
output?: string | null;
164164
errors: number | ErrorEntry[];
165165
}
@@ -169,7 +169,7 @@ type ErrorEntry = Error | string | RegExp;
169169
/**
170170
* Expected error.
171171
*/
172-
export type Error = RequireAtLeastOne<ErrorBase, "message" | "messageId">;
172+
type Error = RequireAtLeastOne<ErrorBase, "message" | "messageId">;
173173

174174
interface ErrorBase {
175175
message?: string | RegExp;
@@ -184,7 +184,7 @@ interface ErrorBase {
184184
/**
185185
* Test cases for a rule.
186186
*/
187-
export interface TestCases {
187+
interface TestCases {
188188
valid: (ValidTestCase | string)[];
189189
invalid: InvalidTestCase[];
190190
}
@@ -990,3 +990,22 @@ function isSerializablePrimitiveOrPlainObject(value: unknown): boolean {
990990
(typeof value === "object" && (value.constructor === Object || isArray(value)))
991991
);
992992
}
993+
994+
// Add types to `RuleTester` namespace
995+
type _Config = Config;
996+
type _DescribeFn = DescribeFn;
997+
type _ItFn = ItFn;
998+
type _ValidTestCase = ValidTestCase;
999+
type _InvalidTestCase = InvalidTestCase;
1000+
type _TestCases = TestCases;
1001+
type _Error = Error;
1002+
1003+
export namespace RuleTester {
1004+
export type Config = _Config;
1005+
export type DescribeFn = _DescribeFn;
1006+
export type ItFn = _ItFn;
1007+
export type ValidTestCase = _ValidTestCase;
1008+
export type InvalidTestCase = _InvalidTestCase;
1009+
export type TestCases = _TestCases;
1010+
export type Error = _Error;
1011+
}

0 commit comments

Comments
 (0)