diff --git a/lib/utils/index.js b/lib/utils/index.js
index 4073b6915..a2b307b05 100644
--- a/lib/utils/index.js
+++ b/lib/utils/index.js
@@ -1361,7 +1361,7 @@ module.exports = {
* Get the Vue component definition type from given node
* Vue.component('xxx', {}) || component('xxx', {})
* @param {ObjectExpression} node Node to check
- * @returns {'component' | 'mixin' | 'extend' | 'createApp' | 'defineComponent' | null}
+ * @returns {'component' | 'mixin' | 'extend' | 'createApp' | 'defineComponent' | 'defineNuxtComponent' | null}
*/
getVueComponentDefinitionType,
/**
@@ -2502,7 +2502,7 @@ function isVueComponentFile(node, path) {
* Get the Vue component definition type from given node
* Vue.component('xxx', {}) || component('xxx', {})
* @param {ObjectExpression} node Node to check
- * @returns {'component' | 'mixin' | 'extend' | 'createApp' | 'defineComponent' | null}
+ * @returns {'component' | 'mixin' | 'extend' | 'createApp' | 'defineComponent' | 'defineNuxtComponent' | null}
*/
function getVueComponentDefinitionType(node) {
const parent = getParent(node)
@@ -2558,6 +2558,12 @@ function getVueComponentDefinitionType(node) {
const isDestructedVueComponent = isObjectArgument(parent)
return isDestructedVueComponent ? 'defineComponent' : null
}
+ if (callee.name === 'defineNuxtComponent') {
+ // for Nuxt 3.x
+ // defineNuxtComponent({})
+ const isDestructedVueComponent = isObjectArgument(parent)
+ return isDestructedVueComponent ? 'defineNuxtComponent' : null
+ }
}
}
@@ -2702,7 +2708,9 @@ function isSFCObject(context, node) {
}
const { callee } = parent
if (
- (callee.type === 'Identifier' && callee.name === 'defineComponent') ||
+ (callee.type === 'Identifier' &&
+ (callee.name === 'defineComponent' ||
+ callee.name === 'defineNuxtComponent')) ||
(callee.type === 'MemberExpression' &&
callee.object.type === 'Identifier' &&
callee.object.name === 'Vue' &&
diff --git a/tests/lib/rules/no-undef-components.js b/tests/lib/rules/no-undef-components.js
index 0941f003d..f66400e0e 100644
--- a/tests/lib/rules/no-undef-components.js
+++ b/tests/lib/rules/no-undef-components.js
@@ -265,6 +265,21 @@ tester.run('no-undef-components', rule, {
}
]
},
+ {
+ filename: 'test.vue',
+ code: `
+
+
+
+
+ `
+ },
{
filename: 'test.vue',
code: `
diff --git a/tests/lib/rules/order-in-components.js b/tests/lib/rules/order-in-components.js
index 669383e52..acb12bda5 100644
--- a/tests/lib/rules/order-in-components.js
+++ b/tests/lib/rules/order-in-components.js
@@ -219,6 +219,84 @@ ruleTester.run('order-in-components', rule, {
}
]
},
+ {
+ filename: 'test.vue',
+ code: `
+ import { defineComponent } from 'vue'
+ export default defineComponent({
+ name: 'app',
+ data () {
+ return {
+ msg: 'Welcome to Your Vue.js App'
+ }
+ },
+ props: {
+ propA: Number,
+ },
+ })
+ `,
+ output: `
+ import { defineComponent } from 'vue'
+ export default defineComponent({
+ name: 'app',
+ props: {
+ propA: Number,
+ },
+ data () {
+ return {
+ msg: 'Welcome to Your Vue.js App'
+ }
+ },
+ })
+ `,
+ parserOptions,
+ errors: [
+ {
+ message:
+ 'The "props" property should be above the "data" property on line 5.',
+ line: 10
+ }
+ ]
+ },
+ {
+ filename: 'test.vue',
+ code: `
+ import { defineNuxtComponent } from '#app'
+ export default defineNuxtComponent({
+ name: 'app',
+ data () {
+ return {
+ msg: 'Welcome to Your Vue.js App'
+ }
+ },
+ props: {
+ propA: Number,
+ },
+ })
+ `,
+ output: `
+ import { defineNuxtComponent } from '#app'
+ export default defineNuxtComponent({
+ name: 'app',
+ props: {
+ propA: Number,
+ },
+ data () {
+ return {
+ msg: 'Welcome to Your Vue.js App'
+ }
+ },
+ })
+ `,
+ parserOptions,
+ errors: [
+ {
+ message:
+ 'The "props" property should be above the "data" property on line 5.',
+ line: 10
+ }
+ ]
+ },
{
filename: 'test.jsx',
code: `
diff --git a/tests/lib/utils/vue-component.js b/tests/lib/utils/vue-component.js
index c66b3338f..6cce0009b 100644
--- a/tests/lib/utils/vue-component.js
+++ b/tests/lib/utils/vue-component.js
@@ -313,6 +313,12 @@ function invalidTests(ext) {
code: `export default defineComponent({})`,
parserOptions,
errors: [makeError(1)]
+ },
+ {
+ filename: `test.${ext}`,
+ code: `export default defineNuxtComponent({})`,
+ parserOptions,
+ errors: [makeError(1)]
}
]
}