File: using-clang-format.md

package info (click to toggle)
opentelemetry-cpp 1.23.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,368 kB
  • sloc: cpp: 96,239; sh: 1,766; makefile: 38; python: 31
file content (53 lines) | stat: -rw-r--r-- 1,756 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# Using clang-format

## Command-line use

To format a file according to Coding style using command line, please setup the
build tools environment first.

For Windows - cmd.exe command:

```call tools\setup-devenv.cmd```

For Linux and Mac:

```. tools/setup-devenv.sh```

Command will add the tools from repo *tools* directory to PATH environment
variable.

Then run:

```git cl format <filename>```

At the moment the tool requires you to specify the path to file you want to
format. Long-term goal is to integrate the [clang-format from
Chromium](https://chromium.googlesource.com/chromium/src/+/master/docs/clang_format.md)
to automatically format all source code files being changed.

## Alternative

Run: `tools/format.sh`

Or, via Docker: `./ci/run_docker.sh ./ci/do_ci.sh format`

## Editor integrations

For further guidance on editor integration, see these specific pages:

* [Download link for LLVM tools for
  Windows](https://releases.llvm.org/9.0.0/LLVM-9.0.0-win64.exe)
* [LLVM tools extension for Visual
  Studio](https://marketplace.visualstudio.com/items?itemName=LLVMExtensions.llvm-toolchain)
* [Visual Studio code
  extension](https://marketplace.visualstudio.com/items?itemName=xaver.clang-format)
* [CppStyle Eclipse CDT
  extension](https://marketplace.eclipse.org/content/cppstyle)

## Are robots taking over my freedom to choose where newlines go

No. For the project as a whole, using clang-format is just one optional way to
format your code. While it will produce style-guide conformant code, other
formats would also satisfy the style guide. For certain modules it may be
appropriate to use alternate coding style. In those scenarios a local directory
*.clang-format* settings file takes precedence over the one at top-level.