Skip to content

Commit ba53039

Browse files
refactor: replace file-level eslint-disable with targeted suppressions
Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
1 parent deea406 commit ba53039

21 files changed

Lines changed: 53 additions & 24 deletions

File tree

packages/compiler/src/testing/code-fix-testing.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable @typescript-eslint/no-deprecated */
21
import { ok, strictEqual } from "assert";
32
import { applyCodeFix, applyCodeFixes } from "../core/code-fixes.js";
43
import { getNodeAtPosition, parse, visitChildren } from "../core/parser.js";
@@ -49,6 +48,7 @@ export function expectCodeFixOnAst(code: string, callback: (node: Node) => CodeF
4948
const node = getNodeAtPosition(script, pos);
5049
ok(node, "Expected node at cursor. Make sure to have ┆ to mark which node.");
5150
const codefix = callback(node);
51+
// eslint-disable-next-line @typescript-eslint/no-deprecated
5252
const host = await createTestHost();
5353
let updatedContent: string | undefined;
5454
await applyCodeFix(
@@ -91,6 +91,7 @@ export function expectCodeFixesOnAst(
9191
}
9292
ok(diagnostics.length > 0, "Expected node at cursor. Make sure to have ┆ to mark which node.");
9393
const codeFixes = callback(diagnostics);
94+
// eslint-disable-next-line @typescript-eslint/no-deprecated
9495
const host = await createTestHost();
9596
let updatedContent: string | undefined;
9697
await applyCodeFixes(

packages/compiler/src/testing/fs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable @typescript-eslint/no-deprecated */
21
import { readdir, readFile, stat } from "fs/promises";
32
import { join } from "path";
43
import { pathToFileURL } from "url";
@@ -124,6 +123,7 @@ function createTestFileSystemInternal(
124123
jsImports.set(key, exports);
125124
}
126125

126+
// eslint-disable-next-line @typescript-eslint/no-deprecated
127127
async function addTypeSpecLibrary(testLibrary: TypeSpecTestLibrary) {
128128
assertNotFrozen();
129129

packages/compiler/src/testing/index.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable @typescript-eslint/no-deprecated */
21
export {
32
/** @deprecated Using this should be a noop. Prefer new test framework*/
43
StandardTestLibrary,
@@ -16,6 +15,7 @@ export {
1615
} from "./rule-tester.js";
1716
export { extractCursor, extractSquiggles } from "./source-utils.js";
1817
export type { TestHostOptions } from "./test-compiler-host.js";
18+
/* eslint-disable @typescript-eslint/no-deprecated -- exporting deprecated APIs for backward compatibility */
1919
export { createTestHost, createTestRunner, findFilesFromPattern } from "./test-host.js";
2020
export {
2121
createTestLibrary,
@@ -26,9 +26,9 @@ export {
2626
trimBlankLines,
2727
type TestWrapperOptions,
2828
} from "./test-utils.js";
29+
/* eslint-enable @typescript-eslint/no-deprecated */
2930
export { createTester } from "./tester.js";
3031
export type {
31-
BasicTestRunner,
3232
EmitterTester,
3333
EmitterTesterInstance,
3434
JsFile,
@@ -37,12 +37,17 @@ export type {
3737
TestCompileResult,
3838
TestEmitterCompileResult,
3939
TestFileSystem as TestFileSystem,
40+
Tester,
41+
TesterInstance,
42+
} from "./types.js";
43+
/* eslint-disable @typescript-eslint/no-deprecated -- exporting deprecated APIs for backward compatibility */
44+
export type {
45+
BasicTestRunner,
4046
TestFiles,
4147
TestHost,
4248
TestHostConfig,
4349
TestHostError,
44-
Tester,
45-
TesterInstance,
4650
TypeSpecTestLibrary,
4751
TypeSpecTestLibraryInit,
4852
} from "./types.js";
53+
/* eslint-enable @typescript-eslint/no-deprecated */

packages/compiler/src/testing/rule-tester.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable @typescript-eslint/no-deprecated */
21
import { ok, strictEqual } from "assert";
32
import { applyCodeFix as applyCodeFixReal } from "../core/code-fixes.js";
43
import { createDiagnosticCollector } from "../core/diagnostics.js";
@@ -70,6 +69,7 @@ export interface ApplyCodeFixExpect {
7069
}
7170

7271
export function createLinterRuleTester(
72+
// eslint-disable-next-line @typescript-eslint/no-deprecated
7373
runner: BasicTestRunner | TesterInstance,
7474
ruleDef: LinterRuleDefinition<string, DiagnosticMessages>,
7575
libraryName: string,
@@ -222,6 +222,7 @@ export function createLinterRuleTester(
222222
}
223223
}
224224

225+
// eslint-disable-next-line @typescript-eslint/no-deprecated
225226
function isLegacyTestRunner(tester: BasicTestRunner | TesterInstance): tester is BasicTestRunner {
226227
return "autoCodeOffset" in tester;
227228
}

packages/compiler/src/testing/test-compiler-host.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable @typescript-eslint/no-deprecated */
21
import { RmOptions } from "fs";
32
import { fileURLToPath, pathToFileURL } from "url";
43
import { CompilerPackageRoot, NodeHost } from "../core/node-host.js";
@@ -7,6 +6,7 @@ import { CompilerHost, StringLiteral, Type } from "../core/types.js";
76
import { resolveVirtualPath } from "./fs.js";
87
import { TestFileSystem, TestHostError, TypeSpecTestLibrary } from "./types.js";
98

9+
// eslint-disable-next-line @typescript-eslint/no-deprecated
1010
export const StandardTestLibrary: TypeSpecTestLibrary = {
1111
name: "@typespec/compiler",
1212
packageRoot: CompilerPackageRoot,
@@ -45,6 +45,7 @@ export function createTestCompilerHost(
4545
async readUrl(url: string) {
4646
const contents = virtualFs.get(url);
4747
if (contents === undefined) {
48+
// eslint-disable-next-line @typescript-eslint/no-deprecated
4849
throw new TestHostError(`File ${url} not found.`, "ENOENT");
4950
}
5051
return createSourceFile(contents, url);
@@ -53,6 +54,7 @@ export function createTestCompilerHost(
5354
path = resolveVirtualPath(path);
5455
const contents = virtualFs.get(path);
5556
if (contents === undefined) {
57+
// eslint-disable-next-line @typescript-eslint/no-deprecated
5658
throw new TestHostError(`File ${path} not found.`, "ENOENT");
5759
}
5860
return createSourceFile(contents, path);
@@ -101,6 +103,7 @@ export function createTestCompilerHost(
101103
path = resolveVirtualPath(path);
102104
const module = jsImports.get(path);
103105
if (module === undefined) {
106+
// eslint-disable-next-line @typescript-eslint/no-deprecated
104107
throw new TestHostError(`Module ${path} not found`, "ERR_MODULE_NOT_FOUND");
105108
}
106109
return module;
@@ -133,6 +136,7 @@ export function createTestCompilerHost(
133136
}
134137
}
135138

139+
// eslint-disable-next-line @typescript-eslint/no-deprecated
136140
throw new TestHostError(`File ${path} not found`, "ENOENT");
137141
},
138142

packages/compiler/src/testing/test-host.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable @typescript-eslint/no-deprecated */
21
import assert from "assert";
32
import { glob } from "fs/promises";
43
import { logDiagnostics, logVerboseTestOutput } from "../core/diagnostics.js";
@@ -12,6 +11,7 @@ import { addTestLib, StandardTestLibrary } from "./test-compiler-host.js";
1211
import { createTestWrapper, resolveVirtualPath } from "./test-utils.js";
1312
import { BasicTestRunner, TestHost, TestHostConfig, TypeSpecTestLibrary } from "./types.js";
1413

14+
/* eslint-disable @typescript-eslint/no-deprecated -- implementing deprecated APIs for backward compatibility */
1515
/** @deprecated Use {@link createTester} */
1616
export async function createTestHost(config: TestHostConfig = {}): Promise<TestHost> {
1717
const testHost = await createTestHostInternal();
@@ -81,6 +81,7 @@ async function createTestHostInternal(): Promise<TestHost> {
8181
return [testTypes, p.diagnostics];
8282
}
8383
}
84+
/* eslint-enable @typescript-eslint/no-deprecated */
8485

8586
export async function findFilesFromPattern(directory: string, pattern: string): Promise<string[]> {
8687
const results: string[] = [];

packages/compiler/src/testing/test-utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable @typescript-eslint/no-deprecated */
21
import { fail, ok } from "assert";
32
import { fileURLToPath } from "url";
43
import { getTypeName } from "../core/helpers/type-name-utils.js";
@@ -34,6 +33,7 @@ export function findTestPackageRoot(fileUrl: string): Promise<string> {
3433
* @returns TypeSpec Test library.
3534
* @deprecated Use {@link createTester} instead
3635
*/
36+
// eslint-disable-next-line @typescript-eslint/no-deprecated
3737
export function createTestLibrary(init: TypeSpecTestLibraryInit): TypeSpecTestLibrary {
3838
const { name } = init;
3939
const typespecFileFolder = init.typespecFileFolder ?? "lib";
@@ -74,6 +74,7 @@ export interface TestWrapperOptions {
7474
compilerOptions?: CompilerOptions;
7575
}
7676
/** @deprecated Use {@link createTester} instead */
77+
/* eslint-disable @typescript-eslint/no-deprecated -- implementing deprecated API for backward compatibility */
7778
export function createTestWrapper(
7879
host: TestHost,
7980
testWrapperOptions: TestWrapperOptions = {},
@@ -117,6 +118,7 @@ export function createTestWrapper(
117118
},
118119
};
119120
}
121+
/* eslint-enable @typescript-eslint/no-deprecated */
120122

121123
export function trimBlankLines(code: string) {
122124
let start = 0;

packages/compiler/src/testing/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable @typescript-eslint/no-deprecated */
21
import type { CompilerOptions } from "../core/options.js";
32
import type { Program } from "../core/program.js";
43
import type { CompilerHost, Diagnostic, Entity, Type } from "../core/types.js";
@@ -39,6 +38,7 @@ export interface TestFileSystem {
3938
addRealTypeSpecFile(path: string, realPath: string): Promise<void>;
4039
addRealJsFile(path: string, realPath: string): Promise<void>;
4140
addRealFolder(path: string, realPath: string): Promise<void>;
41+
// eslint-disable-next-line @typescript-eslint/no-deprecated
4242
addTypeSpecLibrary(testLibrary: TypeSpecTestLibrary): Promise<void>;
4343

4444
/** @internal */
@@ -221,6 +221,7 @@ export interface PositionedMarkerInFile extends PositionedMarker {
221221
// #endregion
222222

223223
// #region Legacy Test host
224+
/* eslint-disable @typescript-eslint/no-deprecated -- defining deprecated APIs for backward compatibility */
224225
/** @deprecated Use {@link Tester} */
225226
export interface TestHost extends Pick<
226227
TestFileSystem,
@@ -317,4 +318,5 @@ export interface BasicTestRunner {
317318
options?: CompilerOptions,
318319
): Promise<[Record<string, Type>, readonly Diagnostic[]]>;
319320
}
321+
/* eslint-enable @typescript-eslint/no-deprecated */
320322
// #endregion
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
/* eslint-disable @typescript-eslint/no-deprecated */
21
import { createTestLibrary, findTestPackageRoot } from "@typespec/compiler/testing";
32

43
/** @deprecated Use `createTester` from `@typespec/compiler/testing` instead */
4+
/* eslint-disable @typescript-eslint/no-deprecated */
55
export const EventsTestLibrary = createTestLibrary({
66
name: "@typespec/events",
77
packageRoot: await findTestPackageRoot(import.meta.url),
88
});
9+
/* eslint-enable @typescript-eslint/no-deprecated */
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
/* eslint-disable @typescript-eslint/no-deprecated */
21
import {
32
createTestLibrary,
43
findTestPackageRoot,
54
type TypeSpecTestLibrary,
65
} from "@typespec/compiler/testing";
76

87
/** @deprecated Use `createTester` from `@typespec/compiler/testing` instead */
8+
/* eslint-disable @typescript-eslint/no-deprecated */
99
export const ProgramViewerTestLibrary: TypeSpecTestLibrary = createTestLibrary({
1010
name: "@typespec/html-program-viewer",
1111
jsFileFolder: "dist/emitter",
1212
packageRoot: await findTestPackageRoot(import.meta.url),
1313
});
14+
/* eslint-enable @typescript-eslint/no-deprecated */

0 commit comments

Comments
 (0)