在.prettierrc文件中尾随逗号规则

发布于 2025-02-11 15:02:42 字数 1349 浏览 1 评论 0原文

我有一个 next。 eslint 。我想通过将其值设置为来启用Prettier规则 “ TrailingComma” .prettierrc文件包含以下内容:

    // ".prettierrc"

    {
        "trailingComma": "all"
    }

我正在使用 .eslintrc.json 文件以配置ESLINT,我已经配置了它以应用一对夫妇插件,并扩展插件的几个规则集。

This is an image of my file:

  {
    "next",
    "next/core-web-vitals",
    "prettier",
    "eslint:recommended",
    "plugin:jsx-a11y/recommended",
    "plugin:prettier/recommended",
    "plugin:typescript-eslint/recommended",
  }

"comma-dangle": "off",

​规则被证明会影响TrailComma规则,如错误消息中所述:

"prettier/prettier": ["error", {}, { "usePrettierrc": true }],



Prettier在我保存时似乎执行了,并且逗号添加到列表的末尾,但是我得到了以下错误消息(如图所示)。

我尝试将“ endofline”选项添加到.prettierrc.eslintrc.json rule “ Prettier/Prettier” ,有人说它可以解决该问题,但没有解决问题。

如何防止尾逗号在编辑器中显示错误?

I have a Next.js project that is configured to use Prettier & ESLint. I want to enable the Prettier rule "trailingComma" by setting its value to "all", such that the .prettierrc file contains the following:

    // ".prettierrc"

    {
        "trailingComma": "all"
    }

I am using an .eslintrc.json file to configure ESLint, and I have it configured to apply a couple of plug-ins, and to extend a couple of the plug-in's rule-sets.

This is an image of my file:

enter image description here

  {
    "next",
    "next/core-web-vitals",
    "prettier",
    "eslint:recommended",
    "plugin:jsx-a11y/recommended",
    "plugin:prettier/recommended",
    "plugin:typescript-eslint/recommended",
  }

The following ESLint rule is the rule ESLint uses to configure commas:

"comma-dangle": "off",

This rule is shown to affect the trailingComma rule, as it is mentioned in the error message:

"prettier/prettier": ["error", {}, { "usePrettierrc": true }],

Prettier seems to execute when I save, and the commas are added to the end of the list, but then I get the following error message (shown in the image).

enter image description here

I tried adding the "endOfLine" option both to .prettierrc and .eslintrc.json rule "prettier/prettier", someone said that it would fix the issue, but it didn't fix it.

How can I keep the trailing commas from displaying errors in the editor?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文