gpt4 book ai didi

javascript - 如何让 eslint/vscode-eslint 停止 linting .eslintrc?

转载 作者:行者123 更新时间:2023-11-28 14:21:16 25 4
gpt4 key购买 nike

问题

我的 VS Code PROBLEMS Pane 中有一堆来自 eslint 的“问题”,提示我的 .eslintrc 存在各种 JSON 问题。对 VS Code 外部的目录进行 Linting 不会显示 .eslintrc 问题。我的 .eslintrc.eslintignore 文件位于我的工作区目录中(与我的 .vscode 目录位于同一位置。

我尝试过的事情

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

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

但是它们都无法阻止 VS Code 在文件编辑器和“问题” Pane 中显示错误。

我已将 .eslintrc 添加到 VS Code 中的排除文件设置,然后激活“问题” Pane 中的排除文件筛选器,但我不想从“资源管理器” Pane 中隐藏该文件。

问题

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

.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 式格式,虽然 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> 首选项:打开用户设置),然后添加一些规则,以便 VS Code 可以忽略某些文件,例如

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

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

<小时/>

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

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

关于javascript - 如何让 eslint/vscode-eslint 停止 linting .eslintrc?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55153736/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com