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

clang-tidy: enforce identifier naming and enable rule for classes. #977

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

fabratu
Copy link
Member

@fabratu fabratu commented Aug 15, 2022

During #940 (unifying naming scheme of enums) it became clear, that currently clang-tidy does not enforce the already defined naming conventions. It is not straightforward however how to activate them. There are currently some established practices in NetworKit, which would lead to mixed naming schemes (for example G or G([a-z]*|[0-9]*) as a name for graph-datastructure variables).

The PR includes a first version of a modified clang-tidy file using regular expressions for ignoring some "special" cases of NetworKit. The remaining changes will nevertheless be quite huge anyway, since it includes changes in the API for both C++ and Python. I am not sure, whether this special treatment is the best approach though - so this PR is a starting point to ignite a discussion about how to proceed.

@avdgrinten
Copy link
Contributor

It would be good to add comments to the code that indicate why we need to add these exclusion regexps. For example, why do we need to exclude names starting/ending with underscores?

@fabratu fabratu force-pushed the 20220815_clang_tidy_readability branch from 7daf473 to eb0fcdb Compare August 18, 2022 10:45
@fabratu
Copy link
Member Author

fabratu commented Aug 18, 2022

Makes sense. I added explanations for all ignored expressions.

Also tweaked some expressions:

  • Removed leading/trailing underscores for template parameters. Is currently used in some places, but doesn't seem to be of any purpose.
  • Removed trailing underscore for function names. This I think is not used, was just inserted to match the leading underscore.
  • Added [a-z0-9]* to member, variable and parameter expressions. There are cases, where multiple instances of graphs or other structures/mathematical symbols are used in one block of code (like G1/G2 or G/Gnew).

@avdgrinten
Copy link
Contributor

LGTM now. AFAICS the PR also enables the check (which was previously disabled), right?

@fabratu
Copy link
Member Author

fabratu commented Aug 18, 2022

Yes, it also enables the check.

Maybe it is a good idea (like we did with networkit-format), to enable each check one-by-one in seperate PRs. This way, it would be easier to review and discuss possible problems.

@fabratu fabratu force-pushed the 20220815_clang_tidy_readability branch 2 times, most recently from a5047c7 to 79d5e51 Compare August 24, 2022 08:47
@fabratu fabratu changed the title [WIP] Enforce naming conventions via clang-tidy clang-tidy: enforce identifier naming and enable rule for classes. Aug 24, 2022
@fabratu fabratu force-pushed the 20220815_clang_tidy_readability branch from 79d5e51 to 0e5917b Compare August 24, 2022 09:18
@fabratu fabratu force-pushed the 20220815_clang_tidy_readability branch from 0e5917b to c10419e Compare August 24, 2022 10:26
@fabratu
Copy link
Member Author

fabratu commented Aug 24, 2022

Changed the scope of the PR and enabled the check for class-naming only (+ required changes in the code).

Copy link
Contributor

@avdgrinten avdgrinten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we need deprecations and aliases?

@fabratu
Copy link
Member Author

fabratu commented Sep 8, 2022

Don't we need deprecations and aliases?

@avdgrinten Good point. Most of the current changes concern private structs. Any advise whether they should also be deprecated?

@@ -35,7 +35,7 @@ struct AttributizedEdge {
}
};

struct greater {
struct Greater {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this used anywhere? If not it can be removed.

@angriman
Copy link
Member

angriman commented Jan 6, 2023

Private structs don't need to be deprecated I think.

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

Successfully merging this pull request may close these issues.

None yet

3 participants