Suppress ESLint warnings in VSCode

依然范特西╮ 提交于 2021-01-29 06:58:45

问题


I am using ESLint extension in VSCode to format and check my JavaScript code. However, I don't want ESLint to show me warnings (red lines below code), esp. the ones related to code formatting, but still do the formatting every time I save the file. Is it possible to do this?

Here is my VSCode config:

{
  "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
}

回答1:


You should set your settings in the .eslintrc file (it can either be js, json, or yaml file, the best way to be sure you have the right file is to use the "eslint --init" command), Head into the "rules" sections and just add the name of the rule that you do not want to use, following by a comma and "0", for example:

"rules": {
    "no-inner-declarations": 0,
}

If you want to find the right settings name, you can stand with your mouse on the error indicated by esLint and the floating window that says what is the problem will contain the setting name.

you can also refer to this YouTube video for complete explanation: https://www.youtube.com/watch?v=cMrDePs86Uo

In the video it looks a bit different then now (I think this is an old version of VSCode) Today it looks like that:

Also in case you did configure that and it still doesn't work I recommend you to start with a new small configuration file and step-by-step adding a new config each time and checking to see if it does not break the rest of the configurations.

This is my basic file that is working:

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,
    }
};


来源:https://stackoverflow.com/questions/54761916/suppress-eslint-warnings-in-vscode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!