mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-25 16:22:42 +01:00
Add a lint error about use of PHP short array syntax ('[...]')
Summary: Ref T11409. Add lint to detect using `[...]` to define arrays. This doesn't work in PHP 5.2/5.3, which some of our users run. Test Plan: - Ran `arc unit`. - Ran `arc lint src/applications/harbormaster/conduit/HarbormasterQueryBuildsConduitAPIMethod.php` to detect the issue in T11409. Reviewers: yelirekim, chad Reviewed By: chad Maniphest Tasks: T11409 Differential Revision: https://secure.phabricator.com/D16357
This commit is contained in:
parent
06c641f92c
commit
f20d4b15c7
2 changed files with 16 additions and 0 deletions
|
@ -369,6 +369,19 @@ final class ArcanistPHPCompatibilityXHPASTLinterRule
|
|||
}
|
||||
}
|
||||
|
||||
$literals = $root->selectDescendantsOftype('n_ARRAY_LITERAL');
|
||||
foreach ($literals as $literal) {
|
||||
$open_token = head($literal->getTokens())->getValue();
|
||||
if ($open_token == '[') {
|
||||
$this->raiseLintAtNode(
|
||||
$literal,
|
||||
pht(
|
||||
'The short array syntax ("[...]") was not introduced until '.
|
||||
'PHP 5.4, but this codebase targets an earlier version of PHP. '.
|
||||
'You can rewrite this expression using `array(...)` instead.'));
|
||||
}
|
||||
}
|
||||
|
||||
$closures = $this->getAnonymousClosures($root);
|
||||
foreach ($closures as $closure) {
|
||||
$static_accesses = $closure
|
||||
|
|
|
@ -22,12 +22,15 @@ final class SomeClass extends Phobject {
|
|||
|
||||
0b1;
|
||||
|
||||
[];
|
||||
|
||||
~~~~~~~~~~
|
||||
error:3:5
|
||||
error:4:9
|
||||
error:12:7
|
||||
error:18:7
|
||||
error:23:1
|
||||
error:25:1
|
||||
~~~~~~~~~~
|
||||
~~~~~~~~~~
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue