Skip to content

Commit aa34d1a

Browse files
authored
[suppressions] enable typescript-eslint (#38876)
1 parent 45d8f52 commit aa34d1a

File tree

6 files changed

+47
-8
lines changed

6 files changed

+47
-8
lines changed

.github/workflows/suppressions-test.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ jobs:
2525
uses: ./.github/workflows/_reusable-eng-tools-test.yaml
2626
with:
2727
package: suppressions
28+
lint: true
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Keep in sync with .github/shared/eslint.config.js
2+
3+
import eslint from "@eslint/js";
4+
import { defineConfig } from "eslint/config";
5+
import globals from "globals";
6+
import tseslint from "typescript-eslint";
7+
8+
/** @type {import('eslint').Linter.Config[]} */
9+
export default defineConfig(
10+
eslint.configs.recommended,
11+
tseslint.configs.recommendedTypeChecked,
12+
{
13+
languageOptions: {
14+
// we only run in node, not browser
15+
globals: globals.node,
16+
// required to use tseslint.configs.recommendedTypeChecked
17+
parserOptions: {
18+
projectService: {
19+
allowDefaultProject: ["*.js", "cmd/*.js"],
20+
},
21+
// ensures the tsconfig path resolves relative to this file
22+
// default is process.cwd() when running eslint, which may be incorrect
23+
tsconfigRootDir: import.meta.dirname,
24+
},
25+
},
26+
},
27+
{
28+
ignores: ["coverage/**", "dist/**"],
29+
},
30+
);

eng/tools/suppressions/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
},
99
"scripts": {
1010
"build": "tsc --build",
11+
"check": "npm run build && npm run lint && npm run format:check && npm run test:ci",
1112
"format": "prettier . --ignore-path ../.prettierignore --write",
1213
"format:check": "prettier . --ignore-path ../.prettierignore --check",
1314
"format:check:ci": "prettier . --ignore-path ../.prettierignore --check --log-level debug",
15+
"lint": "cross-env DEBUG=eslint:eslint eslint",
1416
"test": "vitest",
1517
"test:ci": "vitest run --coverage --reporter=verbose"
1618
},
@@ -23,11 +25,14 @@
2325
"zod": "^4.1.11"
2426
},
2527
"devDependencies": {
28+
"@eslint/js": "^9.22.0",
2629
"@types/node": "^20.0.0",
2730
"@vitest/coverage-v8": "^3.1.2",
31+
"eslint": "^9.22.0",
2832
"prettier": "~3.6.2",
2933
"prettier-plugin-organize-imports": "^4.2.0",
3034
"typescript": "~5.9.2",
35+
"typescript-eslint": "^8.45.0",
3136
"vitest": "^3.2.4"
3237
}
3338
}

eng/tools/suppressions/src/suppressions.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const suppressionSchema = z.array(
3636
path: ["path", "paths"],
3737
})
3838
.transform((s) => {
39-
let paths: string[] = Array.from(s.paths || []);
39+
const paths: string[] = Array.from(s.paths || []);
4040
if (s.path) {
4141
// if "path" is defined, it is inserted at the start of "paths".
4242
paths.unshift(s.path);
@@ -78,17 +78,17 @@ const suppressionSchema = z.array(
7878
export async function getSuppressions(
7979
tool: string,
8080
path: string,
81-
context: Record<string, any> = {},
81+
context: Record<string, unknown> = {},
8282
): Promise<Suppression[]> {
8383
path = resolve(path);
8484

8585
// If path doesn't exist, throw instead of returning "[]" to prevent confusion
8686
await access(path, constants.R_OK);
8787

88-
let suppressionsFiles: string[] = await findSuppressionsFiles(path);
88+
const suppressionsFiles: string[] = await findSuppressionsFiles(path);
8989
let suppressions: Suppression[] = [];
9090

91-
for (let suppressionsFile of suppressionsFiles) {
91+
for (const suppressionsFile of suppressionsFiles) {
9292
suppressions = suppressions.concat(
9393
getSuppressionsFromYaml(
9494
tool,
@@ -135,13 +135,13 @@ export function getSuppressionsFromYaml(
135135
path: string,
136136
suppressionsFile: string,
137137
suppressionsYaml: string,
138-
context: Record<string, any> = {},
138+
context: Record<string, unknown> = {},
139139
): Suppression[] {
140140
path = resolve(path);
141141
suppressionsFile = resolve(suppressionsFile);
142142

143143
// Treat empty yaml as empty array
144-
const parsedYaml: any = yamlParse(suppressionsYaml) ?? [];
144+
const parsedYaml: unknown = yamlParse(suppressionsYaml) ?? [];
145145

146146
let suppressions: Suppression[];
147147
try {

eng/tools/suppressions/test/suppressions.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ test("yaml array not suppression", () => {
253253
});
254254

255255
test("suppression with rules", () => {
256-
let suppressions: Suppression[] = getSuppressionsFromYaml(
256+
const suppressions: Suppression[] = getSuppressionsFromYaml(
257257
"TestTool",
258258
"foo",
259259
"suppressions.yaml",
@@ -320,7 +320,7 @@ test.each([
320320
reason: process-version
321321
`;
322322

323-
let suppressions: Suppression[] = getSuppressionsFromYaml(
323+
const suppressions: Suppression[] = getSuppressionsFromYaml(
324324
"TestTool",
325325
"test-path",
326326
"suppressions.yaml",

package-lock.json

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)