Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upNew Rule: ES6 sort-imports #435
Comments
This comment has been minimized.
This comment has been minimized.
|
I looked at this rule and considered enabling it for standard 6, because I personally sort my commonJS But the ES6 import rule seems super unintuitive to me, since it's enforcing sorting based on the type of ES6 import, before sorting alphabetically. And ES6 has 4 different ways to import. And no order seems particularly intuitive to me. |
feross
added
the
enhancement
label
Feb 23, 2016
This comment has been minimized.
This comment has been minimized.
|
Sidenote: It's irritating how complicated all these new language features are. Standards folks don't seem to appreciate simplicity as much as they ought to. Arrow functions have 5 different syntaxes for example... :( |
This comment has been minimized.
This comment has been minimized.
|
Yep, I hear you about the complexity. One thing import Zebra from 'animals'
import baboon from 'animals'It's configurable, but still. To some extent, the sheer complexity of a lot of ES6 makes linters like Standard even more important now. This one is a good example. We've made the language so complex that even though the general principle of a sorting order for imports is intuitive (general to specific, alphabetical) it's really hard to enforce without external tools. |
This comment has been minimized.
This comment has been minimized.
|
Can you check how many packages in the test suite fail when you enable your desired configuration of this rule? Still not sure if the rule is a good idea, but the numbers would be interesting to see. |
This comment has been minimized.
This comment has been minimized.
|
I get the same results if I run it where it cares about alphabetization vs not:
Packages that failed:
|
This comment has been minimized.
This comment has been minimized.
|
This would conflict with how I write code - I've found my brain doesn't automatically sort things alphabetically, but can easily recall if a word was long or not. // alphabetically
import Zebra from 'animals'
import ape from 'animals'
import baboon from 'animals'
import cockatoo from 'animals'
import hyena from 'animals'// length based
import cockatoo from 'animals'
import baboon from 'animals'
import hyena from 'animals'
import Zebra from 'animals'
import ape from 'animals'I'd rather this be left up to the discretion of the author, as I feel this wouldn't have any noticable benefits. |
This comment has been minimized.
This comment has been minimized.
|
I personally sort |
This comment has been minimized.
This comment has been minimized.
|
@dcousens As much as it weirds me out I'm totally all for taking the eslint default if it doesn't bother other people. This is why Standard is valuable |
This comment has been minimized.
This comment has been minimized.
ianstormtaylor
commented
Jun 6, 2016
|
I tend to use alphabetical because it's easy as an editor shortcut, but if the eslint defaults were enforced with the formatter on save, then this would be pretty much the same. Even though the order is slightly different than alphabetical (symbols wise), anything that's got a defined order seems fine. It's something you'll easily adjust to within a week or two of use. So +1! |
This comment has been minimized.
This comment has been minimized.
|
I try alpha-sorting based on the import location, but sometimes you sadly have circular dependencies which affect how you import stuff. :( Also, sometimes you have multiple long named imports: import {
AnotherEvenLongerImportFromFooBar,
createSomeFoobarThing,
SomeReallyReallyLongImportFromFooBar
} from './foobar' |
This comment has been minimized.
This comment has been minimized.
|
For me, alphabetical or length-based sorting is a waste of potential information. I try to encode some kind of rough meaning to the order of imports, based on their importance or how common they are over the project, e.g. in order:
This ordering means that for similar files in a project, the first few lines will remain roughly the same. Regardless, I think this proposal is a non-starter given that |
This comment has been minimized.
This comment has been minimized.
|
Closing for the reasons that @timoxley and @cesarandreu stated. |
benjohnson commentedFeb 23, 2016
Hi, I'm wondering if Standard feels like sorting ES6 imports are a good standard😸
Docs are here: http://eslint.org/docs/rules/sort-imports. This is one of those nice rules that doesn't affect ES5 code and so can be enabled without relying on new infrastructure. The downside is that this could potentially cause a lot of new linter errors in big ES6 codebases.
If people are interested in this, I can put a PR up in the sharable config.
Thanks for considering.