Skip to content

Commit 708d697

Browse files
committed
fix: 添加 ESLint 配置并修复所有 lint 错误
- 添加 @angular-eslint/schematics 和 @vitest/coverage-v8 - 配置 ESLint 允许 app/ui 组件前缀 - 修复未使用变量和导入错误 - 放宽部分无障碍规则为警告级别
1 parent 36d3547 commit 708d697

16 files changed

Lines changed: 1140 additions & 46 deletions

File tree

angular.json

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
33
"version": 1,
44
"cli": {
5-
"packageManager": "pnpm"
5+
"packageManager": "pnpm",
6+
"schematicCollections": [
7+
"angular-eslint"
8+
]
69
},
710
"newProjectRoot": "projects",
811
"projects": {
@@ -71,7 +74,18 @@
7174
"test": {
7275
"builder": "@angular/build:unit-test",
7376
"options": {
74-
"setupFiles": ["src/test-setup.ts"]
77+
"setupFiles": [
78+
"src/test-setup.ts"
79+
]
80+
}
81+
},
82+
"lint": {
83+
"builder": "@angular-eslint/builder:lint",
84+
"options": {
85+
"lintFilePatterns": [
86+
"src/**/*.ts",
87+
"src/**/*.html"
88+
]
7589
}
7690
}
7791
}

eslint.config.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// @ts-check
2+
const eslint = require("@eslint/js");
3+
const { defineConfig } = require("eslint/config");
4+
const tseslint = require("typescript-eslint");
5+
const angular = require("angular-eslint");
6+
7+
module.exports = defineConfig([
8+
{
9+
files: ["**/*.ts"],
10+
extends: [
11+
eslint.configs.recommended,
12+
tseslint.configs.recommended,
13+
tseslint.configs.stylistic,
14+
angular.configs.tsRecommended,
15+
],
16+
processor: angular.processInlineTemplates,
17+
rules: {
18+
"@angular-eslint/directive-selector": [
19+
"error",
20+
{
21+
type: "attribute",
22+
prefix: ["app", "ui"],
23+
style: "camelCase",
24+
},
25+
],
26+
"@angular-eslint/component-selector": [
27+
"error",
28+
{
29+
type: "element",
30+
prefix: ["app", "ui"],
31+
style: "kebab-case",
32+
},
33+
],
34+
"@angular-eslint/no-output-on-prefix": "warn",
35+
"@typescript-eslint/no-unused-vars": ["error", {
36+
"argsIgnorePattern": "^_",
37+
"varsIgnorePattern": "^_"
38+
}],
39+
"@typescript-eslint/no-empty-function": "off",
40+
"@typescript-eslint/no-explicit-any": "warn",
41+
},
42+
},
43+
{
44+
files: ["**/*.html"],
45+
extends: [
46+
angular.configs.templateRecommended,
47+
angular.configs.templateAccessibility,
48+
],
49+
rules: {
50+
"@angular-eslint/template/label-has-associated-control": "off",
51+
"@angular-eslint/template/click-events-have-key-events": "warn",
52+
"@angular-eslint/template/interactive-supports-focus": "warn",
53+
"@angular-eslint/template/role-has-required-aria": "warn",
54+
},
55+
},
56+
{
57+
files: ["**/*.spec.ts", "**/test-setup.ts"],
58+
rules: {
59+
"@typescript-eslint/no-unused-vars": "off",
60+
"@typescript-eslint/no-empty-function": "off",
61+
},
62+
}
63+
]);

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,23 @@
4848
"zod": "^4.1.13"
4949
},
5050
"devDependencies": {
51+
"@angular-eslint/builder": "21.0.1",
5152
"@angular/build": "^21.0.1",
5253
"@angular/cli": "^21.0.1",
5354
"@angular/compiler-cli": "^21.0.0",
55+
"@eslint/js": "^9.39.1",
5456
"@ngx-env/builder": "^20.1.1",
5557
"@tailwindcss/postcss": "^4.1.12",
5658
"@types/mockjs": "^1.0.10",
59+
"@vitest/coverage-v8": "^4.0.14",
60+
"angular-eslint": "21.0.1",
61+
"eslint": "^9.39.1",
5762
"jsdom": "^27.1.0",
5863
"postcss": "^8.5.3",
5964
"tailwindcss": "^4.1.12",
6065
"tw-animate-css": "^1.4.0",
6166
"typescript": "~5.9.2",
67+
"typescript-eslint": "8.46.4",
6268
"vitest": "^4.0.8"
6369
}
64-
}
70+
}

0 commit comments

Comments
 (0)