@@ -143,7 +143,10 @@ export default createEslintRule<Options, MESSAGE_ID>({
143143 ruleName : id ,
144144 sourceCode,
145145 } )
146- let sortingNodes : SortImportsSortingNode [ ] = [ ]
146+ let sortingNodesWithoutPartitionId : Omit <
147+ SortImportsSortingNode ,
148+ 'partitionId'
149+ > [ ] = [ ]
147150
148151 let flatGroups = new Set ( options . groups . flat ( ) )
149152 let shouldRegroupSideEffectNodes = flatGroups . has ( 'side-effect' )
@@ -271,7 +274,18 @@ export default createEslintRule<Options, MESSAGE_ID>({
271274 name,
272275 } ) ?? 'unknown'
273276
274- sortingNodes . push ( {
277+ let hasMultipleImportDeclarations = isSortable (
278+ ( node as TSESTree . ImportDeclaration ) . specifiers ,
279+ )
280+ let size = rangeToDiff ( node , sourceCode )
281+ if (
282+ hasMultipleImportDeclarations &&
283+ options . maxLineLength &&
284+ size > options . maxLineLength
285+ ) {
286+ size = name . length + 10
287+ }
288+ sortingNodesWithoutPartitionId . push ( {
275289 isIgnored :
276290 ! options . sortSideEffects &&
277291 isSideEffect &&
@@ -280,17 +294,11 @@ export default createEslintRule<Options, MESSAGE_ID>({
280294 isEslintDisabled : isNodeEslintDisabled ( node , eslintDisabledLines ) ,
281295 dependencyNames : computeDependencyNames ( { sourceCode, node } ) ,
282296 dependencies : computeDependencies ( node ) ,
283- size : rangeToDiff ( node , sourceCode ) ,
284297 addSafetySemicolonWhenInline : true ,
285298 group,
299+ size,
286300 name,
287301 node,
288- ...( options . type === 'line-length' &&
289- options . maxLineLength && {
290- hasMultipleImportDeclarations : isSortable (
291- ( node as TSESTree . ImportDeclaration ) . specifiers ,
292- ) ,
293- } ) ,
294302 } )
295303 }
296304
@@ -299,15 +307,19 @@ export default createEslintRule<Options, MESSAGE_ID>({
299307 let contentSeparatedSortingNodeGroups : SortImportsSortingNode [ ] [ ] [ ] = [
300308 [ [ ] ] ,
301309 ]
302- for ( let sortingNode of sortingNodes ) {
310+ for ( let sortingNodeWithoutPartitionId of sortingNodesWithoutPartitionId ) {
303311 let lastGroupWithNoContentBetween =
304312 contentSeparatedSortingNodeGroups . at ( - 1 ) !
305313 let lastGroup = lastGroupWithNoContentBetween . at ( - 1 ) !
306314 let lastSortingNode = lastGroup . at ( - 1 )
307315
308316 if (
309317 lastSortingNode &&
310- hasContentBetweenNodes ( sourceCode , lastSortingNode , sortingNode )
318+ hasContentBetweenNodes (
319+ sourceCode ,
320+ lastSortingNode ,
321+ sortingNodeWithoutPartitionId ,
322+ )
311323 ) {
312324 lastGroup = [ ]
313325 lastGroupWithNoContentBetween = [ lastGroup ]
@@ -316,8 +328,8 @@ export default createEslintRule<Options, MESSAGE_ID>({
316328 )
317329 } else if (
318330 shouldPartition ( {
331+ sortingNode : sortingNodeWithoutPartitionId ,
319332 lastSortingNode,
320- sortingNode,
321333 sourceCode,
322334 options,
323335 } )
@@ -326,7 +338,10 @@ export default createEslintRule<Options, MESSAGE_ID>({
326338 lastGroupWithNoContentBetween . push ( lastGroup )
327339 }
328340
329- lastGroup . push ( sortingNode )
341+ lastGroup . push ( {
342+ ...sortingNodeWithoutPartitionId ,
343+ partitionId : lastGroupWithNoContentBetween . length ,
344+ } )
330345 }
331346
332347 for ( let sortingNodeGroups of contentSeparatedSortingNodeGroups ) {
@@ -517,8 +532,8 @@ export default createEslintRule<Options, MESSAGE_ID>({
517532
518533let hasContentBetweenNodes = (
519534 sourceCode : TSESLint . SourceCode ,
520- left : SortImportsSortingNode ,
521- right : SortImportsSortingNode ,
535+ left : Pick < SortImportsSortingNode , 'node' > ,
536+ right : Pick < SortImportsSortingNode , 'node' > ,
522537) : boolean =>
523538 sourceCode . getTokensBetween ( left . node , right . node , {
524539 includeComments : false ,
0 commit comments