Skip to content

Commit 6badee0

Browse files
authored
Merge pull request #21 from DrSkillIssue/fix/lint-warnings
fix: resolve ESLint warnings in test utilities and cross-file test suites
2 parents 2f14347 + 32d99f4 commit 6badee0

7 files changed

Lines changed: 26 additions & 16 deletions

packages/ganko/test/cross-file/layout-cls-rules.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, expect, it } from "vitest"
1+
import { afterAll, describe, expect, it } from "vitest"
22
import type { Diagnostic } from "../../src/diagnostic"
33
import { analyzeCrossFileInput } from "../../src/cross-file"
44
import { parseCode } from "../solid/test-utils"
@@ -14,6 +14,7 @@ interface CssFixture {
1414
* The SolidInput is created lazily on first access and cached for reuse.
1515
*/
1616
const tsxToSolidInput = new Map<string, ReturnType<typeof parseCode>>()
17+
afterAll(() => tsxToSolidInput.clear())
1718
let batchFileCounter = 0
1819

1920
function getOrCreateSolidInput(tsx: string): ReturnType<typeof parseCode> {

packages/ganko/test/cross-file/layout-sibling-alignment-conditional-evidence.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { describe, expect, it } from "vitest";
1+
import { afterAll, describe, expect, it } from "vitest";
22
import type { Diagnostic } from "../../src/diagnostic";
33
import { analyzeCrossFileInput, getLatestLayoutPerfStatsForTest } from "../../src/cross-file";
44
import { parseCode } from "../solid/test-utils";
55

66
const _ceCache = new Map<string, ReturnType<typeof parseCode>>()
7+
afterAll(() => _ceCache.clear())
78
let _ceFC = 0
89

910
function runRule(tsx: string, css: string): readonly Diagnostic[] {

packages/ganko/test/cross-file/layout-sibling-alignment-context.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { noopLogger } from "@drskillissue/ganko-shared";
2-
import { describe, expect, it } from "vitest";
2+
import { afterAll, describe, expect, it } from "vitest";
33
import type { Diagnostic } from "../../src/diagnostic";
44
import { analyzeCrossFileInput, buildLayoutGraph, collectAlignmentCases, evaluateAlignmentCase, ContextCertainty } from "../../src/cross-file";
55
import { buildSolidGraph } from "../../src/solid/plugin";
@@ -12,6 +12,7 @@ interface CssFixture {
1212
}
1313

1414
const _ctxCache = new Map<string, ReturnType<typeof parseCode>>()
15+
afterAll(() => _ctxCache.clear())
1516
let _ctxFC = 0
1617

1718
function runRule(tsx: string, files: readonly CssFixture[]): readonly Diagnostic[] {

packages/ganko/test/cross-file/layout-sibling-alignment-determinism.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, expect, it } from "vitest";
1+
import { afterAll, describe, expect, it } from "vitest";
22
import type { Diagnostic } from "../../src/diagnostic";
33
import type { SolidInput } from "../../src/solid/input";
44
import { analyzeCrossFileInput } from "../../src/cross-file";
@@ -10,6 +10,7 @@ interface CssFixture {
1010
}
1111

1212
const _detCache = new Map<string, ReturnType<typeof parseCode>>()
13+
afterAll(() => _detCache.clear())
1314
let _detFC = 0
1415

1516
function runRule(tsx: string, files: readonly CssFixture[]): readonly Diagnostic[] {

packages/ganko/test/cross-file/layout-sibling-alignment-policy-semantics.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { noopLogger } from "@drskillissue/ganko-shared";
2-
import { describe, expect, it } from "vitest";
2+
import { afterAll, describe, expect, it } from "vitest";
33
import type { Diagnostic } from "../../src/diagnostic";
44
import {
55
analyzeCrossFileInput,
@@ -27,6 +27,7 @@ import { alignmentPolicyCalibration } from "../../src/cross-file/layout/calibrat
2727
import { parseCode } from "../solid/test-utils";
2828

2929
const _psCache = new Map<string, ReturnType<typeof parseCode>>()
30+
afterAll(() => _psCache.clear())
3031
let _psFC = 0
3132

3233
function runRule(tsx: string, css: string): readonly Diagnostic[] {

packages/ganko/test/cross-file/layout-sibling-alignment-rule.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, expect, it } from "vitest";
1+
import { afterAll, describe, expect, it } from "vitest";
22
import type { Diagnostic } from "../../src/diagnostic";
33
import { analyzeCrossFileInput } from "../../src/cross-file";
44
import { getLatestLayoutPerfStatsForTest } from "../../src/cross-file";
@@ -13,6 +13,7 @@ interface CssFixture {
1313
}
1414

1515
const tsxCache = new Map<string, ReturnType<typeof parseCode>>();
16+
afterAll(() => tsxCache.clear())
1617
let fileCounter = 0;
1718

1819
function runRule(tsx: string, css: string | readonly CssFixture[]): readonly Diagnostic[] {

packages/ganko/test/solid/test-utils.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const defaultHost = ts.createCompilerHost(compilerOptions)
2323
* immutable so parsing them once and reusing across all ts.createProgram
2424
* invocations is safe and eliminates the dominant cost per call (~100 lib files).
2525
*/
26+
const MODULE_MARKER_RE = /export |import /
2627
const LIB_CACHE_MAX = 200
2728
const libSourceFileCache = new Map<string, ts.SourceFile | undefined>()
2829

@@ -40,9 +41,9 @@ let lastProgram: ts.Program | null = null
4041
* Falls back to the real filesystem for lib files (e.g. lib.d.ts).
4142
* Uses oldProgram for incremental reuse of lib SourceFiles and checker state.
4243
*/
43-
export function createTestProgram(files: Record<string, string>): ts.Program {
44+
export function createTestProgram(files: Map<string, string>): ts.Program {
4445
const fileMap = new Map<string, string>()
45-
for (const [key, value] of Object.entries(files)) {
46+
for (const [key, value] of files) {
4647
fileMap.set(resolve(key), value)
4748
}
4849

@@ -84,7 +85,7 @@ export function createTestProgram(files: Record<string, string>): ts.Program {
8485
*/
8586
export function parseCode(code: string, filePath = "test.tsx"): SolidInput {
8687
const resolvedPath = resolve(filePath)
87-
const program = createTestProgram({ [filePath]: code })
88+
const program = createTestProgram(new Map([[filePath, code]]))
8889
return createSolidInput(resolvedPath, program)
8990
}
9091

@@ -139,25 +140,28 @@ export function createRuleBatch(
139140
// Build a single program with all snippets as separate virtual files.
140141
// Each snippet gets `export {}` appended to force TypeScript module mode,
141142
// ensuring separate module scopes (no global variable collisions).
142-
const fileMap: Record<string, string> = {}
143+
const fileMap = new Map<string, string>()
143144
for (let i = 0; i < snippets.length; i++) {
144145
const code = snippets[i]!
145146
// Only add export {} if the snippet doesn't already have an export/import
146-
const needsModuleMarker = !code.includes("export ") && !code.includes("import ")
147-
fileMap[`batch_${i}.tsx`] = needsModuleMarker ? code + "\nexport {}" : code
147+
const needsModuleMarker = !MODULE_MARKER_RE.test(code)
148+
fileMap.set(`batch_${i}.tsx`, needsModuleMarker ? code + "\nexport {}" : code)
148149
}
149150
const program = createTestProgram(fileMap)
150151

151152
// Build SolidGraph and run rule for each file independently
152153
const results: RuleTestResult[] = []
154+
const collector: { target: Diagnostic[] | null } = { target: null }
155+
const collect = (d: Diagnostic) => collector.target!.push(d)
153156
for (let i = 0; i < snippets.length; i++) {
154157
const filePath = resolve(`batch_${i}.tsx`)
155158
const input = createSolidInput(filePath, program)
156159
const graph = buildSolidGraph(input)
157160
const diagnostics: Diagnostic[] = []
158161
const setup = setupPerSnippet?.[i]
159162
if (setup) setup()
160-
rule.check(graph, (d) => diagnostics.push(d))
163+
collector.target = diagnostics
164+
rule.check(graph, collect)
161165
results.push({ diagnostics, graph, code: snippets[i]! })
162166
}
163167

@@ -250,12 +254,12 @@ export function lazyParseBatch(): {
250254
},
251255
result(index: number): SolidInput {
252256
if (results === null) {
253-
const fileMap: Record<string, string> = {}
257+
const fileMap = new Map<string, string>()
254258
for (let i = 0; i < entries.length; i++) {
255259
const entry = entries[i]!
256260
const code = entry.code
257-
const needsModuleMarker = !code.includes("export ") && !code.includes("import ")
258-
fileMap[entry.filePath] = needsModuleMarker ? code + "\nexport {}" : code
261+
const needsModuleMarker = !MODULE_MARKER_RE.test(code)
262+
fileMap.set(entry.filePath, needsModuleMarker ? code + "\nexport {}" : code)
259263
}
260264
const program = createTestProgram(fileMap)
261265
results = []

0 commit comments

Comments
 (0)