Skip to content

Commit 588c3ee

Browse files
authored
[typespec-validation] Enable eslint (minimal config) (#38903)
1 parent 7fa7be2 commit 588c3ee

File tree

11 files changed

+54
-9
lines changed

11 files changed

+54
-9
lines changed

.github/workflows/typespec-validation-test.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ jobs:
2727
uses: ./.github/workflows/_reusable-eng-tools-test.yaml
2828
with:
2929
package: typespec-validation
30+
lint: true
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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.recommended,
12+
// TODO: Enable "recommendedTypeChecked" rules, fix all violations
13+
// tseslint.configs.recommendedTypeChecked,
14+
{
15+
languageOptions: {
16+
// we only run in node, not browser
17+
globals: globals.node,
18+
// required to use tseslint.configs.recommendedTypeChecked
19+
// parserOptions: {
20+
// projectService: {
21+
// allowDefaultProject: ["*.js", "cmd/*.js"],
22+
// },
23+
// // ensures the tsconfig path resolves relative to this file
24+
// // default is process.cwd() when running eslint, which may be incorrect
25+
// tsconfigRootDir: import.meta.dirname,
26+
// },
27+
},
28+
},
29+
{
30+
// TODO: Remove exclusion for "test/**"
31+
ignores: ["coverage/**", "dist/**", "test/**"],
32+
},
33+
);

eng/tools/typespec-validation/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,24 @@
1717
"yaml": "^2.4.2"
1818
},
1919
"devDependencies": {
20+
"@eslint/js": "^9.22.0",
2021
"@types/debug": "^4.1.12",
2122
"@types/node": "^20.0.0",
2223
"@vitest/coverage-v8": "^3.1.2",
24+
"eslint": "^9.22.0",
2325
"prettier": "~3.6.2",
2426
"prettier-plugin-organize-imports": "^4.2.0",
2527
"typescript": "~5.9.2",
28+
"typescript-eslint": "^8.45.0",
2629
"vitest": "^3.2.4"
2730
},
2831
"scripts": {
2932
"build": "tsc --build",
33+
"check": "npm run build && npm run lint && npm run format:check && npm run test:ci",
3034
"format": "prettier . --ignore-path ../.prettierignore --write",
3135
"format:check": "prettier . --ignore-path ../.prettierignore --check",
3236
"format:check:ci": "prettier . --ignore-path ../.prettierignore --check --log-level debug",
37+
"lint": "cross-env DEBUG=eslint:eslint eslint",
3338
"test": "vitest",
3439
"test:ci": "vitest run --coverage --reporter=verbose"
3540
},

eng/tools/typespec-validation/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { SdkTspConfigValidationRule } from "./rules/sdk-tspconfig-validation.js"
1212
import { fileExists, getSuppressions, normalizePath } from "./utils.js";
1313

1414
// Context argument may add new properties or override checkingAllSpecs
15-
export var context: Record<string, any> = { checkingAllSpecs: false };
15+
export let context: Record<string, unknown> = { checkingAllSpecs: false };
1616

1717
export async function main() {
1818
const args = process.argv.slice(2);

eng/tools/typespec-validation/src/rules/compile.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class CompileRule implements Rule {
1818
let errorOutput = "";
1919

2020
if (await fileExists(path.join(folder, "main.tsp"))) {
21-
let [err, stdout, stderr] = await runNpm([
21+
const [err, stdout, stderr] = await runNpm([
2222
"exec",
2323
"--no",
2424
"--",
@@ -178,7 +178,7 @@ export class CompileRule implements Rule {
178178

179179
const clientTsp = path.join(folder, "client.tsp");
180180
if (await fileExists(clientTsp)) {
181-
let [err, stdout, stderr] = await runNpm([
181+
const [err, stdout, stderr] = await runNpm([
182182
"exec",
183183
"--no",
184184
"--",

eng/tools/typespec-validation/src/rules/folder-structure.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export class FolderStructureRule implements Rule {
136136
success = false;
137137
}
138138

139-
const rpNamespaceRegex = /^[A-Za-z0-9\.]+$/;
139+
const rpNamespaceRegex = /^[A-Za-z0-9.]+$/;
140140
const rpNamespaceFolder = folderStruct[folderStruct.length - 2];
141141

142142
if (!rpNamespaceRegex.test(rpNamespaceFolder)) {

eng/tools/typespec-validation/src/rules/linter-ruleset.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class LinterRulesetRule implements Rule {
3333

3434
const mainTspExists = await fileExists(join(folder, "main.tsp"));
3535
const clientTspExists = await fileExists(join(folder, "client.tsp"));
36-
let files = [];
36+
const files = [];
3737
if (mainTspExists) {
3838
files.push("main.tsp");
3939
}

eng/tools/typespec-validation/src/rules/npm-prefix.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class NpmPrefixRule implements Rule {
2929
const actual_npm_prefix = normalizePath((await runNpm(["prefix"], folder))[1].trim());
3030

3131
let success = true;
32-
let stdOutput =
32+
const stdOutput =
3333
"Expected npm prefix: " +
3434
expected_npm_prefix +
3535
"\n" +

eng/tools/typespec-validation/src/rules/sdk-tspconfig-validation.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/* eslint-disable */
2+
// TODO: Enable eslint, fix errors
3+
14
import { join } from "path";
25
import { Suppression } from "suppressions";
36
import { parse as yamlParse } from "yaml";

eng/tools/typespec-validation/src/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ export function normalizePathImpl(folder: string, path: PlatformPath = defaultPa
5959

6060
export async function gitDiffTopSpecFolder(folder: string) {
6161
const git = simpleGit(folder);
62-
let topSpecFolder = folder.replace(/(^.*specification\/[^\/]*)(.*)/, "$1");
63-
let stdOutput = `Running git diff on folder ${topSpecFolder}`;
64-
let gitStatus = await git.status(["--porcelain", topSpecFolder]);
62+
const topSpecFolder = folder.replace(/(^.*specification\/[^/]*)(.*)/, "$1");
63+
const stdOutput = `Running git diff on folder ${topSpecFolder}`;
64+
const gitStatus = await git.status(["--porcelain", topSpecFolder]);
6565

6666
let success = true;
6767
let errorOutput: string | undefined;

0 commit comments

Comments
 (0)