File: Formatting.md

package info (click to toggle)
jacktrip 2.7.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,788 kB
  • sloc: cpp: 44,373; sh: 965; makefile: 152; ansic: 32; ruby: 20; python: 15
file content (76 lines) | stat: -rw-r--r-- 1,882 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# Formatting with clang-format

JackTrip uses clang-format to specify the Code Formatting Style.
Most IDEs are able to recognize the `.clang-format` file in JackTrip's project
directory and integrate the formatting capabilities.

Formatting specific files is done like this:

```bash
clang-format -i class.cpp class.h
```

This overrides all given files. If you only want to check the formatting `-i` has
to be removed.

Areas in the source code that must not be formatted have to be embraced in following statements:

```c++
this = is.formatted;
// clang-format off
this+=   isnot     ;
// clang-format on
this = again;
```

## Forget about formatting with a git pre-commit hook

With git the user can install hooks that are executed when specific tasks are done.
We can add a pre-commit hook for clang-format. So that everytime we commit our
changes, git runs clang-format for us.

Handling git hooks by hand is cumbersome. With [pre-commit](https://pre-commit.com/)
this becomes a lot easier.

Pre-commit is a Python app that can be installed with pip.

```bash
pip install pre-commit
```

Within the root directory of the jacktrip repository the pre-commit hook can be
installed as follows:

```bash
pre-commit install
```

Pre-commit only runs on changed files. Running pre-commit on all files is done
by:

```bash
pre-commit run --all-files
```

Sometimes these hooks come into your way. But you can disable them when committing:

```bash
git commit -am "Commit all my stuff" --no-verify
```

### Pre-commit configuration

Pre-commit is configured by the *.pre-commit-config.yaml* file in the repository's
root. Currently it only includes the clang-format hook.

```yaml
fail_fast: false
repos:
  - repo: https://github.com/ssciwr/clang-format-hook
    rev: v13.0.1
    hooks:
    - id: clang-format
      files: ^src/
      types_or: [c++]
      exclude: '^src/.+dsp\.h'
```