From 395c15e630632c06c3eac64f015521a2e5b85ca2 Mon Sep 17 00:00:00 2001 From: Lajos Veres Date: Tue, 9 Jul 2013 12:46:59 +0100 Subject: [PATCH 1/3] add css lint --- src/lint/engine/ComprehensiveLintEngine.php | 3 + src/lint/linter/ArcanistCSSLintLinter.php | 122 ++++++++++++++++++++ 2 files changed, 125 insertions(+) create mode 100644 src/lint/linter/ArcanistCSSLintLinter.php diff --git a/src/lint/engine/ComprehensiveLintEngine.php b/src/lint/engine/ComprehensiveLintEngine.php index e8a104d2..c138e0c2 100644 --- a/src/lint/engine/ComprehensiveLintEngine.php +++ b/src/lint/engine/ComprehensiveLintEngine.php @@ -48,6 +48,9 @@ final class ComprehensiveLintEngine extends ArcanistLintEngine { $linters[] = id(new ArcanistJSHintLinter()) ->setPaths(preg_grep('/\.js$/', $paths)); + $linters[] = id(new ArcanistCSSLintLinter()) + ->setPaths(preg_grep('/\.css$/', $paths)); + return $linters; } diff --git a/src/lint/linter/ArcanistCSSLintLinter.php b/src/lint/linter/ArcanistCSSLintLinter.php new file mode 100644 index 00000000..fa336374 --- /dev/null +++ b/src/lint/linter/ArcanistCSSLintLinter.php @@ -0,0 +1,122 @@ +getEngine()->getWorkingCopy(); + + $options = $working_copy->getConfig('lint.csslint.options'); + + return $options; + } + + private function getCSSLintPath() { + $working_copy = $this->getEngine()->getWorkingCopy(); + $bin = $working_copy->getConfig('lint.csslint.bin'); + + if ($bin === null) { + $bin = 'csslint'; + } + + return $bin; + } + + public function willLintPaths(array $paths) { + $csslint_bin = $this->getCSSLintPath(); + $csslint_options = $this->getCSSLintOptions(); + $futures = array(); + + foreach ($paths as $path) { + $filepath = $this->getEngine()->getFilePathOnDisk($path); + $this->reports[$path] = new TempFile(); + $futures[$path] = new ExecFuture('%C %C --format=lint-xml >%s %s', + $csslint_bin, + $csslint_options, + $this->reports[$path], + $filepath); + } + + foreach (Futures($futures)->limit(8) as $path => $future) { + $this->results[$path] = $future->resolve(); + } + + libxml_use_internal_errors(true); + } + + public function lintPath($path) { + list($rc, $stdout) = $this->results[$path]; + + $report = Filesystem::readFile($this->reports[$path]); + + if ($report) { + $report_dom = new DOMDocument(); + libxml_clear_errors(); + $report_dom->loadXML($report); + } + if (!$report || libxml_get_errors()) { + throw new ArcanistUsageException('CSS Linter failed to load ' . + 'reporting file. Something happened when running csslint. ' . + "Output:\n$stdout" . + "\nTry running lint with --trace flag to get more details."); + } + + $files = $report_dom->getElementsByTagName('file'); + foreach ($files as $file) { + foreach ($file->childNodes as $child) { + if (!($child instanceof DOMElement)) { + continue; + } + + $data = $this->getData($path); + $lines = explode("\n", $data); + $name = $this->getLinterName() . ' - ' . $child->getAttribute('reason'); + $severity = $child->getAttribute('severity') == 'warning' ? + ArcanistLintSeverity::SEVERITY_WARNING + : ArcanistLintSeverity::SEVERITY_ERROR; + + $message = new ArcanistLintMessage(); + $message->setPath($path); + $message->setLine($child->getAttribute('line')); + $message->setChar($child->getAttribute('char')); + $message->setCode($child->getAttribute('severity')); + $message->setName($name); + $message->setDescription($child->getAttribute('reason')."\nEvidence:".$child->getAttribute('evidence')); + $message->setSeverity($severity); + + if($child->hasAttribute('line')){ + $line = $lines[$child->getAttribute('line') - 1]; + $text = substr($line, $child->getAttribute('char') - 1); + $message->setOriginalText($text); + } + $this->addLintMessage($message); + } + } + } +} From 2b07f22e08407df6e8bb14599b37a48862cb59a3 Mon Sep 17 00:00:00 2001 From: Lajos Veres Date: Tue, 9 Jul 2013 12:48:07 +0100 Subject: [PATCH 2/3] update __phutil_library_map__ --- src/__phutil_library_map__.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index a4963e2b..363d9973 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -28,6 +28,7 @@ phutil_register_library_map(array( 'ArcanistBrowseWorkflow' => 'workflow/ArcanistBrowseWorkflow.php', 'ArcanistBundle' => 'parser/ArcanistBundle.php', 'ArcanistBundleTestCase' => 'parser/__tests__/ArcanistBundleTestCase.php', + 'ArcanistCSSLintLinter' => 'lint/linter/ArcanistCSSLintLinter.php', 'ArcanistCallConduitWorkflow' => 'workflow/ArcanistCallConduitWorkflow.php', 'ArcanistCapabilityNotSupportedException' => 'workflow/exception/ArcanistCapabilityNotSupportedException.php', 'ArcanistChooseInvalidRevisionException' => 'exception/ArcanistChooseInvalidRevisionException.php', @@ -189,6 +190,7 @@ phutil_register_library_map(array( 'ArcanistBritishTestCase' => 'ArcanistTestCase', 'ArcanistBrowseWorkflow' => 'ArcanistBaseWorkflow', 'ArcanistBundleTestCase' => 'ArcanistTestCase', + 'ArcanistCSSLintLinter' => 'ArcanistLinter', 'ArcanistCallConduitWorkflow' => 'ArcanistBaseWorkflow', 'ArcanistCapabilityNotSupportedException' => 'Exception', 'ArcanistChooseInvalidRevisionException' => 'Exception', From 2e30c97ade294e81c7ba729e1c8cc92035f008aa Mon Sep 17 00:00:00 2001 From: Lajos Veres Date: Tue, 9 Jul 2013 14:11:21 +0100 Subject: [PATCH 3/3] comment typo fix --- src/lint/linter/ArcanistCSSLintLinter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lint/linter/ArcanistCSSLintLinter.php b/src/lint/linter/ArcanistCSSLintLinter.php index fa336374..54b537ef 100644 --- a/src/lint/linter/ArcanistCSSLintLinter.php +++ b/src/lint/linter/ArcanistCSSLintLinter.php @@ -8,7 +8,7 @@ * * Based on ArcanistPhpcsLinter.php * - * lint.cssling.options + * lint.csslint.options * lint.csslint.bin * * @group linter