diff --git a/.linters/clang-format-linter/.arclint b/.linters/clang-format-linter/.arclint new file mode 100644 index 000000000..423ba8c54 --- /dev/null +++ b/.linters/clang-format-linter/.arclint @@ -0,0 +1,22 @@ +{ + "linters": { + "text": { + "type": "text" + }, + "merges": { + "type": "merge-conflict" + }, + "phutil-library": { + "type": "phutil-library", + "include": "(\\.php$)" + }, + "phutil-xhpast": { + "type": "phutil-xhpast", + "include": "(\\.php$)" + }, + "xhpast": { + "type": "xhpast", + "include": "(\\.php$)" + } + } +} diff --git a/.linters/clang-format-linter/.gitignore b/.linters/clang-format-linter/.gitignore new file mode 100644 index 000000000..6b193c3e1 --- /dev/null +++ b/.linters/clang-format-linter/.gitignore @@ -0,0 +1 @@ +.phutil_module_cache diff --git a/.linters/clang-format-linter/LICENSE b/.linters/clang-format-linter/LICENSE new file mode 100644 index 000000000..484847f78 --- /dev/null +++ b/.linters/clang-format-linter/LICENSE @@ -0,0 +1,28 @@ +Copyright (c) 2015, Valerii Hiora +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of clang-format-linter nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + diff --git a/.linters/clang-format-linter/README.md b/.linters/clang-format-linter/README.md new file mode 100644 index 000000000..eef39447d --- /dev/null +++ b/.linters/clang-format-linter/README.md @@ -0,0 +1,113 @@ +# clang-format-linter + +Tired of spending half time of code review on marking code style +issues? + +Here we go - this allows to use `clang-format` as a linter for +[arcanist](https://phacility.com/phabricator/arcanist) to enforce style over +your C/C++/Objective-C codebase. + +It's not invasive (yet) and at the moment just suggests to autofix +code. + +## Installation + +What you want to get is to make this module to be available for +`arcanist`. There are a couple of ways to achieve it depending on your +requirements. + +### Prerequisites + +Right now `clang-format` should be installed beforehand. On OS X you +can do it through [homebrew](https://brew.sh) `brew install +clang-format`. + +You also have to configure your style in `.clang-format` +([documentation](http://clang.llvm.org/docs/ClangFormatStyleOptions.html)) + +Best way is to start from a predefined style by dumping an existing +style `clang-format -style=LLVM -dump-config > .clang-format` and tune +parameters. + +There is also a wonderful +[interactive builder](http://clangformat.com/) available. + +### Project-specific installation + +You can add this repository as a git submodule and in this case +`.arcconfig` should look like: + +```json +{ + "load": [ + "path/to/submodule" + ] + // ... +} +``` + +### Global installation +`arcanist` can load modules from an absolute path. But there is one +more trick - it also searches for modules in a directory up one level +from itself. + +It means that you can clone this repository to the same directory +where `arcanist` and `libphutil` are located. In the end it should +look like this: + +```sh +> ls +arcanist +clang-format-linter +libphutil +``` + +In this case you `.arcconfig` should look like + +```json +{ + "load": [ + "clang-format-linter" + ] + // ... +} +``` + +Another approach is to clone `clang-format-linter` to a fixed location +and use absolute path like: + +```sh +cd ~/.dev-tools +git clone https://github.com/vhbit/clang-format-linter +``` + +```json +{ + "load": [ + "~/.dev-tools/clang-format-linter" + ] + // ... +} +``` + +Both ways of global installation are actually almost equally as in +most cases you'd like to have a bootstrapping script for all tools. + +## Setup + +Once installed, linter can be used and configured just as any other +`arcanist linter` + +Here is a simplest `.arclint`: + +```json +{ + "linters": { + "clang-format": { + "type": "clang-format", + "include": "(^Source/.*\\.(m|h|mm)$)" + }, + // ... + } +} +``` diff --git a/.linters/clang-format-linter/__phutil_library_init__.php b/.linters/clang-format-linter/__phutil_library_init__.php new file mode 100644 index 000000000..41b2534a5 --- /dev/null +++ b/.linters/clang-format-linter/__phutil_library_init__.php @@ -0,0 +1,3 @@ + 2, + 'class' => array( + 'ClangFormatLinter' => 'lint/linter/ClangFormatLinter.php', + ), + 'function' => array(), + 'xmap' => array( + 'ClangFormatLinter' => 'ArcanistExternalLinter', + ), +)); diff --git a/.linters/clang-format-linter/lint/linter/ClangFormatLinter.php b/.linters/clang-format-linter/lint/linter/ClangFormatLinter.php new file mode 100644 index 000000000..3d6153e1b --- /dev/null +++ b/.linters/clang-format-linter/lint/linter/ClangFormatLinter.php @@ -0,0 +1,79 @@ +getProjectRoot(); + $path = Filesystem::resolvePath($path, $root); + $orig = file_get_contents($path); + if ($orig == $stdout) { + return array(); + } + + $message = id(new ArcanistLintMessage()) + ->setPath($path) + ->setLine(1) + ->setChar(1) + ->setGranularity(ArcanistLinter::GRANULARITY_FILE) + ->setCode('CFMT') + ->setSeverity(ArcanistLintSeverity::SEVERITY_AUTOFIX) + ->setName('Code style violation') + ->setDescription("'$path' has code style errors.") + ->setOriginalText($orig) + ->setReplacementText($stdout); + return array($message); + } +}