Rob*_*ste 21 eslint angular typescript-eslint
使用 Angular 12 和 eslint,我在模板中遇到错误,因为我正在这样做:
<button [disabled]="someVariable == null"></button>
Run Code Online (Sandbox Code Playgroud)
预期
===但收到==eslint(@angular-eslint/template/eqeqeq)
在查看源代码时,我注意到一个名为 的选项allowNullOrUndefined。
我尝试像这样定义规则:
"@angular-eslint/template/eqeqeq": [
"error",
{
"allowNullOrUndefined": true
}
]
Run Code Online (Sandbox Code Playgroud)
但我仍然收到错误。所以我尝试完全禁用该规则,如下所示:
"@angular-eslint/template/eqeqeq": ["off"]
Run Code Online (Sandbox Code Playgroud)
或者像这样:
"@angular-eslint/template/eqeqeq": "off"
Run Code Online (Sandbox Code Playgroud)
但不幸的是,我仍然在模板中收到错误。
我找不到有关该规则的任何文档。我可以禁用它或允许双等于 null 或 undefined 吗?
dan*_*y74 39
2年后!你很接近。将其添加到 HTML 部分,.eslintrc.json如下所示:
{
"files": [
"*.html"
],
"extends": [
"plugin:@angular-eslint/template/recommended"
],
"rules": {
"@angular-eslint/template/eqeqeq": [
"error",
{
"allowNullOrUndefined": true
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
显然,请确保安装了正确的 npm 模块,例如@angular-eslint/template-parser
ng add @angular-eslint/schematics --skip-confirmation如果您曾经将 eslint 安装到 Angular 项目中,那么这些应该已经安装。
| 归档时间: |
|
| 查看次数: |
8095 次 |
| 最近记录: |