ESLINT:如何用Eslint-Plugin-Import对Import成员进行排序?

发布于 2025-02-10 09:27:49 字数 1007 浏览 2 评论 0 原文

我正在尝试添加 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'

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

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

发布评论

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

评论(1

本王不退位尔等都是臣 2025-02-17 09:27:49

我最终我自己找到了解决方案:尽管 MextryntaxSortorder 是强制性的,并且仅接受数组,但实际上,您可以通过简单地使用 bighoredeclarationsort 规则来忽略此规则,但设置为 true

因此,要使 sort/import 与多个导入行的字母顺序订单一起工作,只需在您的规则块中添加:

'sort-imports': [
  'error',
  {
    ignoreDeclarationSort: true,
  },
],

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 the ignoreDeclarationSort rule, set to true.

So to make sort/import work with an alphabetical order of multiple import lines, simply add in your rule block:

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