2013-08-02 05:13:23 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2015-01-12 06:47:16 +11:00
|
|
|
* Uses "CSS Lint" to detect checkstyle errors in CSS code.
|
2013-08-02 05:13:23 -07:00
|
|
|
*/
|
2013-08-23 11:52:44 -07:00
|
|
|
final class ArcanistCSSLintLinter extends ArcanistExternalLinter {
|
2013-08-02 05:13:23 -07:00
|
|
|
|
2014-05-11 16:16:45 -07:00
|
|
|
public function getInfoName() {
|
|
|
|
return 'CSSLint';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getInfoURI() {
|
|
|
|
return 'http://csslint.net';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getInfoDescription() {
|
2015-01-12 06:47:16 +11:00
|
|
|
return pht(
|
|
|
|
'Use `%s` to detect issues with CSS source files.',
|
|
|
|
'csslint');
|
2014-05-11 16:16:45 -07:00
|
|
|
}
|
|
|
|
|
2013-08-02 05:13:23 -07:00
|
|
|
public function getLinterName() {
|
|
|
|
return 'CSSLint';
|
|
|
|
}
|
|
|
|
|
2013-08-23 11:58:07 -07:00
|
|
|
public function getLinterConfigurationName() {
|
|
|
|
return 'csslint';
|
|
|
|
}
|
|
|
|
|
2015-01-07 07:36:07 +11:00
|
|
|
protected function getMandatoryFlags() {
|
2014-05-10 01:52:57 -07:00
|
|
|
return array(
|
|
|
|
'--format=lint-xml',
|
|
|
|
);
|
2013-08-02 05:13:23 -07:00
|
|
|
}
|
|
|
|
|
2015-01-07 07:36:07 +11:00
|
|
|
protected function getDefaultFlags() {
|
2014-05-11 18:39:28 -07:00
|
|
|
return $this->getDeprecatedConfiguration('lint.csslint.options', array());
|
2013-08-02 05:13:23 -07:00
|
|
|
}
|
|
|
|
|
2013-08-23 11:52:44 -07:00
|
|
|
public function getDefaultBinary() {
|
2014-05-11 18:39:28 -07:00
|
|
|
return $this->getDeprecatedConfiguration('lint.csslint.bin', 'csslint');
|
2013-08-02 05:13:23 -07: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-05 15:10:20 -07: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 11:52:44 -07:00
|
|
|
public function getInstallInstructions() {
|
2015-01-12 06:47:16 +11:00
|
|
|
return pht(
|
|
|
|
'Install %s using `%s`.', 'CSSLint',
|
|
|
|
'npm install -g csslint');
|
2013-08-02 05:13:23 -07:00
|
|
|
}
|
|
|
|
|
2013-08-23 11:52:44 -07:00
|
|
|
protected function parseLinterOutput($path, $err, $stdout, $stderr) {
|
|
|
|
$report_dom = new DOMDocument();
|
|
|
|
$ok = @$report_dom->loadXML($stdout);
|
2013-08-02 05:13:23 -07:00
|
|
|
|
2013-08-23 11:52:44 -07:00
|
|
|
if (!$ok) {
|
|
|
|
return false;
|
2013-08-02 05:13:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
$files = $report_dom->getElementsByTagName('file');
|
2013-08-23 11:52:44 -07:00
|
|
|
$messages = array();
|
2015-01-12 06:47:16 +11:00
|
|
|
|
2013-08-02 05:13:23 -07:00
|
|
|
foreach ($files as $file) {
|
|
|
|
foreach ($file->childNodes as $child) {
|
2015-01-12 06:47:16 +11:00
|
|
|
$message = id(new ArcanistLintMessage())
|
|
|
|
->setPath($path)
|
|
|
|
->setLine($child->getAttribute('line'))
|
|
|
|
->setChar($child->getAttribute('char'))
|
2015-01-12 06:47:51 +11:00
|
|
|
->setCode($this->getLinterName())
|
|
|
|
->setDescription($child->getAttribute('reason'))
|
|
|
|
->setOriginalText(
|
|
|
|
substr(
|
|
|
|
$child->getAttribute('evidence'),
|
|
|
|
$child->getAttribute('char') - 1));
|
|
|
|
|
|
|
|
switch ($child->getAttribute('severity')) {
|
|
|
|
case 'error':
|
|
|
|
$message->setSeverity(ArcanistLintSeverity::SEVERITY_ERROR);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'warning':
|
|
|
|
$message->setSeverity(ArcanistLintSeverity::SEVERITY_WARNING);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
$message->setSeverity(ArcanistLintSeverity::SEVERITY_ERROR);
|
|
|
|
break;
|
2013-08-02 05:13:23 -07:00
|
|
|
}
|
|
|
|
|
2013-08-23 11:52:44 -07:00
|
|
|
$messages[] = $message;
|
2013-08-02 05:13:23 -07:00
|
|
|
}
|
|
|
|
}
|
2013-08-23 11:52:44 -07:00
|
|
|
|
|
|
|
return $messages;
|
2013-08-02 05:13:23 -07:00
|
|
|
}
|
2013-08-23 11:58:07 -07: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(
|
2015-01-12 06:47:16 +11:00
|
|
|
"%s does not currently support custom severity levels, because ".
|
|
|
|
"rules can't be identified from messages in output.",
|
|
|
|
'CSSLint'));
|
2013-08-23 11:58:07 -07:00
|
|
|
}
|
|
|
|
|
2013-08-02 05:13:23 -07:00
|
|
|
}
|