Skip to content

Commit 807cbdf

Browse files
committed
Add few more tests and filter -> find
1 parent 3e18ed0 commit 807cbdf

File tree

2 files changed

+34
-19
lines changed

2 files changed

+34
-19
lines changed

lib/rules/require-render-return.js

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,21 @@ module.exports = {
2222
},
2323

2424
create (context) {
25-
// ----------------------------------------------------------------------
26-
// Public
27-
// ----------------------------------------------------------------------
28-
2925
return utils.executeOnVue(context, obj => {
30-
obj.properties
31-
.filter(item => item.type === 'Property' &&
32-
utils.getStaticPropertyName(item) === 'render' &&
33-
(item.value.type === 'ArrowFunctionExpression' || item.value.type === 'FunctionExpression') &&
34-
!item.value.expression // render: () => test
35-
)
36-
.forEach(item => {
37-
const body = item.value.body
38-
if (body.type === 'BlockStatement' && !body.body.find(item => item.type === 'ReturnStatement')) {
39-
context.report({
40-
node: item.key,
41-
message: 'Expected to return a value in render function.'
42-
})
43-
}
44-
})
26+
const node = obj.properties.find(item => item.type === 'Property' &&
27+
utils.getStaticPropertyName(item) === 'render' &&
28+
(item.value.type === 'ArrowFunctionExpression' || item.value.type === 'FunctionExpression') &&
29+
!item.value.expression // render: () => test
30+
)
31+
if (node) {
32+
const body = node.value.body
33+
if (body.type === 'BlockStatement' && !body.body.find(item => item.type === 'ReturnStatement')) {
34+
context.report({
35+
node: node.key,
36+
message: 'Expected to return a value in render function.'
37+
})
38+
}
39+
}
4540
})
4641
}
4742
}

tests/lib/rules/require-render-return.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,26 @@ ruleTester.run('require-render-return', rule, {
3232
})`,
3333
parserOptions
3434
},
35+
{
36+
code: `Vue.component('test', {
37+
foo() {
38+
return {}
39+
}
40+
})`,
41+
parserOptions
42+
},
43+
{
44+
code: `Vue.component('test', {
45+
foo: {}
46+
})`,
47+
parserOptions
48+
},
49+
{
50+
code: `Vue.component('test', {
51+
render: foo
52+
})`,
53+
parserOptions
54+
},
3555
{
3656
code: `Vue.component('test', {
3757
render() {

0 commit comments

Comments
 (0)