reactjs 更漂亮的下一个(2.6.0)+导入订单插件@trivago/更漂亮的插件排序导入错误忽略未知选项{importOrderSeparation:真}

kognpnkq  于 2023-02-08  发布在  React
关注(0)|答案(3)|浏览(75)

我正在从Prettier 2.0.5的稳定版本移动到Prettier 2.6.0的下一个版本,这与稳定版本不同。并且在@trivago/prettier-plugin-sort-imports插件上遇到了问题,该插件可以与prettier 2.0.5一起使用,但不能与2.6.0一起使用。因为只有2.6.0版本支持此参数https://prettier.io/docs/en/next/options.html#single-attribute-per-line。我已经更新了@trivago/prettier-plugin-sort-imports插件。根据https://github.com/trivago/prettier-plugin-sort-imports/blob/master/docs/MIGRATION.md导入到最新版本并迁移到3x
package.json

"scripts": {
"prettier-check": "prettier --check 'src/**/*.{css,scss,json,html,md,yml,yaml,js,jsx,ts,tsx}'",
},
"devDependencies": {
...
"@trivago/prettier-plugin-sort-imports": "^3.2.0",
"eslint-config-prettier": "^8.4.0",
"eslint-plugin-prettier": "^4.0.0",
"prettier": "prettier/prettier",
...
},
"eslintConfig": {
    "extends": [
      "react-app",
      "plugin:prettier/recommended",
      "plugin:cypress/recommended"
    ],
    "ignorePatterns": [
      "node_modules",
      "build",
      "openapi-client",
      "cypress/integration/examples",
      "!.storybook",
      ".github",
      ".ci",
      ".git"
    ],
    "rules": {
      "react-hooks/exhaustive-deps": 0,
      "react/self-closing-comp": [
        "error",
        {
          "component": true,
          "html": true
        }
      ]
    }
  }

.漂亮

{
  "singleQuote": true,
  "semi": true,
  "tabWidth": 4,
  "printWidth": 100,
  "quoteProps": "consistent",
  "trailingComma": "es5",
  "importOrder": [
    "^@(assets|components|context|hooks|lib|pages|routes|services|styles|ui|utils)/?(.*)$",
    "^[./]"
  ],
  "importOrderSeparation": true,
  "importOrderParserPlugins": [
    "jsx",
    "typescript"
  ],
  "overrides": [
    {
      "files": [
        "*.js",
        "*.jsx",
        "*.ts",
        "*.tsx",
        "*.json",
        "*.yml",
        "*.yaml",
        "*.md"
      ],
      "options": {
        "tabWidth": 2,
        "singleAttributePerLine": true
      }
    }
  ]
}

控制台说:

[warn] Ignored unknown option { importOrder: ["^@(assets|components|context|hooks|lib|pages|routes|services|styles|ui|utils)/?(.*)$", "^[./]"] }.
[warn] Ignored unknown option { importOrderSeparation: true }.
[warn] Ignored unknown option { importOrderParserPlugins: ["jsx", "typescript"] }.

漂亮的看不出这个插件似乎是.任何帮助是高度赞赏

cetgtptt

cetgtptt1#

我也有同样的问题,漂亮的看不到这些东西。我只是使用排序导入插件在vscode.idk关于漂亮的集成一个虽然。

qq24tv8q

qq24tv8q2#

您需要在您的Prettier配置上加载插件:

{
  ...
  plugins: ['@trivago/prettier-plugin-sort-imports'],
}

有关参考,请参见Prettier文档中的使用插件部分。

lb3vh1jj

lb3vh1jj3#

您只需要在devDependencies中安装更漂亮的

yarn add --dev prettier

相关问题