Skip to content

Commit

Permalink
Update: allow more cases in require-direct-export (#1450)
Browse files Browse the repository at this point in the history
(fixes #907)
  • Loading branch information
g-plane committed Mar 22, 2021
1 parent 43a01cf commit ff8cfaa
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/rules/require-direct-export.js
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
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.']
}
]
})

0 comments on commit ff8cfaa

Please sign in to comment.