Skip to content
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

Consider using clang-tidy at some point #30

Open
malespiaut opened this issue Jul 19, 2023 · 2 comments
Open

Consider using clang-tidy at some point #30

malespiaut opened this issue Jul 19, 2023 · 2 comments

Comments

@malespiaut
Copy link
Contributor

As for another bold proposal, clang-tidy is an intersting tool to automate a large number of code modification to increade quality.

That includes initialising variables, and putting brackets for one line ifs (a change to consider regarding some confusing parts of the source code).

If you haven't used clang-tidy before, I highly encourage you to give it a try on small pieces of example code. I think that it can play an essential part for this project.

@fabiangreffrath
Copy link
Owner

So, what's the difference to clang-format then?

@malespiaut
Copy link
Contributor Author

To summarize, clang-format only reformats the code by only changing whitespaces and newlines.

clang-tidy will modify the code according to certain rules.

For instance, clang-tidy have a rule called cppcoreguidelines-init-variables with initialize all variables to 0.

It'll change this code:

void function() {
  int x;
  char *txt;
  double d;

  // Rest of the function.
}

to this

#include <math.h>

void function() {
  int x = 0;
  char *txt = nullptr;
  double d = NAN;

  // Rest of the function.
}

See https://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines/init-variables.html for more details.

There's also the rule readability-braces-around-statements which, as the name implies, adds braces around statements, for readability.

It'll change this code:

if (condition)
  statement;

to this

if (condition) {
  statement;
}

See https://releases.llvm.org/11.0.0/tools/clang/tools/extra/docs/clang-tidy/checks/readability-braces-around-statements.html for more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants