Skip to content

Commit 37e8300

Browse files
brettz9l1bbcsg
authored andcommitted
fix(require-returns-check): check WithStatement for return statements
1 parent 19a6590 commit 37e8300

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
@@ -276,7 +276,8 @@ const STATEMENTS_WITH_CHILDREN = [
276276
'SwitchStatement',
277277
'IfStatement',
278278
'BlockStatement',
279-
'TryStatement'
279+
'TryStatement',
280+
'WithStatement'
280281
];
281282

282283
const RETURNFREE_STATEMENTS = [
@@ -288,7 +289,6 @@ const RETURNFREE_STATEMENTS = [
288289
'LabeledStatement',
289290
'DebuggerStatement',
290291
'EmptyStatement',
291-
'WithStatement',
292292
'ThrowStatement',
293293
'ExpressionStatement'
294294
];
@@ -316,6 +316,14 @@ const lookupTable = {
316316
return true;
317317
}
318318
},
319+
WithStatement: {
320+
is (node) {
321+
return node.type === 'WithStatement';
322+
},
323+
check (node, context) {
324+
return lookupTable.BlockStatement.check(node.body, context);
325+
}
326+
},
319327
IfStatement: {
320328
is (node) {
321329
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)