简体   繁体   English

Eslint 自定义导入顺序

[英]Eslint custom import order

Is it possible to make Eslint rule that supports custom import order是否可以制作支持自定义导入顺序的 Eslint 规则

I want to trigger Eslint warning or error upon having following invalid order.我想在遵循无效订单时触发 Eslint 警告或错误。

ie IE

Invalid:无效的:

import utilsMicky from 'utils/micky';
import containersMicky from'containers/micky';
import componentsMicky from 'components/micky';

Valid:有效的:

import containersMicky from 'containers/micky';
import utilsMicky from 'utils/micky';
import componentsMicky from 'components/micky';

Apparently reading from the discussion there you probably would have to create your own ESLint rule for that kind of specific requirement.显然,从那里的讨论中阅读您可能必须为这种特定要求创建自己的 ESLint 规则。 Their own requirement is to prevent people from importing from a nested path, as you can see in the unit-test .他们自己的要求是防止人们从嵌套路径导入,正如您在单元测试中看到的那样。 Based on this, you could potentially implement a rule enforcing this specific import order of yours.基于此,您可能会实施一个规则来强制执行您的此特定导入顺序。

eslint-plugin-import also has an existing order related rule , but I haven't tested it so I'm not quite sure it fits for your requirement. eslint-plugin-import也有一个现有的与订单相关的规则,但我还没有测试过,所以我不太确定它是否符合您的要求。 Might be worth giving a try first :)可能值得先试一试:)

Hope this helps!希望这可以帮助!

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

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