Skip to content

Commit 47b3f81

Browse files
committed
import/order: leave more space in rankings for consecutive path groups
1 parent d82670c commit 47b3f81

File tree

2 files changed

+70
-2
lines changed

2 files changed

+70
-2
lines changed

Diff for: 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

Diff for: 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: new Array(11).fill('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)