From abbbf570c79b36fb89acdd2a8e0ca6923e32e713 Mon Sep 17 00:00:00 2001 From: Pearce Date: Sat, 23 Jul 2022 14:15:37 -0700 Subject: [PATCH] import/order: leave more space in rankings for consecutive path groups --- src/rules/order.js | 4 +-- tests/src/rules/order.js | 68 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/src/rules/order.js b/src/rules/order.js index 3f033eb82b..4fb1787685 100644 --- a/src/rules/order.js +++ b/src/rules/order.js @@ -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; }, {}); @@ -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); diff --git a/tests/src/rules/order.js b/tests/src/rules/order.js index e8a5143c52..b3d0f2e971 100644 --- a/tests/src/rules/order.js +++ b/tests/src/rules/order.js @@ -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: new Array(11).fill('There should be at least one empty line between import groups'), + }), // reorder fix cannot cross non import or require test(withoutAutofixOutput({