]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/arcanist_util/lint_engine/FacebookFbcodeLintEngine.php
2 // Copyright 2004-present Facebook. All rights reserved.
3 // This source code is licensed under the BSD-style license found in the
4 // LICENSE file in the root directory of this source tree. An additional grant
5 // of patent rights can be found in the PATENTS file in the same directory.
7 class FacebookFbcodeLintEngine
extends ArcanistLintEngine
{
9 public function buildLinters() {
11 $paths = $this->getPaths();
13 // Remove all deleted files, which are not checked by the
15 foreach ($paths as $key => $path) {
16 if (!Filesystem
::pathExists($this->getFilePathOnDisk($path))) {
21 $generated_linter = new ArcanistGeneratedLinter();
22 $linters[] = $generated_linter;
24 $nolint_linter = new ArcanistNoLintLinter();
25 $linters[] = $nolint_linter;
27 $text_linter = new ArcanistTextLinter();
28 $text_linter->setCustomSeverityMap(array(
29 ArcanistTextLinter
::LINT_LINE_WRAP
30 => ArcanistLintSeverity
::SEVERITY_ADVICE
,
32 $linters[] = $text_linter;
34 $java_text_linter = new ArcanistTextLinter();
35 $java_text_linter->setMaxLineLength(100);
36 $java_text_linter->setCustomSeverityMap(array(
37 ArcanistTextLinter
::LINT_LINE_WRAP
38 => ArcanistLintSeverity
::SEVERITY_ADVICE
,
40 $linters[] = $java_text_linter;
42 $python_linter = new ArcanistPEP8Linter();
43 $linters[] = $python_linter;
45 $cpp_linters = array();
46 $cpp_linters[] = $linters[] = new ArcanistCpplintLinter();
47 $cpp_linters[] = $linters[] = new FbcodeCppLinter();
49 $clang_format_linter = new FbcodeClangFormatLinter();
50 $linters[] = $clang_format_linter;
52 $spelling_linter = new ArcanistSpellingLinter();
53 $linters[] = $spelling_linter;
55 foreach ($paths as $path) {
60 'cpp|cxx|c|cc|h|hpp|hxx|tcc|'.
70 if (preg_match($text_extensions, $path)) {
74 $nolint_linter->addPath($path);
76 $generated_linter->addPath($path);
77 $generated_linter->addData($path, $this->loadData($path));
79 if (preg_match('/\.java$/', $path)) {
80 $java_text_linter->addPath($path);
81 $java_text_linter->addData($path, $this->loadData($path));
83 $text_linter->addPath($path);
84 $text_linter->addData($path, $this->loadData($path));
87 $spelling_linter->addPath($path);
88 $spelling_linter->addData($path, $this->loadData($path));
90 if (preg_match('/\.(cpp|c|cc|cxx|h|hh|hpp|hxx|tcc)$/', $path)
91 && !preg_match('/third-party/', $path)) {
92 foreach ($cpp_linters as &$linter) {
93 $linter->addPath($path);
94 $linter->addData($path, $this->loadData($path));
97 $clang_format_linter->addPath($path);
98 $clang_format_linter->addData($path, $this->loadData($path));
99 $clang_format_linter->setPathChangedLines(
100 $path, $this->getPathChangedLines($path));
103 // Match *.py and contbuild config files
104 if (preg_match('/(\.(py|tw|smcprops)|^contbuild\/configs\/[^\/]*)$/',
107 $real_path = $this->getFilePathOnDisk($path);
108 $dir = dirname($real_path);
110 if (file_exists($dir.'/.python2space')) {
114 $dir = dirname($dir);
115 } while ($dir != '/' && $dir != '.');
117 $cur_path_linter = $python_linter;
118 $cur_path_linter->addPath($path);
119 $cur_path_linter->addData($path, $this->loadData($path));
121 if (preg_match('/\.tw$/', $path)) {
122 $cur_path_linter->setCustomSeverityMap(array(
123 'E251' => ArcanistLintSeverity
::SEVERITY_DISABLED
,
129 $name_linter = new ArcanistFilenameLinter();
130 $linters[] = $name_linter;
131 foreach ($paths as $path) {
132 $name_linter->addPath($path);