1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-21 22:32:41 +01:00

Improve array comma rule

Summary: Improve `ArcanistXHPASTLinter::LINT_ARRAY_SEPARATOR` in handling multi-line arrays, see D12280 and D12281 for example.  Depends on D12295.

Test Plan: Updated unit tests.

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: Korvin, epriestley

Differential Revision: https://secure.phabricator.com/D12296
This commit is contained in:
Joshua Spence 2015-04-07 07:51:52 +10:00
parent 4b2d8e3f69
commit 3a5ffdc2fd
2 changed files with 37 additions and 5 deletions

View file

@ -2951,11 +2951,23 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
continue; continue;
} }
$this->raiseLintAtNode( list($before, $after) = $value->getSurroundingNonsemanticTokens();
$value, $after = implode('', mpull($after, 'getValue'));
$original = $value->getConcreteString();
$replacement = $value->getConcreteString().',';
if (strpos($after, "\n") === false) {
$original .= $after;
$replacement .= rtrim($after)."\n".$array->getIndentation();
}
$this->raiseLintAtOffset(
$value->getOffset(),
self::LINT_ARRAY_SEPARATOR, self::LINT_ARRAY_SEPARATOR,
pht('Multi-lined arrays should have trailing commas.'), pht('Multi-lined arrays should have trailing commas.'),
$value->getConcreteString().','); $original,
$replacement);
} else if (!$multiline && $after && $after->getValue() == ',') { } else if (!$multiline && $after && $after->getValue() == ',') {
$this->raiseLintAtToken( $this->raiseLintAtToken(
$after, $after,

View file

@ -9,7 +9,7 @@ array(
array( array(
1, 1,
2, 2,
3 3 // comment
); );
array( array(
'foo', 'foo',
@ -20,10 +20,20 @@ array(
This is some heredoc text. This is some heredoc text.
EOTEXT EOTEXT
); );
array(
1,
2,
3);
array(
1,
2,
3 /* comment */ );
~~~~~~~~~~ ~~~~~~~~~~
advice:3:14 advice:3:14
advice:12:3 advice:12:3
advice:16:3 advice:16:3
advice:26:3
advice:30:3
~~~~~~~~~~ ~~~~~~~~~~
<?php <?php
array(1, 2, 3); array(1, 2, 3);
@ -36,7 +46,7 @@ array(
array( array(
1, 1,
2, 2,
3, 3, // comment
); );
array( array(
'foo', 'foo',
@ -47,3 +57,13 @@ array(
This is some heredoc text. This is some heredoc text.
EOTEXT EOTEXT
); );
array(
1,
2,
3,
);
array(
1,
2,
3, /* comment */
);