Skip to content

Commit 795a9b1

Browse files
committed
fix(import/order): do not compare first sibling and parent path segment
1 parent 66cb10f commit 795a9b1

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/rules/order.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,8 @@ function getSorter(alphabetizeOptions) {
302302
const b = B.length;
303303

304304
for (let i = 0; i < Math.min(a, b); i++) {
305+
// Skip comparing the first path segment, if they are relative segments for both imports
306+
if (i === 0 && ((A[i] === '.' || A[i] === '..') && (B[i] === '.' || B[i] === '..'))) { continue; }
305307
result = compareString(A[i], B[i]);
306308
if (result) { break; }
307309
}

tests/src/rules/order.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,22 @@ ruleTester.run('order', rule, {
169169
['sibling', 'parent', 'external'],
170170
] }],
171171
}),
172+
// Grouping import types and alphabetize
173+
test({
174+
code: `
175+
import async from 'async';
176+
import fs from 'fs';
177+
import path from 'path';
178+
179+
import index from '.';
180+
import relParent3 from '../';
181+
import relParent1 from '../foo';
182+
import sibling from './foo';
183+
`,
184+
options: [{ groups: [
185+
['builtin', 'external'],
186+
], alphabetize: { order: 'asc', caseInsensitive: true } }],
187+
}),
172188
// Omitted types should implicitly be considered as the last type
173189
test({
174190
code: `

0 commit comments

Comments
 (0)