Skip to content

Update and enforce formatting for C/C++ (#1474) #1496

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 6, 2025

Conversation

AMS21
Copy link
Contributor

@AMS21 AMS21 commented Nov 4, 2023

Every new commit or pull request will now be checked with clang-format.
Note that only violations in new code will be reported and any old code will stay just as it is.

Here is an example PR to showcase how this would look like.

@AMS21 AMS21 force-pushed the code_style/clang-format branch 2 times, most recently from 76ac8a8 to c604d26 Compare November 6, 2023 09:54
@AMS21 AMS21 force-pushed the code_style/clang-format branch from c604d26 to 305b51f Compare November 17, 2023 14:13
@AMS21 AMS21 force-pushed the code_style/clang-format branch from 305b51f to 7a4db46 Compare November 25, 2023 13:04
@AMS21 AMS21 force-pushed the code_style/clang-format branch from 7a4db46 to bc1bfa3 Compare December 4, 2023 11:00
@Xottab-DUTY Xottab-DUTY force-pushed the dev branch 2 times, most recently from 143d1ca to 118d39d Compare December 16, 2023 10:39
@AMS21 AMS21 force-pushed the code_style/clang-format branch from bc1bfa3 to 33d492d Compare March 15, 2024 10:16
@AMS21
Copy link
Contributor Author

AMS21 commented Mar 15, 2024

Rebased and update to LLVM 18

@Xottab-DUTY Xottab-DUTY force-pushed the dev branch 2 times, most recently from 5b2ec76 to 6fffce9 Compare May 4, 2024 03:27
@AMS21 AMS21 force-pushed the code_style/clang-format branch from 33d492d to a94e78c Compare May 14, 2024 16:19
@Xottab-DUTY Xottab-DUTY force-pushed the dev branch 2 times, most recently from e89fcc8 to f6fd5cc Compare October 24, 2024 02:36
@Xottab-DUTY Xottab-DUTY force-pushed the dev branch 3 times, most recently from c3ffa4d to 09b0b99 Compare March 6, 2025 15:34
@AMS21 AMS21 force-pushed the code_style/clang-format branch 2 times, most recently from eb26ab5 to a3da552 Compare March 6, 2025 22:12
@AMS21 AMS21 force-pushed the code_style/clang-format branch from a3da552 to 12704e2 Compare March 6, 2025 22:16
@AMS21
Copy link
Contributor Author

AMS21 commented Mar 6, 2025

Rebased and updated to LLVM 20
@Xottab-DUTY Thoughts on getting this merged?

@Xottab-DUTY
Copy link
Member

Xottab-DUTY commented Mar 18, 2025

Rebased and updated to LLVM 20 @Xottab-DUTY Thoughts on getting this merged?

I need to check that .clang-format corresponds to our code style, which currently has some relaxed requirements:
We generally follow the naming style of a certain file or a certain class. It can be a developer preference if the naming style of the class or file is already mixed. Generally, there are two choices for naming:

  1. PascalCase based variable naming
    • All global/public variables and both private/public functions should be in PascalCase
    • Local/private variables should be in camelCase
    • Using camelCase for global/public variables is strongly discouraged, but can be used if the entire class or a file follows it and not using it would look alien. Renaming to PascalCase should be considered
    • Hungarian notation is discouraged, but can be used if the entire class or a file follows it and not using it would look alien. Renaming in spare time should be considered
    • Template parameter names should be in PascalCase
  2. snake_case based variable naming
    • non-static global variables should have g_ prefix
    • static global variables should have s_ prefix
    • global constexpr variables should be upper case, omitting g_/s_ prefixes
    • local constexpr variables can be named like global constexpr variables or just like generic variables
    • private member variables in classes should have m_ prefix, public members should not have this prefix
    • Template parameter names should be in PascalCase

As for formatting style, here are some rules:

  • Braces always should be on a new line if it's a code block/scope
    • if (condition) { // not allowed
      
      if (condition)
      { // correct
    • One-line lambda-functions is ok. Writing standard functions in one-line is discouraged
  • Braced initializers should always have spaces inside
    • auto vec = Fvector{1,2,3}; // incorrect!!
      auto vec = Fvector{1, 2, 3}; // incorrect
      auto vec = Fvector{ 1, 2, 3 }; // correct
  • Preprocessor directives should be indented, leaving the # at the beginning of the line
    • #if defined(A)
      #   define B
      #   if defined(C)
      #       define D
      #   endif
      #endif
      

For third-party dependencies, we should strictly follow their code style.

Xottab-DUTY added a commit that referenced this pull request Jun 6, 2025
@Xottab-DUTY Xottab-DUTY linked an issue Jun 6, 2025 that may be closed by this pull request
6 tasks
@Xottab-DUTY Xottab-DUTY moved this from To do to In Progress in Roadmap Jun 6, 2025
@Xottab-DUTY Xottab-DUTY merged commit 3f88167 into OpenXRay:dev Jun 6, 2025
4 of 34 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in Roadmap Jun 6, 2025
@Xottab-DUTY
Copy link
Member

Much thanks for this gem!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Thoughts on improving and enforcing coding style
2 participants