docs: Update clang-format instructions in CONTRIBUTING. (#1053)

* docs: Update clang-format instructions in CONTRIBUTING.

* Accomodate more changes in the PR section of CONTRIBUTING.

* code formatting

* code sample as a shell script

* format build command

* Add instructions for clang-format installation.

* gitpod

* remove a sentence.
This commit is contained in:
Filip Hlasek 2020-08-30 10:38:49 -07:00 committed by GitHub
parent 4ed75018e3
commit 072fc95228
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -154,19 +154,33 @@ Common prefixes:
### Pull Requests ### Pull Requests
- Checkout our [pull request template](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/.github/pull_request_template.md) - Checkout our [pull request template](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/.github/pull_request_template.md)
#### cpplint #### Building Locally
To see if [__cpplint__](https://github.com/cpplint/cpplint) is already installed, do: Before submitting a pull request, build the code locally or using the convenient [![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/TheAlgorithms/C-Plus-Plus) service.
* `cpplint --version` # currently returns "cpplint 1.4.4" ```
If cpplint is ___not___ installed then do: cmake -B build -S .
* `python3 -m pip install cpplint` # If that does not work then try... ```
* `py -m pip install cpplint` # If that does not work then try...
* `pip install cpplint`
Once cpplint is installed, test your file(s) with:
* `cpplint --filter=-legal my_file.cpp my_other_file.cpp` # Fix any issues and try again.
The [__clang-format__](https://clang.llvm.org/docs/ClangFormat.html) tool can fix whitespace related _cpplint_ issues. #### Static Code Analyzer
* On Macs only: `brew install clang-format` # Only needs to be installed once. We use [clang-tidy](https://clang.llvm.org/extra/clang-tidy/) as a static code analyzer with a configuration in [.clang-tidy](.clang-tidy).
* All platforms: `clang-format -i -style="{IndentWidth: 4}" my_file.cpp` ```
clang-tidy --fix --quiet -p build subfolder/file_to_check.cpp --
```
#### Code Formatter
[__clang-format__](https://clang.llvm.org/docs/ClangFormat.html) is used for code forrmating.
* Installation (Only needs to be installed once.)
* Mac (using home-brew): `brew install clang-format`
* Mac (using macports): `sudo port install clang-10 +analyzer`
* Windows (MSYS2 64-bit): `pacman -S mingw-w64-x86_64-clang-tools-extra`
* Linux (Debian): `sudo apt-get install clang-format-10 clang-tidy-10`
* Running (all platforms): `clang-format -i -style="file" my_file.cpp`
#### GitHub Actions
Enable GitHub Actions on your fork of the repository.
After enabling it will execute `clang-tidy` and `clang-format` after every a push (not a commit).
The result can create another commit if the actions made any changes on your behalf.
Hence, it is better to wait and check the results of GitHub Actions after every push.
Run `git pull` in your local clone if these actions made many changes in order to avoid merge conflicts.
Most importantly, Most importantly,
- Happy coding! - Happy coding!