Skip to content

Enable clang-tidy cognitive complexity checks#7995

Merged
maxtropets merged 8 commits into
mainfrom
copilot/enable-clang-tidy-readability-function-cognitive-c
Jun 30, 2026
Merged

Enable clang-tidy cognitive complexity checks#7995
maxtropets merged 8 commits into
mainfrom
copilot/enable-clang-tidy-readability-function-cognitive-c

Conversation

Copilot AI commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

readability-function-cognitive-complexity was disabled, leaving highly complex functions invisible to clang-tidy. This enables the check with a higher initial threshold and macro expansion ignored.

  • clang-tidy configuration
    • Enables readability-function-cognitive-complexity.
    • Sets IgnoreMacros=true to avoid logging/registration macro noise.
    • Sets Threshold=50 as the initial enforcement level.
CheckOptions:
  - key: readability-function-cognitive-complexity.IgnoreMacros
    value: 'true'
  - key: readability-function-cognitive-complexity.Threshold
    value: '50'
  • Baseline suppressions
    • Adds targeted NOLINTNEXTLINE(readability-function-cognitive-complexity) annotations for existing non-vendored functions currently above the threshold.
    • This establishes a clean baseline so new over-threshold functions are reported without requiring broad refactors in this PR.

Co-authored-by: achamayou <4016369+achamayou@users.noreply.github.com>
Copilot AI changed the title [WIP] Enable clang-tidy's readability-function-cognitive-complexity check Enable clang-tidy cognitive complexity checks Jun 27, 2026
Copilot AI requested a review from achamayou June 27, 2026 09:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Enables clang-tidy’s readability-function-cognitive-complexity check (previously disabled) with an initial higher threshold and macro-ignoring configuration, and establishes a baseline by adding targeted NOLINTNEXTLINE suppressions for existing over-threshold functions.

Changes:

  • Enable readability-function-cognitive-complexity and configure it with IgnoreMacros=true and Threshold=50 in .clang-tidy.
  • Add targeted NOLINTNEXTLINE(readability-function-cognitive-complexity) annotations to known complex functions/tests to keep the new check actionable immediately.

Custom instructions used:

  • .github/copilot-instructions.md
  • .github/instructions/reviewing.instructions.md

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated no comments.

Show a summary per file
File Description
.clang-tidy Enables and configures cognitive complexity checking with initial threshold + macro ignoring.
src/node/test/historical_queries.cpp Suppresses existing over-threshold complexity in a TEST_CASE.
src/node/rpc/node_frontend.h Suppresses existing over-threshold complexity in init_handlers().
src/node/rpc/frontend.h Suppresses existing over-threshold complexity in process_command_inner().
src/node/rpc/file_serving_handlers.h Suppresses existing over-threshold complexity in file-serving helper/initializer functions.
src/node/node_state.h Suppresses existing over-threshold complexity in initiate_join_unsafe().
src/node/gov/handlers/service_state.h Suppresses existing over-threshold complexity in handler registration.
src/node/gov/handlers/proposals.h Suppresses existing over-threshold complexity in handler registration.
src/node/gov/handlers/acks.h Suppresses existing over-threshold complexity in handler registration.
src/js/registry.cpp Suppresses existing over-threshold complexity in JS request execution path.
src/indexing/test/indexing.cpp Suppresses existing over-threshold complexity in a multi-threaded indexing test.
samples/apps/programmability/programmability.cpp Suppresses existing over-threshold complexity in constructor/handler setup.
samples/apps/logging/logging.cpp Suppresses existing over-threshold complexity in init_handlers().

@achamayou achamayou marked this pull request as ready for review June 29, 2026 16:22
@achamayou achamayou requested a review from a team as a code owner June 29, 2026 16:22
@achamayou

Copy link
Copy Markdown
Member

@copilot check you did not miss any functions?

Copilot AI commented Jun 29, 2026

Copy link
Copy Markdown
Contributor Author

@copilot check you did not miss any functions?

I ran clang-tidy with readability-function-cognitive-complexity (Threshold=50, IgnoreMacros=true) across all 182 CCF source files in the compile database. With the current NOLINTNEXTLINE annotations in place, zero additional warnings were produced. I also confirmed the tool is actually detecting violations — removing the annotation from src/js/registry.cpp immediately surfaced a complexity-of-69 warning for do_execute_request.

So no functions appear to have been missed for the files that could be fully analyzed in this environment. Any files that depend on system headers not present locally (e.g. nghttp2) will be validated by the CI run where all dependencies are available.

@achamayou

Copy link
Copy Markdown
Member

@copilot what's failing in the latest CI then?

Co-authored-by: achamayou <4016369+achamayou@users.noreply.github.com>

Copilot AI commented Jun 29, 2026

Copy link
Copy Markdown
Contributor Author

@copilot what's failing in the latest CI then?

CI was failing because setup_basic_hooks in src/node/node_state.h (line 2679) had a cognitive complexity of 66 and was missing a suppression annotation. This function includes the nghttp2 header transitively, which wasn't available in my local sandbox, so it wasn't caught in my earlier analysis. Fixed in the latest commit by adding the missing NOLINTNEXTLINE(readability-function-cognitive-complexity) annotation.

@maxtropets maxtropets merged commit 03fcee6 into main Jun 30, 2026
17 checks passed
@maxtropets maxtropets deleted the copilot/enable-clang-tidy-readability-function-cognitive-c branch June 30, 2026 09:19
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.

4 participants