mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-12-29 00:40:57 +01:00
Improve the "unexpected return value" linter rule
Summary: Return values within constructors are acceptable if they are within a closure or anonymous function. Test Plan: Added a test case. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: Korvin Differential Revision: https://secure.phabricator.com/D14564
This commit is contained in:
parent
72d9013d29
commit
9e78d15fc0
2 changed files with 26 additions and 0 deletions
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
class SomeClass {
|
||||
private $closure;
|
||||
|
||||
public function __construct() {
|
||||
$this->closure = function() {
|
||||
return null;
|
||||
};
|
||||
}
|
||||
}
|
||||
~~~~~~~~~~
|
Loading…
Reference in a new issue