rocksdb/linters/cpp_linter/PfffCppLinter.php
kailiu d0458469c8 Add google-style checker to "arc lint"
Summary:
After we reached a consensus on code format, which follows exactly
Google's coding style, a natural follow-up is to have a style checker
that can handle stuffs beyond format.

Google already has a powerful style checker "cpplint.py" and,
luckily, phabricator already provides the built-in linter for it!
Next time with "arc lint" most style inconsistency will be detected
(but will not be fixed).

Also I copied cpplint.py to linters directory, which is mostly
because we may need the flexibility to make some modifications on
it for our own need.

Test Plan:
ran arc lint table/block_based_table_builder.cc to see the amazing
results.

Reviewers: haobo, sdong, igor, dhruba

Reviewed By: haobo

CC: leveldb

Differential Revision: https://reviews.facebook.net/D15369
2014-01-23 15:04:12 -08:00

69 lines
1.7 KiB
PHP

<?php
// Copyright 2004-present Facebook. All rights reserved.
class PfffCppLinter extends ArcanistLinter {
const PROGRAM = "/home/engshare/tools/checkCpp";
public function getLinterName() {
return "checkCpp";
}
public function getLintNameMap() {
return array(
);
}
public function getLintSeverityMap() {
return array(
);
}
public function willLintPaths(array $paths) {
$program = false;
$ret_value = 0;
$last_line = system("which checkCpp", $ret_value);
if ($ret_value == 0) {
$program = $last_line;
} else if (file_exists(self::PROGRAM)) {
$program = self::PROGRAM;
}
if ($program) {
$futures = array();
foreach ($paths as $p) {
$futures[$p] = new ExecFuture("%s --lint %s 2>&1",
$program, $this->getEngine()->getFilePathOnDisk($p));
}
foreach (Futures($futures)->limit(8) as $p => $f) {
list($stdout, $stderr) = $f->resolvex();
$raw = json_decode($stdout, true);
if (!is_array($raw)) {
throw new Exception(
"checkCpp returned invalid JSON!".
"Stdout: {$stdout} Stderr: {$stderr}"
);
}
foreach($raw as $err) {
$this->addLintMessage(
ArcanistLintMessage::newFromDictionary(
array(
'path' => $err['file'],
'line' => $err['line'],
'char' => 0,
'name' => $err['name'],
'description' => $err['info'],
'code' => $this->getLinterName(),
'severity' => ArcanistLintSeverity::SEVERITY_WARNING,
)
)
);
}
}
}
return;
}
public function lintPath($path) {
return;
}
}