Skip to content

Commit

Permalink
fix(prefer-import-from-vue): skip side-effect import in .d.ts files (
Browse files Browse the repository at this point in the history
…#1907)

* fix(prefer-import-from-vue): skip side-effect import

* fix: only skip in .d.ts

* Update tests/lib/rules/prefer-import-from-vue.js

Co-authored-by: Yosuke Ota <otameshiyo23@gmail.com>

Co-authored-by: Yosuke Ota <otameshiyo23@gmail.com>
  • Loading branch information
antfu and ota-meshi committed May 30, 2022
1 parent 35bf100 commit c1c9dc2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 7 additions & 0 deletions lib/rules/prefer-import-from-vue.js
Expand Up @@ -94,6 +94,13 @@ module.exports = {

return {
ImportDeclaration(node) {
// Skip imports without specifiers in `.d.ts` files
if (
node.specifiers.length === 0 &&
context.getFilename().endsWith('.d.ts')
)
return

verifySource(node.source, () => {
if (SUBSET_AT_VUE_MODULES.has(node.source.value)) {
// If the module is a subset of 'vue', we can safely change it to 'vue'.
Expand Down
6 changes: 5 additions & 1 deletion tests/lib/rules/prefer-import-from-vue.js
Expand Up @@ -22,7 +22,11 @@ tester.run('prefer-import-from-vue', rule, {
`export * from 'vue'`,
`import Foo from 'foo'`,
`import { createApp } from 'vue'
export { createApp }`
export { createApp }`,
{
filename: 'test.d.ts',
code: `import '@vue/runtime-dom'`
}
],
invalid: [
{
Expand Down

0 comments on commit c1c9dc2

Please sign in to comment.