Skip to content

Feature Request: Include code snippet (+2 lines) around issue line in report output #457

@RumaisAbdulla

Description

@RumaisAbdulla

✅ Feature Request: Include Code Snippet (±2 Lines) Around Issue Line in Report


📌 Summary

Currently, the Sonar CNES Report lists issues with file name and line number, but the actual code snippet around the issue is not shown in the generated report.

To make the report more developer-friendly and actionable, I propose adding an additional section or column that shows the code snippet around the issue line — ideally 2 lines before and 2 lines after.


🎯 Example of Expected Output Improvement

Issue: Hardcoded credentials detected
File: src/config.yaml
Line: 10

Line 8: some previous config
Line 9: some previous config
Line 10: password: "admin123" <-- ⚠ Reported issue line
Line 11: metadata: value
Line 12: more metadata


💡 Implementation Suggestion (Optional)

  • Use SonarQube Web API to extract source code snippet dynamically:
    GET /api/sources/raw?key=<file_key>&from=<start_line>&to=<end_line>

  • Logic for selecting code window:

  • start_line = max(1, issue_line - 2)

  • end_line = issue_line + 2

  • Display snippet in report output under each issue OR add a dedicated "Snippet" column/section.


🚀 Benefits

  • Faster review without switching between report and SonarQube UI
  • Offline reports become self-contained and review-ready
  • Better context awareness for auditors and developers

📝 Notes

If maintainers agree, I’m happy to:

  • Contribute this feature via PR
  • Follow project guidelines for formatting and output rendering
  • Discuss snippet formatting (inline, collapsible, or extended section)

👍 Let me know if you agree — I can start working on a PR once approved.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions