在我的Angular应用程序中,当我生成新的组件时,会触发错误"Unexpected @typescript-eslint/no- empty -function“和"Unexpected method 'ngOnInit‘@typescript-eslint/no- empty -function”。
这是我的脚本:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-header',
templateUrl: './header.component.html',
styleUrls: ['./header.component.sass']
})
export class HeaderComponent implements OnInit {
constructor() {
//
}
ngOnInit(): void {
//
}
}如你所见,我试图添加//,但页脚和页眉的问题仍然存在没有problems.Can的情况下,同样的想法也有效有人告诉我我遗漏了什么,或者我还能做什么?
发布于 2021-07-29 13:38:10
这不是编译错误。Eslint给出这个错误是为了迫使你维护代码标准。如果你想使用Eslint,但忽略'no-empty-function‘,有一些方法。你可以全局禁用错误,或者只在文件中禁用错误,或者只在构造函数中禁用错误。
在那里创建.eslintrc.json添加-
{
"root": true,
"overrides": [
{
"files": ["*.ts"],
"rules": {
"@typescript-eslint/no-empty-function": "off"
}
}
]
}此配置全局禁用'no-empty-function‘规则。您也可以仅在构造函数中允许此规则。将以前的规则值替换为以下值-
"rules":{
"@typescript-eslint/no-empty-function":[
"error",
{
"allow":[
"constructors"
]
}
]
}如果您只是想要特定行的规则,则需要添加以下行-
// eslint-disable-next-line @typescript-eslint/no-empty-function在你的功能之上。
https://stackoverflow.com/questions/68568264
复制相似问题