public bool SuppressionExists(IFilterableIssue issue)
        {
            if (issue == null)
            {
                throw new ArgumentNullException(nameof(issue));
            }


            // File-level issues (i.e. line = null) match if:
            // 1. Same component, same file, same error code.

            // Non-file-level issues match if:
            // 1. Same component, same file, same error code, same line hash        // tolerant to line number changing
            // 2. Same component, same file, same error code, same line             // tolerant to code on the line changing e.g. var rename

            // File-level issues never match non-file-level issues.

            // Retrieve all issues relating to this file (file level or precise location) or project (for module level issues)
            var serverIssues = issuesProvider.GetSuppressedIssues(issue.ProjectGuid, issue.FilePath);

            // Try to find an issue with the same ID and either the same line number or some line hash
            bool matchFound = serverIssues.Any(s => IsMatch(issue, s));

            return(matchFound);
        }
Beispiel #2
0
 private void ConfigureServerIssues(
     IFilterableIssue issueToMatch,
     params SonarQubeIssue[] issuesToReturn)
 {
     mockIssuesProvider
     .Setup(x => x.GetSuppressedIssues(issueToMatch.ProjectGuid, issueToMatch.FilePath)).Returns(issuesToReturn);
 }
        private static bool IsMatch(IFilterableIssue issue, SonarQubeIssue serverIssue)
        {
            if (!StringComparer.OrdinalIgnoreCase.Equals(issue.RuleId, serverIssue.RuleId))
            {
                return(false);
            }

            if (!issue.StartLine.HasValue) // i.e. file-level issue
            {
                return(serverIssue.TextRange == null);
            }

            // Non-file level issue
            return(issue.StartLine == serverIssue.TextRange?.StartLine || StringComparer.Ordinal.Equals(issue.LineHash, serverIssue.Hash));
        }