Page Menu
Home
GnuPG
Search
Configure Global Search
Log In
Files
F34211982
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Size
3 KB
Subscribers
None
View Options
diff --git a/src/lint/linter/xhpast/rules/ArcanistBraceFormattingXHPASTLinterRule.php b/src/lint/linter/xhpast/rules/ArcanistBraceFormattingXHPASTLinterRule.php
index d2908154..0a8c33b7 100644
--- a/src/lint/linter/xhpast/rules/ArcanistBraceFormattingXHPASTLinterRule.php
+++ b/src/lint/linter/xhpast/rules/ArcanistBraceFormattingXHPASTLinterRule.php
@@ -1,105 +1,112 @@
<?php
final class ArcanistBraceFormattingXHPASTLinterRule
extends ArcanistXHPASTLinterRule {
const ID = 24;
public function getLintName() {
return pht('Brace Placement');
}
public function getLintSeverity() {
return ArcanistLintSeverity::SEVERITY_WARNING;
}
public function process(XHPASTNode $root) {
foreach ($root->selectDescendantsOfType('n_STATEMENT_LIST') as $list) {
$tokens = $list->getTokens();
if (!$tokens || head($tokens)->getValue() != '{') {
continue;
}
list($before, $after) = $list->getSurroundingNonsemanticTokens();
if (!$before) {
$first = head($tokens);
// Only insert the space if we're after a closing parenthesis. If
// we're in a construct like "else{}", other rules will insert space
// after the 'else' correctly.
$prev = $first->getPrevToken();
if (!$prev || $prev->getValue() !== ')') {
continue;
}
$this->raiseLintAtToken(
$first,
pht(
'Put opening braces on the same line as control statements and '.
'declarations, with a single space before them.'),
' '.$first->getValue());
} else if (count($before) === 1) {
$before = reset($before);
if ($before->getValue() !== ' ') {
$this->raiseLintAtToken(
$before,
pht(
'Put opening braces on the same line as control statements and '.
'declarations, with a single space before them.'),
' ');
}
}
}
$nodes = $root->selectDescendantsOfType('n_STATEMENT');
foreach ($nodes as $node) {
$parent = $node->getParentNode();
if (!$parent) {
continue;
}
$type = $parent->getTypeName();
- if ($type != 'n_STATEMENT_LIST' && $type != 'n_DECLARE') {
- $this->raiseLintAtNode(
- $node,
- pht('Use braces to surround a statement block.'));
+ switch ($type) {
+ case 'n_DECLARE':
+ case 'n_NAMESPACE':
+ case 'n_STATEMENT_LIST':
+ break;
+
+ default:
+ $this->raiseLintAtNode(
+ $node,
+ pht('Use braces to surround a statement block.'));
+ break;
}
}
$nodes = $root->selectDescendantsOfTypes(array(
'n_DO_WHILE',
'n_ELSE',
'n_ELSEIF',
));
foreach ($nodes as $list) {
$tokens = $list->getTokens();
if (!$tokens || last($tokens)->getValue() != '}') {
continue;
}
list($before, $after) = $list->getSurroundingNonsemanticTokens();
if (!$before) {
$first = head($tokens);
$this->raiseLintAtToken(
$first,
pht(
'Put opening braces on the same line as control statements and '.
'declarations, with a single space before them.'),
' '.$first->getValue());
} else if (count($before) === 1) {
$before = reset($before);
if ($before->getValue() !== ' ') {
$this->raiseLintAtToken(
$before,
pht(
'Put opening braces on the same line as control statements and '.
'declarations, with a single space before them.'),
' ');
}
}
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Fri, Dec 19, 3:26 AM (1 d, 6 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
84/86/8d5ebce06d50acffa8f299cdcf52
Attached To
rARC Arcanist
Event Timeline
Log In to Comment