Skip to content

Commit 57c07d0

Browse files
authored
[EngSys] Share eslint config (#39051)
1 parent 78b8699 commit 57c07d0

File tree

12 files changed

+106
-172
lines changed

12 files changed

+106
-172
lines changed

.github/eslint.config.js

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,7 @@
1-
// Keep in sync with .github/shared/eslint.config.js
1+
import { defineBaseConfig } from "./shared/eslint.base.config.js";
22

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: true,
19-
// ensures the tsconfig path resolves relative to this file
20-
// default is process.cwd() when running eslint, which may be incorrect
21-
tsconfigRootDir: import.meta.dirname,
22-
},
23-
},
24-
},
25-
{
26-
ignores: ["coverage/**", "shared/coverage/**"],
27-
},
28-
);
3+
export default defineBaseConfig({
4+
// ensures the tsconfig path resolves relative to this file (so cannot be defined in base file)
5+
// default is process.cwd() when running eslint, which may be incorrect
6+
tsconfigRootDir: import.meta.dirname,
7+
});
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import eslint from "@eslint/js";
2+
import { defineConfig } from "eslint/config";
3+
import globals from "globals";
4+
import tseslint from "typescript-eslint";
5+
6+
/**
7+
* @param {object} options
8+
* @param {boolean|object} [options.projectService]
9+
* @param {string} options.tsconfigRootDir
10+
* @returns {import('eslint').Linter.Config[]}
11+
*/
12+
export function defineBaseConfig(options) {
13+
const { projectService = true, tsconfigRootDir } = options;
14+
15+
return defineConfig(
16+
eslint.configs.recommended,
17+
tseslint.configs.recommendedTypeChecked,
18+
{
19+
languageOptions: {
20+
// we only run in node, not browser
21+
globals: globals.node,
22+
// required to use tseslint.configs.recommendedTypeChecked
23+
parserOptions: {
24+
// Defaults to "true", which is the minimum required to use tseslint.configs.recommendedTypeChecked
25+
// Can be overridden by caller, by setting to a config object
26+
projectService,
27+
// Must be set by caller, since this should point to the root directory of the project being analyzed
28+
tsconfigRootDir,
29+
},
30+
},
31+
},
32+
{
33+
ignores: [
34+
// generated by `vitest --coverage`
35+
"coverage/**",
36+
],
37+
},
38+
);
39+
}

.github/shared/eslint.config.js

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,7 @@
1-
// Keep in sync with .github/eslint.config.js
1+
import { defineBaseConfig } from "./eslint.base.config.js";
22

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: true,
19-
// ensures the tsconfig path resolves relative to this file
20-
// default is process.cwd() when running eslint, which may be incorrect
21-
tsconfigRootDir: import.meta.dirname,
22-
},
23-
},
24-
},
25-
{
26-
ignores: ["coverage/**"],
27-
},
28-
);
3+
export default defineBaseConfig({
4+
// ensures the tsconfig path resolves relative to this file (so cannot be defined in base file)
5+
// default is process.cwd() when running eslint, which may be incorrect
6+
tsconfigRootDir: import.meta.dirname,
7+
});

.github/shared/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"./breaking-change": "./src/breaking-change.js",
88
"./changed-files": "./src/changed-files.js",
99
"./error-reporting": "./src/error-reporting.js",
10+
"./eslint-base-config": "./eslint.base.config.js",
1011
"./exec": "./src/exec.js",
1112
"./git": "./src/git.js",
1213
"./github": "./src/github.js",

eng/tools/eslint.base.config.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { defineBaseConfig as defineSharedBaseConfig } from "@azure-tools/specs-shared/eslint-base-config";
2+
import { defineConfig } from "eslint/config";
3+
4+
/**
5+
* @param {object} options
6+
* @param {string} options.tsconfigRootDir
7+
* @returns {import('eslint').Linter.Config[]}
8+
*/
9+
export function defineBaseConfig(options) {
10+
return defineConfig(
11+
defineSharedBaseConfig({
12+
...options,
13+
projectService: {
14+
// include hand-written JS files (excluded from TS project)
15+
allowDefaultProject: ["*.js", "cmd/*.js"],
16+
},
17+
}),
18+
{
19+
ignores: [
20+
// generated by `tsc compile`
21+
"dist/**",
22+
],
23+
},
24+
);
25+
}
Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,7 @@
1-
// Keep in sync with .github/shared/eslint.config.js
1+
import { defineBaseConfig } from "../eslint.base.config.js";
22

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-
);
3+
export default defineBaseConfig({
4+
// ensures the tsconfig path resolves relative to this file (so cannot be defined in base file)
5+
// default is process.cwd() when running eslint, which may be incorrect
6+
tsconfigRootDir: import.meta.dirname,
7+
});
Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,7 @@
1-
// Keep in sync with .github/shared/eslint.config.js
1+
import { defineBaseConfig } from "../eslint.base.config.js";
22

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-
);
3+
export default defineBaseConfig({
4+
// ensures the tsconfig path resolves relative to this file (so cannot be defined in base file)
5+
// default is process.cwd() when running eslint, which may be incorrect
6+
tsconfigRootDir: import.meta.dirname,
7+
});

eng/tools/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
"name": "azure-rest-api-specs-eng-tools",
3+
"private": true,
4+
"type": "module",
35
"devDependencies": {
46
"@azure-tools/lint-diff": "file:lint-diff",
57
"@azure-tools/oav-runner": "file:oav-runner",
@@ -16,6 +18,5 @@
1618
"scripts": {
1719
"build": "tsc --build",
1820
"postinstall": "npm run build"
19-
},
20-
"private": true
21+
}
2122
}
Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,7 @@
1-
// Keep in sync with .github/shared/eslint.config.js
1+
import { defineBaseConfig } from "../eslint.base.config.js";
22

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-
);
3+
export default defineBaseConfig({
4+
// ensures the tsconfig path resolves relative to this file (so cannot be defined in base file)
5+
// default is process.cwd() when running eslint, which may be incorrect
6+
tsconfigRootDir: import.meta.dirname,
7+
});

eng/tools/suppressions/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"zod": "^4.1.11"
2626
},
2727
"devDependencies": {
28+
"@azure-tools/specs-shared": "file:../../../.github/shared",
2829
"@eslint/js": "^9.22.0",
2930
"@types/node": "^20.0.0",
3031
"@vitest/coverage-v8": "^3.1.2",

0 commit comments

Comments
 (0)