feat: isolate side effect imports
This commit is contained in:
Generated
+5
-1627
File diff suppressed because it is too large
Load Diff
+3
-2
@@ -18,7 +18,8 @@
|
|||||||
"url": "https://github.com/mattuylee/vsc-sort-import/issues"
|
"url": "https://github.com/mattuylee/vsc-sort-import/issues"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"vscode": "^1.0.0"
|
"vscode": "^1.0.0",
|
||||||
|
"node": "14"
|
||||||
},
|
},
|
||||||
"categories": [
|
"categories": [
|
||||||
"Other"
|
"Other"
|
||||||
@@ -46,7 +47,7 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/glob": "^7.1.3",
|
"@types/glob": "^7.1.3",
|
||||||
"@types/mocha": "^8.0.4",
|
"@types/mocha": "^8.0.4",
|
||||||
"@types/node": "^12.11.7",
|
"@types/node": "^14.0.0",
|
||||||
"@types/vscode": "^1.0.0",
|
"@types/vscode": "^1.0.0",
|
||||||
"glob": "^7.1.6",
|
"glob": "^7.1.6",
|
||||||
"mocha": "^8.2.1",
|
"mocha": "^8.2.1",
|
||||||
|
|||||||
+16
-1
@@ -25,6 +25,11 @@ export default function (styleApi: IStyleAPI): IStyleItem[] {
|
|||||||
return i.moduleName.startsWith('@/');
|
return i.moduleName.startsWith('@/');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// eg: import 'foobar'
|
||||||
|
const isSideEffect = (i: IImport) => {
|
||||||
|
return !Boolean(i.defaultMember) && !Boolean(i.namespaceMember) && !Boolean(i.namedMembers[0]?.name)
|
||||||
|
}
|
||||||
|
|
||||||
// comparator function which place non-alphanumeric first
|
// comparator function which place non-alphanumeric first
|
||||||
const natural: IComparatorFunction = (a: string, b: string) => {
|
const natural: IComparatorFunction = (a: string, b: string) => {
|
||||||
if (a === b) {
|
if (a === b) {
|
||||||
@@ -38,7 +43,8 @@ export default function (styleApi: IStyleAPI): IStyleItem[] {
|
|||||||
return sa ? 1 : -1;
|
return sa ? 1 : -1;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// sort: use member primarily, if member is not avaliable, use module name
|
|
||||||
|
// sort: use member primarily, if member is not available, use module name
|
||||||
const memberOrModule: (c: IComparatorFunction) => ISorterFunction = (
|
const memberOrModule: (c: IComparatorFunction) => ISorterFunction = (
|
||||||
comparator: IComparatorFunction
|
comparator: IComparatorFunction
|
||||||
) => {
|
) => {
|
||||||
@@ -88,6 +94,15 @@ export default function (styleApi: IStyleAPI): IStyleItem[] {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
// side effect import
|
||||||
|
{
|
||||||
|
match: isSideEffect,
|
||||||
|
sort: memberOrModule(natural),
|
||||||
|
sortNamedMembers: name(natural),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
separator: true,
|
||||||
|
},
|
||||||
// built-in module, has member
|
// built-in module, has member
|
||||||
{
|
{
|
||||||
match: isNodeModule,
|
match: isNodeModule,
|
||||||
|
|||||||
Reference in New Issue
Block a user