2013-08-02 14:13:23 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Uses "CSS lint" to detect checkstyle errors in css code.
|
|
|
|
* To use this linter, you must install CSS lint.
|
|
|
|
* ##npm install csslint -g## (don't forget the -g flag or NPM will install
|
|
|
|
* the package locally).
|
|
|
|
*
|
|
|
|
* Based on ArcanistPhpcsLinter.php
|
|
|
|
*
|
|
|
|
* lint.csslint.options
|
|
|
|
* lint.csslint.bin
|
|
|
|
*
|
|
|
|
* @group linter
|
|
|
|
*/
|
2013-08-23 20:52:44 +02:00
|
|
|
final class ArcanistCSSLintLinter extends ArcanistExternalLinter {
|
2013-08-02 14:13:23 +02:00
|
|
|
|
|
|
|
public function getLinterName() {
|
|
|
|
return 'CSSLint';
|
|
|
|
}
|
|
|
|
|
2013-08-23 20:52:44 +02:00
|
|
|
public function getMandatoryFlags() {
|
|
|
|
return '--format=lint-xml';
|
2013-08-02 14:13:23 +02:00
|
|
|
}
|
|
|
|
|
2013-08-23 20:52:44 +02:00
|
|
|
public function getDefaultFlags() {
|
2013-08-02 14:13:23 +02:00
|
|
|
$working_copy = $this->getEngine()->getWorkingCopy();
|
|
|
|
|
|
|
|
$options = $working_copy->getConfig('lint.csslint.options');
|
2013-08-23 20:52:44 +02:00
|
|
|
// TODO: Deprecation warning.
|
2013-08-02 14:13:23 +02:00
|
|
|
|
|
|
|
return $options;
|
|
|
|
}
|
|
|
|
|
2013-08-23 20:52:44 +02:00
|
|
|
public function getDefaultBinary() {
|
|
|
|
// TODO: Deprecation warning.
|
2013-08-02 14:13:23 +02:00
|
|
|
$working_copy = $this->getEngine()->getWorkingCopy();
|
|
|
|
$bin = $working_copy->getConfig('lint.csslint.bin');
|
2013-08-23 20:52:44 +02:00
|
|
|
if ($bin) {
|
|
|
|
return $bin;
|
2013-08-02 14:13:23 +02:00
|
|
|
}
|
|
|
|
|
2013-08-23 20:52:44 +02:00
|
|
|
return 'csslint';
|
2013-08-02 14:13:23 +02:00
|
|
|
}
|
|
|
|
|
2013-08-23 20:52:44 +02:00
|
|
|
public function getInstallInstructions() {
|
|
|
|
return pht('Install CSSLint using `npm install -g csslint`.');
|
2013-08-02 14:13:23 +02:00
|
|
|
}
|
|
|
|
|
2013-08-23 20:52:44 +02:00
|
|
|
protected function parseLinterOutput($path, $err, $stdout, $stderr) {
|
|
|
|
$report_dom = new DOMDocument();
|
|
|
|
$ok = @$report_dom->loadXML($stdout);
|
2013-08-02 14:13:23 +02:00
|
|
|
|
2013-08-23 20:52:44 +02:00
|
|
|
if (!$ok) {
|
|
|
|
return false;
|
2013-08-02 14:13:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$files = $report_dom->getElementsByTagName('file');
|
2013-08-23 20:52:44 +02:00
|
|
|
$messages = array();
|
2013-08-02 14:13:23 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-08-23 20:52:44 +02:00
|
|
|
$messages[] = $message;
|
2013-08-02 14:13:23 +02:00
|
|
|
}
|
|
|
|
}
|
2013-08-23 20:52:44 +02:00
|
|
|
|
|
|
|
return $messages;
|
2013-08-02 14:13:23 +02:00
|
|
|
}
|
|
|
|
}
|