Skip to content

Commit

Permalink
fix(sort-imports): fix explicit fallback sort overriding side-effects
Browse files Browse the repository at this point in the history
  • Loading branch information
hugop95 authored Mar 9, 2025
1 parent 8d4ad4f commit 1ac83c9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/rules/sort-imports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1829,6 +1829,31 @@ describe(ruleName, () => {
valid: [],
},
)

ruleTester.run(
`${ruleName}(${type}): does not sort side-effects and side-effect-style even with fallback sort`,
rule,
{
valid: [
{
options: [
{
groups: ['side-effect', 'side-effect-style'],
fallbackSort: { type: 'alphabetical' },
},
],
code: dedent`
import 'b';
import 'a';
import 'b.css';
import 'a.css';
`,
},
],
invalid: [],
},
)
})

ruleTester.run(
Expand Down
4 changes: 4 additions & 0 deletions utils/compare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ export let compare = <T extends SortingNode>({
a,
b,
}: CompareParameters<T>): number => {
if (options.type === 'unsorted') {
return 0
}

let finalNodeValueGetter = nodeValueGetter ?? ((node: T) => node.name)
let compareValue = computeCompareValue({
nodeValueGetter: finalNodeValueGetter,
Expand Down

0 comments on commit 1ac83c9

Please sign in to comment.