diff --git a/lib/rules/require-direct-export.js b/lib/rules/require-direct-export.js index c3eaebd01..18897eb07 100644 --- a/lib/rules/require-direct-export.js +++ b/lib/rules/require-direct-export.js @@ -55,6 +55,25 @@ module.exports = { // OK return } + if (node.type === 'CallExpression') { + const { + callee, + arguments: [firstArg] + } = node + if (firstArg && firstArg.type === 'ObjectExpression') { + if ( + (callee.type === 'Identifier' && + callee.name === 'defineComponent') || + (callee.type === 'MemberExpression' && + callee.object.type === 'Identifier' && + callee.object.name === 'Vue' && + callee.property.type === 'Identifier' && + callee.property.name === 'extend') + ) { + return + } + } + } if (!disallowFunctional) { if (node.type === 'ArrowFunctionExpression') { if (node.body.type !== 'BlockStatement') { diff --git a/tests/lib/rules/require-direct-export.js b/tests/lib/rules/require-direct-export.js index d8dc568b1..4f16e0fcd 100644 --- a/tests/lib/rules/require-direct-export.js +++ b/tests/lib/rules/require-direct-export.js @@ -74,6 +74,20 @@ ruleTester.run('require-direct-export', rule, { import { h } from 'vue' export default props => h('div', props.msg) ` + }, + { + filename: 'test.vue', + code: ` + import Vue from 'vue' + export default Vue.extend({}) + ` + }, + { + filename: 'test.vue', + code: ` + import { defineComponent } from 'vue' + export default defineComponent({}) + ` } ], @@ -224,6 +238,40 @@ ruleTester.run('require-direct-export', rule, { `, options: [{ disallowFunctionalComponentFunction: true }], errors: ['Expected the component literal to be directly exported.'] + }, + { + filename: 'test.vue', + code: ` + import Vue from 'vue' + export default Vue.extend() + `, + errors: ['Expected the component literal to be directly exported.'] + }, + { + filename: 'test.vue', + code: ` + import Vue from 'vue' + const A = {} + export default Vue.extend(A) + `, + errors: ['Expected the component literal to be directly exported.'] + }, + { + filename: 'test.vue', + code: ` + import { defineComponent } from 'vue' + export default defineComponent() + `, + errors: ['Expected the component literal to be directly exported.'] + }, + { + filename: 'test.vue', + code: ` + import { defineComponent } from 'vue' + const A = {} + export default defineComponent(A) + `, + errors: ['Expected the component literal to be directly exported.'] } ] })