Skip to content

Commit

Permalink
fix: [import/order] ensure arcane imports do not cause undefined beha…
Browse files Browse the repository at this point in the history
…vior
  • Loading branch information
Xunnamius committed Jan 21, 2025
1 parent d472b80 commit 64ccfb5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/rules/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,10 @@ function computeRank(context, ranks, importEntry, excludedImportTypes, isSorting

if (typeof rank === 'undefined') {
rank = ranks.groups[impType];

if (typeof rank === 'undefined') {
return -1;
}
}

if (isTypeOnlyImport && isSortingTypesGroup) {
Expand Down
32 changes: 30 additions & 2 deletions tests/src/rules/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -3115,7 +3115,6 @@ context('TypeScript', function () {
}),
// Option alphabetize: {order: 'asc'} with type group & path group
test({
// only: true,
code: `
import c from 'Bar';
import a from 'foo';
Expand Down Expand Up @@ -3145,7 +3144,6 @@ context('TypeScript', function () {
}),
// Option alphabetize: {order: 'asc'} with path group
test({
// only: true,
code: `
import c from 'Bar';
import type { A } from 'foo';
Expand Down Expand Up @@ -3739,6 +3737,36 @@ context('TypeScript', function () {
},
],
}),
// Ensure the rule doesn't choke and die on absolute paths trying to pass NaN around
test({
code: `
import fs from 'node:fs';
import '@scoped/package';
import type { B } from 'node:fs';
import type { A1 } from '/bad/bad/bad/bad';
import './a/b/c';
import type { A2 } from '/bad/bad/bad/bad';
import type { A3 } from '/bad/bad/bad/bad';
import type { D1 } from '/bad/bad/not/good';
import type { D2 } from '/bad/bad/not/good';
import type { D3 } from '/bad/bad/not/good';
import type { C } from '@something/else';
import type { E } from './index.js';
`,
...parserConfig,
options: [
{
alphabetize: { order: 'asc' },
groups: ['builtin', 'type', 'unknown', 'external'],
sortTypesGroup: true,
'newlines-between': 'always',
},
],
}),
),
invalid: [].concat(
// Option alphabetize: {order: 'asc'}
Expand Down

0 comments on commit 64ccfb5

Please sign in to comment.