Skip to content

Fix Sonar code smells: static method and test exception patterns#106

Merged
Malcolmnixon merged 4 commits intomainfrom
copilot/fix-sonar-code-smells
Feb 13, 2026
Merged

Fix Sonar code smells: static method and test exception patterns#106
Malcolmnixon merged 4 commits intomainfrom
copilot/fix-sonar-code-smells

Conversation

Copy link
Contributor

Copilot AI commented Feb 13, 2026

Pull Request

Description

Addresses Sonar code smells flagged by static analysis: unused instance access (CA1822) and improper exception testing patterns (MSTEST0058).

Production Code

  • TraceMatrix.cs: Made SectionHasFilteredContent static (doesn't access instance data)
  • Validation.cs: String literal duplication (S1192) suppressed per maintainer preference for inline readability

Test Code

Refactored 49 test methods across 5 files to use MSTest v4's Assert.ThrowsExactly<T>() pattern:

Before:

try
{
    Context.Create(["--results"]);
    Assert.Fail("Expected ArgumentException was not thrown");
}
catch (ArgumentException ex)
{
    Assert.Contains("--results requires a filename argument", ex.Message);
}

After:

var ex = Assert.ThrowsExactly<ArgumentException>(() => Context.Create(["--results"]));
Assert.Contains("--results requires a filename argument", ex.Message);

Pattern applied to:

  • ContextTests.cs: 15 methods
  • RequirementsReadTests.cs: 28 methods
  • RequirementsExportTests.cs: 2 methods
  • TraceMatrixExportTests.cs: 2 methods
  • TraceMatrixReadTests.cs: 2 methods

Type of Change

  • Code quality improvement

Related Issues

Pre-Submission Checklist

Build and Test

  • Code builds successfully: dotnet build --configuration Release
  • All tests pass: dotnet test --configuration Release
  • Code produces zero warnings

Code Quality

  • Code formatting is correct: dotnet format --verify-no-changes
  • New code has appropriate XML documentation comments
  • Static analyzer warnings have been addressed

Quality Checks

  • Spell checker passes: cspell "**/*.{md,cs}"
  • Markdown linter passes: markdownlint "**/*.md"
  • YAML linter passes: yamllint '**/*.{yml,yaml}'

Testing

  • Added unit tests for new functionality
  • Updated existing tests if behavior changed
  • All tests follow the AAA (Arrange, Act, Assert) pattern
  • Test coverage is maintained or improved

Documentation

  • Updated README.md (if applicable)
  • Updated ARCHITECTURE.md (if applicable)
  • Added code examples for new features (if applicable)
  • Updated requirements.yaml (if applicable)

Additional Notes

CodeQL security scan: No vulnerabilities found. All 132 tests pass.


💡 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.

Copilot AI and others added 3 commits February 13, 2026 12:03
Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
@Malcolmnixon Malcolmnixon marked this pull request as ready for review February 13, 2026 12:10
Copilot AI changed the title [WIP] Fix Sonar issues in codebase Fix Sonar code smells: static method and test exception patterns Feb 13, 2026
Copilot AI requested a review from Malcolmnixon February 13, 2026 12:12
@Malcolmnixon Malcolmnixon merged commit fd46ea6 into main Feb 13, 2026
11 checks passed
@Malcolmnixon Malcolmnixon deleted the copilot/fix-sonar-code-smells branch February 13, 2026 12:19
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.

2 participants