简体   繁体   中英

Eslint custom import order

Is it possible to make Eslint rule that supports custom import order

I want to trigger Eslint warning or error upon having following invalid order.

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. 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. Might be worth giving a try first :)

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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