Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions lib/rules/require-direct-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
48 changes: 48 additions & 0 deletions tests/lib/rules/require-direct-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({})
`
}
],

Expand Down Expand Up @@ -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.']
}
]
})