簡體   English   中英

ESLint 排序導入多行換行

[英]ESLint sort imports multiline wrap

我想使用sort-imports eslint 規則對導入語句進行排序,但是當我進行多行導入時,它會將每個導入的內容分成一個新行。

我的問題是我想使導入多行,但在指定寬度后換行。

//My use case
import { a, b, c, z, x, h } from x;

//How is linting
import {
  a
  , b
  , c
  , h
  , x
  , z
} from x;

//How I want to works
import {
  a, b, c
  , h, x, z
} from x;

在這種情況下只有 3 個導入我不介意導入的東西是否只是一行,但我的問題是當我有很多東西時(比如我正在導入 20 個 ramda 函數)並且我不想破壞每個導入function 換行。

這是我目前的 eslint + prettier 配置:

.eslintrc.json

{
  "root": true,
  "extends": [
    "plugin:vue/essential",
    "plugin:prettier/recommended",
    "eslint:recommended"
  ],
  "parserOptions": {
    "ecmaVersion": 2019,
    "sourceType": "module"
  },
  "env": {
    "es6": true
  },
  "rules": {
    "indent": ["error", 2],
    "arrow-parens": ["error", "always"],
    "sort-imports": [
      "error",
      {
        "ignoreDeclarationSort": true
      }
    ],
    "comma-style": ["error", "first"],
    "comma-spacing" :["error", {
      "after": true
    }]
  }
}

.prettierrc.json

{
  "arrowParens": "always",
  "bracketSpacing": true,
  "htmlWhitespaceSensitivity": "css",
  "insertPragma": false,
  "jsxBracketSameLine": false,
  "jsxSingleQuote": false,
  "printWidth": 80,
  "proseWrap": "preserve",
  "quoteProps": "as-needed",
  "requirePragma": true,
  "semi": true,
  "singleQuote": true,
  "tabWidth": 2,
  "trailingComma": "es5",
  "useTabs": false,
  "vueIndentScriptAndStyle": false
}

您應該在 eslint 之后加載plugin:prettier/recommended eslint:recommended以停止 eslint 重新格式化 prettier 處理的內容

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM