我怎样才能让 eslint/vscode-eslint 停止检查 .eslintrc?

How can I make eslint/vscode-eslint stop linting .eslintrc?

问题

我的 VS 代码问题窗格中有一堆 "Problems" 来自 eslint 的抱怨,抱怨我的 .eslintrc 的各种 JSON 问题。在 VS Code 之外检查目录不会向我显示 .eslintrc 问题。我的 .eslintrc.eslintignore 文件在我的工作区目录中(与我的 .vscode 目录相同的位置。

我尝试过的东西

我尝试将以下条目添加到我的 .eslintignore 文件中:

  1. **/.*
  2. **/.eslintrc
  3. .eslintrc
  4. ./.eslintrc

但是 none 它们阻止 VS Code 在文件编辑器和问题窗格中显示错误。

我已将 .eslintrc 添加到 VS Code 中的排除文件设置,然后在“问题”窗格中激活排除文件过滤器,但我不想从“浏览器”窗格中隐藏该文件。

问题

如何强制 VS Code/ESLint/vscode-eslint/the 罪魁祸首忽略我的 .eslintrc 而在 VS Code 中进行 linting?

.eslintrc

{
  extends: 'airbnb',
  parser: 'babel-eslint',
  plugins: [
    'react',
    'jest',
  ],
  env: {
    browser: true,
    node: true,
    es6: true,
    jest/globals: true,
  },
  globals: {
    LOGGING_ENDPOINT: false,
    $: false,
    beautify: false,
    testContext: false,
    page: false,
  },
  settings: {
    react: {
      pragma: 'h',
    },
  },
  rules: {
    import/no-extraneous-dependencies: 'off',
    import/no-unresolved: ['error', { ignore: ['^react$', '^react-dom$'] }],
    import/extensions: 'off',
    react/react-in-jsx-scope: 'off',
    no-underscore-dangle: 'off',
    react/no-danger: 'off',
    no-unused-vars: ['error', { varsIgnorePattern: 'React' }],
    react/require-default-props: 'off',
    function-paren-newline: 'off',
    import/no-named-as-default: 'off',
    object-curly-newline: 'off',
    jest/no-focused-tests: 'error',
  },
}

谢谢!

解决方案

问题是我的 .eslintrc 是一种奇怪的 JSON-esque 格式,虽然 ESLint 读得很好,但 VS Code 告诉我所有问题。一旦我将其正确格式化为 JSON,VS Code 就停止了抱怨。

我认为你的问题与 VS Code 最相关,而不是 ESLint。

The .eslintrc file is used to set rules and configurations for ESLint.

您可以打开 VS Code 用户设置或工作区设置 (Ctrl+Shift+P > Preferences: Open User Settings), 并添加一些规则,以便 VS Code 可以忽略一些文件,例如

  "eslint.options": {
    "extensions": [".js", ".jsx"]
  },
  "eslint.validate": [
    "javascript",
    "javascriptreact",
    "typescript",
    "typescriptreact"
  ],

查看有关 vscode-eslint 扩展程序的更多详细信息。


此外,如果您想在保存文件时添加自动修复,您可以将以下内容添加到您的 user/workspace 设置中:

  "files.autoSave": "off",
  "editor.formatOnSave": true,
  "eslint.autoFixOnSave": true,
  "editor.codeActionsOnSave": {
    "source.fixAll": true,
    "source.organizeImports": true
  },