2013-08-02 14:13:23 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2014-05-10 10:53:21 +02:00
|
|
|
* Uses "CSS Lint" to detect checkstyle errors in css code.
|
2013-08-02 14:13:23 +02:00
|
|
|
*/
|
2013-08-23 20:52:44 +02:00
|
|
|
final class ArcanistCSSLintLinter extends ArcanistExternalLinter {
|
2013-08-02 14:13:23 +02:00
|
|
|
|
2014-05-12 01:16:45 +02:00
|
|
|
public function getInfoName() {
|
|
|
|
return 'CSSLint';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getInfoURI() {
|
|
|
|
return 'http://csslint.net';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getInfoDescription() {
|
|
|
|
return pht(
|
|
|
|
'Use `csslint` to detect issues with CSS source files.');
|
|
|
|
}
|
|
|
|
|
2013-08-02 14:13:23 +02:00
|
|
|
public function getLinterName() {
|
|
|
|
return 'CSSLint';
|
|
|
|
}
|
|
|
|
|
2013-08-23 20:58:07 +02:00
|
|
|
public function getLinterConfigurationName() {
|
|
|
|
return 'csslint';
|
|
|
|
}
|
|
|
|
|
2013-08-23 20:52:44 +02:00
|
|
|
public function getMandatoryFlags() {
|
2014-05-10 10:52:57 +02:00
|
|
|
return array(
|
|
|
|
'--format=lint-xml',
|
|
|
|
'--quiet',
|
|
|
|
);
|
2013-08-02 14:13:23 +02:00
|
|
|
}
|
|
|
|
|
2013-08-23 20:52:44 +02:00
|
|
|
public function getDefaultFlags() {
|
|
|
|
// TODO: Deprecation warning.
|
2014-03-04 20:00:01 +01:00
|
|
|
$config = $this->getEngine()->getConfigurationManager();
|
2014-04-24 01:22:49 +02:00
|
|
|
return $config->getConfigFromAnySource('lint.csslint.options', array());
|
2013-08-02 14:13:23 +02:00
|
|
|
}
|
|
|
|
|
2013-08-23 20:52:44 +02:00
|
|
|
public function getDefaultBinary() {
|
|
|
|
// TODO: Deprecation warning.
|
2013-10-23 00:34:06 +02:00
|
|
|
$config = $this->getEngine()->getConfigurationManager();
|
2014-03-04 20:00:01 +01:00
|
|
|
return $config->getConfigFromAnySource('lint.csslint.bin', 'csslint');
|
2013-08-02 14:13:23 +02:00
|
|
|
}
|
|
|
|
|
Add a `getVersion` function to `ArcanistExternalLinter`.
Summary:
This method will, theoretically, allow `arc lint` to be configured to require some minimum version of an external linter (although this would probably require significantly more work).
Additionally, the existence of this method simplifies the `getCacheVersion` function which, previously, was implemented by the external linters individually. Instead, a general approach to determining the version for cacheing purposes can be used.
Fixes T4954.
Test Plan: I'm not sure how to test this.
Reviewers: chad, epriestley, #blessed_reviewers
Reviewed By: epriestley, #blessed_reviewers
Subscribers: epriestley, Korvin
Maniphest Tasks: T4954
Differential Revision: https://secure.phabricator.com/D8971
2014-05-06 00:10:20 +02:00
|
|
|
public function getVersion() {
|
|
|
|
list($stdout) = execx('%C --version', $this->getExecutableCommand());
|
|
|
|
|
|
|
|
$matches = array();
|
|
|
|
if (preg_match('/^v(?P<version>\d+\.\d+\.\d+)$/', $stdout, $matches)) {
|
|
|
|
return $matches['version'];
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-12-23 14:44:47 +01:00
|
|
|
public function shouldExpectCommandErrors() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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);
|
2013-08-23 20:58:07 +02:00
|
|
|
$name = $child->getAttribute('reason');
|
2013-08-02 14:13:23 +02:00
|
|
|
$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'));
|
2013-08-23 20:58:07 +02:00
|
|
|
$message->setCode('CSSLint');
|
|
|
|
$message->setDescription($child->getAttribute('reason'));
|
2013-08-02 14:13:23 +02:00
|
|
|
$message->setSeverity($severity);
|
|
|
|
|
2013-12-23 14:44:47 +01:00
|
|
|
if ($child->hasAttribute('line') && $child->getAttribute('line') > 0) {
|
2013-08-02 14:13:23 +02:00
|
|
|
$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
|
|
|
}
|
2013-08-23 20:58:07 +02:00
|
|
|
|
|
|
|
protected function getLintCodeFromLinterConfigurationKey($code) {
|
|
|
|
|
|
|
|
// NOTE: We can't figure out which rule generated each message, so we
|
|
|
|
// can not customize severities. I opened a pull request to add this
|
|
|
|
// ability; see:
|
|
|
|
//
|
|
|
|
// https://github.com/stubbornella/csslint/pull/409
|
|
|
|
|
|
|
|
throw new Exception(
|
|
|
|
pht(
|
|
|
|
"CSSLint does not currently support custom severity levels, because ".
|
|
|
|
"rules can't be identified from messages in output. ".
|
|
|
|
"See Pull Request #409."));
|
|
|
|
}
|
|
|
|
|
2013-08-02 14:13:23 +02:00
|
|
|
}
|