Skip to content
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

Implement -IncludeSuppressions parameter #1701

Merged
merged 20 commits into from
Aug 4, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add IsSuppressed property to diagnostics
rjmholt committed Jul 25, 2021
commit 50bdfa90146c4f6158768b84221a2f861bd5f6da
13 changes: 10 additions & 3 deletions Engine/Generic/DiagnosticRecord.cs
Original file line number Diff line number Diff line change
@@ -92,12 +92,13 @@ public IEnumerable<CorrectionExtent> SuggestedCorrections
set { suggestedCorrections = value; }
}

public bool IsSuppressed { get; protected set; } = false;

/// <summary>
/// DiagnosticRecord: The constructor for DiagnosticRecord class.
/// </summary>
public DiagnosticRecord()
{

}

/// <summary>
@@ -109,7 +110,14 @@ public DiagnosticRecord()
/// <param name="severity">The severity of this diagnostic</param>
/// <param name="scriptPath">The full path of the script file being analyzed</param>
/// <param name="suggestedCorrections">The correction suggested by the rule to replace the extent text</param>
public DiagnosticRecord(string message, IScriptExtent extent, string ruleName, DiagnosticSeverity severity, string scriptPath, string ruleId = null, IEnumerable<CorrectionExtent> suggestedCorrections = null)
public DiagnosticRecord(
string message,
IScriptExtent extent,
string ruleName,
DiagnosticSeverity severity,
string scriptPath,
string ruleId = null,
IEnumerable<CorrectionExtent> suggestedCorrections = null)
{
Message = message;
RuleName = ruleName;
@@ -119,7 +127,6 @@ public DiagnosticRecord(string message, IScriptExtent extent, string ruleName, D
RuleSuppressionID = ruleId;
this.suggestedCorrections = suggestedCorrections;
}

}


1 change: 1 addition & 0 deletions Engine/Generic/SuppressedRecord.cs
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@ public class SuppressedRecord : DiagnosticRecord
public SuppressedRecord(DiagnosticRecord record, IReadOnlyList<RuleSuppression> suppressions)
{
Suppression = new ReadOnlyCollection<RuleSuppression>(new List<RuleSuppression>(suppressions));
IsSuppressed = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this ever be called with a suppression list count of zero? In that case IsSuppressed really true?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Very good question. I think the mere wrapping in the SuppressedRecord object classes the diagnostic as suppressed, but I agree that this opens up the possibility of an invalid object, which I dislike... I'm not sure I see a way around this without changing a few things around though, and I'm not sure that's worth it.

if (record != null)
{
RuleName = record.RuleName;
4 changes: 4 additions & 0 deletions Tests/Engine/RuleSuppression.tests.ps1
Original file line number Diff line number Diff line change
@@ -119,8 +119,10 @@ function MyFunc
$diagnostics | Should -HaveCount 1
$diagnostics[0].RuleName | Should -BeExactly "PSAvoidUsingPlainTextForPassword"
$diagnostics[0].RuleSuppressionID | Should -BeExactly "password2"
$diagnostics[0].IsSuppressed | Should -BeFalse

$suppressions | Should -HaveCount 1
$suppressions[0].IsSuppressed | Should -BeTrue
$suppressions[0].RuleName | Should -BeExactly "PSAvoidUsingPlainTextForPassword"
$suppressions[0].RuleSuppressionID | Should -BeExactly "password1"
$suppressions[0].Suppression | Should -HaveCount 2
@@ -172,11 +174,13 @@ function MyFunc
$diagnostics | Should -HaveCount 2
$diagnostics[0].RuleName | Should -BeExactly "PSAvoidUsingPlainTextForPassword"
$diagnostics[0].RuleSuppressionID | Should -BeExactly "password2"
$diagnostics[0].IsSuppressed | Should -BeFalse

$diagnostics[1].RuleName | Should -BeExactly "PSAvoidUsingPlainTextForPassword"
$diagnostics[1].RuleSuppressionID | Should -BeExactly "password1"
$diagnostics[1].Suppression | Should -HaveCount 2
$diagnostics[1].Suppression.Justification | Sort-Object | Should -Be @('a', 'a')
$diagnostics[1].IsSuppressed | Should -BeTrue
}