Skip to content

Commit 1ac83c9

Browse files
authored
fix(sort-imports): fix explicit fallback sort overriding side-effects
1 parent 8d4ad4f commit 1ac83c9

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

test/rules/sort-imports.test.ts

+25
Original file line numberDiff line numberDiff line change
@@ -1829,6 +1829,31 @@ describe(ruleName, () => {
18291829
valid: [],
18301830
},
18311831
)
1832+
1833+
ruleTester.run(
1834+
`${ruleName}(${type}): does not sort side-effects and side-effect-style even with fallback sort`,
1835+
rule,
1836+
{
1837+
valid: [
1838+
{
1839+
options: [
1840+
{
1841+
groups: ['side-effect', 'side-effect-style'],
1842+
fallbackSort: { type: 'alphabetical' },
1843+
},
1844+
],
1845+
code: dedent`
1846+
import 'b';
1847+
import 'a';
1848+
1849+
import 'b.css';
1850+
import 'a.css';
1851+
`,
1852+
},
1853+
],
1854+
invalid: [],
1855+
},
1856+
)
18321857
})
18331858

18341859
ruleTester.run(

utils/compare.ts

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ export let compare = <T extends SortingNode>({
3030
a,
3131
b,
3232
}: CompareParameters<T>): number => {
33+
if (options.type === 'unsorted') {
34+
return 0
35+
}
36+
3337
let finalNodeValueGetter = nodeValueGetter ?? ((node: T) => node.name)
3438
let compareValue = computeCompareValue({
3539
nodeValueGetter: finalNodeValueGetter,

0 commit comments

Comments
 (0)