Skip to content

Commit

Permalink
chore: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Jan 24, 2024
1 parent 120e382 commit fb6728b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
8 changes: 5 additions & 3 deletions src/core/ctx.ts
Expand Up @@ -80,20 +80,22 @@ ${dts}`.trim()}\n`
if (!imports.length && !resolvers.length && !dirs?.length)
console.warn('[auto-import] plugin installed but no imports has defined, see https://github.com/antfu/unplugin-auto-import#configurations for configurations')

const compare = (left: string|undefined, right: NonNullable<(Options['ignore'] | Options['ignoreDts'])>[number]) => {
const compare = (left: string | undefined, right: NonNullable<(Options['ignore'] | Options['ignoreDts'])>[number]) => {
return right instanceof RegExp
? right.test(left!)
: right === left
}

options.ignore?.forEach((name) => {
const i = imports.find(i => compare(i.as, name))
if (i) i.disabled = true
if (i)
i.disabled = true
})

options.ignoreDts?.forEach((name) => {
const i = imports.find(i => compare(i.as, name))
if (i) i.dtsDisabled = true
if (i)
i.dtsDisabled = true
})

return unimport.getInternalContext().replaceImports(imports)
Expand Down
8 changes: 4 additions & 4 deletions test/dts.ignore.test.ts
Expand Up @@ -10,13 +10,13 @@ it('dts ignore', async () => {
'shouldBePresent',
'shouldAlsoBePresent',
'shouldBeIgnored',
'ignoreme_shoudAlsoBeIgnored'
]
'ignoreme_shoudAlsoBeIgnored',
],
}],
ignoreDts: [
'shouldBeIgnored',
/^ignoreme_/
]
/^ignoreme_/,
],
})

const dtsContent = await ctx.generateDTS(join(cwd, 'index.d.ts'))
Expand Down

0 comments on commit fb6728b

Please sign in to comment.