Page MenuHomePhabricator

D10440.id25105.diff
No OneTemporary

D10440.id25105.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
@@ -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,
);
}
@@ -254,7 +257,10 @@
'lintKeywordCasing' => self::LINT_KEYWORD_CASING,
'lintStrings' => self::LINT_DOUBLE_QUOTE,
'lintElseIfStatements' => self::LINT_ELSEIF_USAGE,
- 'lintSemicolons' => self::LINT_SEMICOLON_SPACING,
+ 'lintSemicolons' => array(
+ self::LINT_SEMICOLON_SPACING,
+ self::LINT_ONE_STATEMENT_PER_LINE,
+ ),
'lintSpaceAroundConcatenationOperators' =>
self::LINT_CONCATENATION_OPERATOR,
'lintPHPCompatibility' => self::LINT_PHP_COMPATIBILITY,
@@ -2514,6 +2520,7 @@
foreach ($tokens as $token) {
$prev = $token->getPrevToken();
+ $next = $token->getNextToken();
if ($prev->isAnyWhitespace()) {
$this->raiseLintAtToken(
@@ -2522,6 +2529,24 @@
pht('Space found before semicolon.'),
'');
}
+
+ $fail = null;
+ for ($fail === null; $next = $next->getNextToken();) {
+ if (strpos($next->getValue(), "\n") !== false) {
+ break;
+ }
+
+ if ($next->isSemantic()) {
+ $fail = $next;
+ }
+ }
+
+ if ($fail) {
+ $this->raiseLintAtToken(
+ $fail,
+ self::LINT_ONE_STATEMENT_PER_LINE,
+ pht('Multiple statements on a single line.'));
+ }
}
}
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,5 @@
+<?php
+foo(); bar(); baz();
+~~~~~~~~~~
+advice:2:8
+advice:2:15

File Metadata

Mime Type
text/plain
Expires
May 10 2024, 9:05 PM (5 w, 3 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6284122
Default Alt Text
D10440.id25105.diff (2 KB)

Event Timeline