private static void ReportDiagnostic(ReportingContext reportingContext)
        {
            // This is the new way SonarLint will handle how and what to report...
            if (SonarAnalysisContext.ReportDiagnostic != null)
            {
                Debug.Assert(SonarAnalysisContext.ShouldDiagnosticBeReported == null, "Not expecting SonarLint to set both the old and the new delegates.");
                SonarAnalysisContext.ReportDiagnostic(reportingContext);
                return;
            }

            // ... but for compatibility purposes we need to keep handling the old-fashioned way. Old SonarLint can be used with latest NuGet.
            if (SonarAnalysisContext.AreAnalysisScopeMatching(reportingContext.Compilation, new[] { reportingContext.Diagnostic.Descriptor }) &&
                !VbcHelper.IsTriggeringVbcError(reportingContext.Diagnostic) &&
                (SonarAnalysisContext.ShouldDiagnosticBeReported?.Invoke(reportingContext.SyntaxTree, reportingContext.Diagnostic) ?? true))
            {
                reportingContext.ReportDiagnostic(reportingContext.Diagnostic);
            }
        }
Ejemplo n.º 2
0
        private static void ReportDiagnostic(ReportingContext reportingContext)
        {
            // This is the new way SonarLint will handle how and what to report...
            if (SonarAnalysisContext.ReportDiagnostic != null)
            {
                Debug.Assert(SonarAnalysisContext.ShouldDiagnosticBeReported == null, "Not expecting SonarLint to set both the " +
                             "old and the new delegates.");
                SonarAnalysisContext.ReportDiagnostic(reportingContext);
                return;
            }

            // ... but for compatibility purposes we need to keep handling the old-fashioned way
            if (!VbcHelper.IsTriggeringVbcError(reportingContext.Diagnostic) &&
                (SonarAnalysisContext.ShouldDiagnosticBeReported?.Invoke(reportingContext.SyntaxTree, reportingContext.Diagnostic) ?? true))
            {
                reportingContext.ReportDiagnostic(reportingContext.Diagnostic);
            }
        }
        private static void ReportDiagnostic(ReportingContext reportingContext, bool?isTestProject)
        {
            if (isTestProject.HasValue && !SonarAnalysisContext.IsAnalysisScopeMatching(reportingContext.Compilation, isTestProject.Value, new[] { reportingContext.Diagnostic.Descriptor }))
            {
                return;
            }

            // This is the current way SonarLint will handle how and what to report.
            if (SonarAnalysisContext.ReportDiagnostic != null)
            {
                Debug.Assert(SonarAnalysisContext.ShouldDiagnosticBeReported == null, "Not expecting SonarLint to set both the old and the new delegates.");
                SonarAnalysisContext.ReportDiagnostic(reportingContext);
                return;
            }

            // Standalone NuGet, Scanner run and SonarLint < 4.0 used with latest NuGet
            if (!VbcHelper.IsTriggeringVbcError(reportingContext.Diagnostic) &&
                (SonarAnalysisContext.ShouldDiagnosticBeReported?.Invoke(reportingContext.SyntaxTree, reportingContext.Diagnostic) ?? true))
            {
                reportingContext.ReportDiagnostic(reportingContext.Diagnostic);
            }
        }