From 968a50738cb5f3dbf58f4b9e1ecb3538fc99133d Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sat, 7 Dec 2024 17:58:53 +0000 Subject: [PATCH] PR guidelines: add style --- .../PR-Guidelines.md | 39 ++++++++++++------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/pages/Contributing and Debugging/PR-Guidelines.md b/pages/Contributing and Debugging/PR-Guidelines.md index 4af1bd3..dfc55b0 100644 --- a/pages/Contributing and Debugging/PR-Guidelines.md +++ b/pages/Contributing and Debugging/PR-Guidelines.md @@ -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("name"); +This is non-negotiable. Your code **must** be formatted. -// e.g. -static const auto PBORDERSIZE = CConfigValue("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 \ No newline at end of file