Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15483150
D10440.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.diff
View Options
diff --git a/.editorconfig b/.editorconfig
--- a/.editorconfig
+++ b/.editorconfig
@@ -7,6 +7,9 @@
trim_trailing_whitespace = true
insert_final_newline = true
+[src/lint/linter/__tests__/**.lint-test]
+trim_trailing_whitespace = false
+
[src/parser/__tests__/bundle/*]
trim_trailing_whitespace = false
insert_final_newline = false
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
@@ -53,6 +53,7 @@
const LINT_BLACKLISTED_FUNCTION = 51;
const LINT_IMPLICIT_VISIBILITY = 52;
const LINT_CALL_TIME_PASS_BY_REF = 53;
+ const LINT_ONE_STATEMENT_PER_LINE = 54;
private $blacklistedFunctions = array();
private $naminghook;
@@ -118,6 +119,7 @@
self::LINT_BLACKLISTED_FUNCTION => 'Use of Blacklisted Function',
self::LINT_IMPLICIT_VISIBILITY => 'Implicit Method Visibility',
self::LINT_CALL_TIME_PASS_BY_REF => 'Call-Time Pass-By-Reference',
+ self::LINT_ONE_STATEMENT_PER_LINE => 'One Statement Per Line',
);
}
@@ -160,6 +162,7 @@
self::LINT_ARRAY_SEPARATOR => $advice,
self::LINT_CONSTRUCTOR_PARENTHESES => $advice,
self::LINT_IMPLICIT_VISIBILITY => $advice,
+ self::LINT_ONE_STATEMENT_PER_LINE => $advice,
);
}
@@ -216,7 +219,7 @@
public function getVersion() {
// The version number should be incremented whenever a new rule is added.
- return '15';
+ return '16';
}
protected function resolveFuture($path, Future $future) {
@@ -293,6 +296,7 @@
'lintMethodModifier' => self::LINT_IMPLICIT_VISIBILITY,
'lintPropertyModifier' => self::LINT_IMPLICIT_VISIBILITY,
'lintCallTimePassByReference' => self::LINT_CALL_TIME_PASS_BY_REF,
+ 'lintStatements' => self::LINT_ONE_STATEMENT_PER_LINE,
);
foreach ($method_codes as $method => $codes) {
@@ -3101,6 +3105,33 @@
}
}
+ protected function lintStatements(XHPASTNode $root) {
+ $statements = $root->selectDescendantsOfType('n_STATEMENT');
+
+ $line = null;
+ $indent = '';
+
+ 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();
+
+ foreach ($before as $token) {
+ if (preg_match("/\n/", $token->getValue())) {
+ $indent = '';
+ }
+ $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
Details
Attached
Mime Type
text/plain
Expires
Thu, Apr 10, 10:17 AM (5 d, 18 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7383597
Default Alt Text
D10440.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