]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Improve parsing of `csslint` output
authorJoshua Spence <josh@joshuaspence.com>
Sun, 11 Jan 2015 19:47:51 +0000 (06:47 +1100)
committerJoshua Spence <josh@joshuaspence.com>
Sun, 11 Jan 2015 19:47:51 +0000 (06:47 +1100)
Summary: `csslint` returns an `evidence` field which contains the line of the "original text" which produced the linter message (see https://github.com/CSSLint/csslint/blob/5dd84b259b90c5ea8adbaf03d31e9df093cc3dcd/src/core/Reporter.js#L64). We can use this data instead of trying to achieve the same result using `$this->getData($path)`.

Test Plan: {F265449}

Reviewers: chad, #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: Korvin, epriestley

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

src/lint/linter/ArcanistCSSLintLinter.php
src/lint/linter/__tests__/csslint/parse-error.lint-test [new file with mode: 0644]

index 10ecf4613be307d74ed7a658f622cd6bfbf0b511..7733393c250c62134003db89ad593e3d21501f91 100644 (file)
@@ -75,25 +75,29 @@ final class ArcanistCSSLintLinter extends ArcanistExternalLinter {
 
     foreach ($files as $file) {
       foreach ($file->childNodes as $child) {
-        $data = $this->getData($path);
-        $lines = explode("\n", $data);
-        $name = $child->getAttribute('reason');
-        $severity = ($child->getAttribute('severity') == 'warning')
-          ? ArcanistLintSeverity::SEVERITY_WARNING
-          : ArcanistLintSeverity::SEVERITY_ERROR;
-
         $message = id(new ArcanistLintMessage())
           ->setPath($path)
           ->setLine($child->getAttribute('line'))
           ->setChar($child->getAttribute('char'))
-          ->setCode('CSSLint')
-          ->setSeverity($severity)
-          ->setDescription($child->getAttribute('reason'));
-
-        if ($child->hasAttribute('line') && $child->getAttribute('line') > 0) {
-          $line = $lines[$child->getAttribute('line') - 1];
-          $text = substr($line, $child->getAttribute('char') - 1);
-          $message->setOriginalText($text);
+          ->setCode($this->getLinterName())
+          ->setDescription($child->getAttribute('reason'))
+          ->setOriginalText(
+            substr(
+              $child->getAttribute('evidence'),
+              $child->getAttribute('char') - 1));
+
+        switch ($child->getAttribute('severity')) {
+          case 'error':
+            $message->setSeverity(ArcanistLintSeverity::SEVERITY_ERROR);
+            break;
+
+          case 'warning':
+            $message->setSeverity(ArcanistLintSeverity::SEVERITY_WARNING);
+            break;
+
+          default:
+            $message->setSeverity(ArcanistLintSeverity::SEVERITY_ERROR);
+            break;
         }
 
         $messages[] = $message;
diff --git a/src/lint/linter/__tests__/csslint/parse-error.lint-test b/src/lint/linter/__tests__/csslint/parse-error.lint-test
new file mode 100644 (file)
index 0000000..0927205
--- /dev/null
@@ -0,0 +1,6 @@
+li {
+  float: left;
+  float left;
+}
+~~~~~~~~~~
+error:3:9