diff --git a/.arcconfig b/.arcconfig index 6d4b053980dac1afb525c4e3eb62a642fafc3ce0..68180b89aea69896a9ddf7189b0b29157b20630d 100644 --- a/.arcconfig +++ b/.arcconfig @@ -1,6 +1,10 @@ { "project_id" : "leveldb", "conduit_uri" : "https://reviews.facebook.net/", - "copyright_holder" : "" + "copyright_holder" : "", + "load" : [ + "linters/src/" + ], + "lint.engine" : "FacebookFbcodeLintEngine", + "lint.engine.single.linter" : "FbcodeCppLinter" } - diff --git a/linters/src/.phutil_module_cache b/linters/src/.phutil_module_cache new file mode 100644 index 0000000000000000000000000000000000000000..bfd0fda28f57badab693d2c52790a31da7c07a45 --- /dev/null +++ b/linters/src/.phutil_module_cache @@ -0,0 +1 @@ +{"__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"]}},"4443484928afb005f585843d07b04190":{"have":{"class":{"FbcodeCppLinter":13}},"need":{"function":{"Futures":1265},"class":{"ArcanistLinter":37,"ExecFuture":934,"ArcanistLintSeverity":1729}},"xmap":{"FbcodeCppLinter":["ArcanistLinter"]}},"02e2a613e371424b2108d2d6cb849d39":{"have":{"class":{"PfffCppLinter":71}},"need":{"function":{"Futures":875},"class":{"ArcanistLinter":93,"ExecFuture":756,"ArcanistLintMessage":1270,"ArcanistLintSeverity":1607}},"xmap":{"PfffCppLinter":["ArcanistLinter"]}}} \ No newline at end of file diff --git a/linters/src/__phutil_library_init__.php b/linters/src/__phutil_library_init__.php new file mode 100644 index 0000000000000000000000000000000000000000..4b8d3d1316c38ee06ad5759c5a98a0f37f443c5b --- /dev/null +++ b/linters/src/__phutil_library_init__.php @@ -0,0 +1,3 @@ + 2, + 'class' => + array( + 'FacebookFbcodeLintEngine' => 'lint_engine/FacebookFbcodeLintEngine.php', + 'FbcodeCppLinter' => 'cpp_linter/FbcodeCppLinter.php', + 'PfffCppLinter' => 'cpp_linter/PfffCppLinter.php', + ), + 'function' => + array( + ), + 'xmap' => + array( + 'FacebookFbcodeLintEngine' => 'ArcanistLintEngine', + 'FbcodeCppLinter' => 'ArcanistLinter', + 'PfffCppLinter' => 'ArcanistLinter', + ), +)); diff --git a/linters/src/cpp_linter/FbcodeCppLinter.php b/linters/src/cpp_linter/FbcodeCppLinter.php new file mode 100644 index 0000000000000000000000000000000000000000..e62d3bbe1b8561bd8ccea56402b2163f5f3dfdb7 --- /dev/null +++ b/linters/src/cpp_linter/FbcodeCppLinter.php @@ -0,0 +1,99 @@ +getEngine()->getFilePathOnDisk($p); + $lpath_file = file($lpath); + if (preg_match('/\.(c)$/', $lpath) || + preg_match('/-\*-.*Mode: C[; ].*-\*-/', $lpath_file[0]) || + preg_match('/vim(:.*)*:\s*(set\s+)?filetype=c\s*:/', $lpath_file[0]) + ) { + $futures[$p] = new ExecFuture("%s %s %s 2>&1", + $CPP_LINT, self::C_FLAG, + $this->getEngine()->getFilePathOnDisk($p)); + } else { + $futures[$p] = new ExecFuture("%s %s 2>&1", + self::CPPLINT, $this->getEngine()->getFilePathOnDisk($p)); + } + } + + foreach (Futures($futures)->limit(8) as $p => $f) { + $this->rawLintOutput[$p] = $f->resolvex(); + } + } + return; + } + + public function getLinterName() { + return "FBCPP"; + } + + public function lintPath($path) { + $msgs = $this->getCppLintOutput($path); + foreach ($msgs as $m) { + $this->raiseLintAtLine($m['line'], 0, $m['severity'], $m['msg']); + } + } + + public function getLintSeverityMap() { + return array( + self::LINT_WARNING => ArcanistLintSeverity::SEVERITY_WARNING, + self::LINT_ERROR => ArcanistLintSeverity::SEVERITY_ERROR + ); + } + + public function getLintNameMap() { + return array( + self::LINT_WARNING => "CppLint Warning", + self::LINT_ERROR => "CppLint Error" + ); + } + + private function getCppLintOutput($path) { + list($output) = $this->rawLintOutput[$path]; + + $msgs = array(); + $current = null; + foreach (explode("\n", $output) as $line) { + if (preg_match('/[^:]*\((\d+)\):(.*)$/', $line, $matches)) { + if ($current) { + $msgs[] = $current; + } + $line = $matches[1]; + $text = $matches[2]; + $sev = preg_match('/.*Warning.*/', $text) + ? self::LINT_WARNING + : self::LINT_ERROR; + $current = array('line' => $line, + 'msg' => $text, + 'severity' => $sev); + } else if ($current) { + $current['msg'] .= ' ' . $line; + } + } + if ($current) { + $msgs[] = $current; + } + + return $msgs; + } +} + diff --git a/linters/src/cpp_linter/PfffCppLinter.php b/linters/src/cpp_linter/PfffCppLinter.php new file mode 100644 index 0000000000000000000000000000000000000000..67366143cec55fb6c8dd3d3b1a2c3cd6b2fa65bc --- /dev/null +++ b/linters/src/cpp_linter/PfffCppLinter.php @@ -0,0 +1,68 @@ +&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; + } +} diff --git a/linters/src/lint_engine/FacebookFbcodeLintEngine.php b/linters/src/lint_engine/FacebookFbcodeLintEngine.php new file mode 100644 index 0000000000000000000000000000000000000000..c34530c3bcd1df5e81cae56a4ded9bc77b549279 --- /dev/null +++ b/linters/src/lint_engine/FacebookFbcodeLintEngine.php @@ -0,0 +1,147 @@ +getPaths(); + + // Remove all deleted files, which are not checked by the + // following linters. + foreach ($paths as $key => $path) { + if (!Filesystem::pathExists($this->getFilePathOnDisk($path))) { + unset($paths[$key]); + } + } + + $generated_linter = new ArcanistGeneratedLinter(); + $linters[] = $generated_linter; + + $nolint_linter = new ArcanistNoLintLinter(); + $linters[] = $nolint_linter; + + $text_linter = new ArcanistTextLinter(); + $text_linter->setCustomSeverityMap(array( + ArcanistTextLinter::LINT_LINE_WRAP + => ArcanistLintSeverity::SEVERITY_ADVICE, + )); + $linters[] = $text_linter; + + $java_text_linter = new ArcanistTextLinter(); + $java_text_linter->setMaxLineLength(100); + $java_text_linter->setCustomSeverityMap(array( + ArcanistTextLinter::LINT_LINE_WRAP + => ArcanistLintSeverity::SEVERITY_ADVICE, + )); + $linters[] = $java_text_linter; + + $pep8_options = $this->getPEP8WithTextOptions().',E302'; + + $python_linter = new ArcanistPEP8Linter(); + $python_linter->setConfig(array('options' => $pep8_options)); + $linters[] = $python_linter; + + $python_2space_linter = new ArcanistPEP8Linter(); + $python_2space_linter->setConfig(array('options' => $pep8_options.',E111')); + $linters[] = $python_2space_linter; + + // Currently we can't run cpplint in commit hook mode, because it + // depends on having access to the working directory. + if (!$this->getCommitHookMode()) { + $cpp_linter = new FbcodeCppLinter(); + $cpp_linter2 = new PfffCppLinter(); + $linters[] = $cpp_linter; + $linters[] = $cpp_linter2; + } + + $spelling_linter = new ArcanistSpellingLinter(); + $linters[] = $spelling_linter; + + foreach ($paths as $path) { + $is_text = false; + + $text_extensions = ( + '/\.('. + 'cpp|cxx|c|cc|h|hpp|hxx|tcc|'. + 'py|rb|hs|pl|pm|tw|'. + 'php|phpt|css|js|'. + 'java|'. + 'thrift|'. + 'lua|'. + 'siv|'. + 'txt'. + ')$/' + ); + if (preg_match($text_extensions, $path)) { + $is_text = true; + } + if ($is_text) { + $nolint_linter->addPath($path); + + $generated_linter->addPath($path); + $generated_linter->addData($path, $this->loadData($path)); + + if (preg_match('/\.java$/', $path)) { + $java_text_linter->addPath($path); + $java_text_linter->addData($path, $this->loadData($path)); + } else { + $text_linter->addPath($path); + $text_linter->addData($path, $this->loadData($path)); + } + + $spelling_linter->addPath($path); + $spelling_linter->addData($path, $this->loadData($path)); + } + if (isset($cpp_linter) && isset($cpp_linter2) && + preg_match('/\.(cpp|c|cc|cxx|h|hh|hpp|hxx|tcc)$/', $path)) { + $cpp_linter->addPath($path); + $cpp_linter->addData($path, $this->loadData($path)); + $cpp_linter2->addPath($path); + $cpp_linter2->addData($path, $this->loadData($path)); + + } + + // Match *.py and contbuild config files + if (preg_match('/(\.(py|tw|smcprops)|^contbuild\/configs\/[^\/]*)$/', + $path)) { + $space_count = 4; + $real_path = $this->getFilePathOnDisk($path); + $dir = dirname($real_path); + do { + if (file_exists($dir.'/.python2space')) { + $space_count = 2; + break; + } + $dir = dirname($dir); + } while ($dir != '/' && $dir != '.'); + + if ($space_count == 4) { + $cur_path_linter = $python_linter; + } else { + $cur_path_linter = $python_2space_linter; + } + $cur_path_linter->addPath($path); + $cur_path_linter->addData($path, $this->loadData($path)); + + if (preg_match('/\.tw$/', $path)) { + $cur_path_linter->setCustomSeverityMap(array( + 'E251' => ArcanistLintSeverity::SEVERITY_DISABLED, + )); + } + } + + + + } + + $name_linter = new ArcanistFilenameLinter(); + $linters[] = $name_linter; + foreach ($paths as $path) { + $name_linter->addPath($path); + } + + return $linters; + } + +}