Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F13967585
D10571.id26279.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D10571.id26279.diff
View Options
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
Details
Attached
Mime Type
text/plain
Expires
Thu, Oct 17, 2:37 PM (3 w, 5 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6722429
Default Alt Text
D10571.id26279.diff (2 KB)
Attached To
Mode
D10571: Extend `LINT_BRACE_FORMATTING` to warn on missing braces
Attached
Detach File
Event Timeline
Log In to Comment