Skip to content

Commit

Permalink
[Fix] order: leave more space in rankings for consecutive path groups
Browse files Browse the repository at this point in the history
Fixes #2494.
  • Loading branch information
Pearce-Ropion authored and ljharb committed Jul 23, 2022
1 parent 5fe9aa4 commit 7a37f90
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
- [`no-restricted-paths`]: fix an error message ([#2466], thanks [@AdriAt360])
- [`no-restricted-paths`]: use `Minimatch.match` instead of `minimatch` to comply with Windows Native paths ([#2466], thanks [@AdriAt360])
- [`order`]: require with member expression could not be fixed if alphabetize.order was used ([#2490], thanks [@msvab])
- [`order`]: leave more space in rankings for consecutive path groups ([#2506], thanks [@Pearce-Ropion])

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

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

[#2506]: https://github.com/import-js/eslint-plugin-import/pull/2506
[#2503]: https://github.com/import-js/eslint-plugin-import/pull/2503
[#2490]: https://github.com/import-js/eslint-plugin-import/pull/2490
[#2466]: https://github.com/import-js/eslint-plugin-import/pull/2466
Expand Down Expand Up @@ -1657,6 +1659,7 @@ for info on changes for earlier releases.
[@panrafal]: https://github.com/panrafal
[@paztis]: https://github.com/paztis
[@pcorpet]: https://github.com/pcorpet
[@Pearce-Ropion]: https://github.com/Pearce-Ropion
[@Pessimistress]: https://github.com/Pessimistress
[@pmcelhaney]: https://github.com/pmcelhaney
[@preco21]: https://github.com/preco21
Expand Down
4 changes: 2 additions & 2 deletions src/rules/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ function convertGroupsToRanks(groups) {
if (res[groupItem] !== undefined) {
throw new Error('Incorrect configuration of the rule: `' + groupItem + '` is duplicated');
}
res[groupItem] = index;
res[groupItem] = index * 2;
});
return res;
}, {});
Expand All @@ -417,7 +417,7 @@ function convertGroupsToRanks(groups) {
});

const ranks = omittedTypes.reduce(function (res, type) {
res[type] = groups.length;
res[type] = groups.length * 2;
return res;
}, rankObject);

Expand Down
68 changes: 68 additions & 0 deletions tests/src/rules/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -2099,6 +2099,74 @@ ruleTester.run('order', rule, {
},
],
}),
test({
code: `
import path from 'path';
import { namespace } from '@namespace';
import { a } from 'a';
import { b } from 'b';
import { c } from 'c';
import { d } from 'd';
import { e } from 'e';
import { f } from 'f';
import { g } from 'g';
import { h } from 'h';
import { i } from 'i';
import { j } from 'j';
import { k } from 'k';`,
output: `
import path from 'path';
import { namespace } from '@namespace';
import { a } from 'a';
import { b } from 'b';
import { c } from 'c';
import { d } from 'd';
import { e } from 'e';
import { f } from 'f';
import { g } from 'g';
import { h } from 'h';
import { i } from 'i';
import { j } from 'j';
import { k } from 'k';`,
options: [
{
groups: [
'builtin',
'external',
'internal',
],
pathGroups: [
{ pattern: '@namespace', group: 'external', position: 'after' },
{ pattern: 'a', group: 'internal', position: 'before' },
{ pattern: 'b', group: 'internal', position: 'before' },
{ pattern: 'c', group: 'internal', position: 'before' },
{ pattern: 'd', group: 'internal', position: 'before' },
{ pattern: 'e', group: 'internal', position: 'before' },
{ pattern: 'f', group: 'internal', position: 'before' },
{ pattern: 'g', group: 'internal', position: 'before' },
{ pattern: 'h', group: 'internal', position: 'before' },
{ pattern: 'i', group: 'internal', position: 'before' },
],
'newlines-between': 'always',
pathGroupsExcludedImportTypes: ['builtin'],
},
],
settings: {
'import/internal-regex': '^(a|b|c|d|e|f|g|h|i|j|k)(\\/|$)',
},
errors: Array.from({ length: 11 }, () => 'There should be at least one empty line between import groups'),
}),

// reorder fix cannot cross non import or require
test(withoutAutofixOutput({
Expand Down

0 comments on commit 7a37f90

Please sign in to comment.