]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/arcanist_util/lint_engine/FacebookFbcodeLintEngine.php
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / rocksdb / arcanist_util / lint_engine / FacebookFbcodeLintEngine.php
1 <?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.
6
7 class FacebookFbcodeLintEngine extends ArcanistLintEngine {
8
9 public function buildLinters() {
10 $linters = array();
11 $paths = $this->getPaths();
12
13 // Remove all deleted files, which are not checked by the
14 // following linters.
15 foreach ($paths as $key => $path) {
16 if (!Filesystem::pathExists($this->getFilePathOnDisk($path))) {
17 unset($paths[$key]);
18 }
19 }
20
21 $generated_linter = new ArcanistGeneratedLinter();
22 $linters[] = $generated_linter;
23
24 $nolint_linter = new ArcanistNoLintLinter();
25 $linters[] = $nolint_linter;
26
27 $text_linter = new ArcanistTextLinter();
28 $text_linter->setCustomSeverityMap(array(
29 ArcanistTextLinter::LINT_LINE_WRAP
30 => ArcanistLintSeverity::SEVERITY_ADVICE,
31 ));
32 $linters[] = $text_linter;
33
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,
39 ));
40 $linters[] = $java_text_linter;
41
42 $python_linter = new ArcanistPEP8Linter();
43 $linters[] = $python_linter;
44
45 $cpp_linters = array();
46 $cpp_linters[] = $linters[] = new ArcanistCpplintLinter();
47 $cpp_linters[] = $linters[] = new FbcodeCppLinter();
48
49 $clang_format_linter = new FbcodeClangFormatLinter();
50 $linters[] = $clang_format_linter;
51
52 $spelling_linter = new ArcanistSpellingLinter();
53 $linters[] = $spelling_linter;
54
55 foreach ($paths as $path) {
56 $is_text = false;
57
58 $text_extensions = (
59 '/\.('.
60 'cpp|cxx|c|cc|h|hpp|hxx|tcc|'.
61 'py|rb|hs|pl|pm|tw|'.
62 'php|phpt|css|js|'.
63 'java|'.
64 'thrift|'.
65 'lua|'.
66 'siv|'.
67 'txt'.
68 ')$/'
69 );
70 if (preg_match($text_extensions, $path)) {
71 $is_text = true;
72 }
73 if ($is_text) {
74 $nolint_linter->addPath($path);
75
76 $generated_linter->addPath($path);
77 $generated_linter->addData($path, $this->loadData($path));
78
79 if (preg_match('/\.java$/', $path)) {
80 $java_text_linter->addPath($path);
81 $java_text_linter->addData($path, $this->loadData($path));
82 } else {
83 $text_linter->addPath($path);
84 $text_linter->addData($path, $this->loadData($path));
85 }
86
87 $spelling_linter->addPath($path);
88 $spelling_linter->addData($path, $this->loadData($path));
89 }
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));
95 }
96
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));
101 }
102
103 // Match *.py and contbuild config files
104 if (preg_match('/(\.(py|tw|smcprops)|^contbuild\/configs\/[^\/]*)$/',
105 $path)) {
106 $space_count = 4;
107 $real_path = $this->getFilePathOnDisk($path);
108 $dir = dirname($real_path);
109 do {
110 if (file_exists($dir.'/.python2space')) {
111 $space_count = 2;
112 break;
113 }
114 $dir = dirname($dir);
115 } while ($dir != '/' && $dir != '.');
116
117 $cur_path_linter = $python_linter;
118 $cur_path_linter->addPath($path);
119 $cur_path_linter->addData($path, $this->loadData($path));
120
121 if (preg_match('/\.tw$/', $path)) {
122 $cur_path_linter->setCustomSeverityMap(array(
123 'E251' => ArcanistLintSeverity::SEVERITY_DISABLED,
124 ));
125 }
126 }
127 }
128
129 $name_linter = new ArcanistFilenameLinter();
130 $linters[] = $name_linter;
131 foreach ($paths as $path) {
132 $name_linter->addPath($path);
133 }
134
135 return $linters;
136 }
137
138 }