我正在尝试添加 sort-member 。
但是,由于我已经在使用 eslint-plugin-import ,存在冲突,因为这些规则中的每一个都试图根据不同的参数对导入进行排序:
-
sort-member
按顺序 [“无”,“ all”,“ astory”多个多个“,”单人”
,取决于从一个模块 eSlint-plugin-import中有多少导入
- ,按顺序
[“ hildin”,“外部”,“,” parent”,“兄弟姐妹”,“索引”]
,取决于导入的
类型>会员YNTAXSORTORDER 规则),或是否存在类似于成员的功能内置 eslint-plugin-import
?
我要做的就是要有一个错误:
import { b, a, c } from 'foo.js'
并将其自动修复到:
import { a, b, c } from 'foo.js'
I'm trying to add the sorting of import members such as this rule in sort-member.
However, since I'm already using eslint-plugin-import, there is a conflict because each of these rules is trying to sort imports based on different parameters:
sort-member
sorts following the order ["none", "all", "multiple", "single"]
, depending on how many imports there is from one module
eslint-plugin-import
sorts following the order ["builtin", "external", "parent", "sibling", "index"]
, depending on the type of import
Is there a way to only use the member sort of sort-member
(== ignore the memberSyntaxSortOrder
rule), or is there a feature similar to memberSort built in eslint-plugin-import
?
All I'm trying to do is to have an error for:
import { b, a, c } from 'foo.js'
And have it automatically fixed to:
import { a, b, c } from 'foo.js'
发布评论
评论(1)
我最终我自己找到了解决方案:尽管
MextryntaxSortorder
是强制性的,并且仅接受数组,但实际上,您可以通过简单地使用bighoredeclarationsort
规则来忽略此规则,但设置为true
。因此,要使
sort/import
与多个导入行的字母顺序订单一起工作,只需在您的规则块中添加:I ended up finding the solution by myself: despite
memberSyntaxSortOrder
being mandatory and only accepting an array, you can actually ignore this rule by simply using theignoreDeclarationSort
rule, set totrue
.So to make
sort/import
work with an alphabetical order of multiple import lines, simply add in your rule block: