Skip to content

Commit

Permalink
fix(import/order): do not compare first sibling and parent path segment
Browse files Browse the repository at this point in the history
  • Loading branch information
mihkeleidast committed Sep 26, 2023
1 parent 66cb10f commit 795a9b1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/rules/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@ function getSorter(alphabetizeOptions) {
const b = B.length;

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; }
result = compareString(A[i], B[i]);
if (result) { break; }
}
Expand Down
16 changes: 16 additions & 0 deletions tests/src/rules/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,22 @@ ruleTester.run('order', rule, {
['sibling', 'parent', 'external'],
] }],
}),
// Grouping import types and alphabetize
test({
code: `
import async from 'async';
import fs from 'fs';
import path from 'path';
import index from '.';
import relParent3 from '../';
import relParent1 from '../foo';
import sibling from './foo';
`,
options: [{ groups: [
['builtin', 'external'],
], alphabetize: { order: 'asc', caseInsensitive: true } }],
}),
// Omitted types should implicitly be considered as the last type
test({
code: `
Expand Down

0 comments on commit 795a9b1

Please sign in to comment.