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
12 changes: 7 additions & 5 deletions apps/oxlint/conformance/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { TEST_GROUPS } from "./groups/index.ts";
import { setCurrentGroup, setCurrentRule, resetCurrentRule } from "./capture.ts";
import { SHOULD_SKIP_GROUP, SHOULD_SKIP_RULE } from "./filter.ts";
import { generateReport } from "./report.ts";
import { RuleTester, parserModules, parserModulePaths } from "./rule_tester.ts";
import { RuleTester, parseForESLintFns, parserPaths } from "./rule_tester.ts";

import type { RuleResult } from "./capture.ts";
import type { Language, TestCase } from "./rule_tester.ts";
Expand Down Expand Up @@ -254,8 +254,8 @@ function runGroup(group: TestGroup, mocks: Mocks) {
// Get custom parsers
console.log(`Loading custom parsers for ${groupName}...`);

parserModules.clear();
parserModulePaths.clear();
parseForESLintFns.clear();
parserPaths.clear();

for (const parserDetails of group.parsers) {
const path = resolveFromTestsDir(parserDetails.specifier);
Expand All @@ -264,8 +264,10 @@ function runGroup(group: TestGroup, mocks: Mocks) {
// Set `default` export on parser module to work around apparent bug in `tsx`
if (parser && parser.default === undefined) parser.default = parser;

parserModules.set(parser, parserDetails);
parserModulePaths.set(path, parserDetails);
if (typeof parser.parseForESLint === "function") {
parseForESLintFns.set(parser.parseForESLint, parserDetails);
}
parserPaths.set(path, parserDetails);
}

// Find test files and run tests
Expand Down
12 changes: 6 additions & 6 deletions apps/oxlint/conformance/src/rule_tester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ export type ValidTestCase = RuleTester.ValidTestCase & TestCaseExtension;
export type InvalidTestCase = RuleTester.InvalidTestCase & TestCaseExtension;
export type TestCase = ValidTestCase | InvalidTestCase;

// Maps of parser modules and parser paths to parser details (language + specifier)
export const parserModules: Map<unknown, ParserDetails> = new Map();
export const parserModulePaths: Map<string, ParserDetails> = new Map();
// Maps of parser `parseForESLint` functions and parser paths to parser details (language + specifier)
export const parseForESLintFns: Map<Function, ParserDetails> = new Map();
export const parserPaths: Map<string, ParserDetails> = new Map();

// Set up `RuleTester` to use our hooks
RuleTester.describe = describe;
Expand Down Expand Up @@ -174,16 +174,16 @@ function modifyTestCase(test: TestCase): void {
// - Old ESLint versions: `test.parser` (absolute path to parser)
let parserDetails: ParserDetails | null = null;

if (languageOptions.parser != null) {
parserDetails = parserModules.get(languageOptions.parser) ?? null;
if (languageOptions.parser?.parseForESLint != null) {
parserDetails = parseForESLintFns.get(languageOptions.parser.parseForESLint) ?? null;
if (parserDetails !== null) delete languageOptions.parser;
}

if (test.parser != null) {
if (parserDetails !== null) {
throw new Error("Both `test.parser` and `test.languageOptions.parser` specified");
}
parserDetails = parserModulePaths.get(test.parser) ?? null;
parserDetails = parserPaths.get(test.parser) ?? null;
if (parserDetails === null) {
// Set `languageOptions.parser` so an error is thrown.
// Store in stored test case so appears in snapshot.
Expand Down
Loading