1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-09-19 16:38:51 +02: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:
Joshua Spence 2015-05-20 07:05:34 +10:00
parent 25855c4427
commit 993166fa49
3 changed files with 43 additions and 23 deletions

View file

@ -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

View file

@ -3223,7 +3223,8 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
$value = last($values);
$after = last($value->getTokens())->getNextToken();
if ($multiline && (!$after || $after->getValue() != ',')) {
if ($multiline) {
if (!$after || $after->getValue() != ',') {
if ($value->getChildByIndex(1)->getTypeName() == 'n_HEREDOC') {
continue;
}
@ -3236,7 +3237,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
if (strpos($after, "\n") === false) {
$original .= $after;
$replacement .= rtrim($after)."\n".$array->getIndentation();
$replacement .= $after."\n".$array->getIndentation();
}
$this->raiseLintAtOffset(
@ -3245,7 +3246,16 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
pht('Multi-lined arrays should have trailing commas.'),
$original,
$replacement);
} else if (!$multiline && $after && $after->getValue() == ',') {
} 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());
}
} else if ($after && $after->getValue() == ',') {
$this->raiseLintAtToken(
$after,
self::LINT_ARRAY_SEPARATOR,

View file

@ -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 */
);