Skip to content

Commit ca2d3ad

Browse files
mihkeleidastljharb
authored andcommitted
[Fix] order: add and fix repro case from #2682
1 parent 855346b commit ca2d3ad

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
1717
- [`no-cycle`]: use scc algorithm to optimize ([#2998], thanks [@soryy708])
1818
- [`no-duplicates`]: Removing duplicates breaks in TypeScript ([#3033], thanks [@yesl-kim])
1919
- [`newline-after-import`]: fix considerComments option when require ([#2952], thanks [@developer-bandi])
20+
- [`order`]: add and fix repro case from [#2682] ([#2885], thanks [@mihkeleidast])
2021

2122
### Changed
2223
- [Docs] `no-extraneous-dependencies`: Make glob pattern description more explicit ([#2944], thanks [@mulztob])
@@ -1141,6 +1142,7 @@ for info on changes for earlier releases.
11411142
[#2944]: https://github.com/import-js/eslint-plugin-import/pull/2944
11421143
[#2942]: https://github.com/import-js/eslint-plugin-import/pull/2942
11431144
[#2919]: https://github.com/import-js/eslint-plugin-import/pull/2919
1145+
[#2885]: https://github.com/import-js/eslint-plugin-import/pull/2885
11441146
[#2884]: https://github.com/import-js/eslint-plugin-import/pull/2884
11451147
[#2866]: https://github.com/import-js/eslint-plugin-import/pull/2866
11461148
[#2854]: https://github.com/import-js/eslint-plugin-import/pull/2854
@@ -1486,6 +1488,7 @@ for info on changes for earlier releases.
14861488
[#2930]: https://github.com/import-js/eslint-plugin-import/issues/2930
14871489
[#2687]: https://github.com/import-js/eslint-plugin-import/issues/2687
14881490
[#2684]: https://github.com/import-js/eslint-plugin-import/issues/2684
1491+
[#2682]: https://github.com/import-js/eslint-plugin-import/issues/2682
14891492
[#2674]: https://github.com/import-js/eslint-plugin-import/issues/2674
14901493
[#2668]: https://github.com/import-js/eslint-plugin-import/issues/2668
14911494
[#2666]: https://github.com/import-js/eslint-plugin-import/issues/2666
@@ -1880,6 +1883,7 @@ for info on changes for earlier releases.
18801883
[@mgwalker]: https://github.com/mgwalker
18811884
[@mhmadhamster]: https://github.com/MhMadHamster
18821885
[@michaelfaith]: https://github.com/michaelfaith
1886+
[@mihkeleidast]: https://github.com/mihkeleidast
18831887
[@MikeyBeLike]: https://github.com/MikeyBeLike
18841888
[@minervabot]: https://github.com/minervabot
18851889
[@mpint]: https://github.com/mpint

src/rules/order.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,11 @@ function getSorter(alphabetizeOptions) {
303303

304304
for (let i = 0; i < Math.min(a, b); i++) {
305305
// 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; }
306+
if (i === 0 && ((A[i] === '.' || A[i] === '..') && (B[i] === '.' || B[i] === '..'))) {
307+
// If one is sibling and the other parent import, no need to compare at all, since the paths belong in different groups
308+
if (A[i] !== B[i]) { break; }
309+
continue;
310+
}
307311
result = compareString(A[i], B[i]);
308312
if (result) { break; }
309313
}

tests/src/rules/order.js

+12
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,18 @@ ruleTester.run('order', rule, {
185185
['builtin', 'external'],
186186
], alphabetize: { order: 'asc', caseInsensitive: true } }],
187187
}),
188+
test({
189+
code: `
190+
import { fooz } from '../baz.js'
191+
import { foo } from './bar.js'
192+
`,
193+
options: [{
194+
alphabetize: { order: 'asc', caseInsensitive: true },
195+
groups: ['builtin', 'external', 'internal', ['parent', 'sibling', 'index'], 'object'],
196+
'newlines-between': 'always',
197+
warnOnUnassignedImports: true,
198+
}],
199+
}),
188200
// Omitted types should implicitly be considered as the last type
189201
test({
190202
code: `

0 commit comments

Comments
 (0)