devops.cpp.ast.checks.enforce_member_leading_underscore

Enforce a leading underscore on private and protected member variables.

Any non-static or static data member declared under a private: or protected: access specifier must have a name starting with _ (e.g. _count, _isValid). Public members are never flagged, since they are part of the class’s external interface and not the concern of this check.

Member variables synthesized by a macro invoked on the same source line (e.g. gtest’s TEST_F(...) expanding to a fixture class with its own private test_info_ member, declared entirely inside gtest’s macro body) are not flagged: the name was never actually typed by the user, so there is nothing for them to rename.

To disable this check for a project set:

[cpp]
ast_check_disabled_ids = ["memberLeadingUnderscore"]

Classes

EnforceMemberLeadingUnderscore()

Flag private/protected member variables without a leading underscore.

class devops.cpp.ast.checks.enforce_member_leading_underscore.EnforceMemberLeadingUnderscore[source]

Bases: Check

Flag private/protected member variables without a leading underscore.

Reporting is deferred to finalize() because whether a candidate member was synthesized by a macro (and should be skipped) can only be known once every MACRO_INSTANTIATION cursor in the file has been seen — which, in a single preorder walk, may happen before or after the member itself is visited.

id: str = 'memberLeadingUnderscore'

unique id, used as the cppcheck-style [id] suffix

visit(cursor, filename)[source]

Record macro-instantiation lines and candidate members for filename.

Parameters:
  • cursor (clang.Cursor) – The AST node currently being visited.

  • filename (str) – Path of the file being checked.

Returns:

list[Diagnostic] – Always empty — diagnostics are emitted from finalize() once the whole file (including its macro instantiations) is known.

Return type:

list[Diagnostic]

finalize(filename)[source]

Emit diagnostics for buffered members not on a macro-instantiation line.

Parameters:

filename (str) – Path of the file being checked.

Returns:

list[Diagnostic] – One diagnostic per offending member variable whose line isn’t covered by a macro instantiation.

Return type:

list[Diagnostic]