-
Notifications
You must be signed in to change notification settings - Fork 139
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
Add the ability to override default position of "3rd party" imports #65
Conversation
@ayusharma Can you check it please? |
Hi @risenforces, Sorry for the delayed response. We are looking into it. 👍 |
I was about to add a feature request for this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks really good to me, I left a few comments.
Could you please add another snapshot test case for imports all being third-party?
I also changed the base branch to v3.x so we can release this in the upcoming version.
src/utils/get-sorted-nodes.ts
Outdated
const getMatchedGroup = (node: ImportDeclaration) => { | ||
for (const { group, regexp } of regexps) { | ||
const matched = node.source.value.match(regexp) !== null; | ||
if (matched) return group; | ||
} | ||
|
||
// nothing matched, move to REST | ||
return THIRD_PARTY_SPECIAL_WORD; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it might be better if we extract these kinds of functions and abstract them to a separate file + unit tests so they are more maintainable. What do you think?
src/utils/get-sorted-nodes.ts
Outdated
groups[matchedGroup].push(node); | ||
} | ||
|
||
type ImportOrLine = ImportDeclaration | ExpressionStatement; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please extract the types outside and import them on top.
Hey @risenforces, as we want to release the v3 very soon, I'll take over and apply the changes. |
Hi @risenforces , thanks for the PR ❤️ What do you mean by "REST" terminology in your PR ? |
I meant this. But as I remember, I replaced these things everywhere.. Did I forgot to do it in some place? |
Hi @risenforces, There were some breaking changes from the other PR. I took some freedom to modify some parts of the code and make it mergeable. I hope you would not mind my interfering. Thank you so much for the amazing contribution. 🎉 |
Hi @risenforces , Thank you so much for your PR. Please respond to the notification here. #118 |
The problem
I am the author of ESLint Kit.
There, I wanted to migrate from the buggy
import/sort
ESLint rule to something better and easier.And I found your library pretty good in this.
But my case is not as simple as the examples in the README - I need to get the following order:
I found that it's very hard to do in the current version of
sort-imports
plugin.The reason is that 3rd party modules are always moved to the top.
So, to get this behavior I have to write a really complicated RegExps.
After that, the prettier config may become very hard to extend and support.
The solution
I offer you the special word
<3RD_PARTY>
.It can be placed in the
importOrder
rule, just like the RegExps.<3RD_PARTY>
"collects" the imports that are not matching to any RegEx specified inimportOrder
.The bonuses