Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15396031
D10440.id25130.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D10440.id25130.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
@@ -46,6 +46,7 @@
const LINT_CONCATENATION_OPERATOR = 44;
const LINT_PHP_COMPATIBILITY = 45;
const LINT_LANGUAGE_CONSTRUCT_PAREN = 46;
+ const LINT_ONE_STATEMENT_PER_LINE = 47;
private $naminghook;
private $switchhook;
@@ -103,6 +104,7 @@
self::LINT_CONCATENATION_OPERATOR => 'Concatenation Spacing',
self::LINT_PHP_COMPATIBILITY => 'PHP Compatibility',
self::LINT_LANGUAGE_CONSTRUCT_PAREN => 'Language Construct Parentheses',
+ self::LINT_ONE_STATEMENT_PER_LINE => 'One Statement Per Line',
);
}
@@ -141,6 +143,7 @@
self::LINT_SEMICOLON_SPACING => $advice,
self::LINT_CONCATENATION_OPERATOR => $warning,
self::LINT_LANGUAGE_CONSTRUCT_PAREN => $warning,
+ self::LINT_ONE_STATEMENT_PER_LINE => $advice,
);
}
@@ -255,6 +258,7 @@
'lintStrings' => self::LINT_DOUBLE_QUOTE,
'lintElseIfStatements' => self::LINT_ELSEIF_USAGE,
'lintSemicolons' => self::LINT_SEMICOLON_SPACING,
+ 'lintStatements' => self::LINT_ONE_STATEMENT_PER_LINE,
'lintSpaceAroundConcatenationOperators' =>
self::LINT_CONCATENATION_OPERATOR,
'lintPHPCompatibility' => self::LINT_PHP_COMPATIBILITY,
@@ -2525,6 +2529,39 @@
}
}
+ protected function lintStatements(XHPASTNode $root) {
+ $statement_lists = $root->selectDescendantsOfType('n_STATEMENT_LIST');
+
+ foreach ($statement_lists as $statement_list) {
+ $line = null;
+ $indent = null;
+ $children = $statement_list->getChildren();
+
+ foreach ($children as $child) {
+ if ($child->getTypeName() != 'n_STATEMENT') {
+ continue;
+ }
+
+ if ($line == $child->getLineNumber()) {
+ $this->raiseLintAtNode(
+ $child,
+ self::LINT_ONE_STATEMENT_PER_LINE,
+ pht('Multiple statements on a single line.'),
+ "\n".$indent.$child->getConcreteString());
+ }
+
+ $line = $child->getLineNumber();
+
+ list($before, $after) = $child->getSurroundingNonsemanticTokens();
+
+ $indent = '';
+ foreach ($before as $token) {
+ $indent .= preg_replace("/^\s*\n/", '', $token->getValue());
+ }
+ }
+ }
+ }
+
protected function lintLanguageConstructParentheses(XHPASTNode $root) {
$nodes = $root->selectDescendantsOfTypes(array(
'n_INCLUDE_FILE',
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();
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Mar 17, 11:21 AM (4 d, 16 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7708304
Default Alt Text
D10440.id25130.diff (3 KB)
Attached To
Mode
D10440: Add an XHPAST linter rule to ensure that only one statement exists per line
Attached
Detach File
Event Timeline
Log In to Comment