]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/arcanist_util/cpp_linter/FbcodeClangFormatLinter.php
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / rocksdb / arcanist_util / cpp_linter / FbcodeClangFormatLinter.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 final class FbcodeClangFormatLinter extends BaseDirectoryScopedFormatLinter {
8
9 const LINT_FORMATTING = 1;
10 const CLANG_FORMAT_BINARY = '/mnt/vol/engshare/admin/scripts/clang-format';
11
12 protected function getPathsToLint() {
13 return array('');
14 }
15
16 public function getLinterName() {
17 return 'CLANG_FORMAT';
18 }
19
20 public function getLintSeverityMap() {
21 return array(
22 self::LINT_FORMATTING => ArcanistLintSeverity::SEVERITY_ADVICE,
23 );
24 }
25
26 public function getLintNameMap() {
27 return array(
28 self::LINT_FORMATTING => pht('Changes are not clang-formatted'),
29 );
30 }
31
32 protected function getFormatFuture($path, array $changed) {
33 $args = "";
34 foreach ($changed as $key => $value) {
35 $args .= " --lines=$key:$key";
36 }
37
38 $binary = self::CLANG_FORMAT_BINARY;
39 if (!file_exists($binary)) {
40 // trust the $PATH
41 $binary = "clang-format";
42 }
43
44 return new ExecFuture(
45 "%s %s $args",
46 $binary,
47 $this->getEngine()->getFilePathOnDisk($path));
48 }
49
50 protected function getLintMessage($diff) {
51 $link_to_clang_format =
52 "[[ http://fburl.com/clang-format | clang-format ]]";
53 return <<<LINT_MSG
54 Changes in this file were not formatted using $link_to_clang_format.
55 Please run build_tools/format-diff.sh or `make format`
56 LINT_MSG;
57 }
58 }