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] Revert breaking group change in order #2854

Merged
merged 1 commit into from Aug 18, 2023
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,9 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange

## [Unreleased]

### Fixed
- [`order`]: revert breaking change to single nested group ([#2854], thanks [@yndajas])

### Changed
- [Docs] remove duplicate fixable notices in docs ([#2850], thanks [@bmish])

Expand Down Expand Up @@ -1082,6 +1085,7 @@ for info on changes for earlier releases.

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

[#2854]: https://github.com/import-js/eslint-plugin-import/pull/2854
[#2850]: https://github.com/import-js/eslint-plugin-import/pull/2850
[#2842]: https://github.com/import-js/eslint-plugin-import/pull/2842
[#2835]: https://github.com/import-js/eslint-plugin-import/pull/2835
Expand Down Expand Up @@ -1887,5 +1891,6 @@ for info on changes for earlier releases.
[@wtgtybhertgeghgtwtg]: https://github.com/wtgtybhertgeghgtwtg
[@xM8WVqaG]: https://github.com/xM8WVqaG
[@xpl]: https://github.com/xpl
[@yndajas]: https://github.com/yndajas
[@yordis]: https://github.com/yordis
[@zloirock]: https://github.com/zloirock
4 changes: 0 additions & 4 deletions src/rules/order.js
Expand Up @@ -422,10 +422,6 @@ const types = ['builtin', 'external', 'internal', 'unknown', 'parent', 'sibling'
// Example: { index: 0, sibling: 1, parent: 1, external: 1, builtin: 2, internal: 2 }
// Will throw an error if it contains a type that does not exist, or has a duplicate
function convertGroupsToRanks(groups) {
if (groups.length === 1) {
// TODO: remove this `if` and fix the bug
return convertGroupsToRanks(groups[0]);
}
const rankObject = groups.reduce(function (res, group, index) {
[].concat(group).forEach(function (groupItem) {
if (types.indexOf(groupItem) === -1) {
Expand Down
61 changes: 26 additions & 35 deletions tests/src/rules/order.js
Expand Up @@ -2753,7 +2753,7 @@ context('TypeScript', function () {
};

ruleTester.run('order', rule, {
valid: [
valid: [].concat(
// #1667: typescript type import support

// Option alphabetize: {order: 'asc'}
Expand Down Expand Up @@ -2962,7 +2962,31 @@ context('TypeScript', function () {
},
],
}),
],
isCoreModule('node:child_process') && isCoreModule('node:fs/promises') ? [
ljharb marked this conversation as resolved.
Show resolved Hide resolved
test({
code: `
import express from 'express';
import log4js from 'log4js';
import chpro from 'node:child_process';
// import fsp from 'node:fs/promises';
`,
options: [{
groups: [
[
'builtin',
'external',
'internal',
'parent',
'sibling',
'index',
'object',
'type',
],
],
}],
}),
] : [],
),
invalid: [].concat(
// Option alphabetize: {order: 'asc'}
test({
Expand Down Expand Up @@ -3218,39 +3242,6 @@ context('TypeScript', function () {
// { message: '`node:fs/promises` import should occur before import of `express`' },
],
}),

test({
code: `
import express from 'express';
yndajas marked this conversation as resolved.
Show resolved Hide resolved
import log4js from 'log4js';
import chpro from 'node:child_process';
// import fsp from 'node:fs/promises';
`,
output: `
import chpro from 'node:child_process';
import express from 'express';
import log4js from 'log4js';
// import fsp from 'node:fs/promises';
`,
options: [{
groups: [
[
'builtin',
'external',
'internal',
'parent',
'sibling',
'index',
'object',
'type',
],
],
}],
errors: [
{ message: '`node:child_process` import should occur before import of `express`' },
// { message: '`node:fs/promises` import should occur before import of `express`' },
],
}),
] : [],
),
});
Expand Down