From: Sébastien Santoro Date: Tue, 17 Nov 2015 15:14:13 +0000 (-0800) Subject: Fix ArcanistCSSLintLinter issue for messages without line number X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=b25cf080bc55d01e6a381bc22a331ad281b51516;p=arcanist.git Fix ArcanistCSSLintLinter issue for messages without line number 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 --- diff --git a/src/lint/linter/ArcanistCSSLintLinter.php b/src/lint/linter/ArcanistCSSLintLinter.php index a7583959..e8fd3546 100644 --- a/src/lint/linter/ArcanistCSSLintLinter.php +++ b/src/lint/linter/ArcanistCSSLintLinter.php @@ -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 index 00000000..409e2a05 --- /dev/null +++ b/src/lint/linter/__tests__/csslint/no-line-related-issue.lint-test @@ -0,0 +1,9 @@ +h1 { + font-weight: bold; +} +h1 { + font-weight: bold; +} +~~~~~~~~~~ +warning:: +warning:4:1