Skip to content

Commit 6b4dc5a

Browse files
authored
Add more details about pre-commit
1 parent eeae95f commit 6b4dc5a

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

codeformatting/index.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,17 @@ Guidelines for code formatting in C++ and Python
88

99
FreeCAD is written primarily in C++ and Python (with a few files in other languages such as CMake). To smooth the process of merging new contributions it is desirable to minimize formatting changes to existing code, and to use a uniform code formatting style when writing new code. Eventually we expect to standardize the codebase on specific coding styles using Clang Format for C++ and a Python code-formatter (such as Black), but that is a work-in-progress and _should not_ be applied to existing otherwise-untouched code.
1010

11+
## Setting up pre-commit
12+
13+
For the sections of the code that have already been auto-formatted, we use [git pre-commit hooks](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks) to enforce that formatting. We use the [pre-commit](https://pre-commit.com/) framework to install and manage our hooks. All developers should install pre-commit following the [instructions here](https://freecad.github.io/DevelopersHandbook/gettingstarted/). When making a new commit, the hooks examine your changed files and ensure that they follow the appropriate formatting for the section of code you are working on. You do not need to manually yourself with your code's formatting as you develop, and may code it as you like (or as your IDE likes...). The hook will ensure that your finished code conforms to project requirements.
14+
15+
Not all of FreeCAD currently uses these hooks: it is up to the Maintainers in charge of a particular Workbench or subdirectory to work with their development team to migrate their code's formatting to the automated tools, and to then enable the hooks on their subdirectory.
16+
17+
Currently the following sections of code are covered by pre-commit: `src/Mod/AddonManager`, `src/Tools`, and `tests/src`.
18+
1119
## C++
1220

13-
FreeCAD's codebase currently includes a preliminary [.clang-format](https://github.com/FreeCAD/FreeCAD/blob/master/.clang-format) file. Many IDEs will automatically apply these settings when editing files. To minimize disruption of other developers, only new or significantly-refactored code should have the formatting automatically applied. Code not being worked on should not be automatically formatted at this time.
21+
FreeCAD's codebase currently includes a [.clang-format](https://github.com/FreeCAD/FreeCAD/blob/master/.clang-format) file. Many IDEs will automatically apply these settings when editing files. To minimize disruption of other developers, only new or significantly-refactored code should have the formatting automatically applied. Code not being worked on should not be automatically formatted at this time.
1422

1523
### C++ Copyright Header
1624

@@ -73,9 +81,3 @@ The following is the standard Python copyright header that should be included in
7381
# * *
7482
# ***************************************************************************
7583
```
76-
77-
### Addon Manager
78-
79-
The Addon Manager uses the Black code formatter: all new code for the Addon Manager should be run through Black (with no additional command-line options) prior to submission. It is recommended that developers working on the Addon Manager set up Black as a pre-commit hook. If also using pylint, in the case of style conflicts Black's formatting takes precedence over that suggested by pylint.
80-
81-
Note that in some cases it is allowable to have line lengths that exceed the Black standard of 88 characters per line in order to support Qt's translate functionality. Qt's translation string extractor does not understand Python string concatenation, so to preserve the easy translatability of longer phrases those phrases must be presented as a single line of text.

0 commit comments

Comments
 (0)