简体   繁体   English

ESLint 排序导入多行换行

[英]ESLint sort imports multiline wrap

I'd like to use the sort-imports eslint rule for sorting imports statements, but when I hace a multiline import it breaks every imported thing into a new line.我想使用sort-imports eslint 规则对导入语句进行排序,但是当我进行多行导入时,它会将每个导入的内容分成一个新行。

My problem is that I want to make imports multiline, but wrapping after an specified width.我的问题是我想使导入多行,但在指定宽度后换行。

//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;

In this case with just 3 imports I dont mind if the imported things are just in one line, but my problem is when i have a lot of thing (like if I'm importing 20 ramda functions) and I dont want to break every imported function into a new line.在这种情况下只有 3 个导入我不介意导入的东西是否只是一行,但我的问题是当我有很多东西时(比如我正在导入 20 个 ramda 函数)并且我不想破坏每个导入function 换行。

This is my currently eslint + prettier config:这是我目前的 eslint + prettier 配置:

.eslintrc.json .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 .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
}

You should load plugin:prettier/recommended after eslint:recommended to stop eslint reformatting stuff that prettier takes care off您应该在 eslint 之后加载plugin:prettier/recommended eslint:recommended以停止 eslint 重新格式化 prettier 处理的内容

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM