Page MenuHomePhabricator

D10571.diff
No OneTemporary

D10571.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
@@ -890,6 +890,18 @@
}
}
}
+
+ $nodes = $root->selectDescendantsOfType('n_STATEMENT');
+ foreach ($nodes as $node) {
+ $parent = $node->getParentNode();
+
+ if ($parent && $parent->getTypeName() != 'n_STATEMENT_LIST') {
+ $this->raiseLintAtNode(
+ $node,
+ self::LINT_BRACE_FORMATTING,
+ 'Use braces to surround a statement block.');
+ }
+ }
}
private function lintTautologicalExpressions(XHPASTNode $root) {
diff --git a/src/lint/linter/__tests__/xhpast/conditional-usage.lint-test b/src/lint/linter/__tests__/xhpast/conditional-usage.lint-test
--- a/src/lint/linter/__tests__/xhpast/conditional-usage.lint-test
+++ b/src/lint/linter/__tests__/xhpast/conditional-usage.lint-test
@@ -23,6 +23,7 @@
error:5:3
error:7:3
error:12:7
+warning:16:3
~~~~~~~~~~
~~~~~~~~~~
{"config": {"xhpast.php-version": "5.3.0"}}
diff --git a/src/lint/linter/__tests__/xhpast/creative-brace-use.lint-test b/src/lint/linter/__tests__/xhpast/creative-brace-use.lint-test
--- a/src/lint/linter/__tests__/xhpast/creative-brace-use.lint-test
+++ b/src/lint/linter/__tests__/xhpast/creative-brace-use.lint-test
@@ -27,6 +27,9 @@
{}
function h(){}
+if ($x) foo();
+else bar();
+do baz(); while ($x);
~~~~~~~~~~
advice:3:14
warning:7:13
@@ -38,6 +41,9 @@
warning:24:4
warning:26:21
warning:29:13
+warning:30:9
+warning:31:6
+warning:32:4
~~~~~~~~~~
<?php
@@ -57,3 +63,6 @@
catch (Exception $x) {}
function h() {}
+if ($x) foo();
+else bar();
+do baz(); while ($x);
diff --git a/src/lint/linter/__tests__/xhpast/space-after-control-keywords.lint-test b/src/lint/linter/__tests__/xhpast/space-after-control-keywords.lint-test
--- a/src/lint/linter/__tests__/xhpast/space-after-control-keywords.lint-test
+++ b/src/lint/linter/__tests__/xhpast/space-after-control-keywords.lint-test
@@ -14,13 +14,14 @@
if
($x) {}
-if ($x)
+if ($x) {
echo 100;
-else
+} else {
echo 10;
-do
+}
+do {
echo 1;
-while(true);
+} while(true);
~~~~~~~~~~
warning:2:1
warning:3:1
@@ -32,7 +33,7 @@
warning:8:1
warning:13:3
warning:14:3
-warning:23:1
+warning:24:3
~~~~~~~~~~
<?php
if ($x) {}
@@ -48,10 +49,11 @@
if ($x) {}
if ($x) {}
-if ($x)
+if ($x) {
echo 100;
-else
+} else {
echo 10;
-do
+}
+do {
echo 1;
-while (true);
+} while (true);

File Metadata

Mime Type
text/plain
Expires
Fri, Oct 25, 9:05 AM (2 w, 4 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6722429
Default Alt Text
D10571.diff (2 KB)

Event Timeline