Skip to content

refactor: reduce cognitive complexity of generateToolDoc (40 → ~5) - #143

Open
devin-ai-integration[bot] wants to merge 2 commits into
mainfrom
devin/1777981970-refactor-generate-docs
Open

devin-ai-integration[bot] wants to merge 2 commits into
mainfrom
devin/1777981970-refactor-generate-docs

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented May 5, 2026

Copy link
Copy Markdown

Closes: SonarQube issue go:S3776 on cmd/github-mcp-server/generate_docs.go:220

Summary

The generateToolDoc function had a cognitive complexity of 40 (allowed: 15) due to deeply nested type assertions for schema property inspection. This PR extracts focused helper functions.

Extracted Functions

Function Responsibility
extractPropertyType Determines the type string from a schema property map (handles arrays)
extractPropertyDescription Extracts the description string from a property map
formatParamLine Formats a single parameter's documentation line

Tradeoffs

  • The main function is now a simple loop over sorted parameters, delegating formatting to helpers.
  • Added 3 small functions but each is self-contained with clear input/output.

Alternatives

  • Considered using a struct to wrap property metadata, but the untyped map[string]interface{} schema makes that overly verbose for this use case.

Link to Devin session: https://app.devin.ai/sessions/dc69091bf9e24bd2871c88e47fa1cb98
Requested by: @VedantKh


Devin Review

Status Commit
⚪ Not started

Run Devin Review

💡 Connect your GitHub account to enable automatic code reviews.

Open in Devin Review (Staging)
Open in Devin Review

Extract helper functions from generateToolDoc to reduce cognitive
complexity from 40 to well within the allowed threshold of 15.

Extracted functions:
- extractPropertyType: determines type string from schema property map
- extractPropertyDescription: extracts description from property map
- formatParamLine: formats a single parameter documentation line

Fixes SonarQube issue go:S3776 on generate_docs.go:220

Co-Authored-By: Vedant Khanna <vedantkhanna@gmail.com>
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

devin-ai-integration[bot]

This comment was marked as resolved.

When items map exists but items["type"] is not a string, return
"unknown" (matching original behavior) instead of "array".

Co-Authored-By: Vedant Khanna <vedantkhanna@gmail.com>
@sonarqubecloud

sonarqubecloud Bot commented May 5, 2026

Copy link
Copy Markdown

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant