]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Allow Script-and-Regex linter to have optional/empty capturing patterns for char...
authorepriestley <git@epriestley.com>
Mon, 19 Oct 2015 21:35:14 +0000 (14:35 -0700)
committerepriestley <git@epriestley.com>
Mon, 19 Oct 2015 21:35:14 +0000 (14:35 -0700)
Summary:
See discussion in D13737. If you're using this linter to match messages which //sometimes// have a character, you can get `""` (empty string) matches when the expression doesn't match. We'll complain about these later.

Instead, cast the matches the expected types.

Test Plan: @csilvers confirmed fix, see D13737.

Reviewers: chad, csilvers

Reviewed By: csilvers

Subscribers: spicyj, csilvers

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

src/lint/linter/ArcanistScriptAndRegexLinter.php

index 70ce944a5250899315ee18019b15b6b6c46e3b2a..ca8883cbbbe79413ae8242134814860f08360621 100644 (file)
@@ -324,7 +324,7 @@ final class ArcanistScriptAndRegexLinter extends ArcanistLinter {
    * Get the line and character of the message from the regex match.
    *
    * @param dict Captured groups from regex.
-   * @return pair<int,int> Line and character of the message.
+   * @return pair<int,int|null> Line and character of the message.
    *
    * @task parse
    */
@@ -336,8 +336,19 @@ final class ArcanistScriptAndRegexLinter extends ArcanistLinter {
       return array($line + 1, $char + 1);
     }
 
-    $line = idx($match, 'line', 1);
+    $line = idx($match, 'line');
+    if ($line) {
+      $line = (int)$line;
+    } else {
+      $line = 1;
+    }
+
     $char = idx($match, 'char');
+    if ($char) {
+      $char = (int)$char;
+    } else {
+      $char = null;
+    }
 
     return array($line, $char);
   }