]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Add a linter rule for spacing before opening parenthesis in function calls
authorJoshua Spence <josh@joshuaspence.com>
Wed, 5 Aug 2015 20:57:46 +0000 (06:57 +1000)
committerJoshua Spence <josh@joshuaspence.com>
Wed, 5 Aug 2015 20:58:22 +0000 (06:58 +1000)
Summary: Repurpose `ArcanistClosingCallParenthesesXHPASTLinterRule` (and rename it to `ArcanistCallParenthesesXHPASTLinterRule`) to ensure that there is no spacing before opening parenthesis in function calls.

Test Plan: Added test case.

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: Korvin

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

src/__phutil_library_map__.php
src/lint/linter/__tests__/xhpast/call-parens-hug-closing.lint-test
src/lint/linter/xhpast/rules/ArcanistCallParenthesesXHPASTLinterRule.php [moved from src/lint/linter/xhpast/rules/ArcanistClosingCallParenthesesXHPASTLinterRule.php with 66% similarity]

index 680febaf4a653c8659b4e338b68e79d5e9d2da91..49ccb0d80d536e00c37f6c258e09184f6627b6ed 100644 (file)
@@ -32,6 +32,7 @@ phutil_register_library_map(array(
     'ArcanistCSSLintLinterTestCase' => 'lint/linter/__tests__/ArcanistCSSLintLinterTestCase.php',
     'ArcanistCSharpLinter' => 'lint/linter/ArcanistCSharpLinter.php',
     'ArcanistCallConduitWorkflow' => 'workflow/ArcanistCallConduitWorkflow.php',
+    'ArcanistCallParenthesesXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistCallParenthesesXHPASTLinterRule.php',
     'ArcanistCallTimePassByReferenceXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistCallTimePassByReferenceXHPASTLinterRule.php',
     'ArcanistCapabilityNotSupportedException' => 'workflow/exception/ArcanistCapabilityNotSupportedException.php',
     'ArcanistCastSpacingXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistCastSpacingXHPASTLinterRule.php',
@@ -42,7 +43,6 @@ phutil_register_library_map(array(
     'ArcanistClassNameLiteralXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistClassNameLiteralXHPASTLinterRule.php',
     'ArcanistCloseRevisionWorkflow' => 'workflow/ArcanistCloseRevisionWorkflow.php',
     'ArcanistCloseWorkflow' => 'workflow/ArcanistCloseWorkflow.php',
-    'ArcanistClosingCallParenthesesXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistClosingCallParenthesesXHPASTLinterRule.php',
     'ArcanistClosureLinter' => 'lint/linter/ArcanistClosureLinter.php',
     'ArcanistClosureLinterTestCase' => 'lint/linter/__tests__/ArcanistClosureLinterTestCase.php',
     'ArcanistCoffeeLintLinter' => 'lint/linter/ArcanistCoffeeLintLinter.php',
@@ -305,6 +305,7 @@ phutil_register_library_map(array(
     'ArcanistCSSLintLinterTestCase' => 'ArcanistExternalLinterTestCase',
     'ArcanistCSharpLinter' => 'ArcanistLinter',
     'ArcanistCallConduitWorkflow' => 'ArcanistWorkflow',
+    'ArcanistCallParenthesesXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
     'ArcanistCallTimePassByReferenceXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
     'ArcanistCapabilityNotSupportedException' => 'Exception',
     'ArcanistCastSpacingXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
@@ -315,7 +316,6 @@ phutil_register_library_map(array(
     'ArcanistClassNameLiteralXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
     'ArcanistCloseRevisionWorkflow' => 'ArcanistWorkflow',
     'ArcanistCloseWorkflow' => 'ArcanistWorkflow',
-    'ArcanistClosingCallParenthesesXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
     'ArcanistClosureLinter' => 'ArcanistExternalLinter',
     'ArcanistClosureLinterTestCase' => 'ArcanistExternalLinterTestCase',
     'ArcanistCoffeeLintLinter' => 'ArcanistExternalLinter',
index 81ad7a1300ff702b81b71d4dbd7c91f6150bb3d8..3ec2eaa576be08e2539abff2362f9dc94da4f765 100644 (file)
@@ -16,9 +16,11 @@ The duck says, "Quack!"
 The robot says, "Beep beep boop boop!"
 EODOC
   );
+f (1);
 ~~~~~~~~~~
 warning:4:4
 warning:9:4
+warning:19:2
 ~~~~~~~~~~
 <?php
 
@@ -37,3 +39,4 @@ The duck says, "Quack!"
 The robot says, "Beep beep boop boop!"
 EODOC
   );
+f(1);
similarity index 66%
rename from src/lint/linter/xhpast/rules/ArcanistClosingCallParenthesesXHPASTLinterRule.php
rename to src/lint/linter/xhpast/rules/ArcanistCallParenthesesXHPASTLinterRule.php
index 6ca026bcbc345aefd87d0d34b9afd8f4fe79ec10..5d6bc2cf6a2690ec8172b03c344fbab560c7c261 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-final class ArcanistClosingCallParenthesesXHPASTLinterRule
+final class ArcanistCallParenthesesXHPASTLinterRule
   extends ArcanistXHPASTLinterRule {
 
   const ID = 37;
@@ -19,6 +19,22 @@ final class ArcanistClosingCallParenthesesXHPASTLinterRule
       'n_METHOD_CALL',
     ));
 
+    foreach ($calls as $call) {
+      $params = $call->getChildOfType(1, 'n_CALL_PARAMETER_LIST');
+      $tokens = $params->getTokens();
+      $first  = head($tokens);
+
+      $leading = $first->getNonsemanticTokensBefore();
+      $leading_text = implode('', mpull($leading, 'getValue'));
+      if (preg_match('/^\s+$/', $leading_text)) {
+        $this->raiseLintAtOffset(
+          $first->getOffset() - strlen($leading_text),
+          pht('Convention: no spaces before opening parenthesis in calls.'),
+          $leading_text,
+          '');
+      }
+    }
+
     foreach ($calls as $call) {
       // If the last parameter of a call is a HEREDOC, don't apply this rule.
       $params = $call