From cd3e4b2232f7b0efb64ac718605e810577c52bfd Mon Sep 17 00:00:00 2001 From: Takanori Sugita Date: Mon, 13 Nov 2023 12:10:07 +0900 Subject: [PATCH 1/4] apply defineNuxtComponent --- lib/utils/index.js | 14 +++++++++++--- tests/lib/rules/no-undef-components.js | 15 +++++++++++++++ tests/lib/utils/vue-component.js | 6 ++++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/lib/utils/index.js b/lib/utils/index.js index 22119ae98..96b3f3c6d 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 ? 'defineComponent' : 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/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)] } ] } From a269589d931a59725556610ede24939b662a9443 Mon Sep 17 00:00:00 2001 From: Takanori Sugita Date: Tue, 14 Nov 2023 20:02:53 +0900 Subject: [PATCH 2/4] fix: name --- lib/utils/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/utils/index.js b/lib/utils/index.js index 96b3f3c6d..3a96f94f6 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -2562,7 +2562,7 @@ function getVueComponentDefinitionType(node) { // for Nuxt 3.x // defineNuxtComponent({}) const isDestructedVueComponent = isObjectArgument(parent) - return isDestructedVueComponent ? 'defineComponent' : null + return isDestructedVueComponent ? 'defineNuxtComponent' : null } } } From f0919854bc9e706bf7f9f98a55bf0cd4c3811f5b Mon Sep 17 00:00:00 2001 From: Takanori Sugita Date: Tue, 14 Nov 2023 20:15:50 +0900 Subject: [PATCH 3/4] add tests --- tests/lib/rules/order-in-components.js | 78 ++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/tests/lib/rules/order-in-components.js b/tests/lib/rules/order-in-components.js index 669383e52..25acbca5b 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: ` From 9924ad98420e54b9083ef67ca74c4a6642fdf34d Mon Sep 17 00:00:00 2001 From: Takanori Sugita Date: Tue, 14 Nov 2023 20:20:07 +0900 Subject: [PATCH 4/4] fix: indents --- tests/lib/rules/order-in-components.js | 52 +++++++++++++------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/tests/lib/rules/order-in-components.js b/tests/lib/rules/order-in-components.js index 25acbca5b..acb12bda5 100644 --- a/tests/lib/rules/order-in-components.js +++ b/tests/lib/rules/order-in-components.js @@ -261,33 +261,33 @@ ruleTester.run('order-in-components', rule, { { 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, - }, - }) - `, + 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' - } - }, - }) - `, + import { defineNuxtComponent } from '#app' + export default defineNuxtComponent({ + name: 'app', + props: { + propA: Number, + }, + data () { + return { + msg: 'Welcome to Your Vue.js App' + } + }, + }) + `, parserOptions, errors: [ {