Page MenuHomePhabricator

D10122.id24348.diff
No OneTemporary

D10122.id24348.diff

diff --git a/src/lint/linter/ArcanistXHPASTLinter.php b/src/lint/linter/ArcanistXHPASTLinter.php
--- a/src/lint/linter/ArcanistXHPASTLinter.php
+++ b/src/lint/linter/ArcanistXHPASTLinter.php
@@ -45,6 +45,7 @@
const LINT_SEMICOLON_SPACING = 43;
const LINT_CONCATENATION_OPERATOR = 44;
const LINT_PHP_COMPATIBILITY = 45;
+ const LINT_LANGUAGE_CONSTRUCT_PAREN = 46;
private $naminghook;
private $switchhook;
@@ -101,6 +102,7 @@
self::LINT_SEMICOLON_SPACING => 'Semicolon Spacing',
self::LINT_CONCATENATION_OPERATOR => 'Concatenation Spacing',
self::LINT_PHP_COMPATIBILITY => 'PHP Compatibility',
+ self::LINT_LANGUAGE_CONSTRUCT_PAREN => 'Language Construct Parentheses',
);
}
@@ -138,6 +140,7 @@
self::LINT_ELSEIF_USAGE => $advice,
self::LINT_SEMICOLON_SPACING => $advice,
self::LINT_CONCATENATION_OPERATOR => $warning,
+ self::LINT_LANGUAGE_CONSTRUCT_PAREN => $warning,
);
}
@@ -187,7 +190,7 @@
public function getVersion() {
// The version number should be incremented whenever a new rule is added.
- return '7';
+ return '8';
}
protected function resolveFuture($path, Future $future) {
@@ -255,6 +258,7 @@
'lintSpaceAroundConcatenationOperators' =>
self::LINT_CONCATENATION_OPERATOR,
'lintPHPCompatibility' => self::LINT_PHP_COMPATIBILITY,
+ 'lintLanguageConstructParentheses' => self::LINT_LANGUAGE_CONSTRUCT_PAREN,
);
foreach ($method_codes as $method => $codes) {
@@ -2521,6 +2525,24 @@
}
}
+ protected function lintLanguageConstructParentheses(XHPASTNode $root) {
+ $nodes = $root->selectDescendantsOfTypes(array(
+ 'n_INCLUDE_FILE',
+ 'n_ECHO_LIST',
+ ));
+
+ foreach ($nodes as $node) {
+ $child = head($node->getChildren());
+
+ if ($child->getTypeName() == 'n_PARENTHETICAL_EXPRESSION') {
+ $this->raiseLintAtNode(
+ $child,
+ self::LINT_LANGUAGE_CONSTRUCT_PAREN,
+ pht('Language construct with parentheses.'));
+ }
+ }
+ }
+
public function getSuperGlobalNames() {
return array(
'$GLOBALS',
diff --git a/src/lint/linter/__tests__/xhpast/language-construct-parentheses.lint-test b/src/lint/linter/__tests__/xhpast/language-construct-parentheses.lint-test
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/__tests__/xhpast/language-construct-parentheses.lint-test
@@ -0,0 +1,18 @@
+<?php
+include 'foo.php';
+include_once 'foo.php';
+require 'foo.php';
+require_once 'foo.php';
+echo 'foo';
+
+include('bar.php');
+include_once('bar.php');
+require('bar.php');
+require_once('bar.php');
+echo('bar');
+~~~~~~~~~~
+warning:8:8
+warning:9:13
+warning:10:8
+warning:11:13
+warning:12:5
diff --git a/src/lint/linter/__tests__/xhpast/undeclared-variables.lint-test b/src/lint/linter/__tests__/xhpast/undeclared-variables.lint-test
--- a/src/lint/linter/__tests__/xhpast/undeclared-variables.lint-test
+++ b/src/lint/linter/__tests__/xhpast/undeclared-variables.lint-test
@@ -141,7 +141,7 @@
function x() {
$lib = $_SERVER['PHP_ROOT'].'/lib/titan/display/read/init.php';
- require_once($lib);
+ require_once $lib;
f(((($lib)))); // Tests for paren expressions.
f(((($lub))));
}

File Metadata

Mime Type
text/plain
Expires
Fri, Mar 7, 2:54 AM (2 w, 2 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7315634
Default Alt Text
D10122.id24348.diff (3 KB)

Event Timeline