我正在使用 ESLint extension在 VSCode 中格式化并检查我的 JavaScript 代码。但是,我不希望 ESLint 显示警告(代码下面的红线),尤其是。与代码格式化相关的那些,但每次保存文件时仍然进行格式化。是否有可能做到这一点?
这是我的 VSCode 配置:
{
"editor.fontSize": 14,
"explorer.openEditors.visible": 0,
"files.autoSave": "onFocusChange",
"terminal.integrated.fontSize": 14,
"terminal.integrated.lineHeight": 1.3,
"terminal.integrated.shell.osx": "zsh",
"editor.codeLens": true,
"editor.occurrencesHighlight": true,
"editor.formatOnSave": true,
"[javascript]": {
"editor.formatOnSave": false
},
"eslint.enable": true,
"eslint.autoFixOnSave": true,
"eslint.alwaysShowStatus": false,
"eslint.run": "onType",
"javascript.updateImportsOnFileMove.enabled": "always",
"explorer.confirmDelete": false,
"diffEditor.ignoreTrimWhitespace": false
}
最佳答案
您应该在 .eslintrc 文件中设置您的设置(它可以是 js、json 或 yaml 文件,确保您拥有正确文件的最佳方法是使用“eslint --init” 命令),进入“规则”部分,只需添加您不想使用的规则名称,后跟逗号和“0”,例如:
"rules": {
"no-inner-declarations": 0,
}
如果您想找到正确的设置名称,您可以将鼠标放在 esLint 指示的错误上,显示问题所在的 float 窗口将包含设置名称。
您还可以引用此 YouTube 视频以获取完整说明: https://www.youtube.com/watch?v=cMrDePs86Uo
在视频中它看起来和现在有点不同(我认为这是旧版本的 VSCode)今天它看起来像这样:
此外,如果您确实配置了该配置但它仍然不起作用,我建议您从一个新的小配置文件开始,并每次逐步添加新配置并检查它是否不会破坏其余配置。
这是我正在运行的基本文件:
module.exports = {
"env": {
"browser": true,
"es6": true
},
"extends": "eslint:recommended",
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 2018,
"sourceType": "module"
},
"plugins": [
"react"
],
"rules": {
"no-inner-declarations": 0,
}
};
关于javascript - 抑制 VSCode 中的 ESLint 警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54761916/