Skip to content

Commit 7a37f90

Browse files
Pearce-Ropionljharb
authored andcommitted
[Fix] order: leave more space in rankings for consecutive path groups
Fixes #2494.
1 parent 5fe9aa4 commit 7a37f90

File tree

3 files changed

+73
-2
lines changed

3 files changed

+73
-2
lines changed

CHANGELOG.md

+3
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-restricted-paths`]: fix an error message ([#2466], thanks [@AdriAt360])
1818
- [`no-restricted-paths`]: use `Minimatch.match` instead of `minimatch` to comply with Windows Native paths ([#2466], thanks [@AdriAt360])
1919
- [`order`]: require with member expression could not be fixed if alphabetize.order was used ([#2490], thanks [@msvab])
20+
- [`order`]: leave more space in rankings for consecutive path groups ([#2506], thanks [@Pearce-Ropion])
2021

2122
### Changed
2223
- [Tests] `named`: Run all TypeScript test ([#2427], thanks [@ProdigySim])
@@ -997,6 +998,7 @@ for info on changes for earlier releases.
997998

998999
[`memo-parser`]: ./memo-parser/README.md
9991000

1001+
[#2506]: https://github.com/import-js/eslint-plugin-import/pull/2506
10001002
[#2503]: https://github.com/import-js/eslint-plugin-import/pull/2503
10011003
[#2490]: https://github.com/import-js/eslint-plugin-import/pull/2490
10021004
[#2466]: https://github.com/import-js/eslint-plugin-import/pull/2466
@@ -1657,6 +1659,7 @@ for info on changes for earlier releases.
16571659
[@panrafal]: https://github.com/panrafal
16581660
[@paztis]: https://github.com/paztis
16591661
[@pcorpet]: https://github.com/pcorpet
1662+
[@Pearce-Ropion]: https://github.com/Pearce-Ropion
16601663
[@Pessimistress]: https://github.com/Pessimistress
16611664
[@pmcelhaney]: https://github.com/pmcelhaney
16621665
[@preco21]: https://github.com/preco21

src/rules/order.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ function convertGroupsToRanks(groups) {
407407
if (res[groupItem] !== undefined) {
408408
throw new Error('Incorrect configuration of the rule: `' + groupItem + '` is duplicated');
409409
}
410-
res[groupItem] = index;
410+
res[groupItem] = index * 2;
411411
});
412412
return res;
413413
}, {});
@@ -417,7 +417,7 @@ function convertGroupsToRanks(groups) {
417417
});
418418

419419
const ranks = omittedTypes.reduce(function (res, type) {
420-
res[type] = groups.length;
420+
res[type] = groups.length * 2;
421421
return res;
422422
}, rankObject);
423423

tests/src/rules/order.js

+68
Original file line numberDiff line numberDiff line change
@@ -2099,6 +2099,74 @@ ruleTester.run('order', rule, {
20992099
},
21002100
],
21012101
}),
2102+
test({
2103+
code: `
2104+
import path from 'path';
2105+
import { namespace } from '@namespace';
2106+
import { a } from 'a';
2107+
import { b } from 'b';
2108+
import { c } from 'c';
2109+
import { d } from 'd';
2110+
import { e } from 'e';
2111+
import { f } from 'f';
2112+
import { g } from 'g';
2113+
import { h } from 'h';
2114+
import { i } from 'i';
2115+
import { j } from 'j';
2116+
import { k } from 'k';`,
2117+
output: `
2118+
import path from 'path';
2119+
2120+
import { namespace } from '@namespace';
2121+
2122+
import { a } from 'a';
2123+
2124+
import { b } from 'b';
2125+
2126+
import { c } from 'c';
2127+
2128+
import { d } from 'd';
2129+
2130+
import { e } from 'e';
2131+
2132+
import { f } from 'f';
2133+
2134+
import { g } from 'g';
2135+
2136+
import { h } from 'h';
2137+
2138+
import { i } from 'i';
2139+
2140+
import { j } from 'j';
2141+
import { k } from 'k';`,
2142+
options: [
2143+
{
2144+
groups: [
2145+
'builtin',
2146+
'external',
2147+
'internal',
2148+
],
2149+
pathGroups: [
2150+
{ pattern: '@namespace', group: 'external', position: 'after' },
2151+
{ pattern: 'a', group: 'internal', position: 'before' },
2152+
{ pattern: 'b', group: 'internal', position: 'before' },
2153+
{ pattern: 'c', group: 'internal', position: 'before' },
2154+
{ pattern: 'd', group: 'internal', position: 'before' },
2155+
{ pattern: 'e', group: 'internal', position: 'before' },
2156+
{ pattern: 'f', group: 'internal', position: 'before' },
2157+
{ pattern: 'g', group: 'internal', position: 'before' },
2158+
{ pattern: 'h', group: 'internal', position: 'before' },
2159+
{ pattern: 'i', group: 'internal', position: 'before' },
2160+
],
2161+
'newlines-between': 'always',
2162+
pathGroupsExcludedImportTypes: ['builtin'],
2163+
},
2164+
],
2165+
settings: {
2166+
'import/internal-regex': '^(a|b|c|d|e|f|g|h|i|j|k)(\\/|$)',
2167+
},
2168+
errors: Array.from({ length: 11 }, () => 'There should be at least one empty line between import groups'),
2169+
}),
21022170

21032171
// reorder fix cannot cross non import or require
21042172
test(withoutAutofixOutput({

0 commit comments

Comments
 (0)