mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-21 22:32:41 +01:00
Further improvements to array comma linter rule
Summary: Improve the `ArcanistXHPASTLinter::LINT_ARRAY_SEPARATOR` rule to be able to autofix the following code: ```lang=php array( 1, 2, 3, /* comment */ ); ``` Test Plan: Added unit tests. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: epriestley Differential Revision: https://secure.phabricator.com/D12308
This commit is contained in:
parent
25855c4427
commit
993166fa49
3 changed files with 43 additions and 23 deletions
|
@ -13,7 +13,7 @@ max_line_length = 80
|
|||
indent_style =
|
||||
end_of_line =
|
||||
max_line_length =
|
||||
trim_trailing_whitespace =
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[src/parser/__tests__/bundle/*]
|
||||
insert_final_newline = false
|
||||
|
|
|
@ -3223,29 +3223,39 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
|
|||
$value = last($values);
|
||||
$after = last($value->getTokens())->getNextToken();
|
||||
|
||||
if ($multiline && (!$after || $after->getValue() != ',')) {
|
||||
if ($value->getChildByIndex(1)->getTypeName() == 'n_HEREDOC') {
|
||||
continue;
|
||||
if ($multiline) {
|
||||
if (!$after || $after->getValue() != ',') {
|
||||
if ($value->getChildByIndex(1)->getTypeName() == 'n_HEREDOC') {
|
||||
continue;
|
||||
}
|
||||
|
||||
list($before, $after) = $value->getSurroundingNonsemanticTokens();
|
||||
$after = implode('', mpull($after, 'getValue'));
|
||||
|
||||
$original = $value->getConcreteString();
|
||||
$replacement = $value->getConcreteString().',';
|
||||
|
||||
if (strpos($after, "\n") === false) {
|
||||
$original .= $after;
|
||||
$replacement .= $after."\n".$array->getIndentation();
|
||||
}
|
||||
|
||||
$this->raiseLintAtOffset(
|
||||
$value->getOffset(),
|
||||
self::LINT_ARRAY_SEPARATOR,
|
||||
pht('Multi-lined arrays should have trailing commas.'),
|
||||
$original,
|
||||
$replacement);
|
||||
} else if ($value->getLineNumber() == $array->getEndLineNumber()) {
|
||||
$close = last($array->getTokens());
|
||||
|
||||
$this->raiseLintAtToken(
|
||||
$close,
|
||||
self::LINT_ARRAY_SEPARATOR,
|
||||
pht('Closing parenthesis should be on a new line.'),
|
||||
"\n".$array->getIndentation().$close->getValue());
|
||||
}
|
||||
|
||||
list($before, $after) = $value->getSurroundingNonsemanticTokens();
|
||||
$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,
|
||||
pht('Multi-lined arrays should have trailing commas.'),
|
||||
$original,
|
||||
$replacement);
|
||||
} else if (!$multiline && $after && $after->getValue() == ',') {
|
||||
} else if ($after && $after->getValue() == ',') {
|
||||
$this->raiseLintAtToken(
|
||||
$after,
|
||||
self::LINT_ARRAY_SEPARATOR,
|
||||
|
|
|
@ -28,12 +28,17 @@ array(
|
|||
1,
|
||||
2,
|
||||
3 /* comment */ );
|
||||
array(
|
||||
1,
|
||||
2,
|
||||
3, /* comment */ );
|
||||
~~~~~~~~~~
|
||||
advice:3:14
|
||||
advice:12:3
|
||||
advice:16:3
|
||||
advice:26:3
|
||||
advice:30:3
|
||||
advice:34:20
|
||||
~~~~~~~~~~
|
||||
<?php
|
||||
array(1, 2, 3);
|
||||
|
@ -67,3 +72,8 @@ array(
|
|||
2,
|
||||
3, /* comment */
|
||||
);
|
||||
array(
|
||||
1,
|
||||
2,
|
||||
3, /* comment */
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue