Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions apps/oxlint/src-js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,3 @@ export type {
Visitor,
VisitorWithHooks,
} from "./plugins/types.ts";

// Rule tester types.
// Export as namespace to avoid lengthy type names.
import type {
Config as _Config,
DescribeFn as _DescribeFn,
ItFn as _ItFn,
ValidTestCase as _ValidTestCase,
InvalidTestCase as _InvalidTestCase,
TestCases as _TestCases,
Error as _Error,
} from "./package/rule_tester.ts";

export namespace RuleTester {
export type Config = _Config;
export type DescribeFn = _DescribeFn;
export type ItFn = _ItFn;
export type ValidTestCase = _ValidTestCase;
export type InvalidTestCase = _InvalidTestCase;
export type TestCases = _TestCases;
export type Error = _Error;
}
33 changes: 26 additions & 7 deletions apps/oxlint/src-js/package/rule_tester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ const { hasOwn } = Object,
// `describe` and `it` functions
// ------------------------------------------------------------------------------

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

/**
* Default `describe` function, if `describe` doesn't exist as a global.
Expand Down Expand Up @@ -111,7 +111,7 @@ function getItOnly(): ItFn {
/**
* Configuration for `RuleTester`.
*/
export interface Config {
interface Config {
/**
* ESLint compatibility mode.
* If `true`, column offsets in diagnostics are incremented by 1, to match ESLint's behavior.
Expand Down Expand Up @@ -154,12 +154,12 @@ interface TestCase {
/**
* Test case for valid code.
*/
export interface ValidTestCase extends TestCase {}
interface ValidTestCase extends TestCase {}

/**
* Test case for invalid code.
*/
export interface InvalidTestCase extends TestCase {
interface InvalidTestCase extends TestCase {
output?: string | null;
errors: number | ErrorEntry[];
}
Expand All @@ -169,7 +169,7 @@ type ErrorEntry = Error | string | RegExp;
/**
* Expected error.
*/
export type Error = RequireAtLeastOne<ErrorBase, "message" | "messageId">;
type Error = RequireAtLeastOne<ErrorBase, "message" | "messageId">;

interface ErrorBase {
message?: string | RegExp;
Expand All @@ -184,7 +184,7 @@ interface ErrorBase {
/**
* Test cases for a rule.
*/
export interface TestCases {
interface TestCases {
valid: (ValidTestCase | string)[];
invalid: InvalidTestCase[];
}
Expand Down Expand Up @@ -990,3 +990,22 @@ function isSerializablePrimitiveOrPlainObject(value: unknown): boolean {
(typeof value === "object" && (value.constructor === Object || isArray(value)))
);
}

// Add types to `RuleTester` namespace
type _Config = Config;
type _DescribeFn = DescribeFn;
type _ItFn = ItFn;
type _ValidTestCase = ValidTestCase;
type _InvalidTestCase = InvalidTestCase;
type _TestCases = TestCases;
type _Error = Error;

export namespace RuleTester {
export type Config = _Config;
export type DescribeFn = _DescribeFn;
export type ItFn = _ItFn;
export type ValidTestCase = _ValidTestCase;
export type InvalidTestCase = _InvalidTestCase;
export type TestCases = _TestCases;
export type Error = _Error;
}
Loading