-
-
Notifications
You must be signed in to change notification settings - Fork 41
feat: add option followTsOrganizeImports
for order
rule
#287
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
base: master
Are you sure you want to change the base?
Changes from 11 commits
77e6cd3
12c17a9
31854ca
dd1f012
7b42ee0
2790318
9a0edb7
e47f0ad
f2b6011
605a9f8
708b5cc
3ea0b5b
6a1397f
213eb21
923ffb4
48fc805
3eaeedc
a80faf7
e4ff449
f5ab8e8
e9d728b
ab4ec1d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"eslint-plugin-import-x": minor | ||
--- | ||
|
||
feat: add option `followTsOrganizeImports` for `order` rule | ||
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -53,6 +53,15 @@ const defaultGroups = [ | |||||||||||||||||||||||||||||||||
'index', | ||||||||||||||||||||||||||||||||||
] as const | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
const defaultGroupsTsOrganizeImports = [ | ||||||||||||||||||||||||||||||||||
'private', | ||||||||||||||||||||||||||||||||||
'external', | ||||||||||||||||||||||||||||||||||
'builtin', | ||||||||||||||||||||||||||||||||||
'parent', | ||||||||||||||||||||||||||||||||||
'index', | ||||||||||||||||||||||||||||||||||
'sibling', | ||||||||||||||||||||||||||||||||||
] as const | ||||||||||||||||||||||||||||||||||
Comment on lines
+56
to
+63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The order in
Suggested change
Spotted by Diamond There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Shinigami92 Can you double check? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll check, but my gut feeling tells me either we missed a import-statement case, or it works correctly right now already and the AI is hallucinating There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AH! so an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you want to get a test case for separated There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Wouldn't the group order be different?
Thta's would be appreciated. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
No, why should it?
Added You should take a case like I added here, and copy-paste it into your VSCode and then hit CTRL+SHIFT+P and run organize imports, then you can experiment yourself a bit with it 🙂 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Finally we got failing test cases, I don't know whether it's expected to you. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Didn't the default order
I also use this command a lot when I develop projects not using this plugin nor |
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
// REPORTING AND FIXING | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
function reverse(array: ImportEntryWithRank[]): ImportEntryWithRank[] { | ||||||||||||||||||||||||||||||||||
|
@@ -824,6 +833,7 @@ function getRequireBlock(node: TSESTree.Node) { | |||||||||||||||||||||||||||||||||
const types: ImportType[] = [ | ||||||||||||||||||||||||||||||||||
'builtin', | ||||||||||||||||||||||||||||||||||
'external', | ||||||||||||||||||||||||||||||||||
'private', | ||||||||||||||||||||||||||||||||||
Shinigami92 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||
'internal', | ||||||||||||||||||||||||||||||||||
'unknown', | ||||||||||||||||||||||||||||||||||
'parent', | ||||||||||||||||||||||||||||||||||
|
@@ -1149,6 +1159,7 @@ export interface Options { | |||||||||||||||||||||||||||||||||
pathGroups?: PathGroup[] | ||||||||||||||||||||||||||||||||||
sortTypesGroup?: boolean | ||||||||||||||||||||||||||||||||||
warnOnUnassignedImports?: boolean | ||||||||||||||||||||||||||||||||||
followTsOrganizeImports?: boolean | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
type MessageId = | ||||||||||||||||||||||||||||||||||
|
@@ -1271,6 +1282,11 @@ export default createRule<[Options?], MessageId>({ | |||||||||||||||||||||||||||||||||
type: 'boolean', | ||||||||||||||||||||||||||||||||||
default: false, | ||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||
followTsOrganizeImports: { | ||||||||||||||||||||||||||||||||||
type: 'boolean', | ||||||||||||||||||||||||||||||||||
// TODO: switch default to true in next major | ||||||||||||||||||||||||||||||||||
default: false, | ||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||
additionalProperties: false, | ||||||||||||||||||||||||||||||||||
dependencies: { | ||||||||||||||||||||||||||||||||||
|
@@ -1388,8 +1404,19 @@ export default createRule<[Options?], MessageId>({ | |||||||||||||||||||||||||||||||||
const { pathGroups, maxPosition } = convertPathGroupsForRanks( | ||||||||||||||||||||||||||||||||||
options.pathGroups || [], | ||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||
if (options.followTsOrganizeImports && options.groups) { | ||||||||||||||||||||||||||||||||||
// TODO: remove warning when default of followTsOrganizeImports switched to true | ||||||||||||||||||||||||||||||||||
// because then the user potentially knows what they are doing | ||||||||||||||||||||||||||||||||||
// and the warning is not needed anymore | ||||||||||||||||||||||||||||||||||
console.warn( | ||||||||||||||||||||||||||||||||||
Shinigami92 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||
'If you have defined your own `groups` in `order`, `followTsOrganizeImports: true` has no effect.', | ||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
Shinigami92 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||
const { groups, omittedTypes } = convertGroupsToRanks( | ||||||||||||||||||||||||||||||||||
options.groups || defaultGroups, | ||||||||||||||||||||||||||||||||||
options.groups || | ||||||||||||||||||||||||||||||||||
(options.followTsOrganizeImports | ||||||||||||||||||||||||||||||||||
? defaultGroupsTsOrganizeImports | ||||||||||||||||||||||||||||||||||
: defaultGroups), | ||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||
ranks = { | ||||||||||||||||||||||||||||||||||
groups, | ||||||||||||||||||||||||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.