From 5e12ad0d252c42a81ee1e6cd44a0c12bdf51b777 Mon Sep 17 00:00:00 2001 From: Mihkel Eidast Date: Wed, 27 Sep 2023 10:09:34 +0300 Subject: [PATCH] fix: add and fix repro case from issue, --- src/rules/order.js | 6 +++++- tests/src/rules/order.js | 12 ++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/rules/order.js b/src/rules/order.js index b45d8557d..19dc9edfa 100644 --- a/src/rules/order.js +++ b/src/rules/order.js @@ -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; } } diff --git a/tests/src/rules/order.js b/tests/src/rules/order.js index 223806af6..c2d659f83 100644 --- a/tests/src/rules/order.js +++ b/tests/src/rules/order.js @@ -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: `