Skip to content

Commit 18edab0

Browse files
committed
Fix grouping bug with undefined settings
1 parent 0c1d3f2 commit 18edab0

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

.changeset/shaggy-meals-serve.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'eslint-plugin-import-sorting': patch
3+
---
4+
5+
Fix bug with grouping when settings are not explicitly defined

src/utils/compute-group.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ export function computeGroup(
3232
if (isSideEffectImport(node, sourceCode)) defineGroup('unassigned')
3333
if (isBuiltin(value)) defineGroup('builtin')
3434
if (isStyle(value)) defineGroup('style')
35-
if (isFramework(value, frameworkPatterns)) defineGroup('framework')
36-
if (isInternal(value, internalPatterns)) defineGroup('internal')
35+
if (frameworkPatterns && isFramework(value, frameworkPatterns)) defineGroup('framework')
36+
if (internalPatterns && isInternal(value, internalPatterns)) defineGroup('internal')
3737
if (isExternal(value)) defineGroup('external')
3838
if (isLocal(value)) defineGroup('local')
3939
}
@@ -122,7 +122,7 @@ function assertString(value: unknown, setting: string) {
122122
function validateSetting(settings: TSESLint.SharedConfigurationSettings, setting: string) {
123123
let value = settings[setting] as string | string[]
124124

125-
if (!value) return ''
125+
if (!value) return undefined
126126
if (Array.isArray(value)) {
127127
for (let item of value) {
128128
assertString(item, setting)

tests/rules/order.test.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,19 +154,32 @@ describe('order', () => {
154154
{
155155
name: 'groups local modules together',
156156
code: dedent`
157+
import { AST_NODE_TYPES, type TSESLint, type TSESTree } from '@typescript-eslint/utils'
157158
import prettier from 'eslint-config-prettier'
158159
import xoTypeScript from 'eslint-config-xo-typescript'
159160
import etc from 'eslint-plugin-etc'
160161
import stylistic from './stylistic.js'
162+
import { other } from '../other.js'
161163
`,
162164
output: dedent`
165+
import { AST_NODE_TYPES, type TSESLint, type TSESTree } from '@typescript-eslint/utils'
163166
import prettier from 'eslint-config-prettier'
164167
import xoTypeScript from 'eslint-config-xo-typescript'
165168
import etc from 'eslint-plugin-etc'
166169
170+
import { other } from '../other.js'
167171
import stylistic from './stylistic.js'
168172
`,
169-
errors: [{ messageId: 'needs-newline' }],
173+
errors: [
174+
{
175+
messageId: 'needs-newline',
176+
data: { left: 'eslint-plugin-etc', right: './stylistic.js' },
177+
},
178+
{
179+
messageId: 'out-of-order',
180+
data: { left: './stylistic.js', right: '../other.js' },
181+
},
182+
],
170183
},
171184

172185
{

0 commit comments

Comments
 (0)