devops.cpp.ast.checks.no_clang_format_toggle

Flag // clang-format off / // clang-format on comments in code.

These comments disable clang-format’s formatting for the region they bracket (or the rest of the file, if unbalanced), letting hand-formatted code drift silently out of sync with the project’s style over time. Both the line-comment (// clang-format off) and block-comment (/* clang-format off */) spellings are flagged, for both off and on.

To disable this check for a project set:

[cpp]
ast_check_disabled_ids = ["noClangFormatToggle"]

Classes

NoClangFormatToggle()

Flag // clang-format off/on comments anywhere in the file.

class devops.cpp.ast.checks.no_clang_format_toggle.NoClangFormatToggle[source]

Bases: Check

Flag // clang-format off/on comments anywhere in the file.

id: str = 'noClangFormatToggle'

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

visit(cursor, filename)[source]

Capture the file’s translation unit for finalize’s token scan.

Comments aren’t exposed as AST cursors, so this check can’t flag anything from a single cursor. Instead it piggybacks on the shared walk just to remember cursor’s translation unit (and the resolved file name libclang matched it under), then does the real work once in finalize.

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.

Return type:

list[Diagnostic]

finalize(filename)[source]

Scan the file’s comment tokens for clang-format toggle comments.

Parameters:

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

Returns:

list[Diagnostic] – One diagnostic per // clang-format off/on comment found in filename itself (comments pulled in from other headers via the AST are ignored).

Return type:

list[Diagnostic]