@@ -626,14 +626,21 @@ function detectSortingWorker(importGroups: ImportDeclaration[][], preferences: U
626
626
const collateCaseSensitive = getOrganizeImportsComparer ( preferences , /*ignoreCase*/ false ) ;
627
627
const collateCaseInsensitive = getOrganizeImportsComparer ( preferences , /*ignoreCase*/ true ) ;
628
628
let sortState = SortKind . Both ;
629
+ let seenUnsortedGroup = false ;
629
630
for ( const importGroup of importGroups ) {
630
631
// Check module specifiers
631
632
if ( importGroup . length > 1 ) {
632
- sortState & = detectSortCaseSensitivity (
633
+ const moduleSpecifierSort = detectSortCaseSensitivity (
633
634
importGroup ,
634
635
i => tryCast ( i . moduleSpecifier , isStringLiteral ) ?. text ?? "" ,
635
636
collateCaseSensitive ,
636
637
collateCaseInsensitive ) ;
638
+ if ( moduleSpecifierSort ) {
639
+ // Don't let a single unsorted group of module specifiers make the whole algorithm detect unsorted.
640
+ // If other things are sorted consistently, that's a stronger indicator than unsorted module specifiers.
641
+ sortState &= moduleSpecifierSort ;
642
+ seenUnsortedGroup = true ;
643
+ }
637
644
if ( ! sortState ) {
638
645
return sortState ;
639
646
}
@@ -644,7 +651,13 @@ function detectSortingWorker(importGroups: ImportDeclaration[][], preferences: U
644
651
importGroup ,
645
652
i => tryCast ( i . importClause ?. namedBindings , isNamedImports ) ?. elements . length ! > 1 ) ;
646
653
if ( declarationWithNamedImports ) {
647
- sortState &= detectImportSpecifierSorting ( ( declarationWithNamedImports . importClause ! . namedBindings as NamedImports ) . elements , preferences ) ;
654
+ const namedImportSort = detectImportSpecifierSorting ( ( declarationWithNamedImports . importClause ! . namedBindings as NamedImports ) . elements , preferences ) ;
655
+ if ( namedImportSort ) {
656
+ // Don't let a single unsorted group of named imports make the whole algorithm detect unsorted.
657
+ // If other things are sorted consistently, that's a stronger indicator than unsorted named imports.
658
+ sortState &= namedImportSort ;
659
+ seenUnsortedGroup = true ;
660
+ }
648
661
if ( ! sortState ) {
649
662
return sortState ;
650
663
}
@@ -657,7 +670,7 @@ function detectSortingWorker(importGroups: ImportDeclaration[][], preferences: U
657
670
return sortState ;
658
671
}
659
672
}
660
- return sortState ;
673
+ return seenUnsortedGroup ? SortKind . None : sortState ;
661
674
}
662
675
663
676
/** @internal */
0 commit comments