Skip to content

Fix related to XML suppressions not working#705

Open
vamsipolavarapu-msft wants to merge 6 commits intomicrosoft:mainfrom
vamsipolavarapu-msft:SuppressionAndProgressBarChanges
Open

Fix related to XML suppressions not working#705
vamsipolavarapu-msft wants to merge 6 commits intomicrosoft:mainfrom
vamsipolavarapu-msft:SuppressionAndProgressBarChanges

Conversation

@vamsipolavarapu-msft
Copy link

Fix related to XML suppressions not working (#588).

Changes:

  • Added xml suppression comments syntax requirements in comments.json
  • Added a test class for testing suppression comments. File: DevSkimRuleProcessorTests.cs

Changes:
- Added xml suppression comments syntax requirements in comments.json
- Added a test class for testing suppression comments. File: DevSkimRuleProcessorTests.cs
@gfs
Copy link
Contributor

gfs commented Oct 14, 2025

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@vamsipolavarapu-msft
Copy link
Author

Sample XML suppression
image

@danfiedler-msft
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@gfs gfs requested a review from Copilot October 22, 2025 18:50
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes an issue where XML suppression comments were not working in DevSkim. The fix adds XML-specific comment syntax definitions and introduces comprehensive test coverage for suppression functionality across multiple languages.

Key changes:

  • Added XML comment syntax (<!-- -->) to the comments configuration
  • Created new test class DevSkimRuleProcessorTests.cs with unit tests for suppression generation across various languages
  • Enhanced existing SuppressionsTest.cs with integration tests specifically for XML suppressions

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
DevSkim-DotNet/Microsoft.DevSkim/resources/comments.json Added XML comment syntax definition with prefix <!-- and suffix -->
DevSkim-DotNet/Microsoft.DevSkim.Tests/SuppressionsTest.cs Added XML-specific integration tests and TestContext property
DevSkim-DotNet/Microsoft.DevSkim.Tests/DevSkimRuleProcessorTests.cs New test class covering suppression generation for multiple languages including XML

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@gfs
Copy link
Contributor

gfs commented Oct 22, 2025

This looks like it'd be the correct way to specify this to me. The test failures I think are a pipeline permission issue, maybe some setting needs to be updated?

@vamsipolavarapu-msft
Copy link
Author

vamsipolavarapu-msft commented Oct 22, 2025

This looks like it'd be the correct way to specify this to me. The test failures I think are a pipeline permission issue, maybe some setting needs to be updated?

Yes, the assert statements are in the correct format. And Dan is checking on the pipeline permissions issue. I cleaned up the other unused test method as well.

@gfs
Copy link
Contributor

gfs commented Oct 22, 2025

@vamsipolavarapu-msft To be able to merge you need to accept the CLA and also add an update to the changelog to satisfy the CI check.

@vamsipolavarapu-msft
Copy link
Author

@microsoft-github-policy-service agree company="Microsoft"

Enabling suppressions for XML files to address bug microsoft#588.
@gfs
Copy link
Contributor

gfs commented Oct 22, 2025

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@gfs
Copy link
Contributor

gfs commented Dec 2, 2025

/azp run

@azure-pipelines
Copy link

Azure Pipelines will not run the associated pipelines, because the pull request was updated after the run command was issued. Review the pull request again and issue a new run command.

@gfs
Copy link
Contributor

gfs commented Feb 4, 2026

/azp run

@azure-pipelines
Copy link

No pipelines are associated with this pull request.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

Comments suppressed due to low confidence (2)

DevSkim-DotNet/Microsoft.DevSkim.Tests/SuppressionsTest.cs:433

  • Assert.Contains is not a method available in MSTest framework. This should use StringAssert.Contains(result, "<!-- DevSkim: ignore") instead, or alternatively use Assert.IsTrue(result.Contains("<!-- DevSkim: ignore")).
            Assert.Contains("<!-- DevSkim: ignore", result, "XML suppression comment should be present");

DevSkim-DotNet/Microsoft.DevSkim.Tests/SuppressionsTest.cs:457

            foreach (string line in lines)
            {
                if (line.Contains("<!-- DevSkim: ignore"))
                {
                    foundSuppression = true;
                    Suppression suppression = new Suppression(line);
                    Assert.IsTrue(suppression.IsInEffect, "Suppression should be in effect");
                    
                    if (!string.IsNullOrEmpty(reviewerName))
                    {
                        Assert.AreEqual(reviewerName, suppression.Reviewer, "Reviewer name should match");
                    }
                    
                    if (duration > 0)
                    {
                        //Assert.IsNotNull(suppression.ExpirationDate, "Expiration date should be set");
                        Assert.AreEqual(expectedExpiration.Date, suppression.ExpirationDate, "Expiration date should match");
                    }
                }
            }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +401 to +405
[TestMethod]
[DataRow("", 30, DisplayName = "XML Suppression with Duration only")]
[DataRow("TestReviewer", 30, DisplayName = "XML Suppression with Reviewer and Duration")]
[DataRow("TestReviewer", 0, DisplayName = "XML Suppression with Reviewer only")]
public void ExecuteSuppressionsForXMLWithReviewerAndDuration(string reviewerName, int duration)
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test method uses [DataRow] attributes but is marked with [TestMethod] instead of [DataTestMethod]. The correct attribute should be [DataTestMethod] for parameterized tests. Without this, the test will fail to execute properly.

Copilot uses AI. Check for mistakes.

if (duration > 0)
{
//Assert.IsNotNull(suppression.ExpirationDate, "Expiration date should be set");
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assertion is commented out without explanation. If the assertion is not needed, the commented code should be removed to keep the codebase clean. If it's needed, it should be uncommented or the reason for commenting it out should be documented.

Suggested change
//Assert.IsNotNull(suppression.ExpirationDate, "Expiration date should be set");

Copilot uses AI. Check for mistakes.
[TestClass]
public class SuppressionTest
{
public TestContext? TestContext { get; set; }
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This TestContext property is declared but never used in any test methods. If it's not needed, it should be removed to keep the code clean. TestContext is typically used for accessing test run information, logging, or data-driven test data sources, none of which appear to be used in this class.

Suggested change
public TestContext? TestContext { get; set; }

Copilot uses AI. Check for mistakes.
Comment on lines +379 to +380
Assert.Contains("<!-- DevSkim: ignore", result, "XML suppression comment should be present");
Assert.Contains("-->", result, "XML suppression comment should be properly closed");
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assert.Contains is not a method available in MSTest framework. MSTest uses StringAssert.Contains(string value, string substring) with the arguments in reverse order. These lines should use StringAssert.Contains(result, "") instead, or alternatively use Assert.IsTrue(result.Contains(...)).

Suggested change
Assert.Contains("<!-- DevSkim: ignore", result, "XML suppression comment should be present");
Assert.Contains("-->", result, "XML suppression comment should be properly closed");
StringAssert.Contains(result, "<!-- DevSkim: ignore", "XML suppression comment should be present");
StringAssert.Contains(result, "-->", "XML suppression comment should be properly closed");

Copilot uses AI. Check for mistakes.
foundSuppression = true;
Suppression suppression = new Suppression(line);
Assert.IsTrue(suppression.IsInEffect, "Suppression should be in effect");
Assert.IsGreaterThan(0,suppression.GetSuppressedIds.Length, "Should have at least one suppressed rule ID");
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assert.IsGreaterThan is not a method available in MSTest framework. The correct assertion would be Assert.IsTrue(suppression.GetSuppressedIds.Length > 0, "Should have at least one suppressed rule ID"). Note that the argument order in the current code is also incorrect - the expected value should come first.

Suggested change
Assert.IsGreaterThan(0,suppression.GetSuppressedIds.Length, "Should have at least one suppressed rule ID");
Assert.IsTrue(suppression.GetSuppressedIds.Length > 0, "Should have at least one suppressed rule ID");

Copilot uses AI. Check for mistakes.
Comment on lines +385 to +394
foreach (string line in lines)
{
if (line.Contains("<!-- DevSkim: ignore"))
{
foundSuppression = true;
Suppression suppression = new Suppression(line);
Assert.IsTrue(suppression.IsInEffect, "Suppression should be in effect");
Assert.IsGreaterThan(0,suppression.GetSuppressedIds.Length, "Should have at least one suppressed rule ID");
}
}
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This foreach loop implicitly filters its target sequence - consider filtering the sequence explicitly using '.Where(...)'.

Copilot uses AI. Check for mistakes.
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.

4 participants