From cadec3b1c8043ae63da8e7be4fe23deb1fa0085f Mon Sep 17 00:00:00 2001 From: IU Date: Tue, 21 Apr 2020 16:11:32 +0800 Subject: [PATCH] Fix detect Vue3 defineComponent (#1088) Co-authored-by: Yosuke Ota --- lib/utils/index.js | 6 +++++ tests/lib/rules/no-dupe-keys.js | 38 ++++++++++++++++++++++++++++++++ tests/lib/utils/vue-component.js | 6 +++++ 3 files changed, 50 insertions(+) diff --git a/lib/utils/index.js b/lib/utils/index.js index e784f2ab3..b302cd6cb 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -550,6 +550,12 @@ module.exports = { const isAppVueComponent = isObjectArgument(node) return isAppVueComponent } + if (callee.name === 'defineComponent') { + // for Vue.js 3.x + // defineComponent({}) + const isDestructedVueComponent = isObjectArgument(node) + return isDestructedVueComponent + } } } diff --git a/tests/lib/rules/no-dupe-keys.js b/tests/lib/rules/no-dupe-keys.js index 0844173f0..a3bc06e77 100644 --- a/tests/lib/rules/no-dupe-keys.js +++ b/tests/lib/rules/no-dupe-keys.js @@ -639,6 +639,44 @@ ruleTester.run('no-dupe-keys', rule, { message: 'Duplicated key \'foo\'.', line: 9 }] + }, + { + filename: 'test.js', + code: ` + defineComponent({ + foo: { + bar: String + }, + data: { + bar: null + }, + }) + `, + options: [{ groups: ['foo'] }], + parserOptions: { ecmaVersion: 6 }, + errors: [{ + message: 'Duplicated key \'bar\'.', + line: 7 + }] + }, + { + filename: 'test.js', + code: ` + export default defineComponent({ + foo: { + bar: String + }, + data: { + bar: null + }, + }) + `, + options: [{ groups: ['foo'] }], + parserOptions: { ecmaVersion: 6, sourceType: 'module' }, + errors: [{ + message: 'Duplicated key \'bar\'.', + line: 7 + }] } ] }) diff --git a/tests/lib/utils/vue-component.js b/tests/lib/utils/vue-component.js index 69d663e92..794075d47 100644 --- a/tests/lib/utils/vue-component.js +++ b/tests/lib/utils/vue-component.js @@ -311,6 +311,12 @@ function invalidTests (ext) { `, parserOptions, errors: (ext === 'js' ? [] : [makeError(2)]).concat([makeError(8)]) + }, + { + filename: `test.${ext}`, + code: `export default defineComponent({})`, + parserOptions, + errors: [makeError(1)] } ] }