1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2025-02-10 22:08:31 +01:00
phorge-arcanist/src/lint/linter/ArcanistCpplintLinter.php
epriestley ddfdfce3f5 Fix CPP Lint severity
Summary: Currently all CPPLint issues are hard-coded to warning level, which prevents customising the severity in .arclint. Change to pick up the configured severity. Note that getLintMessageSeverity will call getDefaultMessageSeverity if nothing is configured for that error category.

Test Plan: Tested manually to confirm configured categories display with the correct severity and that non-configured ones return with the default severity (ERROR).

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: epriestley, Korvin

Differential Revision: https://secure.phabricator.com/D9682
2015-05-19 07:58:59 -07:00

91 lines
2.2 KiB
PHP

<?php
/**
* Uses Google's `cpplint.py` to check code.
*/
final class ArcanistCpplintLinter extends ArcanistExternalLinter {
public function getLinterName() {
return 'CPPLINT';
}
public function getLinterConfigurationName() {
return 'cpplint';
}
public function getDefaultBinary() {
$prefix = $this->getDeprecatedConfiguration('lint.cpplint.prefix');
$bin = $this->getDeprecatedConfiguration('lint.cpplint.bin', 'cpplint.py');
if ($prefix) {
return $prefix.'/'.$bin;
} else {
return $bin;
}
}
public function getInstallInstructions() {
return pht(
'Install cpplint.py using `%s`.',
'wget http://google-styleguide.googlecode.com'.
'/svn/trunk/cpplint/cpplint.py');
}
protected function getDefaultFlags() {
return $this->getDeprecatedConfiguration('lint.cpplint.options', array());
}
protected function getDefaultMessageSeverity($code) {
return ArcanistLintSeverity::SEVERITY_WARNING;
}
protected function parseLinterOutput($path, $err, $stdout, $stderr) {
$lines = explode("\n", $stderr);
$messages = array();
foreach ($lines as $line) {
$line = trim($line);
$matches = null;
$regex = '/^-:(\d+):\s*(.*)\s*\[(.*)\] \[(\d+)\]$/';
if (!preg_match($regex, $line, $matches)) {
continue;
}
foreach ($matches as $key => $match) {
$matches[$key] = trim($match);
}
$severity = $this->getLintMessageSeverity($matches[3]);
$message = new ArcanistLintMessage();
$message->setPath($path);
$message->setLine($matches[1]);
$message->setCode($matches[3]);
$message->setName($matches[3]);
$message->setDescription($matches[2]);
$message->setSeverity($severity);
$messages[] = $message;
}
if ($err && !$messages) {
return false;
}
return $messages;
}
protected function getLintCodeFromLinterConfigurationKey($code) {
if (!preg_match('@^[a-z_]+/[a-z_]+$@', $code)) {
throw new Exception(
pht(
'Unrecognized lint message code "%s". Expected a valid cpplint '.
'lint code like "%s" or "%s".',
$code,
'build/include_order',
'whitespace/braces'));
}
return $code;
}
}