Skip to content

Commit

Permalink
feat: support bun builtin modules in sort-imports rule
Browse files Browse the repository at this point in the history
  • Loading branch information
azat-io committed Sep 12, 2023
1 parent 37512c9 commit 37bca14
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
20 changes: 17 additions & 3 deletions rules/sort-imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,24 @@ export default createEslintRule<Options<string[]>, MESSAGE_ID>({
}),
)

let isCoreModule = (value: string) =>
builtinModules.includes(
value.startsWith('node:') ? value.split('node:')[1] : value,
let isCoreModule = (value: string) => {
let bunModules = [
'bun',
'bun:ffi',
'bun:jsc',
'bun:sqlite',
'bun:test',
'bun:wrap',
'detect-libc',
'undici',
'ws',
]
return (
builtinModules.includes(
value.startsWith('node:') ? value.split('node:')[1] : value,
) || bunModules.includes(value)
)
}

if (node.importKind === 'type') {
if (node.type === 'ImportDeclaration') {
Expand Down
10 changes: 10 additions & 0 deletions test/sort-imports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3558,6 +3558,7 @@ describe(RULE_NAME, () => {
valid: [
{
code: dedent`
import { expect, test } from 'bun:test'
import { writeFile } from 'node:fs/promises'
import { useEffect } from 'react'
Expand All @@ -3574,8 +3575,10 @@ describe(RULE_NAME, () => {
code: dedent`
import { writeFile } from 'node:fs/promises'
import { useEffect } from 'react'
import { expect, test } from 'bun:test'
`,
output: dedent`
import { expect, test } from 'bun:test'
import { writeFile } from 'node:fs/promises'
import { useEffect } from 'react'
Expand All @@ -3593,6 +3596,13 @@ describe(RULE_NAME, () => {
right: 'react',
},
},
{
messageId: 'unexpectedImportsOrder',
data: {
left: 'react',
right: 'bun:test',
},
},
],
},
],
Expand Down

0 comments on commit 37bca14

Please sign in to comment.