Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commited050e9

Browse files
committed
fix: [one-component-per-file] do not check createApp function written by the developer#2201
1 parentd815a48 commited050e9

File tree

5 files changed

+51
-6
lines changed

5 files changed

+51
-6
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ module.exports = {
2929
{},
3030
utils.executeOnVueComponent(context,(node,type)=>{
3131
if(type==='definition'){
32-
constdefType=getVueComponentDefinitionType(node)
32+
constdefType=getVueComponentDefinitionType(context,node)
3333
if(defType==='mixin'){
3434
return
3535
}

‎lib/rules/require-expose.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ module.exports = {
272272
return
273273
}
274274
if(type==='definition'){
275-
constdefType=getVueComponentDefinitionType(component)
275+
constdefType=getVueComponentDefinitionType(context,component)
276276
if(defType==='mixin'){
277277
return
278278
}

‎lib/rules/require-name-property.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ module.exports = {
6060
}
6161
returnutils.executeOnVue(context,(component,type)=>{
6262
if(type==='definition'){
63-
constdefType=getVueComponentDefinitionType(component)
63+
constdefType=getVueComponentDefinitionType(context,component)
6464
if(defType==='mixin'){
6565
return
6666
}

‎lib/utils/index.js‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2479,10 +2479,11 @@ function isVueComponentFile(node, path) {
24792479
/**
24802480
* Get the Vue component definition type from given node
24812481
* Vue.component('xxx', {}) || component('xxx', {})
2482+
*@param {RuleContext} context The rule context to use parser services.
24822483
*@param {ObjectExpression} node Node to check
24832484
*@returns {'component' | 'mixin' | 'extend' | 'createApp' | 'defineComponent' | null}
24842485
*/
2485-
functiongetVueComponentDefinitionType(node){
2486+
functiongetVueComponentDefinitionType(context,node){
24862487
constparent=getParent(node)
24872488
if(parent.type==='CallExpression'){
24882489
constcallee=parent.callee
@@ -2527,6 +2528,23 @@ function getVueComponentDefinitionType(node) {
25272528
if(callee.name==='createApp'){
25282529
// for Vue.js 3.x
25292530
// createApp({})
2531+
2532+
constvariable=findVariable(context.getScope(),callee)
2533+
2534+
// only lint the createApp function that import from vue
2535+
if(variable!=null&&variable.defs.length===1){
2536+
constdef=variable.defs[0]
2537+
if(
2538+
def.type==='ImportBinding'&&
2539+
def.node.type==='ImportSpecifier'&&
2540+
def.node.imported.type==='Identifier'&&
2541+
def.node.parent.type==='ImportDeclaration'&&
2542+
def.node.parent.source.value!=='vue'
2543+
){
2544+
returnnull
2545+
}
2546+
}
2547+
25302548
constisAppVueComponent=isObjectArgument(parent)
25312549
returnisAppVueComponent ?'createApp' :null
25322550
}
@@ -2603,7 +2621,7 @@ function getVueObjectType(context, node) {
26032621
case'CallExpression':{
26042622
// Vue.component('xxx', {}) || component('xxx', {})
26052623
if(
2606-
getVueComponentDefinitionType(node)!=null&&
2624+
getVueComponentDefinitionType(context,node)!=null&&
26072625
skipTSAsExpression(parent.arguments.slice(-1)[0])===node
26082626
){
26092627
return'definition'

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,22 @@ ruleTester.run('one-component-per-file', rule, {
5454
Vue.mixin({})
5555
Vue.component('name', {})
5656
`
57-
}
57+
},
58+
{
59+
filename:'test.js',
60+
code:`
61+
import { createApp } from 'vue'
62+
createApp({})
63+
`
64+
},
65+
{
66+
filename:'test.js',
67+
code:`
68+
import { createApp } from 'other.js'
69+
createApp({})
70+
createApp({})
71+
`
72+
},
5873
],
5974
invalid:[
6075
{
@@ -95,6 +110,18 @@ ruleTester.run('one-component-per-file', rule, {
95110
'There is more than one component in this file.',
96111
'There is more than one component in this file.'
97112
]
113+
},
114+
{
115+
filename:'test.vue',
116+
code:`
117+
import { createApp } from 'vue'
118+
createApp({})
119+
createApp({})
120+
`,
121+
errors:[
122+
'There is more than one component in this file.',
123+
'There is more than one component in this file.'
124+
]
98125
}
99126
]
100127
})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp