Skip to content

Conversation

@devin-ai-integration
Copy link

Summary

This PR addresses two high-severity SonarQube issues in the mcpcurl CLI tool:

  1. String literal duplication (go:S1192): Extracted repeated "stdio-server-cmd" string into a constant
  2. High cognitive complexity (go:S3776): Refactored the main() function to reduce complexity from 18 to under 15

Changes

String Duplication Fix

  • Added stdioServerCmdFlag constant to eliminate 6 duplicate string literals
  • Updated all flag references, error messages, and documentation to use the constant
  • Improves maintainability and reduces risk of typos

Cognitive Complexity Reduction

  • Extracted setupFlags() function to handle command and flag initialization
  • Extracted loadSchemaAndAddCommands() function to handle schema fetching and dynamic command generation
  • Simplified main() function to focus on high-level orchestration
  • Maintains identical functionality while improving code organization

Testing

✅ Linting passes with 0 issues (SonarQube violations resolved)
✅ All existing tests pass
⚠️ Note: The mcpcurl command has no unit tests, so changes were validated through linting and manual verification only

Human Review Checklist

  • Verify all "stdio-server-cmd" string occurrences were replaced with the constant
  • Confirm extracted functions maintain identical behavior to original main() function
  • Check that error handling and program flow work the same way
  • Consider manual testing of the mcpcurl command if critical

Tradeoffs

  • Pro: Significantly improved code maintainability and reduced duplication
  • Con: Added complexity with new functions, though each has a single clear responsibility
  • Risk: No automated tests for this CLI tool, so changes rely on manual verification

Link to Devin run: https://app.devin.ai/sessions/ad0a7f4affc44fd099a2218a8b6632c5
Requested by: @zohebmunshi

…in() cognitive complexity

- Extract 'stdio-server-cmd' string literal to constant (fixes go:S1192)
- Refactor main() function to reduce cognitive complexity from 18 to under 15 (fixes go:S3776)
- Break down main() into smaller focused functions: setupFlags() and loadSchemaAndAddCommands()
- All 6 occurrences of the string literal now use the stdioServerCmdFlag constant
- Maintains existing functionality while improving code maintainability

Co-Authored-By: Zoheb Munshi <zohebmunshi@gmail.com>
@devin-ai-integration
Copy link
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

@sonarqubecloud
Copy link

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.

0 participants