Skip to content

Commit cadec3b

Browse files
Fix detect Vue3 defineComponent (vuejs#1088)
Co-authored-by: Yosuke Ota <otameshiyo23@gmail.com>
1 parent 8d3c99a commit cadec3b

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

lib/utils/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,12 @@ module.exports = {
550550
const isAppVueComponent = isObjectArgument(node)
551551
return isAppVueComponent
552552
}
553+
if (callee.name === 'defineComponent') {
554+
// for Vue.js 3.x
555+
// defineComponent({})
556+
const isDestructedVueComponent = isObjectArgument(node)
557+
return isDestructedVueComponent
558+
}
553559
}
554560
}
555561

tests/lib/rules/no-dupe-keys.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,44 @@ ruleTester.run('no-dupe-keys', rule, {
639639
message: 'Duplicated key \'foo\'.',
640640
line: 9
641641
}]
642+
},
643+
{
644+
filename: 'test.js',
645+
code: `
646+
defineComponent({
647+
foo: {
648+
bar: String
649+
},
650+
data: {
651+
bar: null
652+
},
653+
})
654+
`,
655+
options: [{ groups: ['foo'] }],
656+
parserOptions: { ecmaVersion: 6 },
657+
errors: [{
658+
message: 'Duplicated key \'bar\'.',
659+
line: 7
660+
}]
661+
},
662+
{
663+
filename: 'test.js',
664+
code: `
665+
export default defineComponent({
666+
foo: {
667+
bar: String
668+
},
669+
data: {
670+
bar: null
671+
},
672+
})
673+
`,
674+
options: [{ groups: ['foo'] }],
675+
parserOptions: { ecmaVersion: 6, sourceType: 'module' },
676+
errors: [{
677+
message: 'Duplicated key \'bar\'.',
678+
line: 7
679+
}]
642680
}
643681
]
644682
})

tests/lib/utils/vue-component.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,12 @@ function invalidTests (ext) {
311311
`,
312312
parserOptions,
313313
errors: (ext === 'js' ? [] : [makeError(2)]).concat([makeError(8)])
314+
},
315+
{
316+
filename: `test.${ext}`,
317+
code: `export default defineComponent({})`,
318+
parserOptions,
319+
errors: [makeError(1)]
314320
}
315321
]
316322
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy