Skip to content

Commit 3bc2921

Browse files
committed
fix: handle function createApp and import from @vue/composition-api
1 parent 7baf1ab commit 3bc2921

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

lib/utils/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2534,15 +2534,23 @@ function getVueComponentDefinitionType(context, node) {
25342534
// only lint the createApp function that import from vue
25352535
if (variable !== null && variable.defs.length === 1) {
25362536
const def = variable.defs[0]
2537+
2538+
// ignore import {createApp} from 'other.js'
25372539
if (
25382540
def.type === 'ImportBinding' &&
25392541
def.node.type === 'ImportSpecifier' &&
25402542
def.node.imported.type === 'Identifier' &&
25412543
def.node.parent.type === 'ImportDeclaration' &&
2542-
def.node.parent.source.value !== 'vue'
2544+
def.node.parent.source.value !== 'vue' &&
2545+
def.node.parent.source.value !== '@vue/composition-api'
25432546
) {
25442547
return null
25452548
}
2549+
2550+
// ignore function createApp(){}
2551+
if(def.type === 'FunctionName'){
2552+
return null
2553+
}
25462554
}
25472555

25482556
const isAppVueComponent = isObjectArgument(parent)

tests/lib/rules/one-component-per-file.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ ruleTester.run('one-component-per-file', rule, {
6969
createApp({})
7070
createApp({})
7171
`
72+
},
73+
{
74+
filename: 'test.js',
75+
code: `
76+
function createApp(){}
77+
createApp({})
78+
createApp({})
79+
`
7280
}
7381
],
7482
invalid: [
@@ -122,6 +130,18 @@ ruleTester.run('one-component-per-file', rule, {
122130
'There is more than one component in this file.',
123131
'There is more than one component in this file.'
124132
]
133+
},
134+
{
135+
filename: 'test.vue',
136+
code: `
137+
import { createApp } from '@vue/composition-api'
138+
createApp({})
139+
createApp({})
140+
`,
141+
errors: [
142+
'There is more than one component in this file.',
143+
'There is more than one component in this file.'
144+
]
125145
}
126146
]
127147
})

0 commit comments

Comments
 (0)