4
* Uses Cppcheck to do basic checks in a C++ file.
6
final class ArcanistCppcheckLinter extends ArcanistExternalLinter {
8
public function getInfoName() {
12
public function getInfoURI() {
13
return 'http://cppcheck.sourceforge.net';
16
public function getInfoDescription() {
17
return pht('Use `cppcheck` to perform static analysis on C/C++ code.');
20
public function getLinterName() {
24
public function getLinterConfigurationName() {
28
public function getDefaultBinary() {
29
$prefix = $this->getDeprecatedConfiguration('lint.cppcheck.prefix');
30
$bin = $this->getDeprecatedConfiguration('lint.cppcheck.bin', 'cppcheck');
33
return $prefix.'/'.$bin;
39
public function getVersion() {
40
list($stdout) = execx('%C --version', $this->getExecutableCommand());
43
$regex = '/^Cppcheck (?P<version>\d+\.\d+)$/';
44
if (preg_match($regex, $stdout, $matches)) {
45
return $matches['version'];
51
public function getInstallInstructions() {
52
return pht('Install Cppcheck using `apt-get install cppcheck` or similar.');
55
protected function getMandatoryFlags() {
64
protected function getDefaultFlags() {
65
return $this->getDeprecatedConfiguration(
66
'lint.cppcheck.options',
67
array('-j2', '--enable=performance,style,portability,information'));
70
protected function parseLinterOutput($path, $err, $stdout, $stderr) {
71
$dom = new DOMDocument();
72
$ok = @$dom->loadXML($stderr);
78
$errors = $dom->getElementsByTagName('error');
80
foreach ($errors as $error) {
81
foreach ($error->getElementsByTagName('location') as $location) {
82
$message = new ArcanistLintMessage();
83
$message->setPath($location->getAttribute('file'));
84
$message->setLine($location->getAttribute('line'));
85
$message->setCode('Cppcheck');
86
$message->setName($error->getAttribute('id'));
87
$message->setDescription($error->getAttribute('msg'));
89
switch ($error->getAttribute('severity')) {
91
$message->setSeverity(ArcanistLintSeverity::SEVERITY_ERROR);
95
if ($error->getAttribute('inconclusive')) {
96
$message->setSeverity(ArcanistLintSeverity::SEVERITY_ADVICE);
98
$message->setSeverity(ArcanistLintSeverity::SEVERITY_WARNING);
103
$messages[] = $message;