Skip to content

Commit

Permalink
Try to not reference suppression state for vs2019 (#5108)
Browse files Browse the repository at this point in the history
  • Loading branch information
georgii-borovinskikh-sonarsource authored Dec 12, 2023
1 parent 7790a76 commit 34e0023
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/Infrastructure.VS.UnitTests/ErrorListHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -407,17 +407,17 @@ public void TryGetRuleIdAndSuppressionStateFromSelectedRow_NoSuppressionState_Re
}

[DataTestMethod]
[DataRow(SuppressionState.Suppressed, true)]
[DataRow(SuppressionState.NotApplicable, false)]
[DataRow(SuppressionState.Active, false)]
public void TryGetRuleIdAndSuppressionStateFromSelectedRow_NoSuppressionState_ReturnsIsNotSuppressed(SuppressionState suppressionState, bool expectedSuppression)
[DataRow(Infrastructure.VS.SuppressionState.SuppressedEnumValue, true)]
[DataRow(Infrastructure.VS.SuppressionState.NotApplicableEnumValue, false)]
[DataRow(Infrastructure.VS.SuppressionState.ActiveEnumValue, false)]
public void TryGetRuleIdAndSuppressionStateFromSelectedRow_NoSuppressionState_ReturnsIsNotSuppressed(int suppressionState, bool expectedSuppression)
{
// Arrange
var issueHandle = CreateIssueHandle(111, new Dictionary<string, object>
{
{ StandardTableKeyNames.BuildTool, "SonarLint" },
{ StandardTableKeyNames.ErrorCode, "cpp:S222" },
{ StandardTableKeyNames.SuppressionState, suppressionState },
{ Infrastructure.VS.SuppressionState.ColumnName, suppressionState },
});

var errorList = CreateErrorList(issueHandle);
Expand Down
4 changes: 2 additions & 2 deletions src/Infrastructure.VS/ErrorListHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ public bool TryGetRoslynIssueFromSelectedRow(out IFilterableRoslynIssue filterab
private static bool IsSuppressed(ITableEntryHandle handle)
{
return handle.TryGetSnapshot(out var snapshot, out var index)
&& TryGetValue(snapshot, index, StandardTableKeyNames.SuppressionState, out SuppressionState suppressionState)
&& suppressionState == SuppressionState.Suppressed;
&& TryGetValue(snapshot, index, Infrastructure.VS.SuppressionState.ColumnName, out int suppressionState)
&& suppressionState == Infrastructure.VS.SuppressionState.SuppressedEnumValue;
}

private static string FindErrorCodeForEntry(ITableEntriesSnapshot snapshot, int index)
Expand Down
32 changes: 32 additions & 0 deletions src/Infrastructure.VS/SuppressionState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* SonarLint for Visual Studio
* Copyright (C) 2016-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

namespace SonarLint.VisualStudio.Infrastructure.VS
{
// This class duplicates SuppressionState enum and StandardTableKeyNames.SuppressionState because it's not available in vs2019 assembly (even though it is available in the ide)
internal static class SuppressionState
{
public const string ColumnName = "suppression";

public const int ActiveEnumValue = 0;
public const int SuppressedEnumValue = 1;
public const int NotApplicableEnumValue = 2;
}
}

0 comments on commit 34e0023

Please sign in to comment.