Page MenuHomePhabricator

D10440.id26636.diff
No OneTemporary

D10440.id26636.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
@@ -49,6 +49,7 @@
const LINT_EMPTY_STATEMENT = 47;
const LINT_ARRAY_SEPARATOR = 48;
const LINT_CONSTRUCTOR_PARENTHESES = 49;
+ const LINT_ONE_STATEMENT_PER_LINE = 50;
private $naminghook;
private $switchhook;
@@ -109,6 +110,7 @@
self::LINT_EMPTY_STATEMENT => 'Empty Block Statement',
self::LINT_ARRAY_SEPARATOR => 'Array Separator',
self::LINT_CONSTRUCTOR_PARENTHESES => 'Constructor Parentheses',
+ self::LINT_ONE_STATEMENT_PER_LINE => 'One Statement Per Line',
);
}
@@ -150,6 +152,7 @@
self::LINT_EMPTY_STATEMENT => $advice,
self::LINT_ARRAY_SEPARATOR => $advice,
self::LINT_CONSTRUCTOR_PARENTHESES => $advice,
+ self::LINT_ONE_STATEMENT_PER_LINE => $advice,
);
}
@@ -199,7 +202,7 @@
public function getVersion() {
// The version number should be incremented whenever a new rule is added.
- return '10';
+ return '11';
}
protected function resolveFuture($path, Future $future) {
@@ -271,6 +274,7 @@
'lintEmptyBlockStatements' => self::LINT_EMPTY_STATEMENT,
'lintArraySeparator' => self::LINT_ARRAY_SEPARATOR,
'lintConstructorParentheses' => self::LINT_CONSTRUCTOR_PARENTHESES,
+ 'lintStatements' => self::LINT_ONE_STATEMENT_PER_LINE,
);
foreach ($method_codes as $method => $codes) {
@@ -2868,6 +2872,31 @@
}
}
+ protected function lintStatements(XHPASTNode $root) {
+ $statements = $root->selectDescendantsOfType('n_STATEMENT');
+
+ $line = null;
+ $indent = null;
+
+ foreach ($statements as $statement) {
+ if ($line == $statement->getLineNumber()) {
+ $this->raiseLintAtNode(
+ $statement,
+ self::LINT_ONE_STATEMENT_PER_LINE,
+ pht('Multiple statements on a single line.'),
+ "\n".$indent.$statement->getConcreteString());
+ }
+
+ $line = $statement->getLineNumber();
+ list($before, $after) = $statement->getSurroundingNonsemanticTokens();
+
+ $indent = '';
+ foreach ($before as $token) {
+ $indent .= preg_replace("/^\s*\n/", '', $token->getValue());
+ }
+ }
+ }
+
public function getSuperGlobalNames() {
return array(
'$GLOBALS',
diff --git a/src/lint/linter/__tests__/xhpast/one-statement-per-line.lint-test b/src/lint/linter/__tests__/xhpast/one-statement-per-line.lint-test
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/__tests__/xhpast/one-statement-per-line.lint-test
@@ -0,0 +1,20 @@
+<?php
+foo(); bar(); baz();
+function x() {
+ foo(); bar(); baz();
+}
+~~~~~~~~~~
+advice:2:8
+advice:2:15
+advice:4:10
+advice:4:17
+~~~~~~~~~~
+<?php
+foo();
+bar();
+baz();
+function x() {
+ foo();
+ bar();
+ baz();
+}
diff --git a/src/lint/linter/__tests__/xhpast/switches.lint-test b/src/lint/linter/__tests__/xhpast/switches.lint-test
--- a/src/lint/linter/__tests__/xhpast/switches.lint-test
+++ b/src/lint/linter/__tests__/xhpast/switches.lint-test
@@ -89,6 +89,10 @@
warning:53:3
warning:57:3
warning:66:3
+advice:67:20
+advice:68:20
+advice:69:21
+advice:69:43
warning:71:3
warning:75:3
~~~~~~~~~~

File Metadata

Mime Type
text/plain
Expires
Fri, Apr 11, 10:56 AM (3 d, 21 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7739724
Default Alt Text
D10440.id26636.diff (3 KB)

Event Timeline