Example #1
0
        private static void ReportWhenNotSuppressed(SyntaxTree tree, Diagnostic diagnostic, Action <Diagnostic> report)
        {
            if (SonarAnalysisContext.ShouldDiagnosticBeReported(tree, diagnostic))
            {
                // VB.Net complier (VBC) post-process issues and will fail if the line contains the VbNetErrorPattern.
                // See https://github.com/dotnet/roslyn/issues/5724
                // As a workaround we will prevent reporting the issue if the issue is on a line with the error pattern and the
                // language VB.Net
                // TODO: Remove this workaround when issue is fixed on Microsoft side.
                var rootNode = diagnostic.Location.SourceTree?.GetRoot();

                if (rootNode != null &&
                    rootNode.Language == LanguageNames.VisualBasic)
                {
                    var diagnosticNode = rootNode.FindNode(diagnostic.Location.SourceSpan);
                    var lineContent    = diagnosticNode?.ToString();

                    if (lineContent != null &&
                        VbNetErrorPattern.IsMatch(lineContent))
                    {
                        return;
                    }
                }

                report(diagnostic);
            }
        }
Example #2
0
 private static void ReportWhenNotSuppressed(Diagnostic diagnostic, Action <Diagnostic> report)
 {
     if (SonarAnalysisContext.ShouldDiagnosticBeReported(diagnostic))
     {
         report(diagnostic);
     }
 }