@@ -677,7 +677,7 @@ function removeNewLineAfterImport(context, currentImport, previousImport) {
677
677
return undefined ;
678
678
}
679
679
680
- function makeNewlinesBetweenReport ( context , imported , newlinesBetweenImports , newlinesBetweenTypeOnlyImports , distinctGroup , isSortingTypesGroup ) {
680
+ function makeNewlinesBetweenReport ( context , imported , newlinesBetweenImports , newlinesBetweenTypeOnlyImports_ , distinctGroup , isSortingTypesGroup , isConsolidatingSpaceBetweenImports ) {
681
681
const getNumberOfEmptyLinesBetween = ( currentImport , previousImport ) => {
682
682
const linesBetweenImports = getSourceCode ( context ) . lines . slice (
683
683
previousImport . node . loc . end . line ,
@@ -703,12 +703,24 @@ function makeNewlinesBetweenReport(context, imported, newlinesBetweenImports, ne
703
703
const isTypeOnlyImport = currentImport . node . importKind === 'type' ;
704
704
const isPreviousImportTypeOnlyImport = previousImport . node . importKind === 'type' ;
705
705
706
- const isNormalImportFollowingTypeOnlyImportAndRelevant =
707
- ! isTypeOnlyImport && isPreviousImportTypeOnlyImport && isSortingTypesGroup ;
706
+ const isNormalImportNextToTypeOnlyImportAndRelevant =
707
+ isTypeOnlyImport !== isPreviousImportTypeOnlyImport && isSortingTypesGroup ;
708
708
709
709
const isTypeOnlyImportAndRelevant =
710
710
isTypeOnlyImport && isSortingTypesGroup ;
711
711
712
+ // In the special case where newlinesBetweenTypeOnlyImports and
713
+ // consolidateIslands want the opposite thing, consolidateIslands wins
714
+ const newlinesBetweenTypeOnlyImports =
715
+ newlinesBetweenTypeOnlyImports_ === 'never' &&
716
+ isConsolidatingSpaceBetweenImports &&
717
+ isSortingTypesGroup &&
718
+ ( isNormalImportNextToTypeOnlyImportAndRelevant ||
719
+ previousImport . isMultiline ||
720
+ currentImport . isMultiline )
721
+ ? 'always-and-inside-groups'
722
+ : newlinesBetweenTypeOnlyImports_ ;
723
+
712
724
const isNotIgnored =
713
725
( isTypeOnlyImportAndRelevant &&
714
726
newlinesBetweenTypeOnlyImports !== 'ignore' ) ||
@@ -731,7 +743,7 @@ function makeNewlinesBetweenReport(context, imported, newlinesBetweenImports, ne
731
743
732
744
const shouldAssertNoNewlineBetweenGroup =
733
745
! isSortingTypesGroup ||
734
- ! isNormalImportFollowingTypeOnlyImportAndRelevant ||
746
+ ! isNormalImportNextToTypeOnlyImportAndRelevant ||
735
747
newlinesBetweenTypeOnlyImports === 'never' ;
736
748
737
749
if ( shouldAssertNewlineBetweenGroups ) {
@@ -844,6 +856,12 @@ module.exports = {
844
856
'never' ,
845
857
] ,
846
858
} ,
859
+ consolidateIslands : {
860
+ enum : [
861
+ 'inside-groups' ,
862
+ 'never' ,
863
+ ] ,
864
+ } ,
847
865
sortTypesGroup : {
848
866
type : 'boolean' ,
849
867
default : false ,
@@ -906,6 +924,7 @@ module.exports = {
906
924
const newlinesBetweenTypeOnlyImports = options [ 'newlines-between-types' ] || newlinesBetweenImports ;
907
925
const pathGroupsExcludedImportTypes = new Set ( options . pathGroupsExcludedImportTypes || [ 'builtin' , 'external' , 'object' ] ) ;
908
926
const sortTypesGroup = options . sortTypesGroup ;
927
+ const consolidateIslands = options . consolidateIslands || 'never' ;
909
928
910
929
const named = {
911
930
types : 'mixed' ,
@@ -1168,7 +1187,17 @@ module.exports = {
1168
1187
'Program:exit' ( ) {
1169
1188
importMap . forEach ( ( imported ) => {
1170
1189
if ( newlinesBetweenImports !== 'ignore' || newlinesBetweenTypeOnlyImports !== 'ignore' ) {
1171
- makeNewlinesBetweenReport ( context , imported , newlinesBetweenImports , newlinesBetweenTypeOnlyImports , distinctGroup , isSortingTypesGroup ) ;
1190
+ makeNewlinesBetweenReport (
1191
+ context ,
1192
+ imported ,
1193
+ newlinesBetweenImports ,
1194
+ newlinesBetweenTypeOnlyImports ,
1195
+ distinctGroup ,
1196
+ isSortingTypesGroup ,
1197
+ consolidateIslands === 'inside-groups' &&
1198
+ ( newlinesBetweenImports === 'always-and-inside-groups' ||
1199
+ newlinesBetweenTypeOnlyImports === 'always-and-inside-groups' )
1200
+ ) ;
1172
1201
}
1173
1202
1174
1203
if ( alphabetize . order !== 'ignore' ) {
0 commit comments