Fix related to XML suppressions not working#705
Fix related to XML suppressions not working#705vamsipolavarapu-msft wants to merge 6 commits intomicrosoft:mainfrom
Conversation
Changes: - Added xml suppression comments syntax requirements in comments.json - Added a test class for testing suppression comments. File: DevSkimRuleProcessorTests.cs
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
There was a problem hiding this comment.
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.cswith unit tests for suppression generation across various languages - Enhanced existing
SuppressionsTest.cswith 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.
DevSkim-DotNet/Microsoft.DevSkim.Tests/DevSkimRuleProcessorTests.cs
Outdated
Show resolved
Hide resolved
|
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? |
…evSkimRuleProcessorTests
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. |
|
@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. |
|
@microsoft-github-policy-service agree company="Microsoft" |
Enabling suppressions for XML files to address bug microsoft#588.
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
|
/azp run |
|
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. |
|
/azp run |
|
No pipelines are associated with this pull request. |
There was a problem hiding this comment.
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
- This foreach loop implicitly filters its target sequence - consider filtering the sequence explicitly using '.Where(...)'.
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.
| [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) |
There was a problem hiding this comment.
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.
|
|
||
| if (duration > 0) | ||
| { | ||
| //Assert.IsNotNull(suppression.ExpirationDate, "Expiration date should be set"); |
There was a problem hiding this comment.
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.
| //Assert.IsNotNull(suppression.ExpirationDate, "Expiration date should be set"); |
| [TestClass] | ||
| public class SuppressionTest | ||
| { | ||
| public TestContext? TestContext { get; set; } |
There was a problem hiding this comment.
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.
| public TestContext? TestContext { get; set; } |
| Assert.Contains("<!-- DevSkim: ignore", result, "XML suppression comment should be present"); | ||
| Assert.Contains("-->", result, "XML suppression comment should be properly closed"); |
There was a problem hiding this comment.
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(...)).
| 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"); |
| 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"); |
There was a problem hiding this comment.
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.
| 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"); |
| 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"); | ||
| } | ||
| } |
There was a problem hiding this comment.
This foreach loop implicitly filters its target sequence - consider filtering the sequence explicitly using '.Where(...)'.

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