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;
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',
);
}
self::LINT_ELSEIF_USAGE => $advice,
self::LINT_SEMICOLON_SPACING => $advice,
self::LINT_CONCATENATION_OPERATOR => $warning,
+ self::LINT_LANGUAGE_CONSTRUCT_PAREN => $warning,
);
}
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) {
'lintSpaceAroundConcatenationOperators' =>
self::LINT_CONCATENATION_OPERATOR,
'lintPHPCompatibility' => self::LINT_PHP_COMPATIBILITY,
+ 'lintLanguageConstructParentheses' => self::LINT_LANGUAGE_CONSTRUCT_PAREN,
);
foreach ($method_codes as $method => $codes) {
}
}
+ 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') {
+ list($before, $after) = $child->getSurroundingNonsemanticTokens();
+
+ $replace = preg_replace(
+ '/^\((.*)\)$/',
+ '$1',
+ $child->getConcreteString());
+
+ if (!$before) {
+ $replace = ' '.$replace;
+ }
+
+ $this->raiseLintAtNode(
+ $child,
+ self::LINT_LANGUAGE_CONSTRUCT_PAREN,
+ pht('Language constructs do not require parentheses.'),
+ $replace);
+ }
+ }
+ }
+
public function getSuperGlobalNames() {
return array(
'$GLOBALS',