devops.cpp.ast.checks.enforce_no_public_leading_underscore

Forbid a leading underscore on public member variables and functions.

Any data member or member function (including static and template ones) declared under a public: access specifier — or under no access specifier at all in a struct/union — must have a name that does not start with _ (e.g. count, compute(), not _count / _compute()). A leading underscore is reserved for private/protected members by memberLeadingUnderscore and memberFunctionLeadingUnderscore, so on a public member it signals the wrong access level or a stray rename rather than being the author’s real intent. Private/protected members are never flagged here — that’s the concern of the two checks above.

A handful of member-function kinds are never flagged, because their name is fixed by the language or by a base class and renaming them isn’t something the author can freely do:

  • Constructors and destructors — their name is always the class’s own name (or ~ClassName).

  • Operator overloads and conversion functions (operator==, operator[], operator int() const, …) — the operator’s spelling is fixed by the language grammar.

  • Methods that override a base class’s virtual method — the override must keep the base method’s exact name to bind at all.

A member declared entirely inside a macro invoked on the same source line (e.g. gtest’s TEST_F(...) expanding to a fixture class with its own public members) is not flagged either: 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 = ["noPublicLeadingUnderscore"]

Classes

EnforceNoPublicLeadingUnderscore()

Flag public member variables/functions whose name starts with _.

class devops.cpp.ast.checks.enforce_no_public_leading_underscore.EnforceNoPublicLeadingUnderscore[source]

Bases: Check

Flag public member variables/functions whose name starts with _.

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 = 'noPublicLeadingUnderscore'

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 public member whose line isn’t covered by a macro instantiation.

Return type:

list[Diagnostic]