Skip to content

Commit

Permalink
Fix reporting issues from executeOnFunctionsWithoutReturn (#655)
Browse files Browse the repository at this point in the history
  • Loading branch information
armano2 authored and michalsnik committed Nov 18, 2018
1 parent 8fd7ab8 commit adb4a0d
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/utils/index.js
Expand Up @@ -685,8 +685,12 @@ module.exports = {
node: null
}

function isReachable (segment) {
return segment.reachable
}

function isValidReturn () {
if (!funcInfo.hasReturn) {
if (funcInfo.codePath.currentSegments.some(isReachable)) {
return false
}
return !treatUndefinedAsUnspecified || funcInfo.hasReturnValue
Expand Down
78 changes: 78 additions & 0 deletions tests/lib/rules/require-render-return.js
Expand Up @@ -70,6 +70,36 @@ ruleTester.run('require-render-return', rule, {
}`,
parserOptions
},
{
filename: 'test.vue',
code: `export default {
render() {
const foo = function () {}
return foo
}
}`,
parserOptions
},
{
filename: 'test.vue',
code: `export default {
render() {
if (a) {
if (b) {
}
if (c) {
return true
} else {
return foo
}
} else {
return foo
}
}
}`,
parserOptions
},
{
filename: 'test.vue',
code: `export default {
Expand Down Expand Up @@ -119,6 +149,22 @@ ruleTester.run('require-render-return', rule, {
line: 2
}]
},
{
filename: 'test.vue',
code: `export default {
render: function () {
if (foo) {
return h('div', 'hello')
}
}
}`,
parserOptions,
errors: [{
message: 'Expected to return a value in render function.',
type: 'Identifier',
line: 2
}]
},
{
code: `Vue.component('test', {
render: function () {
Expand All @@ -133,6 +179,38 @@ ruleTester.run('require-render-return', rule, {
type: 'Identifier',
line: 2
}]
},
{
code: `Vue.component('test2', {
render: function () {
if (a) {
return h('div', 'hello')
}
}
})`,
parserOptions,
errors: [{
message: 'Expected to return a value in render function.',
type: 'Identifier',
line: 2
}]
},
{
code: `Vue.component('test2', {
render: function () {
if (a) {
} else {
return h('div', 'hello')
}
}
})`,
parserOptions,
errors: [{
message: 'Expected to return a value in render function.',
type: 'Identifier',
line: 2
}]
}
]
})

0 comments on commit adb4a0d

Please sign in to comment.