diff --git a/src/lint/linter/xhpast/rules/ArcanistUnexpectedReturnValueXHPASTLinterRule.php b/src/lint/linter/xhpast/rules/ArcanistUnexpectedReturnValueXHPASTLinterRule.php index b73ea0a5..10ffda44 100644 --- a/src/lint/linter/xhpast/rules/ArcanistUnexpectedReturnValueXHPASTLinterRule.php +++ b/src/lint/linter/xhpast/rules/ArcanistUnexpectedReturnValueXHPASTLinterRule.php @@ -33,6 +33,10 @@ final class ArcanistUnexpectedReturnValueXHPASTLinterRule continue; } + if ($this->isInAnonymousFunction($return)) { + continue; + } + $this->raiseLintAtNode( $return, pht( @@ -45,4 +49,15 @@ final class ArcanistUnexpectedReturnValueXHPASTLinterRule } } + private function isInAnonymousFunction(XHPASTNode $node) { + while ($node) { + if ($node->getTypeName() == 'n_FUNCTION_DECLARATION' && + $node->getChildByIndex(2)->getTypeName() == 'n_EMPTY') { + return true; + } + + $node = $node->getParentNode(); + } + } + } diff --git a/src/lint/linter/xhpast/rules/__tests__/unexpected-return-value/closure.lint-test b/src/lint/linter/xhpast/rules/__tests__/unexpected-return-value/closure.lint-test new file mode 100644 index 00000000..65536bfe --- /dev/null +++ b/src/lint/linter/xhpast/rules/__tests__/unexpected-return-value/closure.lint-test @@ -0,0 +1,11 @@ +closure = function() { + return null; + }; + } +} +~~~~~~~~~~