Page MenuHomePhabricator

D13675.id.diff
No OneTemporary

D13675.id.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -43,7 +43,6 @@
'ArcanistCloseRevisionWorkflow' => 'workflow/ArcanistCloseRevisionWorkflow.php',
'ArcanistCloseWorkflow' => 'workflow/ArcanistCloseWorkflow.php',
'ArcanistClosingCallParenthesesXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistClosingCallParenthesesXHPASTLinterRule.php',
- 'ArcanistClosingDeclarationParenthesesXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistClosingDeclarationParenthesesXHPASTLinterRule.php',
'ArcanistClosureLinter' => 'lint/linter/ArcanistClosureLinter.php',
'ArcanistClosureLinterTestCase' => 'lint/linter/__tests__/ArcanistClosureLinterTestCase.php',
'ArcanistCoffeeLintLinter' => 'lint/linter/ArcanistCoffeeLintLinter.php',
@@ -67,6 +66,7 @@
'ArcanistCppcheckLinterTestCase' => 'lint/linter/__tests__/ArcanistCppcheckLinterTestCase.php',
'ArcanistCpplintLinter' => 'lint/linter/ArcanistCpplintLinter.php',
'ArcanistCpplintLinterTestCase' => 'lint/linter/__tests__/ArcanistCpplintLinterTestCase.php',
+ 'ArcanistDeclarationParenthesesXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistDeclarationParenthesesXHPASTLinterRule.php',
'ArcanistDefaultParametersXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistDefaultParametersXHPASTLinterRule.php',
'ArcanistDiffChange' => 'parser/diff/ArcanistDiffChange.php',
'ArcanistDiffChangeType' => 'parser/diff/ArcanistDiffChangeType.php',
@@ -316,7 +316,6 @@
'ArcanistCloseRevisionWorkflow' => 'ArcanistWorkflow',
'ArcanistCloseWorkflow' => 'ArcanistWorkflow',
'ArcanistClosingCallParenthesesXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
- 'ArcanistClosingDeclarationParenthesesXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
'ArcanistClosureLinter' => 'ArcanistExternalLinter',
'ArcanistClosureLinterTestCase' => 'ArcanistExternalLinterTestCase',
'ArcanistCoffeeLintLinter' => 'ArcanistExternalLinter',
@@ -340,6 +339,7 @@
'ArcanistCppcheckLinterTestCase' => 'ArcanistExternalLinterTestCase',
'ArcanistCpplintLinter' => 'ArcanistExternalLinter',
'ArcanistCpplintLinterTestCase' => 'ArcanistExternalLinterTestCase',
+ 'ArcanistDeclarationParenthesesXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
'ArcanistDefaultParametersXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
'ArcanistDiffChange' => 'Phobject',
'ArcanistDiffChangeType' => 'Phobject',
diff --git a/src/lint/linter/__tests__/xhpast/decl-parens-hug-closing.lint-test b/src/lint/linter/__tests__/xhpast/decl-parens-hug-closing.lint-test
--- a/src/lint/linter/__tests__/xhpast/decl-parens-hug-closing.lint-test
+++ b/src/lint/linter/__tests__/xhpast/decl-parens-hug-closing.lint-test
@@ -2,9 +2,10 @@
function f($x) {}
function g($x ) {}
+function h ($x) {}
-function &h($x) {}
-function &i($x ) {}
+function &i($x) {}
+function &j($x ) {}
final class X {
@@ -24,21 +25,23 @@
f(function($x ) use ($z) {});
~~~~~~~~~~
warning:4:14
-warning:7:15
-error:9:13
-warning:12:23
-warning:15:31
-warning:18:33
-warning:23:14
+warning:5:11
+warning:8:15
+error:10:13
+warning:11:23
+warning:16:31
+warning:19:33
warning:24:14
+warning:25:14
~~~~~~~~~~
<?php
function f($x) {}
function g($x) {}
+function h($x) {}
-function &h($x) {}
function &i($x) {}
+function &j($x) {}
final class X {
diff --git a/src/lint/linter/xhpast/rules/ArcanistClosingDeclarationParenthesesXHPASTLinterRule.php b/src/lint/linter/xhpast/rules/ArcanistDeclarationParenthesesXHPASTLinterRule.php
rename from src/lint/linter/xhpast/rules/ArcanistClosingDeclarationParenthesesXHPASTLinterRule.php
rename to src/lint/linter/xhpast/rules/ArcanistDeclarationParenthesesXHPASTLinterRule.php
--- a/src/lint/linter/xhpast/rules/ArcanistClosingDeclarationParenthesesXHPASTLinterRule.php
+++ b/src/lint/linter/xhpast/rules/ArcanistDeclarationParenthesesXHPASTLinterRule.php
@@ -1,6 +1,6 @@
<?php
-final class ArcanistClosingDeclarationParenthesesXHPASTLinterRule
+final class ArcanistDeclarationParenthesesXHPASTLinterRule
extends ArcanistXHPASTLinterRule {
const ID = 38;
@@ -22,11 +22,26 @@
foreach ($decs as $dec) {
$params = $dec->getChildOfType(3, 'n_DECLARATION_PARAMETER_LIST');
$tokens = $params->getTokens();
- $last = array_pop($tokens);
+
+ $first = head($tokens);
+ $last = last($tokens);
+
+ $leading = $first->getNonsemanticTokensBefore();
+ $leading_text = implode('', mpull($leading, 'getValue'));
$trailing = $last->getNonsemanticTokensBefore();
$trailing_text = implode('', mpull($trailing, 'getValue'));
+ if (preg_match('/^\s+$/', $leading_text)) {
+ $this->raiseLintAtOffset(
+ $first->getOffset() - strlen($leading_text),
+ pht(
+ 'Convention: no spaces before opening parenthesis in '.
+ 'function and method declarations.'),
+ $leading_text,
+ '');
+ }
+
if (preg_match('/^\s+$/', $trailing_text)) {
$this->raiseLintAtOffset(
$last->getOffset() - strlen($trailing_text),

File Metadata

Mime Type
text/plain
Expires
Thu, Apr 24, 2:23 PM (1 d, 11 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7733919
Default Alt Text
D13675.id.diff (5 KB)

Event Timeline