Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Lint imports #30

Closed
MartinRosenberg opened this issue Oct 14, 2019 · 5 comments
Closed

Lint imports #30

MartinRosenberg opened this issue Oct 14, 2019 · 5 comments
Labels

Comments

@MartinRosenberg
Copy link
Collaborator

@taniarascia's preference is to sort and group imports as follows:

  1. Libraries
  2. Local imports (absolute, not relative)
  3. CSS/side-effect imports

With each group alphabetized by from, named imports sorted within their lines, and spaces between the groups.

Right now, there are multiple rule/plugin/preset options for linting imports, none of them quite does the trick right now, they all conflict with each other, and none of them individually is really a desired compromise. However, the hopefully-upcoming merging of import-js/eslint-plugin-import#1360 should make import/order a perfect candidate.

@MartinRosenberg
Copy link
Collaborator Author

Current possible compromises include:

  1. Use import/order from eslint-plugin-import
    • No alphabetization within groups
    • No alphabetization within lines
  2. Use eslint-plugin-simple-import-sort
    • CSS imports first
    • Local imports must be relative, or get mixed in with libraries
  3. Use sort-imports
    • Grouped only by what's being imported, not from where

@taniarascia
Copy link
Owner

I would say option 1 is the best of the three. I wonder if you can chain import/order and sort-imports, but that seems like overkill.

@MartinRosenberg
Copy link
Collaborator Author

You can chain... but only by running eslint twice.

@MartinRosenberg
Copy link
Collaborator Author

Ah, I missed something about using import/order: It doesn't move side-effecting (e.g. css) imports at all, because... y'know, side effects. So you still have to order those manually. But you should probably do that anyway, because... y'know, side effects.

@taniarascia
Copy link
Owner

Fixed in #29

Will revisit after import/order has an update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants