Skip to content

Commit ff8cfaa

Browse files
authored
Update: allow more cases in require-direct-export (#1450)
(fixes #907)
1 parent 43a01cf commit ff8cfaa

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

lib/rules/require-direct-export.js

+19
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,25 @@ module.exports = {
5555
// OK
5656
return
5757
}
58+
if (node.type === 'CallExpression') {
59+
const {
60+
callee,
61+
arguments: [firstArg]
62+
} = node
63+
if (firstArg && firstArg.type === 'ObjectExpression') {
64+
if (
65+
(callee.type === 'Identifier' &&
66+
callee.name === 'defineComponent') ||
67+
(callee.type === 'MemberExpression' &&
68+
callee.object.type === 'Identifier' &&
69+
callee.object.name === 'Vue' &&
70+
callee.property.type === 'Identifier' &&
71+
callee.property.name === 'extend')
72+
) {
73+
return
74+
}
75+
}
76+
}
5877
if (!disallowFunctional) {
5978
if (node.type === 'ArrowFunctionExpression') {
6079
if (node.body.type !== 'BlockStatement') {

tests/lib/rules/require-direct-export.js

+48
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,20 @@ ruleTester.run('require-direct-export', rule, {
7474
import { h } from 'vue'
7575
export default props => h('div', props.msg)
7676
`
77+
},
78+
{
79+
filename: 'test.vue',
80+
code: `
81+
import Vue from 'vue'
82+
export default Vue.extend({})
83+
`
84+
},
85+
{
86+
filename: 'test.vue',
87+
code: `
88+
import { defineComponent } from 'vue'
89+
export default defineComponent({})
90+
`
7791
}
7892
],
7993

@@ -224,6 +238,40 @@ ruleTester.run('require-direct-export', rule, {
224238
`,
225239
options: [{ disallowFunctionalComponentFunction: true }],
226240
errors: ['Expected the component literal to be directly exported.']
241+
},
242+
{
243+
filename: 'test.vue',
244+
code: `
245+
import Vue from 'vue'
246+
export default Vue.extend()
247+
`,
248+
errors: ['Expected the component literal to be directly exported.']
249+
},
250+
{
251+
filename: 'test.vue',
252+
code: `
253+
import Vue from 'vue'
254+
const A = {}
255+
export default Vue.extend(A)
256+
`,
257+
errors: ['Expected the component literal to be directly exported.']
258+
},
259+
{
260+
filename: 'test.vue',
261+
code: `
262+
import { defineComponent } from 'vue'
263+
export default defineComponent()
264+
`,
265+
errors: ['Expected the component literal to be directly exported.']
266+
},
267+
{
268+
filename: 'test.vue',
269+
code: `
270+
import { defineComponent } from 'vue'
271+
const A = {}
272+
export default defineComponent(A)
273+
`,
274+
errors: ['Expected the component literal to be directly exported.']
227275
}
228276
]
229277
})

0 commit comments

Comments
 (0)