-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Use same alphabetize props as ESLint sort-imports #1670
Comments
|
It does alphabetize, but the ordering is based on the That's why I was suggesting similar functionality to what's in the It also optionally has the ability to sort single-line imports as well so this would get alphabetically sorted in the deconstruction as well: import { one, two } from './numbers' |
Ah, thanks for clarifying. I don't see value in sorting by the identifier names - especially since you can have multiples. What would you sort by in this:? import { a as z, b, d }, c from 'e'; |
In your example, I'd keep // Sorted deconstruction
import c, { a as z, b, d } from 'e'; |
Right, but then you're sorting by the exported names, but the importing default name. If the name the importer chooses is the primary bit, then i'd expect |
That is a really good point! My main concern is being able to quickly find things. If everything's alphabetical, it's in the same order each time no matter the component. It also needs to be something I could reasonably fix without I have no opinion on sorting by Are we in agreement on the other parts or is there more contention? |
What's the use case tho? Like, what are you hoping to quickly find that you're not using grep ("find" in your editor), or "go to definition" jumping from a usage site? |
Alphabetizing anything where order doesn't matter makes it easier to skim unimportant parts of PRs. There's also improved compression ratio because there are more situations where we have repeat code. And with code-consistency, it becomes easier to find and replace. My main thing for me is having similar functionality to the official ESLint rule, but separating Would it help if I provided the PR myself? I completely understand if that's the determining factor here. |
I appreciate that, and providing the PR certainly helps! While I strongly agree with the sentiment in making it easier to skip unimportant parts of PRs (reducing diff churn, eg), to me it's more important that the lint rule make sense on its own. Just sorting things for the sake of sorting them doesn't seem particularly compelling to me. |
Just playing devil's advocate here, but couldn't you apply your rationale about "sorting things just for the sake of sorting" to the entire idea of grouping and sorting imports in general? If I'm looking to modify an existing import or looking over a PR that made such a modification, it seems just as nice to be able to find an import group as it is to find a imported member/identifier within a single statement. There are rules to order object keys, vars, and as was pointed out here, rules in tslint or other eslint plugins to order the imported members. And this plugin orders and groups imports, so why would you not order the identifiers within? As for your example, I also don't particularly care about which way you choose to order, as long as it's consistent. |
I'd also like to have the imports inside the group sorted. |
just two cents from TypeScript world, in TSLint there was a rule ordered-imports and there was an option named-imports-order: "lowercase-first". As soon as TSLint is dead and everyone somehow migrates to eslint it would be nice to have similar option for compatibility. |
Same! |
What I want:
I have the following config:
example:
This makes It does not complain if I set |
@ThaJay : this is pretty close to what I want. Fortunately in my case, the rules do work without conflict, but I lose auto fixing for the Basically, I'm trying to emulate Python's isort. But isort has an easier time because you cannot combine default/namespace/named imports into one statement. It's all or nothing. My platonic ideal:
First broken up by chunks (builtin, external, internal, relative). Then within that, grouped into import syntax. Then alphabetized. Currently, this plugin can automate all but the last step. If I turn on alphabetize, I get this:
And that to be looks a lot worse. Moreover, I then need to disable So currently I can either: fully automate but lose grouping syntax, or almost fully automate but need to manually group syntax. |
Compared to my previous config posted here, if I add
|
Came here looking for the ability to sort import within a single import: Any luck on the PR @Sawtaytoes or was there any suggested workarounds for this ? |
No luck on my end. Someone will need to patch it. |
I have the following setup with "sort-imports" and "import/order" and they seem to be working well together: {
"import/order": [
"error",
{
"alphabetize": {
"caseInsensitive": true,
"order": "asc"
},
"groups": [
["builtin", "external", "object", "type"],
["internal", "parent", "sibling", "index"]
],
"newlines-between": "always"
}
],
"sort-imports": [
"error",
{
"allowSeparatedGroups": true,
"ignoreCase": true,
"ignoreDeclarationSort": true,
"ignoreMemberSort": false,
"memberSyntaxSortOrder": ["none", "all", "multiple", "single"]
}
]
} |
@KevinNovak Thanks a lot - that got it working for me. I didn't notice the |
I encourage the development of this new feature. I believe it is necessary. I don't think it's right to have to use two plugins to achieve it. |
Loads has changed in the meantime. So I thought it may be useful for someone to share my current config. There's good grouping and 'import/first': 'error',
'import/newline-after-import': 'error',
'simple-import-sort/exports': 'error',
'simple-import-sort/imports': [
'error',
{
groups: [
['^\\u0000'],
['(?=^.)react(?!.)', '(?=^.)react(?!.).*\\u0000$', '(?=^.)react-native(?!.)', '(?=^.)react-native.*\\u0000$'],
['^node:', '^node:.*\\u0000$'],
['^react', '^@?\\w', '^react.*\\u0000$', '^@?\\w.*\\u0000$'],
['(?<!\\u0000)$', '(?<=\\u0000)$'],
['^\\.', '^\\..*\\u0000$'],
],
},
], |
ESLint's native
sort-imports
does the sorting I want, but doesn't care about the grouping of imports. On the other hand,import/order
gives me the ordering I want, but not the powerful alphabetization sort fromsort-imports
.For
sort-imports
, this is the config I use:I'd like to do something similar with
import/order
:I would like this functionality because I'm grouping them differently than the default:
Here's an example I'd expect to see:
The text was updated successfully, but these errors were encountered: