Skip to content

Fix SonarQube double indexing in flat layout by excluding tests from sources#1091

Merged
nathanjmcdougall merged 5 commits intomainfrom
copilot/fix-sonarqube-source-dir-configuration
Nov 5, 2025
Merged

Fix SonarQube double indexing in flat layout by excluding tests from sources#1091
nathanjmcdougall merged 5 commits intomainfrom
copilot/fix-sonarqube-source-dir-configuration

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Nov 5, 2025

  • Analyze the current SonarQube configuration code
  • Modify get_sonar_project_properties() to automatically exclude tests/* when using flat layout (sources=./)
  • Add regression tests for flat layout with and without custom exclusions
  • Run existing tests to ensure no regressions (16/16 SonarQube tests pass)
  • Code review completed and feedback addressed
    • Removed redundant list() cast on line 67
    • Added comment to clarify TypeAdapter(list).validate_python() returns a list
    • Changed from append to prepend (insert at index 0) for exclusion
    • Changed exclusion syntax from ./tests to tests/* for proper SonarQube pattern matching
  • Type checking passed (pyright: 0 errors, 0 warnings)
  • Linting passed (ruff: all checks passed)

Summary

Fixed SonarQube configuration to properly exclude the tests directory when using flat layout to prevent double indexing. The fix ensures that sonar.sources and sonar.tests directories are disjoint by prepending tests/* to the exclusions list. Updated based on PR feedback to use the correct SonarQube exclusion pattern syntax (tests/* instead of ./tests).

Original prompt

This section details on the original issue you should resolve

<issue_title>Properly configure SonarQube source dir when tests and source dir overlap</issue_title>
<issue_description>These directories need to be disjoint. When using src layout, this works fine:

          sonar.sources=./src
          sonar.tests=./tests

But if we have a flat layout, this doesn't work, because files get indexed twice:

          sonar.sources=./
          sonar.tests=./tests

The exclusions should simply be set/augmented to always include ./tests via comma separation and this will fix the issue.

Test strategy is probably just regression-style unit tests to make sure the config contents are sound, and then I'll test them manually on a live pipeline.</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix SonarQube source dir configuration for tests and sources Fix SonarQube double indexing in flat layout by excluding tests from sources Nov 5, 2025
…ions

Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Nov 5, 2025

CodSpeed Performance Report

Merging #1091 will not alter performance

Comparing copilot/fix-sonarqube-source-dir-configuration (ab7bfb5) with main (73f05e1)

Summary

✅ 2 untouched

@codecov
Copy link
Copy Markdown

codecov bot commented Nov 5, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
@nathanjmcdougall nathanjmcdougall marked this pull request as ready for review November 5, 2025 19:43
@nathanjmcdougall nathanjmcdougall merged commit 99c73c5 into main Nov 5, 2025
19 of 21 checks passed
@nathanjmcdougall nathanjmcdougall deleted the copilot/fix-sonarqube-source-dir-configuration branch November 5, 2025 19:43
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.

Properly configure SonarQube source dir when tests and source dir overlap

2 participants