Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add sort rule for named imports #1732

Closed
josh18 opened this issue Apr 19, 2020 · 7 comments
Closed

Add sort rule for named imports #1732

josh18 opened this issue Apr 19, 2020 · 7 comments

Comments

@josh18
Copy link

josh18 commented Apr 19, 2020

import {b, a, c} from 'foo.js';

✔️

import {a, b, c} from 'foo.js';

Not sure if this should be a new rule or an option under import/order. Both tslint and eslint have a option for this in their import order rules.

I can attempt to make a PR if we think this is a good idea.

@ljharb
Copy link
Member

ljharb commented Apr 19, 2020

Duplicate of #1577.

@ljharb ljharb closed this as completed Apr 19, 2020
@josh18
Copy link
Author

josh18 commented Apr 19, 2020

@ljharb I think that might be a different issue. That issue seems to be about the order of import line based on import names instead of path. This issue is about the order of named imports inside an import line.

@golopot
Copy link
Contributor

golopot commented Apr 19, 2020

I think your use case is covered by https://eslint.org/docs/rules/sort-imports

@josh18
Copy link
Author

josh18 commented Apr 19, 2020

Does that work alongside import/order? I thought they might fight

@ljharb
Copy link
Member

ljharb commented Apr 19, 2020

I believe you can use it with ignoreDeclarationSort and it should work

@josh18
Copy link
Author

josh18 commented Apr 19, 2020

👍 Can confirm it does work. Thanks!

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

pastelmind added a commit to pastelmind/d2calc that referenced this issue Aug 14, 2020
The "import/order" rule does NOT enforce in-member sorting; this rule is
provided separately by ESLint, and has been modified to work with
eslint-plugin-import. For more information, see:
import-js/eslint-plugin-import#1732
pastelmind added a commit to pastelmind/ruliweb-hots that referenced this issue Aug 14, 2020
Add ESLint rules for linting imports, based on my own preferences.

- Sort imports using import/order and sort-imports
  (both must be used to sort import declarations and imported members;
  see import-js/eslint-plugin-import#1732 )
- Imports must be at top of file
- Add exactly 1 newline after import
- Other basic sanity checks not covered by TypeScript
@teppeis
Copy link

teppeis commented Feb 11, 2021

duplicate of #163

# for free to join this conversation on GitHub. Already have an account? # to comment
Development

No branches or pull requests

4 participants