From fe6cea911f6780a59fbc4761e79da853da25f1d2 Mon Sep 17 00:00:00 2001 From: Emily Marigold Klassen Date: Fri, 3 Apr 2020 20:54:41 -0700 Subject: [PATCH] [Fix] `order`: Recognize pathGroup config for first group Co-authored-by: Emily Marigold Klassen Co-authored-by: Vitaly Gordon --- CHANGELOG.md | 5 +++++ src/rules/order.js | 2 +- tests/src/rules/order.js | 17 +++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 44c62ee56..a08d7aabc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel ### Fixed - [`group-exports`]: Flow type export awareness ([#1702], thanks [@ernestostifano]) +- [`order`]: Recognize pathGroup config for first group ([#1719], [#1724], thanks [@forivall], [@xpl]) ## [2.20.2] - 2020-03-28 ### Fixed @@ -663,6 +664,8 @@ for info on changes for earlier releases. [`memo-parser`]: ./memo-parser/README.md +[#1724]: https://github.com/benmosher/eslint-plugin-import/issues/1724 +[#1719]: https://github.com/benmosher/eslint-plugin-import/issues/1719 [#1702]: https://github.com/benmosher/eslint-plugin-import/issues/1702 [#1666]: https://github.com/benmosher/eslint-plugin-import/pull/1666 [#1664]: https://github.com/benmosher/eslint-plugin-import/pull/1664 @@ -1128,3 +1131,5 @@ for info on changes for earlier releases. [@richardxia]: https://github.com/richardxia [@TheCrueltySage]: https://github.com/TheCrueltySage [@ernestostifano]: https://github.com/ernestostifano +[@forivall]: https://github.com/forivall +[@xpl]: https://github.com/xpl diff --git a/src/rules/order.js b/src/rules/order.js index 948c5f427..f17b6ad0c 100644 --- a/src/rules/order.js +++ b/src/rules/order.js @@ -318,7 +318,7 @@ function computeRank(context, ranks, name, type, excludedImportTypes) { if (!excludedImportTypes.has(impType)) { rank = computePathRank(ranks.groups, ranks.pathGroups, name, ranks.maxPosition) } - if (!rank) { + if (typeof rank === 'undefined') { rank = ranks.groups[impType] } if (type !== 'import') { diff --git a/tests/src/rules/order.js b/tests/src/rules/order.js index 67deb7b91..aee2b1124 100644 --- a/tests/src/rules/order.js +++ b/tests/src/rules/order.js @@ -307,6 +307,23 @@ ruleTester.run('order', rule, { ], }], }), + // Using pathGroups (a test case for https://github.com/benmosher/eslint-plugin-import/pull/1724) + test({ + code: ` + import fs from 'fs'; + import external from 'external'; + import externalTooPlease from './make-me-external'; + + import sibling from './sibling';`, + options: [{ + 'newlines-between': 'always', + pathGroupsExcludedImportTypes: [], + pathGroups: [ + { pattern: './make-me-external', group: 'external' }, + ], + groups: [['builtin', 'external'], 'internal', 'parent', 'sibling', 'index'], + }], + }), // Monorepo setup, using Webpack resolver, workspace folder name in external-module-folders test({ code: `