MrL*_*oon 16 typescript eslint
我正在配置 ESLint(因为 TSLint 即将被弃用)来处理我的 .ts 文件。我有这个很小的文件:
export default interface Departure {
line: string;
direction: string;
time: Date;
};
Run Code Online (Sandbox Code Playgroud)
在最后一次,分号所在的位置,我的 VSCode 中的 ESLint 发出两个错误信号:一个是关于缺少分号eslint(semi),另一个是关于不必要的分号eslint(no-extra-semi)。

以下是我的.eslintrc.js:
module.exports = {
"env": {
"browser": true,
"commonjs": true,
"es6": true,
"node": true
},
"extends": [
"plugin:@typescript-eslint/recommended",
"airbnb"
],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 2018
},
"plugins": [
"react",
"@typescript-eslint"
],
"settings": {
"import/resolver": {
"node": {
"extensions": [".js", ".jsx", ".ts", ".tsx"]
}
}
},
"rules": {
}
};
Run Code Online (Sandbox Code Playgroud)
我怎样才能摆脱这种奇怪的情况?应该没有任何错误。
ole*_*huk 23
这里的问题是同时应用了 2 个规则:
1.export default需要有分号
2.interface需要去掉分号
此处的解决方法是将接口声明与导出语句分开,如下所示:
interface Departure {
line: string;
direction: string;
time: Date;
}
export default Departure;
Run Code Online (Sandbox Code Playgroud)
我自己没有想出答案。来源是这个提交的问题
小智 11
添加 Ricardo Emerson 的评论,以下.eslintrc设置不会 关闭分号错误:
{
...
"extends": [
...
"eslint:recommended"
],
"rules": {
...
"semi": ["error", "never"],
"@typescript-eslint/semi": "off",
"no-unexpected-multiline": "error"
}
}
Run Code Online (Sandbox Code Playgroud)
no-unexpected-multiline根据文档,还建议在关闭分号时打开错误。
我使用以下规则解决了这个问题:
"rules": {
"semi": "off",
"@typescript-eslint/semi": ["error"],
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7344 次 |
| 最近记录: |