Skip to content

Commit

Permalink
fix: add and fix repro case from issue,
Browse files Browse the repository at this point in the history
  • Loading branch information
mihkeleidast committed Sep 27, 2023
1 parent 795a9b1 commit 5e12ad0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/rules/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,11 @@ function getSorter(alphabetizeOptions) {

for (let i = 0; i < Math.min(a, b); i++) {
// Skip comparing the first path segment, if they are relative segments for both imports
if (i === 0 && ((A[i] === '.' || A[i] === '..') && (B[i] === '.' || B[i] === '..'))) { continue; }
if (i === 0 && ((A[i] === '.' || A[i] === '..') && (B[i] === '.' || B[i] === '..'))) {
// If one is sibling and the other parent import, no need to compare at all, since the paths belong in different groups
if (A[i] !== B[i]) { break; }
continue;
}
result = compareString(A[i], B[i]);
if (result) { break; }
}
Expand Down
12 changes: 12 additions & 0 deletions tests/src/rules/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,18 @@ ruleTester.run('order', rule, {
['builtin', 'external'],
], alphabetize: { order: 'asc', caseInsensitive: true } }],
}),
test({
code: `
import { fooz } from '../baz.js'
import { foo } from './bar.js'
`,
options: [{
alphabetize: { order: 'asc', caseInsensitive: true },
groups: ['builtin', 'external', 'internal', ['parent', 'sibling', 'index'], 'object'],
'newlines-between': 'always',
warnOnUnassignedImports: true,
}],
}),
// Omitted types should implicitly be considered as the last type
test({
code: `
Expand Down

0 comments on commit 5e12ad0

Please sign in to comment.