-
Notifications
You must be signed in to change notification settings - Fork 124
Fix related to XML suppressions not working #705
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Fix related to XML suppressions not working #705
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.
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.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.
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
- 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) |
Copilot
AI
Feb 4, 2026
There was a problem hiding this comment.
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.
|
|
||
| if (duration > 0) | ||
| { | ||
| //Assert.IsNotNull(suppression.ExpirationDate, "Expiration date should be set"); |
Copilot
AI
Feb 4, 2026
There was a problem hiding this comment.
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.
| //Assert.IsNotNull(suppression.ExpirationDate, "Expiration date should be set"); |
| [TestClass] | ||
| public class SuppressionTest | ||
| { | ||
| public TestContext? TestContext { get; set; } |
Copilot
AI
Feb 4, 2026
There was a problem hiding this comment.
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.
| 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"); |
Copilot
AI
Feb 4, 2026
There was a problem hiding this comment.
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(...)).
| 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"); |
Copilot
AI
Feb 4, 2026
There was a problem hiding this comment.
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.
| 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"); | ||
| } | ||
| } |
Copilot
AI
Feb 4, 2026
There was a problem hiding this comment.
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(...)'.

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