prettier 覆盖 eslint array-bracket-spacing 规则

发布于 2025-01-15 14:57:44 字数 879 浏览 1 评论 0原文

ESlint 在数组括号内添加空格,更漂亮地删除它们。

我使用带有 ESLint 和 Prettier 扩展的 vscodium。 index.js中运行命令

{
  "lint": "eslint --fix ./index.js && prettier --write ./index.js"
}

我在 package.json: .eslint.json:

{
  "env": {
    "browser": true,
    "es2021": true
  },
  "extends": ["prettier"],
  "parserOptions": {
    "ecmaVersion": "latest",
    "sourceType": "module"
  },
  "rules": {
    "no-console": "off",
    "array-bracket-spacing": ["error", "always"] // the rule
  }
}

const myTestFunction = () => {
  const [num1] = [1, 3]; // the error
//const [ num1 ] = [ 1, 3 ]; // expected

  return console.log(num1);
};
myTestFunction();

ESlint adds spaces inside array brackets, prettier removes them.

I use vscodium with ESLint and Prettier extensions. I run the command in package.json:

{
  "lint": "eslint --fix ./index.js && prettier --write ./index.js"
}

.eslint.json:

{
  "env": {
    "browser": true,
    "es2021": true
  },
  "extends": ["prettier"],
  "parserOptions": {
    "ecmaVersion": "latest",
    "sourceType": "module"
  },
  "rules": {
    "no-console": "off",
    "array-bracket-spacing": ["error", "always"] // the rule
  }
}

index.js:

const myTestFunction = () => {
  const [num1] = [1, 3]; // the error
//const [ num1 ] = [ 1, 3 ]; // expected

  return console.log(num1);
};
myTestFunction();

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

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

发布评论

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

评论(1

番薯 2025-01-22 14:57:44

由于 Prettier 删除了数组括号内的空格,因此可以修改 ESLint 以接受这一点。

可以从 .eslintrc.json 中删除该选项,例如:

    "array-bracket-spacing": [
      "warn",
      "always"
    ],

Since Prettier removes spacing inside array brackets, ESLint can be modified to accept this.

This option can be deleted from .eslintrc.json, for example:

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