From 97463aee7cd8e7c31ca24998dc77a60458d0ae88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sajn=C3=B3g?= Date: Wed, 3 Jan 2018 00:36:02 +0100 Subject: [PATCH] Add Vue.extend support, add missing info about Vue.mixin check in readme --- README.md | 2 ++ lib/utils/index.js | 2 +- tests/lib/utils/vue-component.js | 6 ++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4ef106767..7fb35d5dd 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,8 @@ module.exports = { All component-related rules are being applied to code that passes any of the following checks: * `Vue.component()` expression +* `Vue.extend()` expression +* `Vue.mixin()` expression * `export default {}` in `.vue` or `.jsx` file If you however want to take advantage of our rules in any of your custom objects that are Vue components, you might need to use special comment `// @vue/component` that marks object in the next line as a Vue component in any file, e.g.: diff --git a/lib/utils/index.js b/lib/utils/index.js index 4667c437d..4f03abd23 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -384,7 +384,7 @@ module.exports = { callee.object.type === 'Identifier' && callee.object.name === 'Vue' && callee.property.type === 'Identifier' && - (callee.property.name === 'component' || callee.property.name === 'mixin') && + ['component', 'mixin', 'extend'].indexOf(callee.property.name) > -1 && node.arguments.length && node.arguments.slice(-1)[0].type === 'ObjectExpression' diff --git a/tests/lib/utils/vue-component.js b/tests/lib/utils/vue-component.js index 0dd2d0cf3..87b8738af 100644 --- a/tests/lib/utils/vue-component.js +++ b/tests/lib/utils/vue-component.js @@ -126,6 +126,12 @@ function invalidTests (ext) { parserOptions, errors: [makeError(1)] }, + { + filename: `test.${ext}`, + code: `Vue.extend({})`, + parserOptions, + errors: [makeError(1)] + }, { filename: `test.${ext}`, code: `