Skip to content

Commit

Permalink
Fix grouping bug with undefined settings
Browse files Browse the repository at this point in the history
  • Loading branch information
stormwarning committed Dec 19, 2024
1 parent 0c1d3f2 commit 18edab0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/shaggy-meals-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'eslint-plugin-import-sorting': patch
---

Fix bug with grouping when settings are not explicitly defined
6 changes: 3 additions & 3 deletions src/utils/compute-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ export function computeGroup(
if (isSideEffectImport(node, sourceCode)) defineGroup('unassigned')
if (isBuiltin(value)) defineGroup('builtin')
if (isStyle(value)) defineGroup('style')
if (isFramework(value, frameworkPatterns)) defineGroup('framework')
if (isInternal(value, internalPatterns)) defineGroup('internal')
if (frameworkPatterns && isFramework(value, frameworkPatterns)) defineGroup('framework')
if (internalPatterns && isInternal(value, internalPatterns)) defineGroup('internal')
if (isExternal(value)) defineGroup('external')
if (isLocal(value)) defineGroup('local')
}
Expand Down Expand Up @@ -122,7 +122,7 @@ function assertString(value: unknown, setting: string) {
function validateSetting(settings: TSESLint.SharedConfigurationSettings, setting: string) {
let value = settings[setting] as string | string[]

if (!value) return ''
if (!value) return undefined
if (Array.isArray(value)) {
for (let item of value) {
assertString(item, setting)
Expand Down
15 changes: 14 additions & 1 deletion tests/rules/order.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,19 +154,32 @@ describe('order', () => {
{
name: 'groups local modules together',
code: dedent`
import { AST_NODE_TYPES, type TSESLint, type TSESTree } from '@typescript-eslint/utils'
import prettier from 'eslint-config-prettier'
import xoTypeScript from 'eslint-config-xo-typescript'
import etc from 'eslint-plugin-etc'
import stylistic from './stylistic.js'
import { other } from '../other.js'
`,
output: dedent`
import { AST_NODE_TYPES, type TSESLint, type TSESTree } from '@typescript-eslint/utils'
import prettier from 'eslint-config-prettier'
import xoTypeScript from 'eslint-config-xo-typescript'
import etc from 'eslint-plugin-etc'
import { other } from '../other.js'
import stylistic from './stylistic.js'
`,
errors: [{ messageId: 'needs-newline' }],
errors: [
{
messageId: 'needs-newline',
data: { left: 'eslint-plugin-etc', right: './stylistic.js' },
},
{
messageId: 'out-of-order',
data: { left: './stylistic.js', right: '../other.js' },
},
],
},

{
Expand Down

0 comments on commit 18edab0

Please sign in to comment.