]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Improve linter handling of short array syntax
authorJoshua Spence <josh@joshuaspence.com>
Wed, 19 Aug 2015 05:35:16 +0000 (15:35 +1000)
committerJoshua Spence <josh@freelancer.com>
Wed, 19 Aug 2015 05:35:16 +0000 (15:35 +1000)
Summary: Currently, linting PHP short array syntax (i.e. `[...]`) throws an exception ("Expected open parentheses"). This diff relaxes some restrictions which prevent short array syntax from linting with `ArcanistParenthesesSpacingXHPASTLinterRule`.

Test Plan: Modified test cases.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: agenticarus, Korvin

Differential Revision: https://secure.phabricator.com/D13895

src/lint/linter/__tests__/xhpast/array-formatting.lint-test
src/lint/linter/xhpast/rules/ArcanistCallParenthesesXHPASTLinterRule.php
src/lint/linter/xhpast/rules/ArcanistParenthesesSpacingXHPASTLinterRule.php

index 3dda317d919928b2ca4805d54680a0e2db246d55..7ae23f5d5aca8c92cd1bd639c9d7afa3429898cf 100644 (file)
@@ -2,6 +2,7 @@
 
 array ( 1, 2, 3 );
 list ( $x, $y ) = array();
+[ 1, 2 , 3 ];
 ~~~~~~~~~~
 warning:3:6
 warning:3:8
@@ -9,8 +10,11 @@ warning:3:16
 warning:4:5
 warning:4:7
 warning:4:14
+warning:5:2
+warning:5:11
 ~~~~~~~~~~
 <?php
 
 array(1, 2, 3);
 list($x, $y) = array();
+[1, 2 , 3];
index 67cb3676a8df928f15d3894ebc218a77f38a072e..594399b345f0395aa63dc93fc986c9fae12178d1 100644 (file)
@@ -24,6 +24,11 @@ final class ArcanistCallParenthesesXHPASTLinterRule
     foreach ($nodes as $node) {
       switch ($node->getTypeName()) {
         case 'n_ARRAY_LITERAL':
+          if (head($node->getTokens())->getTypeName() == '[') {
+            // Short array syntax.
+            continue 2;
+          }
+
           $params = $node->getChildOfType(0, 'n_ARRAY_VALUE_LIST');
           break;
 
@@ -44,6 +49,7 @@ final class ArcanistCallParenthesesXHPASTLinterRule
       $tokens = $params->getTokens();
       $first  = head($tokens);
 
+
       $leading = $first->getNonsemanticTokensBefore();
       $leading_text = implode('', mpull($leading, 'getValue'));
       if (preg_match('/^\s+$/', $leading_text)) {
index 7ad16a44c67a0e77cf942b36bdf9b5cc57a4b96e..7d7f8c4d8c203b7e2d95dc16dc7d2cb7db83b7e0 100644 (file)
@@ -29,12 +29,6 @@ final class ArcanistParenthesesSpacingXHPASTLinterRule
 
       $token_o = array_shift($tokens);
       $token_c = array_pop($tokens);
-      if ($token_o->getTypeName() !== '(') {
-        throw new Exception(pht('Expected open parentheses.'));
-      }
-      if ($token_c->getTypeName() !== ')') {
-        throw new Exception(pht('Expected close parentheses.'));
-      }
 
       $nonsem_o = $token_o->getNonsemanticTokensAfter();
       $nonsem_c = $token_c->getNonsemanticTokensBefore();