Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] order: leave more space in rankings for consecutive path groups #2506

Merged
merged 1 commit into from Aug 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
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
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
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