From 5e7de1602e0645d4c9a95587b999a28d4be0084c Mon Sep 17 00:00:00 2001 From: mary-georgiou-sonarsource Date: Wed, 15 Mar 2023 15:53:23 +0100 Subject: [PATCH] rename mathod and condition --- .../AnalysisContext/SonarAnalysisContextBase.cs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/analyzers/src/SonarAnalyzer.Common/AnalysisContext/SonarAnalysisContextBase.cs b/analyzers/src/SonarAnalyzer.Common/AnalysisContext/SonarAnalysisContextBase.cs index 144c6b41a3a..cd84a6f5aeb 100644 --- a/analyzers/src/SonarAnalyzer.Common/AnalysisContext/SonarAnalysisContextBase.cs +++ b/analyzers/src/SonarAnalyzer.Common/AnalysisContext/SonarAnalysisContextBase.cs @@ -59,7 +59,7 @@ protected SonarAnalysisContextBase(SonarAnalysisContext analysisContext, TContex public bool ShouldAnalyzeTree(SyntaxTree tree, GeneratedCodeRecognizer generatedCodeRecognizer) => SonarLintXml() is var sonarLintXml && (generatedCodeRecognizer is null || sonarLintXml.AnalyzeGeneratedCode || !tree.IsGenerated(generatedCodeRecognizer, Compilation)) - && (tree is null || (!IsUnchanged(tree) && FileIsIncludedInAnalysis(sonarLintXml, tree.FilePath))); + && (tree is null || (!IsUnchanged(tree) && !IsExcluded(sonarLintXml, tree.FilePath))); /// /// Reads configuration from SonarProjectConfig.xml file and caches the result for scope of this analysis. @@ -125,13 +125,12 @@ public bool HasMatchingScope(DiagnosticDescriptor descriptor) descriptor.CustomTags.Contains(tag); } - private bool FileIsIncludedInAnalysis(SonarLintXmlReader sonarLintXml, string filePath) => - // If ProjectType != 'Unknown' we are in S4NET context and all files are analyzed. - // If ProjectType == 'Unknown' then we are in SonarLint or NuGet context and - // we need to check if the file has been excluded from analysis through SonarLint.xml. - ProjectConfiguration().ProjectType != ProjectType.Unknown - || (FileInclusionCache.GetValue(Compilation, _ => new()) is var cache - && cache.GetOrAdd(filePath, _ => IsFileIncluded(sonarLintXml, filePath))); + private bool IsExcluded(SonarLintXmlReader sonarLintXml, string filePath) => + // If ProjectType is not 'Unknown' it means we are in S4NET context and all files are analyzed. + // If ProjectType is 'Unknown' then we are in SonarLint or NuGet context and we need to check if the file has been excluded from analysis through SonarLint.xml. + ProjectConfiguration().ProjectType == ProjectType.Unknown + && FileInclusionCache.GetValue(Compilation, _ => new()) is var cache + && !cache.GetOrAdd(filePath, _ => IsFileIncluded(sonarLintXml, filePath)); private ImmutableHashSet CreateUnchangedFilesHashSet() => ImmutableHashSet.Create(StringComparer.OrdinalIgnoreCase, ProjectConfiguration().AnalysisConfig?.UnchangedFiles() ?? Array.Empty());