PR guidelines: add style

This commit is contained in:
Vaxry 2024-12-07 17:58:53 +00:00
parent cf77151365
commit 968a50738c

View file

@ -8,25 +8,36 @@ title: PR Guidelines
- Described changes and _why_ they were there
- Following the style (see below)
### Code Style
## Code Style
Hyprland's code style is governed by the `.clang-format` file.
Please read this if you are submitting a PR, in order to minimize the amount of style nits received, and save
the time for the maintainers.
Make sure to format accordingly whenever you make a PR.
### Before you submit
### Some code FAQ
Make sure you ran clang-format: `clang-format -i src/**/*{cpp,hpp}`
> Why is the config variable getting so weird?
Check if your changes don't violate `clang-tidy`. Usually this is built into your IDE.
Every variable from the config needs to be found in a hashmap. To limit the
amount of hashmap searches, getting a config option looks like this:
### Clang-format
```cpp
static const auto PVARIABLE = CConfigValue<TYPE>("name");
This is non-negotiable. Your code **must** be formatted.
// e.g.
static const auto PBORDERSIZE = CConfigValue<Hyprlang::INT>("general:border_size");
```
### Clang-tidy
Since the hashmap _cannot_ be mutated during runtime, this pointer will always
be valid, and will not require hashmap lookups every single time it's read.
Clang-tidy violations are not hard requirements, but please try to minimize them, and
_only_ ignore them if it's absolutely necessary.
I've tweaked it so that in 99% of cases you absolutely should fix it.
### Other
Some stuff clang-tidy / clang-format won't catch:
- No uninitialized _primitives_ (int, float, double, size_t, etc.)
- No short ifs. if your if/else body contains 1 _line_ (not 1 statement) do not put `{}` around it.
- The above rule does not apply to loops / etc
- Consider adding a `;` inside of empty function bodies
- Use utilities. Do not invent new types where one already exists.
- Consider the usage of the STL
- Minimize manual memory management to an absolute minimum. You have tons of tools at your disposal to do so
- Whenever you're initializing vectors arrays or maps with a lot of elements, add a `,` after the last element to make the styling nicer