1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-12-23 14:00:55 +01:00

Raise lint warning on missing space after comma

Summary: Saw this in a diff somewhere; complain about it.

Test Plan: Unit coverage.

Reviewers: btrahan, vrana, jungejason

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T1060

Differential Revision: https://secure.phabricator.com/D2153
This commit is contained in:
epriestley 2012-04-08 16:09:11 -07:00
parent f346ab7f9a
commit 2c599f8928
2 changed files with 45 additions and 21 deletions

View file

@ -1333,14 +1333,14 @@ final class ArcanistXHPASTLinter extends ArcanistLinter {
}
protected function lintSpaceAroundBinaryOperators($root) {
// NOTE: '.' is parsed as n_CONCATENATION_LIST, not n_BINARY_EXPRESSION,
// so we don't select it here.
$expressions = $root->selectDescendantsOfType('n_BINARY_EXPRESSION');
foreach ($expressions as $expression) {
$operator = $expression->getChildByIndex(1);
$operator_value = $operator->getConcreteString();
if ($operator_value == '.') {
// TODO: implement this check
continue;
} else {
list($before, $after) = $operator->getSurroundingNonsemanticTokens();
$replace = null;
@ -1361,9 +1361,30 @@ final class ArcanistXHPASTLinter extends ArcanistLinter {
$replace);
}
}
$tokens = $root->selectTokensOfType(',');
foreach ($tokens as $token) {
$next = $token->getNextToken();
switch ($next->getTypeName()) {
case ')':
case 'T_WHITESPACE':
break;
break;
default:
$this->raiseLintAtToken(
$token,
self::LINT_BINARY_EXPRESSION_SPACING,
'Convention: comma should be followed by space.',
', ');
break;
}
}
// TODO: Spacing around ".".
// TODO: Spacing around default parameter assignment in function/method
// declarations (which is not n_BINARY_EXPRESSION).
}
protected function lintDynamicDefines($root) {
$calls = $root->selectDescendantsOfType('n_FUNCTION_CALL');
foreach ($calls as $call) {

View file

@ -21,6 +21,7 @@ $prev = ($total == 1) ? $navids[0] : $navids[$total-1];
$next = ($total == 1) ? $navids[0] : $navids[$current+1];
if ($x instanceof z &&$w) { }
if ($x instanceof z && $w) { }
f(1,2);
~~~~~~~~~~
warning:3:3
warning:4:4
@ -33,6 +34,7 @@ warning:11:3
warning:20:52
warning:21:54
warning:22:21
warning:24:4
~~~~~~~~~~
<?php
$a + $b;
@ -57,3 +59,4 @@ $prev = ($total == 1) ? $navids[0] : $navids[$total - 1];
$next = ($total == 1) ? $navids[0] : $navids[$current + 1];
if ($x instanceof z && $w) { }
if ($x instanceof z && $w) { }
f(1, 2);