Skip to content

Commit fda4186

Browse files
committed
fix(require-returns-check): check WithStatement for return statements
1 parent b5a78ff commit fda4186

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6622,6 +6622,16 @@ function quux () {
66226622
}
66236623
}
66246624

6625+
/**
6626+
* @returns {true}
6627+
*/
6628+
function quux () {
6629+
var a = {};
6630+
with (a) {
6631+
return true;
6632+
}
6633+
}
6634+
66256635
/**
66266636
* @returns {true}
66276637
*/

src/jsdocUtils.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,8 @@ const STATEMENTS_WITH_CHILDREN = [
245245
'SwitchStatement',
246246
'IfStatement',
247247
'BlockStatement',
248-
'TryStatement'
248+
'TryStatement',
249+
'WithStatement'
249250
];
250251

251252
const RETURNFREE_STATEMENTS = [
@@ -257,7 +258,6 @@ const RETURNFREE_STATEMENTS = [
257258
'LabeledStatement',
258259
'DebuggerStatement',
259260
'EmptyStatement',
260-
'WithStatement',
261261
'ThrowStatement',
262262
'ExpressionStatement'
263263
];
@@ -285,6 +285,14 @@ const lookupTable = {
285285
return true;
286286
}
287287
},
288+
WithStatement: {
289+
is (node) {
290+
return node.type === 'WithStatement';
291+
},
292+
check (node, context) {
293+
return lookupTable.BlockStatement.check(node.body, context);
294+
}
295+
},
288296
IfStatement: {
289297
is (node) {
290298
return node.type === 'IfStatement';

test/rules/assertions/requireReturnsCheck.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,19 @@ export default {
457457
}
458458
`
459459
},
460+
{
461+
code: `
462+
/**
463+
* @returns {true}
464+
*/
465+
function quux () {
466+
var a = {};
467+
with (a) {
468+
return true;
469+
}
470+
}
471+
`
472+
},
460473
{
461474
code: `
462475
/**

0 commit comments

Comments
 (0)