]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Fix ArcanistCSSLintLinter issue for messages without line number
authorSébastien Santoro <dereckson@espace-win.org>
Tue, 17 Nov 2015 15:14:13 +0000 (07:14 -0800)
committerepriestley <git@epriestley.com>
Tue, 17 Nov 2015 15:14:13 +0000 (07:14 -0800)
Summary:
csslint offers some diagnostics related to all the document without any
relevant line number.

In such case, arc lint failed, as setLine expects null or an integer,
but not an empty string.

The 'char' and 'line' attributes in XML report are now optional.

Fixes T9804.

Test Plan: test case to repro the issue added

Reviewers: chad, joshuaspence, #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: Korvin

Maniphest Tasks: T9804

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

src/lint/linter/ArcanistCSSLintLinter.php
src/lint/linter/__tests__/csslint/no-line-related-issue.lint-test [new file with mode: 0644]

index a75839598a85ebf7a96d6418e50ff48cea4a7d08..e8fd3546935c4f391735573251bed849b3696f06 100644 (file)
@@ -67,17 +67,28 @@ final class ArcanistCSSLintLinter extends ArcanistExternalLinter {
 
     foreach ($files as $file) {
       foreach ($file->childNodes as $child) {
+        $line = $child->getAttribute('line');
+        $char = $child->getAttribute('char');
+        $original_text = $child->getAttribute('evidence');
+
+        if ($line === '') {
+          $line = null;
+        }
+
+        if ($char === '') {
+          $char = null;
+        } else {
+          $original_text = substr($original_text, $char - 1);
+        }
+
         $message = id(new ArcanistLintMessage())
           ->setPath($path)
-          ->setLine($child->getAttribute('line'))
-          ->setChar($child->getAttribute('char'))
+          ->setLine($line)
+          ->setChar($char)
           ->setCode($this->getLinterName())
           ->setName($this->getLinterName())
           ->setDescription($child->getAttribute('reason'))
-          ->setOriginalText(
-            substr(
-              $child->getAttribute('evidence'),
-              $child->getAttribute('char') - 1));
+          ->setOriginalText($original_text);
 
         switch ($child->getAttribute('severity')) {
           case 'error':
diff --git a/src/lint/linter/__tests__/csslint/no-line-related-issue.lint-test b/src/lint/linter/__tests__/csslint/no-line-related-issue.lint-test
new file mode 100644 (file)
index 0000000..409e2a0
--- /dev/null
@@ -0,0 +1,9 @@
+h1 {
+  font-weight: bold;
+}
+h1 {
+  font-weight: bold;
+}
+~~~~~~~~~~
+warning::
+warning:4:1