我正在尝试使用此 eslint 配置对使用 nx monorepo 创建的 Analogjs 项目进行 lint(我知道该配置中有什么问题,因为如果我从根 eslint 配置的扩展数组中删除配置路径,一切都会正常)。
出现错误
ESLint: 9.12.0
TypeError: Cannot read properties of undefined (reading 'at')
Occurred while linting C:\Users\sergd\work\pohorony.by\pohorony.by\packages\analog-app\index.html:2
Rule: "@typescript-eslint/ban-ts-comment"
at Program (C:\Users\sergd\work\pohorony.by\pohorony.by\node_modules\@typescript-eslint\eslint-plugin\dist\rules\ban-ts-comment.js:118:50)
at ruleErrorHandler (C:\Users\sergd\work\pohorony.by\pohorony.by\node_modules\eslint\lib\linter\linter.js:1084:48)
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>MyApp</title>
<base href="/" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
<link rel="stylesheet" href="/src/styles.css" />
</head>
<body>
<analog-app-root></analog-app-root>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
eslint.base.json
{
"env": { "browser": true, "es2021": true, "node": true },
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "./.eslintrc.angular.json", "prettier"],
"ignorePatterns": ["*dist*"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"project": true,
"sourceType": "module"
},
"plugins": ["@typescript-eslint"],
"overrides": [
{
"files": ["*.ts"],
"rules": {
"@typescript-eslint/array-type": ["error", { "default": "array" }],
"@typescript-eslint/explicit-function-return-type": "error",
"@typescript-eslint/lines-between-class-members": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-unnecessary-type-assertion": "error",
"@typescript-eslint/no-unused-vars": "off",
"block-spacing": ["warn", "always"],
"curly": ["warn", "all"],
"eol-last": "error",
"import/prefer-default-export": "off",
"import/no-unresolved": "error",
"max-len": [
"error",
{
"code": 120,
"ignoreComments": true,
"tabWidth": 2,
"ignoreStrings": true
}
],
"max-lines-per-function": ["error", 80],
"max-classes-per-file": "off",
"no-console": "off",
"no-debugger": "off",
"no-multiple-empty-lines": ["error", { "max": 2, "maxBOF": 0, "maxEOF": 1 }],
"no-param-reassign": ["error", { "props": false }],
"no-plusplus": "off",
"no-return-assign": 1,
"no-restricted-syntax": ["off", "ForInStatement"],
"no-underscore-dangle": "off",
"no-template-curly-in-string": "warn",
"no-unused-vars": "off",
"object-curly-spacing": ["warn", "always"],
"spaced-comment": ["error", "always", { "markers": ["!", "?", "//", "todo", "*"] }],
"class-methods-use-this": "off",
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/explicit-member-accessibility": [
"error",
{
"accessibility": "explicit",
"overrides": {
"accessors": "explicit",
"constructors": "off",
"methods": "explicit",
"properties": "explicit",
"parameterProperties": "explicit"
}
}
]
}
},
{
"files": ["*.spec.ts", "*.test.ts"],
"rules": {
"max-lines-per-function": "off"
}
}
]
}
我尝试删除所有规则和插件:@typescript-eslint/recommended,一切正常。
由于您当前的配置,ESLint 似乎错误地检查了您的 index.html 文件。您可以尝试以下方法:
确保 ESLint 应检查的文件类型已正确定义。更新 ESLint 配置中的ignorePatterns 部分以排除 HTML 文件: json
"ignorePatterns": ["*.html", "*dist*"]
如果您需要对 HTML 文件进行特定处理,请考虑使用像 eslint-plugin-html 这样的 HTML linter,但这对于您的情况来说似乎没有必要。 这应该有助于阻止 ESLint 对 index.html 进行 linting。