vscode/Prettier/Eslint在可选链接操作员中添加空间

发布于 2025-02-10 22:11:33 字数 1051 浏览 0 评论 0原文

不确定发生了什么,但是在vscode w/ eslint和Prettier打开中,它会继续转换这样的行var?.foo?.bar?.bar to var? .foo? .bar然后引发语法错误...我有以下内容:

{
  "trailingComma": "all",
  "tabWidth": 2,
  "useTabs": false,
  "semi": false,
  "singleQuote": true
  }
{
  "extends": ["airbnb", "airbnb-typescript"],
  "parserOptions": {
    "project": "./tsconfig.json"
  },
  "parser": "@babel/eslint-parser",
  "rules": {
   "@typescript-eslint/semi": "off",
   "semi": "off",
   "import/prefer-default-export": "off",
   "no-unused-vars": ["error", { "argsIgnorePattern": "next" }],
   "react/react-in-jsx-scope": "off",
   "react/jsx-one-expression-per-line": "off",
   "react/jsx-props-no-spreading": "off",
   "jsx-a11y/label-has-associated-control": "off",
   "react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx", ".ts", ".tsx"] }],
   "react/function-component-definition": "off",
   "react/require-default-props": "off",
   "no-param-reassign": "off"
  }
}

如何停止vscode添加这些空间?

Not sure what's going on, but in VSCode w/ ESLint and Prettier turned on, it keeps converting lines like this var?.foo?.bar into var ? .foo ? .bar which then throws syntax errors... I have the following:

{
  "trailingComma": "all",
  "tabWidth": 2,
  "useTabs": false,
  "semi": false,
  "singleQuote": true
  }
{
  "extends": ["airbnb", "airbnb-typescript"],
  "parserOptions": {
    "project": "./tsconfig.json"
  },
  "parser": "@babel/eslint-parser",
  "rules": {
   "@typescript-eslint/semi": "off",
   "semi": "off",
   "import/prefer-default-export": "off",
   "no-unused-vars": ["error", { "argsIgnorePattern": "next" }],
   "react/react-in-jsx-scope": "off",
   "react/jsx-one-expression-per-line": "off",
   "react/jsx-props-no-spreading": "off",
   "jsx-a11y/label-has-associated-control": "off",
   "react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx", ".ts", ".tsx"] }],
   "react/function-component-definition": "off",
   "react/require-default-props": "off",
   "no-param-reassign": "off"
  }
}

How do I stop VSCode from adding those spaces?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小红帽 2025-02-17 22:11:33

我可能在这里有点晚,但是至少对我来说,这个问题是由使用另一个扩展名而不是Eslint的“美化”格式的VSCODE引起的。我必须打开命令调色板(ctrl + shift + p),然后选择>格式文档,然后使用...,然后在底部选择配置配置默认值格式化,然后选择ESLINT作为默认值。

I may be a bit late here, but at least for me, this issue was caused by VSCode using a 'Beautify' formatter from another extension, rather than ESlint. I had to open the command palette (Ctrl + Shift + P), then select >Format document with..., then at the bottom select Configure default formatter, and select ESlint as the default.

谜泪 2025-02-17 22:11:33

我安装了Eslint扩展名,并选择它作为格式化.js文件的默认值

,并且可以正常工作

I Installed Eslint extension and choose it as the default value for formatting .js files

and it works fine

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文