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
This commit is contained in:
kailiu 2014-01-23 15:04:12 -08:00
parent fb01755aa4
commit d0458469c8
9 changed files with 4779 additions and 19 deletions

View File

@ -1,10 +1,11 @@
{ {
"project_id" : "leveldb", "project_id" : "rocksdb",
"conduit_uri" : "https://reviews.facebook.net/", "conduit_uri" : "https://reviews.facebook.net/",
"copyright_holder" : "", "copyright_holder" : "Facebook",
"load" : [ "load" : [
"linters/src/" "linters"
], ],
"lint.engine" : "FacebookFbcodeLintEngine", "lint.engine" : "FacebookFbcodeLintEngine",
"lint.engine.single.linter" : "FbcodeCppLinter" "lint.engine.single.linter" : "FbcodeCppLinter",
"lint.cpplint.prefix" : "linters"
} }

1
.gitignore vendored
View File

@ -20,3 +20,4 @@ util/build_version.cc
build_tools/VALGRIND_LOGS/ build_tools/VALGRIND_LOGS/
coverage/COVERAGE_REPORT coverage/COVERAGE_REPORT
.gdbhistory .gdbhistory
.phutil_module_cache

4759
linters/cpplint.py vendored Executable file

File diff suppressed because it is too large Load Diff

View File

@ -49,10 +49,15 @@ class FacebookFbcodeLintEngine extends ArcanistLintEngine {
// Currently we can't run cpplint in commit hook mode, because it // Currently we can't run cpplint in commit hook mode, because it
// depends on having access to the working directory. // depends on having access to the working directory.
if (!$this->getCommitHookMode()) { if (!$this->getCommitHookMode()) {
$cpp_linter = new FbcodeCppLinter(); $cpp_linters = array();
$cpp_linter2 = new PfffCppLinter(); $google_linter = new ArcanistCpplintLinter();
$linters[] = $cpp_linter; $google_linter->setConfig(array(
$linters[] = $cpp_linter2; 'lint.cpplint.prefix' => '',
'lint.cpplint.bin' => 'cpplint',
));
$cpp_linters[] = $linters[] = $google_linter;
$cpp_linters[] = $linters[] = new FbcodeCppLinter();
$cpp_linters[] = $linters[] = new PfffCppLinter();
} }
$spelling_linter = new ArcanistSpellingLinter(); $spelling_linter = new ArcanistSpellingLinter();
@ -93,13 +98,11 @@ class FacebookFbcodeLintEngine extends ArcanistLintEngine {
$spelling_linter->addPath($path); $spelling_linter->addPath($path);
$spelling_linter->addData($path, $this->loadData($path)); $spelling_linter->addData($path, $this->loadData($path));
} }
if (isset($cpp_linter) && isset($cpp_linter2) && if (preg_match('/\.(cpp|c|cc|cxx|h|hh|hpp|hxx|tcc)$/', $path)) {
preg_match('/\.(cpp|c|cc|cxx|h|hh|hpp|hxx|tcc)$/', $path)) { foreach ($cpp_linters as &$linter) {
$cpp_linter->addPath($path); $linter->addPath($path);
$cpp_linter->addData($path, $this->loadData($path)); $linter->addData($path, $this->loadData($path));
$cpp_linter2->addPath($path); }
$cpp_linter2->addData($path, $this->loadData($path));
} }
// Match *.py and contbuild config files // Match *.py and contbuild config files
@ -130,9 +133,6 @@ class FacebookFbcodeLintEngine extends ArcanistLintEngine {
)); ));
} }
} }
} }
$name_linter = new ArcanistFilenameLinter(); $name_linter = new ArcanistFilenameLinter();

View File

@ -1 +0,0 @@
{"__symbol_cache_version__":8,"b937ad5f80a8bd1156038b730ff56ec5":{"have":{"class":{"FacebookFbcodeLintEngine":71}},"need":{"class":{"ArcanistLintEngine":104,"ArcanistGeneratedLinter":488,"ArcanistNoLintLinter":577,"ArcanistTextLinter":658,"ArcanistPEP8Linter":1227,"FbcodeCppLinter":1715,"PfffCppLinter":1759,"ArcanistSpellingLinter":1875,"ArcanistFilenameLinter":4207,"Filesystem":357,"ArcanistLintSeverity":778}},"xmap":{"FacebookFbcodeLintEngine":["ArcanistLintEngine"]}},"02e2a613e371424b2108d2d6cb849d39":{"have":{"class":{"PfffCppLinter":71}},"need":{"function":{"Futures":875},"class":{"ArcanistLinter":93,"ExecFuture":756,"ArcanistLintMessage":1270,"ArcanistLintSeverity":1607}},"xmap":{"PfffCppLinter":["ArcanistLinter"]}},"4443484928afb005f585843d07b04190":{"have":{"class":{"FbcodeCppLinter":13}},"need":{"function":{"Futures":1265},"class":{"ArcanistLinter":37,"ExecFuture":934,"ArcanistLintSeverity":1729}},"xmap":{"FbcodeCppLinter":["ArcanistLinter"]}}}