Skip to content

Commit

Permalink
fix(require-returns-check): check WithStatement for return statem…
Browse files Browse the repository at this point in the history
…ents
  • Loading branch information
brettz9 authored and l1bbcsg committed Aug 8, 2019
1 parent 19a6590 commit 37e8300
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
10 changes: 10 additions & 0 deletions README.md
Expand Up @@ -6622,6 +6622,16 @@ function quux () {
}
}

/**
* @returns {true}
*/
function quux () {
var a = {};
with (a) {
return true;
}
}

/**
* @returns {true}
*/
Expand Down
12 changes: 10 additions & 2 deletions src/jsdocUtils.js
Expand Up @@ -276,7 +276,8 @@ const STATEMENTS_WITH_CHILDREN = [
'SwitchStatement',
'IfStatement',
'BlockStatement',
'TryStatement'
'TryStatement',
'WithStatement'
];

const RETURNFREE_STATEMENTS = [
Expand All @@ -288,7 +289,6 @@ const RETURNFREE_STATEMENTS = [
'LabeledStatement',
'DebuggerStatement',
'EmptyStatement',
'WithStatement',
'ThrowStatement',
'ExpressionStatement'
];
Expand Down Expand Up @@ -316,6 +316,14 @@ const lookupTable = {
return true;
}
},
WithStatement: {
is (node) {
return node.type === 'WithStatement';
},
check (node, context) {
return lookupTable.BlockStatement.check(node.body, context);
}
},
IfStatement: {
is (node) {
return node.type === 'IfStatement';
Expand Down
13 changes: 13 additions & 0 deletions test/rules/assertions/requireReturnsCheck.js
Expand Up @@ -457,6 +457,19 @@ export default {
}
`
},
{
code: `
/**
* @returns {true}
*/
function quux () {
var a = {};
with (a) {
return true;
}
}
`
},
{
code: `
/**
Expand Down

0 comments on commit 37e8300

Please sign in to comment.