mirror of
https://we.phorge.it/source/arcanist.git
synced 2025-03-31 22:48:15 +02:00
Summary: ref T8404 The issue is caused, not by the non-zero return code, but by the fact that $messages is coming back empty due to the incorrect regex. tyhoff pointed out that the regex matched correctly when we used STDIN, but now it is failing. https://secure.phabricator.com/diffusion/ARC/browse/master/src/lint/linter/ArcanistExternalLinter.php;8c589f1f759f0913135b8cc6959a6c1589e14ae4$357 Test Plan: arc lint cpp file containing lint error. run cpplint on the file directly to confirm that there are errors and that the return code is non-zero Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: Korvin Maniphest Tasks: T8404 Differential Revision: https://secure.phabricator.com/D14960
76 lines
1.9 KiB
PHP
76 lines
1.9 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Uses Google's `cpplint.py` to check code.
|
|
*/
|
|
final class ArcanistCpplintLinter extends ArcanistExternalLinter {
|
|
|
|
public function getLinterName() {
|
|
return 'C++ Google\'s Styleguide';
|
|
}
|
|
|
|
public function getLinterConfigurationName() {
|
|
return 'cpplint';
|
|
}
|
|
|
|
public function getDefaultBinary() {
|
|
return 'cpplint';
|
|
}
|
|
|
|
public function getInstallInstructions() {
|
|
return pht(
|
|
'Install cpplint.py using `%s`.',
|
|
'wget http://google-styleguide.googlecode.com'.
|
|
'/svn/trunk/cpplint/cpplint.py');
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
}
|