Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit adb4a0d

Browse files
armano2michalsnik
authored andcommitted
Fix reporting issues from executeOnFunctionsWithoutReturn (#655)
1 parent 8fd7ab8 commit adb4a0d

File tree

2 files changed

+83
-1
lines changed

2 files changed

+83
-1
lines changed

‎lib/utils/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,8 +685,12 @@ module.exports = {
685685
node: null
686686
}
687687

688+
function isReachable (segment) {
689+
return segment.reachable
690+
}
691+
688692
function isValidReturn () {
689-
if (!funcInfo.hasReturn) {
693+
if (funcInfo.codePath.currentSegments.some(isReachable)) {
690694
return false
691695
}
692696
return !treatUndefinedAsUnspecified || funcInfo.hasReturnValue

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

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,36 @@ ruleTester.run('require-render-return', rule, {
7070
}`,
7171
parserOptions
7272
},
73+
{
74+
filename: 'test.vue',
75+
code: `export default {
76+
render() {
77+
const foo = function () {}
78+
return foo
79+
}
80+
}`,
81+
parserOptions
82+
},
83+
{
84+
filename: 'test.vue',
85+
code: `export default {
86+
render() {
87+
if (a) {
88+
if (b) {
89+
90+
}
91+
if (c) {
92+
return true
93+
} else {
94+
return foo
95+
}
96+
} else {
97+
return foo
98+
}
99+
}
100+
}`,
101+
parserOptions
102+
},
73103
{
74104
filename: 'test.vue',
75105
code: `export default {
@@ -119,6 +149,22 @@ ruleTester.run('require-render-return', rule, {
119149
line: 2
120150
}]
121151
},
152+
{
153+
filename: 'test.vue',
154+
code: `export default {
155+
render: function () {
156+
if (foo) {
157+
return h('div', 'hello')
158+
}
159+
}
160+
}`,
161+
parserOptions,
162+
errors: [{
163+
message: 'Expected to return a value in render function.',
164+
type: 'Identifier',
165+
line: 2
166+
}]
167+
},
122168
{
123169
code: `Vue.component('test', {
124170
render: function () {
@@ -133,6 +179,38 @@ ruleTester.run('require-render-return', rule, {
133179
type: 'Identifier',
134180
line: 2
135181
}]
182+
},
183+
{
184+
code: `Vue.component('test2', {
185+
render: function () {
186+
if (a) {
187+
return h('div', 'hello')
188+
}
189+
}
190+
})`,
191+
parserOptions,
192+
errors: [{
193+
message: 'Expected to return a value in render function.',
194+
type: 'Identifier',
195+
line: 2
196+
}]
197+
},
198+
{
199+
code: `Vue.component('test2', {
200+
render: function () {
201+
if (a) {
202+
203+
} else {
204+
return h('div', 'hello')
205+
}
206+
}
207+
})`,
208+
parserOptions,
209+
errors: [{
210+
message: 'Expected to return a value in render function.',
211+
type: 'Identifier',
212+
line: 2
213+
}]
136214
}
137215
]
138216
})

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /