]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Improve strictness around `setLine()` types in ArcanistLintMessage
authorepriestley <git@epriestley.com>
Thu, 23 Jul 2015 20:19:53 +0000 (13:19 -0700)
committerepriestley <git@epriestley.com>
Thu, 23 Jul 2015 20:19:53 +0000 (13:19 -0700)
Summary: Fixes T8921. Harbormaster is strict about types it accepts, but `ArcanistLintMessage` is more liberal. Push the strictness barrier down to the linter level, while maintaining reasonable flexibility in the API.

Test Plan: `arc unit --everything`

Reviewers: btrahan, chad

Reviewed By: chad

Subscribers: epriestley

Maniphest Tasks: T8921

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

src/lint/ArcanistLintMessage.php

index 8d7eb78b47ef9b339a9ff5669b0e4f09b77c52e8..4050202042bf2974a0d4538f4a40a4305703dabd 100644 (file)
@@ -72,6 +72,23 @@ final class ArcanistLintMessage extends Phobject {
   }
 
   public function setLine($line) {
+    if ($line === null) {
+      // This just means that we don't have any line information.
+    } else {
+      // For compatibility, accept digit strings since a lot of linters pass
+      // line numbers that they have parsed from command output or XML, which
+      // won't be properly typed.
+      if (is_string($line) && preg_match('/^\d+\z/', $line)) {
+        $line = (int)$line;
+      }
+
+      if (!is_int($line)) {
+        throw new Exception(
+          pht(
+            'Parameter passed to setLine() must be an integer.'));
+      }
+    }
+
     $this->line = $line;
     return $this;
   }