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 77 78 79 80 81 82 83 84 85 86 87
|
# Coding Style
F3D use different coding styles in each component, however there are some common rules
## C++
### Common rules
Overall syntax:
- CamelCase.
- Avoid using `using` for namespaces.
- Initialize variables in header when possible.
- Local variables starts with a lower case char.
- Class members starts with a upper case char.
- Indents are two spaces.
- One space between instruction and parenthesis.
- Always add curly brace after instruction.
- Curly brace one a new line, aligned with instruction.
- Add `//----------------------------------------------------------------------------` before any method in implementation.
Example:
```cpp
//----------------------------------------------------------------------------
void class::method()
{
if (condition)
{
std::vector<int> myIntVector = { 13 };
}
}
```
Includes:
- Organized by category: `F3DApplication`, `libf3d`, `VTKExtensions`, `other deps`, `std`, `system`.
- Sorted inside category.
### F3D Application rules
- Class starts with `F3D`
- Method starts with an uppercase char.
### libf3d rules
- Class starts with a lower case char.
- Method starts with an lower case char.
### VTKExtensions rules
- Follow VTK rules
- Method starts with an uppercase char.
- Class starts with `vtkF3D` if inheriting from vtkObject.
- Class starts with `F3D` if not inheriting from vtkObject.
### Automatic formatting
Some of the rules above are enforced using clang-format thanks to a `.clang-format` file.
The continuous integration checks it whenever code is pushed to a pull request.
To fix it locally, you can use:
- single file: `clang-format -i /path/to/file.ext`
- all files: `shopt -s globstar; clang-format -i **/*.{h,cxx}`
Please note there can be small discrepancy between the CI and local run of clang-format depending
on the version in use. You may need to fix these manually.
## Python
All python code is simply formatted using [Black style](https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html).
The continuous integration checks the formatting of python code using `black`.
You can fix it locally by running:
- single file: `black /path/to/file.py`
- all files: `black --include '(\.py|\.py\.in)' .`
## Markdown and others
Markdown, JavaScript, JSON, HTML and YAML files are formatted using [Prettier](https://prettier.io/docs/).
The continuous integration checks the formatting of all these files using `prettier`.
You can fix them locally by running:
- single file: `prettier -w /path/to/file.ext`
- all files: `shopt -s dotglob;shopt -s globstar; prettier -w **/*.{js,json,md,html,yml}`
|