]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Minor improvement for array value linter rule
authorJoshua Spence <josh@joshuaspence.com>
Mon, 10 Aug 2015 21:55:11 +0000 (07:55 +1000)
committerJoshua Spence <josh@joshuaspence.com>
Mon, 10 Aug 2015 21:55:11 +0000 (07:55 +1000)
Summary:
This linter rule fails on multi-line arrays with no whitespace before the first array value. Specifically, the following exception is thrown:

```
Fatal error: Call to a member function isAnyWhitespace() on boolean in arcanist/src/lint/linter/xhpast/rules/ArcanistArrayValueXHPASTLinterRule.php on line 40
```

Test Plan: Added another test case.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: Korvin

Differential Revision: https://secure.phabricator.com/D13856

src/lint/linter/__tests__/xhpast/array-value.lint-test
src/lint/linter/xhpast/rules/ArcanistArrayValueXHPASTLinterRule.php

index a13397983037c5d94dceae75f57e40e48c90e18c..9ab10ad7a6d29c601711f07aa8c08697803f94e5 100644 (file)
@@ -16,12 +16,16 @@ array(
   /* OPEN   */ 1,
   /* CLOSED */ 2,
 );
+
+array('quack',
+);
 ~~~~~~~~~~
 warning:4:5
 warning:4:8
 warning:8:18
 warning:12:17
 warning:12:32
+warning:20:7
 ~~~~~~~~~~
 <?php
 
@@ -46,3 +50,7 @@ array(
   /* OPEN   */ 1,
   /* CLOSED */ 2,
 );
+
+array(
+'quack',
+);
index 21f5092863013b5c00dae4ba4a8e882d588ce900..6b960d74dc9eb8293b58eebf33fc20b4b0b6b71f 100644 (file)
@@ -36,7 +36,7 @@ final class ArcanistArrayValueXHPASTLinterRule
         list($before, $after) = $value->getSurroundingNonsemanticTokens();
 
         if (strpos(implode('', mpull($before, 'getValue')), "\n") === false) {
-          if (last($before)->isAnyWhitespace()) {
+          if (last($before) && last($before)->isAnyWhitespace()) {
             $token = last($before);
             $replacement = "\n".$value->getIndentation();
           } else {