Skip to content

Commit 35f5c90

Browse files
Migrate to eslint flat config (microsoft#3123)
resolve microsoft#3121 same change in typespec-azure Azure/typespec-azure#620 ## Single top level config This makes it a little nicer to run as you know get the absolute path for errors No need to have the hacky rushstack dependency to allow using the same shared config. ## Able to lint the projects that are outside of the pnpm workspace <img width="1054" alt="image" src="https://github.com/microsoft/typespec/assets/1031227/f88691d9-1bf2-4140-ba2b-533207b15f9d"> ## Eslint 9 -no yet eslint 9 was just released firday which makes this config the new default however it does include breaking changes and not all our plugins have updated
1 parent 6cae425 commit 35f5c90

File tree

73 files changed

+1101
-1147
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+1101
-1147
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
3+
changeKind: internal
4+
packages:
5+
- "@typespec/bundler"
6+
- "@typespec/compiler"
7+
- "@typespec/eslint-plugin"
8+
- "@typespec/html-program-viewer"
9+
- "@typespec/http"
10+
- "@typespec/internal-build-utils"
11+
- "@typespec/json-schema"
12+
- "@typespec/library-linter"
13+
- "@typespec/openapi"
14+
- "@typespec/openapi3"
15+
- "@typespec/playground"
16+
- "@typespec/prettier-plugin-typespec"
17+
- "@typespec/protobuf"
18+
- "@typespec/rest"
19+
- tmlanguage-generator
20+
- typespec-vscode
21+
- "@typespec/versioning"
22+
- "typespec-vs"
23+
---
24+
25+
Migrate to eslint flat config

.vscode/settings.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,6 @@
5959
"prettier.prettierPath": "./node_modules/prettier/index.cjs",
6060
"prettier.documentSelectors": ["**/*.tsp"],
6161
"testExplorer.errorDecoration": false,
62-
"typespec.tsp-server.path": "${workspaceFolder}/packages/compiler"
62+
"typespec.tsp-server.path": "${workspaceFolder}/packages/compiler",
63+
"eslint.experimental.useFlatConfig": true // Still needed new version coming soon should work without https://github.com/microsoft/vscode-eslint/issues/1644
6364
}

e2e/e2e-tests.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-console */
12
// @ts-check
23
import { existsSync, readdirSync, rmSync, writeFileSync } from "fs";
34
import { join } from "path";

eslint.config.js

+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
// @ts-check
2+
import eslint from "@eslint/js";
3+
import deprecation from "eslint-plugin-deprecation";
4+
import unicorn from "eslint-plugin-unicorn";
5+
import vitest from "eslint-plugin-vitest";
6+
import { dirname } from "path";
7+
import tsEslint from "typescript-eslint";
8+
import { fileURLToPath } from "url";
9+
10+
/** Config that will apply to all files */
11+
const allFilesConfig = tsEslint.config({
12+
plugins: {
13+
unicorn,
14+
},
15+
rules: {
16+
/**
17+
* Typescript plugin overrides
18+
*/
19+
"@typescript-eslint/no-non-null-assertion": "off",
20+
"@typescript-eslint/no-explicit-any": "off",
21+
"@typescript-eslint/no-inferrable-types": "off",
22+
"@typescript-eslint/no-empty-function": "off",
23+
"@typescript-eslint/no-empty-interface": "off",
24+
"@typescript-eslint/no-unused-vars": [
25+
"warn",
26+
{ varsIgnorePattern: "^_", argsIgnorePattern: ".*", ignoreRestSiblings: true },
27+
],
28+
29+
// This rule is bugged https://github.com/typescript-eslint/typescript-eslint/issues/6538
30+
"@typescript-eslint/no-misused-promises": "off",
31+
32+
/**
33+
* Unicorn
34+
*/
35+
"unicorn/filename-case": ["error", { case: "kebabCase" }],
36+
37+
/**
38+
* Core
39+
*/
40+
"no-inner-declarations": "off",
41+
"no-empty": "off",
42+
"no-constant-condition": "off",
43+
"no-case-declarations": "off",
44+
"no-ex-assign": "off",
45+
"no-undef": "off",
46+
"prefer-const": [
47+
"warn",
48+
{
49+
destructuring: "all",
50+
},
51+
],
52+
eqeqeq: ["warn", "always", { null: "ignore" }],
53+
54+
// Do not want console.log left from debugging or using console.log for logging. Use the program logger.
55+
"no-console": "warn",
56+
57+
// Symbols should have a description so it can be serialized.
58+
"symbol-description": "warn",
59+
},
60+
});
61+
62+
/** Config that will apply to all typescript files only
63+
* @param {string} root
64+
*/
65+
export function getTypeScriptProjectRules(root) {
66+
return tsEslint.config({
67+
files: ["**/*.ts", "**/*.tsx"],
68+
plugins: {
69+
deprecation,
70+
},
71+
languageOptions: {
72+
parserOptions: {
73+
project: "./tsconfig.json",
74+
tsconfigRootDir: root,
75+
},
76+
},
77+
rules: {
78+
// Only put rules here that need typescript project information
79+
"@typescript-eslint/no-floating-promises": "error",
80+
"deprecation/deprecation": ["warn"],
81+
},
82+
});
83+
}
84+
85+
/** Config that will apply to all test files only */
86+
const testFilesConfig = tsEslint.config({
87+
/**
88+
* Test files specific rules
89+
*/
90+
files: ["**/*.test.ts"],
91+
plugins: { vitest },
92+
rules: {
93+
"vitest/no-focused-tests": "warn",
94+
"vitest/no-identical-title": "error",
95+
"vitest/no-commented-out-tests": "warn",
96+
"vitest/no-import-node-test": "warn",
97+
"vitest/require-local-test-context-for-concurrent-snapshots": "warn",
98+
"vitest/valid-describe-callback": "warn",
99+
"vitest/valid-expect": "warn",
100+
"@typescript-eslint/no-non-null-asserted-optional-chain": "off",
101+
},
102+
});
103+
104+
export const TypeSpecCommonEslintConfigs = [
105+
eslint.configs.recommended,
106+
...tsEslint.configs.recommended,
107+
...allFilesConfig,
108+
...testFilesConfig,
109+
];
110+
111+
export default tsEslint.config(
112+
{
113+
ignores: [
114+
"**/dist/**/*",
115+
"**/.temp/**/*",
116+
"**/generated-defs/*",
117+
"**/website/build/**/*",
118+
"**/.docusaurus/**/*",
119+
"packages/compiler/templates/**/*", // Ignore the templates which might have invalid code and not follow exactly our rules.
120+
// TODO: enable
121+
"**/.scripts/**/*",
122+
"eng/scripts/**/*",
123+
"packages/*/scripts/**/*",
124+
],
125+
},
126+
...TypeSpecCommonEslintConfigs,
127+
...getTypeScriptProjectRules(dirname(fileURLToPath(import.meta.url)))
128+
);

package.json

+13-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "0.0.1",
44
"private": true,
55
"packageManager": "pnpm@8.13.1",
6+
"type": "module",
67
"scripts": {
78
"build": "pnpm build:all && pnpm gen-compiler-extern-signature",
89
"build:all": "pnpm -r --workspace-concurrency=Infinity --aggregate-output --reporter=append-only build && pnpm gen-compiler-extern-signature",
@@ -17,7 +18,8 @@
1718
"format:check": "prettier . --check",
1819
"format:dir": "prettier --write",
1920
"gen-compiler-extern-signature": "pnpm run -r --filter \"@typespec/compiler\" gen-extern-signature",
20-
"lint": "pnpm -r --parallel --aggregate-output --reporter=append-only run lint",
21+
"lint": "eslint . --max-warnings=0",
22+
"lint:fix": "eslint . --fix",
2123
"merge-coverage": "c8 -- report --reporter=cobertura --reporter=text",
2224
"pack:all": "chronus pack --pack-destination ./temp/artifacts",
2325
"preinstall": "npx only-allow pnpm",
@@ -34,14 +36,24 @@
3436
"devDependencies": {
3537
"@chronus/chronus": "^0.8.3",
3638
"@chronus/github": "^0.2.2",
39+
"@eslint/js": "^8.57.0",
3740
"@pnpm/find-workspace-packages": "^6.0.9",
41+
"@types/node": "~18.11.19",
42+
"@typescript-eslint/parser": "^7.5.0",
43+
"@typescript-eslint/utils": "^7.5.0",
3844
"c8": "^9.1.0",
3945
"cspell": "^8.6.1",
46+
"eslint": "^8.57.0",
47+
"eslint-plugin-deprecation": "^2.0.0",
48+
"eslint-plugin-import": "^2.29.1",
49+
"eslint-plugin-unicorn": "^51.0.1",
50+
"eslint-plugin-vitest": "^0.4.1",
4051
"prettier": "~3.2.5",
4152
"prettier-plugin-organize-imports": "~3.2.4",
4253
"rimraf": "~5.0.5",
4354
"syncpack": "^12.3.0",
4455
"typescript": "~5.4.3",
56+
"typescript-eslint": "^7.5.0",
4557
"vitest": "^1.4.0"
4658
},
4759
"syncpack": {

packages/best-practices/.eslintrc.cjs

-7
This file was deleted.

packages/best-practices/package.json

+2-5
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
"test": "vitest run",
3333
"test:ui": "vitest --ui",
3434
"test:ci": "vitest run --coverage --reporter=junit --reporter=default",
35-
"lint": "eslint . --ext .ts --max-warnings=0",
36-
"lint:fix": "eslint . --fix --ext .ts"
35+
"lint": "eslint . --max-warnings=0",
36+
"lint:fix": "eslint . --fix"
3737
},
3838
"files": [
3939
"lib/*.tsp",
@@ -46,12 +46,9 @@
4646
"devDependencies": {
4747
"@types/node": "~18.11.19",
4848
"@typespec/compiler": "workspace:~",
49-
"@typespec/eslint-config-typespec": "workspace:~",
50-
"@typespec/eslint-plugin": "workspace:~",
5149
"@vitest/coverage-v8": "^1.4.0",
5250
"@vitest/ui": "^1.4.0",
5351
"c8": "^9.1.0",
54-
"eslint": "^8.57.0",
5552
"rimraf": "~5.0.5",
5653
"typescript": "~5.4.3",
5754
"vitest": "^1.4.0"

packages/bundle-uploader/.eslintrc.cjs

-6
This file was deleted.

packages/bundle-uploader/package.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
"watch": "tsc -p . --watch",
2929
"test": "echo 'no test'",
3030
"test:ci": "echo 'no test'",
31-
"lint": "eslint . --ext .ts --max-warnings=0",
32-
"lint:fix": "eslint . --fix --ext .ts"
31+
"lint": "eslint . --max-warnings=0",
32+
"lint:fix": "eslint . --fix"
3333
},
3434
"files": [
3535
"lib/*.tsp",
@@ -48,11 +48,9 @@
4848
"devDependencies": {
4949
"@types/node": "~18.11.19",
5050
"@types/semver": "^7.5.8",
51-
"@typespec/eslint-config-typespec": "workspace:~",
5251
"@vitest/coverage-v8": "^1.4.0",
5352
"@vitest/ui": "^1.4.0",
5453
"c8": "^9.1.0",
55-
"eslint": "^8.57.0",
5654
"rimraf": "~5.0.5",
5755
"typescript": "~5.4.3",
5856
"vitest": "^1.4.0"

packages/bundler/.eslintrc.cjs

-6
This file was deleted.

packages/bundler/package.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
"test": "vitest run",
3434
"test:ui": "vitest --ui",
3535
"test:ci": "vitest run --coverage --reporter=junit --reporter=default",
36-
"lint": "eslint . --ext .ts --max-warnings=0",
37-
"lint:fix": "eslint . --fix --ext .ts"
36+
"lint": "eslint . --max-warnings=0",
37+
"lint:fix": "eslint . --fix"
3838
},
3939
"files": [
4040
"lib/*.tsp",
@@ -56,11 +56,9 @@
5656
"devDependencies": {
5757
"@types/node": "~18.11.19",
5858
"@types/yargs": "~17.0.32",
59-
"@typespec/eslint-config-typespec": "workspace:~",
6059
"@vitest/coverage-v8": "^1.4.0",
6160
"@vitest/ui": "^1.4.0",
6261
"c8": "^9.1.0",
63-
"eslint": "^8.57.0",
6462
"rimraf": "~5.0.5",
6563
"typescript": "~5.4.3",
6664
"vite": "^5.2.7",

packages/compiler/.eslintrc.cjs

-7
This file was deleted.

packages/compiler/package.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@
7878
"gen-manifest": "node scripts/generate-manifest.js",
7979
"regen-nonascii": "node scripts/regen-nonascii.js",
8080
"fuzz": "node dist/test/manual/fuzz.js run",
81-
"lint": "eslint . --ext .ts --max-warnings=0",
82-
"lint:fix": "eslint . --fix --ext .ts"
81+
"lint": "eslint . --max-warnings=0",
82+
"lint:fix": "eslint . --fix"
8383
},
8484
"dependencies": {
8585
"@babel/code-frame": "~7.24.2",
@@ -104,12 +104,10 @@
104104
"@types/semver": "^7.5.8",
105105
"@types/sinon": "~17.0.3",
106106
"@types/yargs": "~17.0.32",
107-
"@typespec/eslint-config-typespec": "workspace:~",
108107
"@typespec/internal-build-utils": "workspace:~",
109108
"@vitest/coverage-v8": "^1.4.0",
110109
"@vitest/ui": "^1.4.0",
111110
"c8": "^9.1.0",
112-
"eslint": "^8.57.0",
113111
"grammarkdown": "~3.3.2",
114112
"rimraf": "~5.0.5",
115113
"sinon": "~17.0.1",

packages/compiler/templates/emitter-ts/.eslintrc.yml

-14
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// @ts-check
2+
import eslint from "@eslint/js";
3+
import tsEslint from "typescript-eslint";
4+
5+
export default tsEslint.config(
6+
{
7+
ignores: ["**/dist/**/*", "**/.temp/**/*"],
8+
},
9+
eslint.configs.recommended,
10+
...tsEslint.configs.recommended
11+
);

packages/compiler/templates/library-ts/.eslintrc.yml

-14
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// @ts-check
2+
import eslint from "@eslint/js";
3+
import tsEslint from "typescript-eslint";
4+
5+
export default tsEslint.config(
6+
{
7+
ignores: ["**/dist/**/*", "**/.temp/**/*"],
8+
},
9+
eslint.configs.recommended,
10+
...tsEslint.configs.recommended
11+
);

0 commit comments

Comments
 (0)