From 7df445f252b67554e46320e44a9fbdaa91fdd3c7 Mon Sep 17 00:00:00 2001 From: Pavel Mikula <57188685+pavel-mikula-sonarsource@users.noreply.github.com> Date: Thu, 23 Jan 2025 17:25:08 +0100 Subject: [PATCH] NET-1033 AnalysisContext: Rename SemanticModel to Model --- ...onarSyntaxNodeAnalysisContextExtensions.cs | 2 +- .../Rules/AvoidListForEach.cs | 2 +- .../Rules/LambdaParameterName.cs | 4 +-- .../Rules/UseNullInsteadOfDefault.cs | 2 +- .../Rules/UseRegexSafeIsMatch.cs | 2 +- .../Rules/UseShortName.cs | 2 +- .../Rules/AlwaysSetDateTimeKind.cs | 2 +- .../AnonymousDelegateEventUnsubscribe.cs | 2 +- ...ArgumentSpecifiedForCallerInfoParameter.cs | 4 +-- .../Rules/ArrayCovariance.cs | 10 +++---- .../AspNet/AnnotateApiActionsWithHttpVerb.cs | 2 +- .../Rules/AspNet/AvoidUnderPosting.cs | 2 +- .../Rules/AspNet/CallModelStateIsValid.cs | 4 +-- .../Rules/AspNet/SpecifyRouteAttribute.cs | 2 +- .../Rules/AspNet/UseAspNetModelBinding.cs | 8 +++--- ...sertionArgsShouldBePassedInCorrectOrder.cs | 4 +-- .../Rules/AssertionsShouldBeComplete.cs | 6 ++-- .../Rules/AsyncVoidMethod.cs | 2 +- .../Rules/AvoidExcessiveClassCoupling.cs | 4 +-- .../Rules/AvoidExcessiveInheritance.cs | 2 +- .../AvoidLambdaExpressionInLoopsInBlazor.cs | 2 +- ...BinaryOperationWithIdenticalExpressions.cs | 2 +- .../Rules/BooleanLiteralUnnecessary.cs | 4 +-- .../CallToAsyncMethodShouldNotBeBlocking.cs | 14 +++++----- ...CallerInformationParametersShouldBeLast.cs | 4 +-- .../Rules/CastConcreteTypeToInterface.cs | 4 +-- .../Rules/CastShouldNotBeDuplicated.cs | 6 ++-- .../SonarAnalyzer.CSharp/Rules/CatchEmpty.cs | 2 +- .../Rules/CheckArgumentException.cs | 4 +-- .../Rules/ClassAndMethodName.cs | 4 +-- ...ssWithEqualityShouldImplementIEquatable.cs | 2 +- .../AzureFunctionsCatchExceptions.cs | 2 +- .../CloudNative/AzureFunctionsLogFailures.cs | 2 +- .../CloudNative/AzureFunctionsStateless.cs | 2 +- .../DurableEntityInterfaceRestrictions.cs | 2 +- .../CollectionPropertiesShouldBeReadOnly.cs | 2 +- .../Rules/CollectionQuerySimplification.cs | 16 +++++------ .../ComparableInterfaceImplementation.cs | 2 +- .../SonarAnalyzer.CSharp/Rules/CompareNaN.cs | 4 +-- .../Rules/ConditionalSimplification.cs | 8 +++--- .../ConditionalStructureSameImplementation.cs | 6 ++-- .../Rules/ConditionalsWithSameCondition.cs | 2 +- .../Rules/ConstructorOverridableCall.cs | 4 +-- .../Rules/ConsumeValueTaskCorrectly.cs | 2 +- .../CryptographicKeyShouldNotBeTooShort.cs | 14 +++++----- .../SonarAnalyzer.CSharp/Rules/DeadStores.cs | 12 ++++---- .../Rules/DebugAssertHasNoSideEffects.cs | 2 +- .../Rules/DeclareEventHandlersCorrectly.cs | 2 +- .../Rules/DelegateSubtraction.cs | 4 +-- .../Rules/DisposableReturnedFromUsing.cs | 8 +++--- .../Rules/DisposableTypesNeedFinalizers.cs | 2 +- .../Rules/DisposeFromDispose.cs | 10 +++---- .../Rules/DoNotCatchNullReferenceException.cs | 4 +-- .../Rules/DoNotCatchSystemException.cs | 2 +- .../Rules/DoNotCheckZeroSizeCollection.cs | 2 +- .../Rules/DoNotCopyArraysInProperties.cs | 2 +- .../Rules/DoNotDecreaseMemberVisibility.cs | 2 +- .../Rules/DoNotExposeListT.cs | 8 +++--- .../Rules/DoNotHideBaseClassMethods.cs | 4 +-- .../Rules/DoNotInstantiateSharedClasses.cs | 2 +- .../Rules/DoNotLockOnSharedResource.cs | 2 +- .../Rules/DoNotMarkEnumsWithFlags.cs | 4 +-- .../Rules/DoNotNestTypesInArguments.cs | 2 +- .../Rules/DoNotOverloadOperatorEqual.cs | 2 +- .../Rules/DoNotShiftByZeroOrIntSize.cs | 2 +- .../DoNotUseCollectionInItsOwnMethodCalls.cs | 2 +- .../Rules/DoNotUseLiteralBoolInAssertions.cs | 4 +-- .../Rules/DoNotUseOutRefParameters.cs | 2 +- .../Rules/DoNotWriteToStandardOutput.cs | 4 +-- .../Rules/DontUseTraceSwitchLevels.cs | 4 +-- .../SonarAnalyzer.CSharp/Rules/EmptyMethod.cs | 2 +- .../Rules/EnumStorageNeedsToBeInt32.cs | 2 +- .../Rules/EnumerableSumInUnchecked.cs | 2 +- .../Rules/EqualityOnFloatingPoint.cs | 12 ++++---- .../Rules/EqualityOnModulus.cs | 4 +-- .../Rules/EquatableClassShouldBeSealed.cs | 2 +- ...andlerDelegateShouldHaveProperArguments.cs | 4 +-- .../Rules/ExceptionRethrow.cs | 4 +-- ...nShouldNotBeThrownFromUnexpectedMethods.cs | 4 +-- .../ExceptionsNeedStandardConstructors.cs | 2 +- .../Rules/ExceptionsShouldBeLogged.cs | 2 +- .../Rules/ExceptionsShouldBeLoggedOrThrown.cs | 2 +- .../Rules/ExceptionsShouldBeUsed.cs | 2 +- ...ensionMethodShouldBeInSeparateNamespace.cs | 2 +- .../Rules/FieldShadowsParentField.cs | 2 +- .../FieldsShouldBeEncapsulatedInProperties.cs | 4 +-- .../Rules/ForLoopCounterChanged.cs | 4 +-- .../Rules/ForLoopCounterCondition.cs | 4 +-- .../Rules/ForeachLoopExplicitConversion.cs | 4 +-- .../Rules/FrameworkTypeNaming.cs | 2 +- ...LoggerInjectionShouldMatchEnclosingType.cs | 2 +- .../GenericReadonlyFieldPropertyAssignment.cs | 6 ++-- .../GenericTypeParameterEmptinessChecking.cs | 2 +- .../Rules/GenericTypeParameterInOut.cs | 8 +++--- .../Rules/GenericTypeParameterUnused.cs | 6 ++-- .../Rules/GenericTypeParametersRequired.cs | 4 +-- .../Rules/GetHashCodeEqualsOverride.cs | 2 +- .../Rules/GetHashCodeMutable.cs | 6 ++-- .../Rules/GetTypeWithIsAssignableFrom.cs | 12 ++++---- .../Rules/GuardConditionOnEqualsOverride.cs | 2 +- .../ClearTextProtocolsAreSensitive.cs | 10 +++---- .../Rules/Hotspots/DisablingCsrfProtection.cs | 6 ++-- .../Rules/Hotspots/DoNotHardcodeSecrets.cs | 6 ++-- .../Rules/Hotspots/DoNotUseRandom.cs | 2 +- .../Rules/Hotspots/InsecureDeserialization.cs | 6 ++-- .../Rules/Hotspots/LooseFilePermissions.cs | 6 ++-- .../Rules/Hotspots/PermissiveCors.cs | 4 +-- .../Hotspots/RequestsWithExcessiveLength.cs | 4 +-- .../Rules/ImplementIDisposableCorrectly.cs | 4 +-- .../ImplementSerializationMethodsCorrectly.cs | 4 +-- .../Rules/InfiniteRecursion.RoslynCfg.cs | 8 +++--- .../Rules/InfiniteRecursion.SonarCfg.cs | 6 ++-- .../Rules/InfiniteRecursion.cs | 10 +++---- .../InheritedCollidingInterfaceMembers.cs | 4 +-- .../Rules/InitializeStaticFieldsInline.cs | 6 ++-- ...faceMethodsShouldBeCallableByChildTypes.cs | 2 +- .../Rules/InterfacesShouldNotBeEmpty.cs | 2 +- .../InvocationResolvesToOverrideWithParams.cs | 10 +++---- .../Rules/IssueSuppression.cs | 2 +- .../Rules/JSInvokableMethodsShouldBePublic.cs | 2 +- ...sShouldNotBePassedAsLocalizedParameters.cs | 14 +++++----- .../Rules/LockedFieldShouldBeReadonly.cs | 2 +- ...ggerFieldsShouldBePrivateStaticReadonly.cs | 2 +- .../Rules/LoggerMembersNamesShouldComply.cs | 2 +- .../LoggersShouldBeNamedForEnclosingType.cs | 4 +-- ...LoggingArgumentsShouldBePassedCorrectly.cs | 6 ++-- .../Rules/LoopsAndLinq.cs | 8 +++--- .../Rules/LossOfFractionInDivision.cs | 10 +++---- ...lyWithNeutralResourcesLanguageAttribute.cs | 2 +- .../Rules/MemberInitializedToDefault.cs | 6 ++-- .../Rules/MemberInitializerRedundant.cs | 8 +++--- .../Rules/MemberOverrideCallsBaseMember.cs | 4 +-- .../Rules/MemberShouldBeStatic.cs | 4 +-- ...otHaveConflictingTransparencyAttributes.cs | 2 +- ...gingTemplatePlaceHoldersShouldBeInOrder.cs | 2 +- .../MessageTemplateAnalyzer.cs | 2 +- .../MessageTemplatesShouldBeCorrect.cs | 2 +- .../Rules/MethodOverrideAddsParams.cs | 4 +-- .../MethodOverrideChangedDefaultValue.cs | 2 +- .../Rules/MethodOverrideNoParams.cs | 2 +- .../Rules/MethodParameterMissingOptional.cs | 2 +- .../Rules/MethodParameterUnused.cs | 16 +++++------ ...odShouldBeNamedAccordingToSynchronicity.cs | 2 +- .../MethodShouldNotOnlyReturnConstant.cs | 4 +-- .../Rules/MethodsShouldUseBaseTypes.cs | 2 +- .../Rules/MutableFieldsShouldNotBe.cs | 6 ++-- .../Rules/NativeMethodsShouldBeWrapped.cs | 4 +-- .../Rules/NonAsyncTaskShouldNotReturnNull.cs | 2 +- .../Rules/NonFlagsEnumInBitwiseOperation.cs | 4 +-- .../ObjectShouldBeInitializedCorrectlyBase.cs | 4 +-- ...torOverloadsShouldHaveNamedAlternatives.cs | 2 +- .../OptionalParameterWithDefaultValue.cs | 2 +- .../Rules/OptionalRefOutParameter.cs | 2 +- .../Rules/OrderByRepeated.cs | 4 +-- .../OverrideGetHashCodeOnOverridingEquals.cs | 2 +- .../Rules/PInvokesShouldNotBeVisible.cs | 2 +- ...rameterValidationInAsyncShouldBeWrapped.cs | 4 +-- ...rameterValidationInYieldShouldBeWrapped.cs | 2 +- .../Rules/PartialMethodNoImplementation.cs | 4 +-- .../Rules/PointersShouldBePrivate.cs | 2 +- .../PreferJaggedArraysOverMultidimensional.cs | 2 +- .../Rules/PrivateFieldUsedAsLocalVariable.cs | 4 +-- ...rivateStaticMethodUsedOnlyByNestedClass.cs | 2 +- .../Rules/PropertiesShouldBePreferred.cs | 2 +- .../Rules/PropertyToAutoProperty.cs | 6 ++-- .../Rules/PureAttributeOnVoidMethod.cs | 2 +- ...dancyInConstructorDestructorDeclaration.cs | 4 +-- .../Rules/RedundantArgument.cs | 4 +-- .../Rules/RedundantCast.cs | 10 +++---- .../RedundantConditionalAroundAssignment.cs | 2 +- .../Rules/RedundantDeclaration.cs | 28 +++++++++---------- .../Rules/RedundantInheritanceList.cs | 12 ++++---- .../Rules/RedundantJumpStatement.cs | 2 +- .../Rules/RedundantModifier.cs | 14 +++++----- .../Rules/RedundantNullableTypeComparison.cs | 4 +-- .../Rules/RedundantToArrayCall.cs | 2 +- .../Rules/RedundantToStringCall.cs | 18 ++++++------ .../ReferenceEqualityCheckWhenEqualsExists.cs | 6 ++-- .../Rules/ReferenceEqualsOnValueType.cs | 4 +-- .../Rules/RequireAttributeUsageAttribute.cs | 2 +- .../ReturnEmptyCollectionInsteadOfNull.cs | 2 +- .../Rules/ReturnValueIgnored.cs | 4 +-- .../Rules/ReuseClientBase.cs | 4 +-- ...erializationConstructorsShouldBeSecured.cs | 4 +-- .../Rules/SetLocaleForDataTypes.cs | 10 +++---- .../SpecifyIFormatProviderOrCultureInfo.cs | 4 +-- .../Rules/SpecifyStringComparison.cs | 4 +-- .../Rules/SqlKeywordsDelimitedBySpace.cs | 4 +-- .../Rules/StaticFieldInGenericClass.cs | 2 +- .../Rules/StaticFieldInitializerOrder.cs | 4 +-- .../Rules/StaticFieldVisible.cs | 2 +- .../Rules/StaticFieldWrittenFrom.cs | 6 ++-- .../StaticSealedClassProtectedMembers.cs | 2 +- .../Rules/StreamReadStatement.cs | 2 +- .../Rules/StringFormatValidator.cs | 4 +-- .../Rules/StringOffsetMethods.cs | 2 +- .../Rules/StringOperationWithoutCulture.cs | 2 +- .../Rules/StringOrIntegralTypesForIndexers.cs | 2 +- .../Rules/SuppressFinalizeUseless.cs | 4 +-- .../Rules/SwaggerActionReturnType.cs | 4 +-- .../Rules/TaskConfigureAwait.cs | 2 +- .../Rules/TestClassShouldHaveTestMethod.cs | 2 +- .../Rules/TestMethodShouldContainAssertion.cs | 4 +-- .../TestMethodShouldHaveCorrectSignature.cs | 2 +- .../Rules/TestMethodShouldNotBeIgnored.cs | 4 +-- .../ThisShouldNotBeExposedFromConstructors.cs | 4 +-- .../Rules/ThreadStaticNonStaticField.cs | 2 +- .../Rules/ThreadStaticWithInitializer.cs | 2 +- .../Rules/TooManyLoggingCalls.cs | 2 +- .../Rules/TrackNotImplementedException.cs | 2 +- .../Rules/TypeExaminationOnSystemType.cs | 10 +++---- .../Rules/TypeMemberVisibility.cs | 2 +- .../TypeNamesShouldNotMatchNamespaces.cs | 2 +- .../UnchangedLocalVariablesShouldBeConst.cs | 10 +++---- .../Rules/UnnecessaryBitwiseOperation.cs | 2 +- .../UnnecessaryMathematicalComparison.cs | 6 ++-- .../Rules/UnnecessaryUsings.cs | 12 ++++---- .../Rules/UnusedReturnValue.cs | 4 +-- .../Rules/UseAwaitableMethod.cs | 2 +- .../Rules/UseConstantLoggingTemplate.cs | 4 +-- .../Rules/UseConstantsWhereAppropriate.cs | 4 +-- .../Rules/UseGenericEventHandlerInstances.cs | 2 +- .../Rules/UseGenericWithRefParameters.cs | 2 +- .../Rules/UseParamsForVariableArguments.cs | 2 +- .../Rules/UseStringCreate.cs | 2 +- .../Rules/UseStringIsNullOrEmpty.cs | 10 +++---- .../Rules/UseUriInsteadOfString.cs | 10 +++---- .../Rules/UseValueParameter.cs | 4 +-- .../Rules/ValuesUselesslyIncremented.cs | 2 +- .../Rules/VariableUnused.cs | 2 +- .../XmlExternalEntityShouldNotBeParsed.cs | 18 ++++++------ .../SonarCodeBlockReportingContext.cs | 2 +- .../SonarCodeBlockStartAnalysisContext.cs | 2 +- .../SonarSemanticModelReportingContext.cs | 4 +-- .../SonarSyntaxNodeReportingContext.cs | 2 +- .../Rules/AlwaysSetDateTimeKindBase.cs | 2 +- .../Rules/ArrayPassedAsParamsBase.cs | 4 +-- ...kslashShouldBeAvoidedInAspNetRoutesBase.cs | 4 +-- ...outeTemplateShouldNotStartWithSlashBase.cs | 2 +- .../AvoidDateTimeNowForBenchmarkingBase.cs | 10 +++---- .../Rules/AvoidUnsealedAttributesBase.cs | 2 +- .../BeginInvokePairedWithEndInvokeBase.cs | 6 ++-- .../Rules/BooleanCheckInvertedBase.cs | 4 +-- .../Rules/BooleanLiteralUnnecessaryBase.cs | 4 +-- .../Rules/CatchRethrowBase.cs | 2 +- .../Rules/CertificateValidationCheckBase.cs | 16 +++++------ .../Rules/ClassNamedExceptionBase.cs | 2 +- .../Rules/ClassShouldNotBeEmptyBase.cs | 2 +- .../Rules/CollectionEmptinessCheckingBase.cs | 2 +- ...ConstructorArgumentValueShouldExistBase.cs | 4 +-- .../DateTimeFormatShouldNotBeHardcodedBase.cs | 4 +-- .../DebuggerDisplayUsesExistingMembersBase.cs | 6 ++-- .../Rules/DeclareTypesInNamespacesBase.cs | 2 +- .../DoNotCallInsecureSecurityAlgorithmBase.cs | 4 +-- .../Rules/DoNotCallMethodsBase.cs | 6 ++-- .../Rules/DoNotCheckZeroSizeCollectionBase.cs | 6 ++-- .../Rules/DoNotLockWeakIdentityObjectsBase.cs | 2 +- .../DoNotOverwriteCollectionElementsBase.cs | 2 +- .../Rules/DoNotUseDateTimeNowBase.cs | 2 +- .../Rules/EnumNameShouldFollowRegexBase.cs | 2 +- .../Rules/ExceptionsShouldBePublicBase.cs | 2 +- ...CoverageAttributesNeedJustificationBase.cs | 4 +-- ...xtensionMethodShouldNotExtendObjectBase.cs | 4 +-- .../Rules/FieldShouldNotBePublicBase.cs | 2 +- .../Rules/FindInsteadOfFirstOrDefaultBase.cs | 6 ++-- .../Rules/FlagsEnumWithoutInitializerBase.cs | 2 +- .../Rules/FlagsEnumZeroMemberBase.cs | 4 +-- .../Rules/FunctionComplexityBase.cs | 2 +- ...ericInheritanceShouldNotBeRecursiveBase.cs | 2 +- .../Hotspots/DoNotHardcodeCredentialsBase.cs | 4 +-- .../Rules/Hotspots/HardcodedIpAddressBase.cs | 2 +- .../PubliclyWritableDirectoriesBase.cs | 6 ++-- .../RequestsWithExcessiveLengthBase.cs | 6 ++-- .../Hotspots/SpecifyTimeoutOnRegexBase.cs | 4 +-- .../UsingNonstandardCryptographyBase.cs | 2 +- .../Rules/IndexOfCheckAgainstZeroBase.cs | 4 +-- .../InsecureTemporaryFilesCreationBase.cs | 2 +- .../Rules/InsteadOfAnyBase.cs | 10 +++---- .../Rules/InvalidCastToInterfaceBase.cs | 8 +++--- ...inkedListPropertiesInsteadOfMethodsBase.cs | 2 +- .../MarkWindowsFormsMainWithStaThreadBase.cs | 4 +-- .../MethodOverloadsShouldBeGroupedBase.cs | 6 ++-- ...ouldNotHaveIdenticalImplementationsBase.cs | 2 +- .../Rules/ObsoleteAttributesBase.cs | 4 +-- .../Rules/OptionalParameterBase.cs | 4 +-- ...ptionalParameterNotPassedToBaseCallBase.cs | 4 +-- .../Rules/ParameterAssignedToBase.cs | 4 +-- .../Rules/ParameterNameMatchesOriginalBase.cs | 2 +- .../Rules/ParametersCorrectOrderBase.cs | 2 +- ...licyShouldBeUsedWithExportAttributeBase.cs | 4 +-- .../Rules/PreferGuidEmptyBase.cs | 6 ++-- .../Rules/PropertyGetterWithThrowBase.cs | 2 +- .../Rules/PublicConstantFieldBase.cs | 2 +- ...blicMethodWithMultidimensionalArrayBase.cs | 2 +- .../RegexMustHaveValidSyntaxBase.cs | 6 ++-- ...urityPInvokeMethodShouldNotBeCalledBase.cs | 6 ++-- .../SetPropertiesInsteadOfMethodsBase.cs | 4 +-- .../Rules/ShiftDynamicNotIntegerBase.cs | 6 ++-- .../ShouldImplementExportedInterfacesBase.cs | 6 ++-- .../Rules/StringConcatenationInLoopBase.cs | 12 ++++---- .../Rules/TestsShouldNotUseThreadSleepBase.cs | 4 +-- .../Rules/ThrowReservedExceptionsBase.cs | 2 +- .../Rules/TooManyLabelsInSwitchBase.cs | 2 +- .../Rules/TooManyParametersBase.cs | 2 +- .../Rules/UnconditionalJumpStatementBase.cs | 2 +- .../Rules/UnnecessaryBitwiseOperationBase.cs | 4 +-- .../Rules/UnusedStringBuilderBase.cs | 4 +-- .../Rules/UriShouldNotBeHardcodedBase.cs | 4 +-- .../UseCharOverloadOfStringMethodsBase.cs | 2 +- .../UseDateTimeOffsetInsteadOfDateTimeBase.cs | 4 +-- ...FormatProviderForParsingDateAndTimeBase.cs | 2 +- .../UseIndexingInsteadOfLinqMethodsBase.cs | 4 +-- ...mbdaParameterInConcurrentDictionaryBase.cs | 4 +-- .../Rules/UseShortCircuitingOperatorBase.cs | 8 +++--- .../Rules/UseTestableTimeProviderBase.cs | 4 +-- .../Rules/UseTrueForAllBase.cs | 4 +-- .../Rules/UseUnixEpochBase.cs | 8 +++--- .../Rules/UseWhereBeforeOrderByBase.cs | 4 +-- .../Rules/Utilities/UtilityAnalyzerBase.cs | 2 +- .../ValueTypeShouldImplementIEquatableBase.cs | 2 +- .../Rules/VariableUnusedBase.cs | 4 +-- .../Rules/WcfNonVoidOneWayBase.cs | 2 +- .../Rules/WeakSslTlsProtocolsBase.cs | 2 +- .../Trackers/ElementAccessContext.cs | 2 +- .../Trackers/InvocationContext.cs | 2 +- .../Trackers/ObjectCreationContext.cs | 2 +- .../Trackers/PropertyAccessContext.cs | 2 +- .../Trackers/SyntaxBaseContext.cs | 2 +- ...onarSyntaxNodeAnalysisContextExtensions.cs | 2 +- .../Rules/ArrayCreationLongSyntax.cs | 6 ++-- .../ArrayInitializationMultipleStatements.cs | 6 ++-- .../Rules/BooleanLiteralUnnecessary.cs | 4 +-- .../Rules/CertificateValidationCheck.cs | 2 +- .../Rules/DoNotInstantiateSharedClasses.cs | 2 +- .../Rules/DoNotLockOnSharedResource.cs | 2 +- .../Rules/DoNotUseIIf.cs | 2 +- .../Rules/EmptyMethod.cs | 4 +-- .../Rules/FieldShadowsParentField.cs | 2 +- .../Rules/LooseFilePermissions.cs | 6 ++-- .../Rules/MethodParameterUnused.cs | 4 +-- .../Rules/Naming/EventHandlerName.cs | 2 +- .../Rules/Naming/FieldNameChecker.cs | 2 +- .../Rules/Naming/FunctionName.cs | 2 +- .../Rules/Naming/LocalVariableName.cs | 4 +-- .../Rules/NonAsyncTaskShouldNotReturnNull.cs | 2 +- .../Rules/PropertyWithArrayType.cs | 2 +- .../Rules/StringConcatenationWithPlus.cs | 4 +-- .../Rules/UnsignedTypesUsage.cs | 2 +- .../Rules/UseWithStatement.cs | 2 +- .../SonarCodeBlockReportingContextTest.cs | 2 +- .../SonarCodeBlockStartAnalysisContextTest.cs | 2 +- .../SonarSemanticModelReportingContextTest.cs | 2 +- .../SonarSyntaxNodeReportingContextTest.cs | 2 +- .../SonarAnalysisContextTest.Register.cs | 2 +- 354 files changed, 720 insertions(+), 720 deletions(-) diff --git a/analyzers/src/SonarAnalyzer.CSharp.Core/Extensions/SonarSyntaxNodeAnalysisContextExtensions.cs b/analyzers/src/SonarAnalyzer.CSharp.Core/Extensions/SonarSyntaxNodeAnalysisContextExtensions.cs index 661fa8eb361..7f036f85e86 100644 --- a/analyzers/src/SonarAnalyzer.CSharp.Core/Extensions/SonarSyntaxNodeAnalysisContextExtensions.cs +++ b/analyzers/src/SonarAnalyzer.CSharp.Core/Extensions/SonarSyntaxNodeAnalysisContextExtensions.cs @@ -24,5 +24,5 @@ context.Node is CompilationUnitSyntax compilationUnitSyntax && context.ContainingSymbol.IsGlobalNamespace(); // Needed to avoid the duplicate calls from Roslyn 4.0.0 public static bool IsInExpressionTree(this SonarSyntaxNodeReportingContext context) => - context.Node.IsInExpressionTree(context.SemanticModel); + context.Node.IsInExpressionTree(context.Model); } diff --git a/analyzers/src/SonarAnalyzer.CSharp.Styling/Rules/AvoidListForEach.cs b/analyzers/src/SonarAnalyzer.CSharp.Styling/Rules/AvoidListForEach.cs index 5ace38e392e..da426afa45c 100644 --- a/analyzers/src/SonarAnalyzer.CSharp.Styling/Rules/AvoidListForEach.cs +++ b/analyzers/src/SonarAnalyzer.CSharp.Styling/Rules/AvoidListForEach.cs @@ -26,7 +26,7 @@ protected override void Initialize(SonarAnalysisContext context) => { var name = ((MemberAccessExpressionSyntax)c.Node).Name; if (name.Identifier.ValueText == nameof(List.ForEach) - && c.SemanticModel.GetSymbolInfo(name).Symbol is IMethodSymbol method + && c.Model.GetSymbolInfo(name).Symbol is IMethodSymbol method && method.Is(KnownType.System_Collections_Generic_List_T, nameof(List.ForEach))) { c.ReportIssue(Rule, name); diff --git a/analyzers/src/SonarAnalyzer.CSharp.Styling/Rules/LambdaParameterName.cs b/analyzers/src/SonarAnalyzer.CSharp.Styling/Rules/LambdaParameterName.cs index 36a7df6d8e5..2b5954b1565 100644 --- a/analyzers/src/SonarAnalyzer.CSharp.Styling/Rules/LambdaParameterName.cs +++ b/analyzers/src/SonarAnalyzer.CSharp.Styling/Rules/LambdaParameterName.cs @@ -27,7 +27,7 @@ protected override void Initialize(SonarAnalysisContext context) => if (c.Node is SimpleLambdaExpressionSyntax { Parameter: { Identifier.ValueText: not ("x" or "_") } parameter, Parent: { } parent } lambda && parent.FirstAncestorOrSelf() is null && !IsSonarContextAction(c) - && !MatchesDelegateParameterName(c.SemanticModel, lambda)) + && !MatchesDelegateParameterName(c.Model, lambda)) { c.ReportIssue(Rule, parameter); } @@ -48,7 +48,7 @@ private static bool IsFuncOrAction(INamedTypeSymbol delegateType) => delegateType.IsAny(KnownType.System_Func_T_TResult, KnownType.System_Action_T); private static bool IsSonarContextAction(SonarSyntaxNodeReportingContext context) => - context.SemanticModel.GetSymbolInfo(context.Node).Symbol is IMethodSymbol lambda + context.Model.GetSymbolInfo(context.Node).Symbol is IMethodSymbol lambda && lambda.ReturnsVoid && IsSonarContextName(lambda.Parameters.Single().Type.Name); diff --git a/analyzers/src/SonarAnalyzer.CSharp.Styling/Rules/UseNullInsteadOfDefault.cs b/analyzers/src/SonarAnalyzer.CSharp.Styling/Rules/UseNullInsteadOfDefault.cs index 669ab80d0a9..3c1bbd39946 100644 --- a/analyzers/src/SonarAnalyzer.CSharp.Styling/Rules/UseNullInsteadOfDefault.cs +++ b/analyzers/src/SonarAnalyzer.CSharp.Styling/Rules/UseNullInsteadOfDefault.cs @@ -24,7 +24,7 @@ public sealed class UseNullInsteadOfDefault : StylingAnalyzer protected override void Initialize(SonarAnalysisContext context) => context.RegisterNodeAction(c => { - if (IsReferenceType(c.Node, c.SemanticModel)) + if (IsReferenceType(c.Node, c.Model)) { c.ReportIssue(Rule, c.Node); } diff --git a/analyzers/src/SonarAnalyzer.CSharp.Styling/Rules/UseRegexSafeIsMatch.cs b/analyzers/src/SonarAnalyzer.CSharp.Styling/Rules/UseRegexSafeIsMatch.cs index 366634c68fe..7dad5d1a86e 100644 --- a/analyzers/src/SonarAnalyzer.CSharp.Styling/Rules/UseRegexSafeIsMatch.cs +++ b/analyzers/src/SonarAnalyzer.CSharp.Styling/Rules/UseRegexSafeIsMatch.cs @@ -42,7 +42,7 @@ private void Verify( { var memberAccess = (MemberAccessExpressionSyntax)c.Node; if (memberAccess.NameIs(methodName) - && c.SemanticModel.GetSymbolInfo(memberAccess).Symbol is IMethodSymbol method + && c.Model.GetSymbolInfo(memberAccess).Symbol is IMethodSymbol method && method.ContainingType.Is(KnownType.System_Text_RegularExpressions_Regex)) { c.ReportIssue( diff --git a/analyzers/src/SonarAnalyzer.CSharp.Styling/Rules/UseShortName.cs b/analyzers/src/SonarAnalyzer.CSharp.Styling/Rules/UseShortName.cs index 7f3809d6ec9..f5390712e8c 100644 --- a/analyzers/src/SonarAnalyzer.CSharp.Styling/Rules/UseShortName.cs +++ b/analyzers/src/SonarAnalyzer.CSharp.Styling/Rules/UseShortName.cs @@ -56,7 +56,7 @@ protected override void Initialize(SonarAnalysisContext context) private void ValidateDeclaration(SonarSyntaxNodeReportingContext context, SyntaxToken identifier) { if (FindRename(identifier.ValueText) is { } name - && context.SemanticModel.GetDeclaredSymbol(context.Node).GetSymbolType() is { } type + && context.Model.GetDeclaredSymbol(context.Node).GetSymbolType() is { } type && type.Name == name.TypeName) { context.ReportIssue(Rule, identifier, identifier.ValueText.Replace(name.UsedName, name.SuggestedName)); diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/AlwaysSetDateTimeKind.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/AlwaysSetDateTimeKind.cs index c48555d759f..c83fe50df0c 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/AlwaysSetDateTimeKind.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/AlwaysSetDateTimeKind.cs @@ -30,7 +30,7 @@ protected override void Initialize(SonarAnalysisContext context) base.Initialize(context); context.RegisterNodeAction(c => { - if (IsDateTimeConstructorWithoutKindParameter(c.Node, c.SemanticModel)) + if (IsDateTimeConstructorWithoutKindParameter(c.Node, c.Model)) { c.ReportIssue(Rule, c.Node); } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/AnonymousDelegateEventUnsubscribe.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/AnonymousDelegateEventUnsubscribe.cs index 8e661cdeaab..4331b1cbea6 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/AnonymousDelegateEventUnsubscribe.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/AnonymousDelegateEventUnsubscribe.cs @@ -35,7 +35,7 @@ protected override void Initialize(SonarAnalysisContext context) var assignment = (AssignmentExpressionSyntax)c.Node; - if (c.SemanticModel.GetSymbolInfo(assignment.Left).Symbol is IEventSymbol @event && + if (c.Model.GetSymbolInfo(assignment.Left).Symbol is IEventSymbol @event && assignment.Right is AnonymousFunctionExpressionSyntax) { c.ReportIssue(rule, assignment.OperatorToken.CreateLocation(assignment)); diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/ArgumentSpecifiedForCallerInfoParameter.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/ArgumentSpecifiedForCallerInfoParameter.cs index 95b54f261d3..d187729125f 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/ArgumentSpecifiedForCallerInfoParameter.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/ArgumentSpecifiedForCallerInfoParameter.cs @@ -35,12 +35,12 @@ public sealed class ArgumentSpecifiedForCallerInfoParameter : SonarDiagnosticAna protected override void Initialize(SonarAnalysisContext context) => context.RegisterNodeAction(c => { - if (new CSharpMethodParameterLookup((InvocationExpressionSyntax)c.Node, c.SemanticModel) is { MethodSymbol: { } } methodParameterLookup + if (new CSharpMethodParameterLookup((InvocationExpressionSyntax)c.Node, c.Model) is { MethodSymbol: { } } methodParameterLookup && methodParameterLookup.GetAllArgumentParameterMappings() is { } argumentMappings) { foreach (var argumentMapping in argumentMappings.Where(x => x.Symbol.GetAttributes(CallerInfoAttributesToReportOn).Any() - && !IsArgumentPassthroughOfParameter(c.SemanticModel, x.Node, x.Symbol))) + && !IsArgumentPassthroughOfParameter(c.Model, x.Node, x.Symbol))) { c.ReportIssue(Rule, argumentMapping.Node); } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/ArrayCovariance.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/ArrayCovariance.cs index 45d67bf2f61..3b234c69f97 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/ArrayCovariance.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/ArrayCovariance.cs @@ -36,13 +36,13 @@ protected override void Initialize(SonarAnalysisContext context) private static void RaiseOnArrayCovarianceInSimpleAssignmentExpression(SonarSyntaxNodeReportingContext context) { var assignment = (AssignmentExpressionSyntax)context.Node; - VerifyExpression(assignment.Right, context.SemanticModel.GetTypeInfo(assignment.Left).Type, context); + VerifyExpression(assignment.Right, context.Model.GetTypeInfo(assignment.Left).Type, context); } private static void RaiseOnArrayCovarianceInVariableDeclaration(SonarSyntaxNodeReportingContext context) { var variableDeclaration = (VariableDeclarationSyntax)context.Node; - var baseType = context.SemanticModel.GetTypeInfo(variableDeclaration.Type).Type; + var baseType = context.Model.GetTypeInfo(variableDeclaration.Type).Type; foreach (var declaration in variableDeclaration.Variables.Where(syntax => syntax.Initializer != null)) { @@ -53,7 +53,7 @@ private static void RaiseOnArrayCovarianceInVariableDeclaration(SonarSyntaxNodeR private static void RaiseOnArrayCovarianceInInvocationExpression(SonarSyntaxNodeReportingContext context) { var invocation = (InvocationExpressionSyntax)context.Node; - var methodParameterLookup = new CSharpMethodParameterLookup(invocation, context.SemanticModel); + var methodParameterLookup = new CSharpMethodParameterLookup(invocation, context.Model); foreach (var argument in invocation.ArgumentList.Arguments) { @@ -69,14 +69,14 @@ private static void RaiseOnArrayCovarianceInInvocationExpression(SonarSyntaxNode private static void RaiseOnArrayCovarianceInCastExpression(SonarSyntaxNodeReportingContext context) { var castExpression = (CastExpressionSyntax)context.Node; - var baseType = context.SemanticModel.GetTypeInfo(castExpression.Type).Type; + var baseType = context.Model.GetTypeInfo(castExpression.Type).Type; VerifyExpression(castExpression.Expression, baseType, context); } private static void VerifyExpression(SyntaxNode node, ITypeSymbol baseType, SonarSyntaxNodeReportingContext context) { - foreach (var pair in GetPossibleTypes(node, context.SemanticModel).Where(pair => AreCovariantArrayTypes(pair.Symbol, baseType))) + foreach (var pair in GetPossibleTypes(node, context.Model).Where(pair => AreCovariantArrayTypes(pair.Symbol, baseType))) { context.ReportIssue(Rule, pair.Node); } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/AspNet/AnnotateApiActionsWithHttpVerb.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/AspNet/AnnotateApiActionsWithHttpVerb.cs index b16720f31e3..9663a2af430 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/AspNet/AnnotateApiActionsWithHttpVerb.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/AspNet/AnnotateApiActionsWithHttpVerb.cs @@ -49,7 +49,7 @@ protected override void Initialize(SonarAnalysisContext context) => symbolStartContext.RegisterSyntaxNodeAction(c => { var methodNode = (MethodDeclarationSyntax)c.Node; - var methodSymbol = c.SemanticModel.GetDeclaredSymbol(methodNode); + var methodSymbol = c.Model.GetDeclaredSymbol(methodNode); var methodAttributes = methodSymbol.GetAttributesWithInherited(); if (methodSymbol.IsControllerActionMethod() diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/AspNet/AvoidUnderPosting.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/AspNet/AvoidUnderPosting.cs index 96b5f35b2f6..0ec2a691375 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/AspNet/AvoidUnderPosting.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/AspNet/AvoidUnderPosting.cs @@ -60,7 +60,7 @@ protected override void Initialize(SonarAnalysisContext context) => private static void ProcessControllerMethods(SonarSyntaxNodeReportingContext context, ConcurrentDictionary examinedTypes) { - if (context.SemanticModel.GetDeclaredSymbol(context.Node) is IMethodSymbol method + if (context.Model.GetDeclaredSymbol(context.Node) is IMethodSymbol method && method.IsControllerActionMethod()) { var modelParameterTypes = method.Parameters diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/AspNet/CallModelStateIsValid.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/AspNet/CallModelStateIsValid.cs index b9e58974a91..f2578fa0dba 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/AspNet/CallModelStateIsValid.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/AspNet/CallModelStateIsValid.cs @@ -75,14 +75,14 @@ private static void ProcessCodeBlock(SonarCodeBlockStartAnalysisContext { if (!isModelValidated) { - isModelValidated = IsTryValidateInvocation(nodeContext.Node, nodeContext.SemanticModel); + isModelValidated = IsTryValidateInvocation(nodeContext.Node, nodeContext.Model); } }, SyntaxKind.InvocationExpression); codeBlockContext.RegisterCodeBlockEndAction(blockEnd => diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/AspNet/SpecifyRouteAttribute.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/AspNet/SpecifyRouteAttribute.cs index 57eb663d479..e82ea21fce6 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/AspNet/SpecifyRouteAttribute.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/AspNet/SpecifyRouteAttribute.cs @@ -45,7 +45,7 @@ protected override void Initialize(SonarAnalysisContext context) => symbolStart.RegisterSyntaxNodeAction(nodeContext => { var methodDeclaration = (MethodDeclarationSyntax)nodeContext.Node; - if (nodeContext.SemanticModel.GetDeclaredSymbol(methodDeclaration, nodeContext.Cancel) is { } method + if (nodeContext.Model.GetDeclaredSymbol(methodDeclaration, nodeContext.Cancel) is { } method && !method.ContainingType.IsAbstract && method.IsControllerActionMethod() && method.GetAttributesWithInherited().Any(x => !CanBeIgnored(x.GetAttributeRouteTemplate()))) diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/AspNet/UseAspNetModelBinding.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/AspNet/UseAspNetModelBinding.cs index 89be87775f0..8d6bc1d9d1f 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/AspNet/UseAspNetModelBinding.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/AspNet/UseAspNetModelBinding.cs @@ -94,7 +94,7 @@ private void RegisterCodeBlockActions( codeBlockStart.RegisterNodeAction(nodeContext => { var argument = (ArgumentSyntax)nodeContext.Node; - var model = nodeContext.SemanticModel; + var model = nodeContext.Model; if (allConstantAccesses && AddMatchingArgumentToCandidates(model, codeBlockCandidates, argument, argumentDescriptors) && model.GetConstantValue(argument.Expression) is not { HasValue: true, Value: string }) @@ -110,12 +110,12 @@ private void RegisterCodeBlockActions( // The property access of Request.Form.Files can be replaced by an IFormFile binding. // Any access to a "Files" property is therefore noncompliant. This is different from the Argument handling above. var memberAccess = (MemberAccessExpressionSyntax)nodeContext.Node; - var context = new PropertyAccessContext(memberAccess, nodeContext.SemanticModel, memberAccess.Name.Identifier.ValueText); + var context = new PropertyAccessContext(memberAccess, nodeContext.Model, memberAccess.Name.Identifier.ValueText); if (Language.Tracker.PropertyAccess.MatchProperty(propertyAccessDescriptors)(context) // form.Files is okay, if "form" is a parameter, because IFormCollection binding is considered appropriate for binding as well - && nodeContext.SemanticModel.GetSymbolInfo(memberAccess.Expression).Symbol is not IParameterSymbol) + && nodeContext.Model.GetSymbolInfo(memberAccess.Expression).Symbol is not IParameterSymbol) { - codeBlockCandidates.Push(new(UseIFormFileBindingMessage, memberAccess.GetLocation(), IsOriginatingFromParameter(nodeContext.SemanticModel, memberAccess))); + codeBlockCandidates.Push(new(UseIFormFileBindingMessage, memberAccess.GetLocation(), IsOriginatingFromParameter(nodeContext.Model, memberAccess))); } }, SyntaxKind.SimpleMemberAccessExpression); } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/AssertionArgsShouldBePassedInCorrectOrder.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/AssertionArgsShouldBePassedInCorrectOrder.cs index 61a25d68564..6789f649aa8 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/AssertionArgsShouldBePassedInCorrectOrder.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/AssertionArgsShouldBePassedInCorrectOrder.cs @@ -30,10 +30,10 @@ protected override void Initialize(SonarAnalysisContext context) => { if (c.Node is InvocationExpressionSyntax { ArgumentList.Arguments.Count: >= 2 } invocation && GetParameters(invocation.GetName()) is { } knownAssertParameters - && c.SemanticModel.GetSymbolInfo(invocation).AllSymbols() + && c.Model.GetSymbolInfo(invocation).AllSymbols() .SelectMany(symbol => symbol is IMethodSymbol { IsStatic: true, ContainingSymbol: INamedTypeSymbol container } methodSymbol - ? knownAssertParameters.Select(knownParameters => FindWrongArguments(c.SemanticModel, container, methodSymbol, invocation, knownParameters)) + ? knownAssertParameters.Select(knownParameters => FindWrongArguments(c.Model, container, methodSymbol, invocation, knownParameters)) : Enumerable.Empty()) .FirstOrDefault(x => x is not null) is (Expected: var expected, Actual: var actual)) { diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/AssertionsShouldBeComplete.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/AssertionsShouldBeComplete.cs index be1069218b1..6df969c2f64 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/AssertionsShouldBeComplete.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/AssertionsShouldBeComplete.cs @@ -34,7 +34,7 @@ protected override void Initialize(SonarAnalysisContext context) => start.RegisterNodeAction(c => CheckInvocation(c, invocation => invocation.NameIs("Should") - && c.SemanticModel.GetSymbolInfo(invocation).AllSymbols().Any(x => + && c.Model.GetSymbolInfo(invocation).AllSymbols().Any(x => x is IMethodSymbol { IsExtensionMethod: true, @@ -52,7 +52,7 @@ x is IMethodSymbol start.RegisterNodeAction(c => CheckInvocation(c, invocation => invocation.NameIs("That", "ThatEnum", "ThatCode", "ThatAsyncCode", "ThatDynamic") - && c.SemanticModel.GetSymbolInfo(invocation) is + && c.Model.GetSymbolInfo(invocation) is { Symbol: IMethodSymbol { @@ -69,7 +69,7 @@ x is IMethodSymbol start.RegisterNodeAction(c => CheckInvocation(c, invocation => invocation.NameIs("Received", "DidNotReceive", "ReceivedWithAnyArgs", "DidNotReceiveWithAnyArgs", "ReceivedCalls") - && c.SemanticModel.GetSymbolInfo(invocation) is + && c.Model.GetSymbolInfo(invocation) is { Symbol: IMethodSymbol { diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/AsyncVoidMethod.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/AsyncVoidMethod.cs index 0a4a3bc86c7..73dd23dc9c4 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/AsyncVoidMethod.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/AsyncVoidMethod.cs @@ -50,7 +50,7 @@ protected override void Initialize(SonarAnalysisContext context) => c => { var methodDeclaration = (MethodDeclarationSyntax)c.Node; - var methodSymbol = c.SemanticModel.GetDeclaredSymbol(methodDeclaration); + var methodSymbol = c.Model.GetDeclaredSymbol(methodDeclaration); if (IsViolatingRule(methodSymbol) && !IsExceptionToTheRule(methodDeclaration, methodSymbol)) { diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/AvoidExcessiveClassCoupling.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/AvoidExcessiveClassCoupling.cs index 3372001a4a6..ec52593c415 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/AvoidExcessiveClassCoupling.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/AvoidExcessiveClassCoupling.cs @@ -72,8 +72,8 @@ protected override void Initialize(SonarParametrizedAnalysisContext context) => return; } - var type = c.SemanticModel.GetDeclaredSymbol(typeDeclaration); - var collector = new TypeDependencyCollector(c.SemanticModel, typeDeclaration); + var type = c.Model.GetDeclaredSymbol(typeDeclaration); + var collector = new TypeDependencyCollector(c.Model, typeDeclaration); collector.SafeVisit(typeDeclaration); var dependentTypes = collector.DependentTypes .SelectMany(ExpandGenericTypes) diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/AvoidExcessiveInheritance.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/AvoidExcessiveInheritance.cs index 1601b755482..926dc998254 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/AvoidExcessiveInheritance.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/AvoidExcessiveInheritance.cs @@ -57,7 +57,7 @@ protected override void Initialize(SonarParametrizedAnalysisContext context) => { return; } - var objectTypeInfo = new ObjectTypeInfo(c.Node, c.SemanticModel); + var objectTypeInfo = new ObjectTypeInfo(c.Node, c.Model); if (objectTypeInfo.Symbol is null) { return; diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/AvoidLambdaExpressionInLoopsInBlazor.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/AvoidLambdaExpressionInLoopsInBlazor.cs index 130521b6278..ff2b9cae1f0 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/AvoidLambdaExpressionInLoopsInBlazor.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/AvoidLambdaExpressionInLoopsInBlazor.cs @@ -42,7 +42,7 @@ protected override void Initialize(SonarAnalysisContext context) => var node = (LambdaExpressionSyntax)c.Node; if (IsWithinLoopBody(node) - && IsWithinRenderTreeBuilderInvocation(node, c.SemanticModel)) + && IsWithinRenderTreeBuilderInvocation(node, c.Model)) { c.ReportIssue(Rule, node); } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/BinaryOperationWithIdenticalExpressions.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/BinaryOperationWithIdenticalExpressions.cs index 8ebbe7ab320..c9312fbf657 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/BinaryOperationWithIdenticalExpressions.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/BinaryOperationWithIdenticalExpressions.cs @@ -66,7 +66,7 @@ protected override void Initialize(SonarAnalysisContext context) private static void ReportOnObjectEqualsMatches(SonarSyntaxNodeReportingContext context, InvocationExpressionSyntax invocation) { - var methodSymbol = context.SemanticModel.GetSymbolInfo(invocation).Symbol as IMethodSymbol; + var methodSymbol = context.Model.GetSymbolInfo(invocation).Symbol as IMethodSymbol; var operands = GetOperands(invocation, methodSymbol); if (operands is not null && CSharpEquivalenceChecker.AreEquivalent(RemoveParentheses(operands.Item1), RemoveParentheses(operands.Item2))) diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/BooleanLiteralUnnecessary.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/BooleanLiteralUnnecessary.cs index f70435e88ed..cf709700265 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/BooleanLiteralUnnecessary.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/BooleanLiteralUnnecessary.cs @@ -95,8 +95,8 @@ private void CheckConditional(SonarSyntaxNodeReportingContext context) { return; } - var typeLeft = context.SemanticModel.GetTypeInfo(whenTrue).Type; - var typeRight = context.SemanticModel.GetTypeInfo(whenFalse).Type; + var typeLeft = context.Model.GetTypeInfo(whenTrue).Type; + var typeRight = context.Model.GetTypeInfo(whenFalse).Type; if (typeLeft.IsNullableBoolean() || typeRight.IsNullableBoolean() || typeLeft == null diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/CallToAsyncMethodShouldNotBeBlocking.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/CallToAsyncMethodShouldNotBeBlocking.cs index bcbbdff1646..d1f91771329 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/CallToAsyncMethodShouldNotBeBlocking.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/CallToAsyncMethodShouldNotBeBlocking.cs @@ -79,15 +79,15 @@ private static void ReportOnViolation(SonarSyntaxNodeReportingContext context) if (memberAccessNameName == null || !InvalidMemberAccess.ContainsKey(memberAccessNameName) || IsResultInContinueWithCall(memberAccessNameName, simpleMemberAccess) - || IsChainedAfterThreadPoolCall(context.SemanticModel, simpleMemberAccess) - || simpleMemberAccess.IsInNameOfArgument(context.SemanticModel) + || IsChainedAfterThreadPoolCall(context.Model, simpleMemberAccess) + || simpleMemberAccess.IsInNameOfArgument(context.Model) || simpleMemberAccess.HasAncestor(SyntaxKind.GlobalStatement)) { return; } var possibleMemberAccesses = InvalidMemberAccess[memberAccessNameName]; - var memberAccessSymbol = context.SemanticModel.GetSymbolInfo(simpleMemberAccess).Symbol; + var memberAccessSymbol = context.Model.GetSymbolInfo(simpleMemberAccess).Symbol; if (memberAccessSymbol?.ContainingType == null || !memberAccessSymbol.ContainingType.ConstructedFrom.IsAny(possibleMemberAccesses)) { return; @@ -98,7 +98,7 @@ private static void ReportOnViolation(SonarSyntaxNodeReportingContext context) { return; // Thread.Sleep should not be used only in async methods } - if (context.SemanticModel.GetDeclaredSymbol(enclosingMethod).IsMainMethod()) + if (context.Model.GetDeclaredSymbol(enclosingMethod).IsMainMethod()) { return; // Main methods are not subject to deadlock issue so no need to report an issue } @@ -112,7 +112,7 @@ private static void ReportOnViolation(SonarSyntaxNodeReportingContext context) private static bool IsAwaited(SonarSyntaxNodeReportingContext context, MemberAccessExpressionSyntax simpleMemberAccess) { - return context.SemanticModel.GetSymbolInfo(simpleMemberAccess.Expression).Symbol is { } accessedSymbol + return context.Model.GetSymbolInfo(simpleMemberAccess.Expression).Symbol is { } accessedSymbol && simpleMemberAccess.FirstAncestorOrSelf() is { } currentStatement && currentStatement.GetPreviousStatements().Any(ContainsAwaitedInvocation); @@ -120,8 +120,8 @@ bool ContainsAwaitedInvocation(StatementSyntax statement) => statement.DescendantNodes().OfType().Where(x => x.Expression.IsKind(SyntaxKind.SimpleMemberAccessExpression)).Any(IsTaskAwaited); bool IsTaskAwaited(InvocationExpressionSyntax invocation) => - IsAwaitForMultipleTasksExecutionCall(context.SemanticModel, invocation, accessedSymbol) - || IsAwaitForSingleTaskExecutionCall(context.SemanticModel, invocation, accessedSymbol); + IsAwaitForMultipleTasksExecutionCall(context.Model, invocation, accessedSymbol) + || IsAwaitForSingleTaskExecutionCall(context.Model, invocation, accessedSymbol); } private static bool IsAwaitForMultipleTasksExecutionCall(SemanticModel model, InvocationExpressionSyntax invocation, ISymbol accessedSymbol) => diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/CallerInformationParametersShouldBeLast.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/CallerInformationParametersShouldBeLast.cs index 78f0ee0e426..6d8a5dcd9c7 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/CallerInformationParametersShouldBeLast.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/CallerInformationParametersShouldBeLast.cs @@ -46,7 +46,7 @@ private static void ReportOnViolation(SonarSyntaxNodeReportingContext context) return; } - var methodSymbol = context.SemanticModel.GetDeclaredSymbol(methodDeclaration); + var methodSymbol = context.Model.GetDeclaredSymbol(methodDeclaration); if (methodSymbol == null || methodSymbol.IsOverride || methodSymbol.GetInterfaceMember() != null) @@ -57,7 +57,7 @@ private static void ReportOnViolation(SonarSyntaxNodeReportingContext context) ParameterSyntax noCallerInfoParameter = null; foreach (var parameter in parameterList.Parameters.Reverse()) { - if (parameter.AttributeLists.GetAttributes(KnownType.CallerInfoAttributes, context.SemanticModel).Any()) + if (parameter.AttributeLists.GetAttributes(KnownType.CallerInfoAttributes, context.Model).Any()) { if (noCallerInfoParameter != null && HasIdentifier(parameter)) { diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/CastConcreteTypeToInterface.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/CastConcreteTypeToInterface.cs index 2a9694e2a29..3cc00c1d0c8 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/CastConcreteTypeToInterface.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/CastConcreteTypeToInterface.cs @@ -47,8 +47,8 @@ protected override void Initialize(SonarAnalysisContext context) private static void CheckForIssue(SonarSyntaxNodeReportingContext context, SyntaxNode fromExpression, SyntaxNode toExpression) { - var castedFrom = context.SemanticModel.GetTypeInfo(fromExpression).Type; - var castedTo = context.SemanticModel.GetTypeInfo(toExpression).Type; + var castedFrom = context.Model.GetTypeInfo(fromExpression).Type; + var castedTo = context.Model.GetTypeInfo(toExpression).Type; if (castedFrom.Is(TypeKind.Interface) && castedFrom.DeclaringSyntaxReferences.Any() && castedTo.Is(TypeKind.Class) diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/CastShouldNotBeDuplicated.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/CastShouldNotBeDuplicated.cs index 6fef88a0dbb..f51208e08e2 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/CastShouldNotBeDuplicated.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/CastShouldNotBeDuplicated.cs @@ -78,7 +78,7 @@ private static void IsExpression(SonarSyntaxNodeReportingContext analysisContext private static Location[] DuplicatedCastLocations(SonarSyntaxNodeReportingContext context, SyntaxNode parentStatement, TypeSyntax castType, SyntaxNode typedVariable) { - var typeExpressionSymbol = context.SemanticModel.GetSymbolInfo(typedVariable).Symbol ?? context.SemanticModel.GetDeclaredSymbol(typedVariable); + var typeExpressionSymbol = context.Model.GetSymbolInfo(typedVariable).Symbol ?? context.Model.GetDeclaredSymbol(typedVariable); return typeExpressionSymbol is null ? [] : parentStatement.DescendantNodes().Where(IsDuplicatedCast).Select(x => x.GetLocation()).ToArray(); bool IsDuplicatedCast(SyntaxNode node) @@ -100,11 +100,11 @@ bool IsDuplicatedCast(SyntaxNode node) bool IsDuplicatedCastOnSameSymbol(ExpressionSyntax expression, SyntaxNode type) => type.WithoutTrivia().IsEquivalentTo(castType.WithoutTrivia()) && IsCastOnSameSymbol(expression) - && !CSharpFacade.Instance.Syntax.IsInExpressionTree(context.SemanticModel, expression); // see https://github.com/SonarSource/sonar-dotnet/issues/8735#issuecomment-1943419398 + && !CSharpFacade.Instance.Syntax.IsInExpressionTree(context.Model, expression); // see https://github.com/SonarSource/sonar-dotnet/issues/8735#issuecomment-1943419398 bool IsCastOnSameSymbol(ExpressionSyntax expression) => IsEquivalentVariable(expression, typedVariable) - && Equals(context.SemanticModel.GetSymbolInfo(expression).Symbol, typeExpressionSymbol); + && Equals(context.Model.GetSymbolInfo(expression).Symbol, typeExpressionSymbol); } private static void ProcessPatternExpression(SonarSyntaxNodeReportingContext analysisContext, SyntaxNode isPattern, SyntaxNode mainVariableExpression, SyntaxNode parentStatement) diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/CatchEmpty.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/CatchEmpty.cs index 43def579565..e4700f3e625 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/CatchEmpty.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/CatchEmpty.cs @@ -36,7 +36,7 @@ protected override void Initialize(SonarAnalysisContext context) if (!HasStatements(catchClause) && !HasComments(catchClause) && - IsGenericCatch(catchClause, c.SemanticModel)) + IsGenericCatch(catchClause, c.Model)) { c.ReportIssue(rule, c.Node); } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/CheckArgumentException.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/CheckArgumentException.cs index 86e98168cc6..e401889f083 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/CheckArgumentException.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/CheckArgumentException.cs @@ -42,7 +42,7 @@ protected override void Initialize(SonarAnalysisContext context) => private static void CheckForIssue(SonarSyntaxNodeReportingContext analysisContext) { var objectCreation = ObjectCreationFactory.Create(analysisContext.Node); - var methodSymbol = objectCreation.MethodSymbol(analysisContext.SemanticModel); + var methodSymbol = objectCreation.MethodSymbol(analysisContext.Model); if (methodSymbol?.ContainingType == null || !methodSymbol.ContainingType.IsAny(ArgumentExceptionTypesToCheck)) { return; @@ -54,7 +54,7 @@ private static void CheckForIssue(SonarSyntaxNodeReportingContext analysisContex return; } - var parameterAndMessage = RetrieveParameterAndMessageArgumentValue(methodSymbol, objectCreation, analysisContext.SemanticModel); + var parameterAndMessage = RetrieveParameterAndMessageArgumentValue(methodSymbol, objectCreation, analysisContext.Model); var constructorParameterArgument = parameterAndMessage.Item1; var constructorMessageArgument = parameterAndMessage.Item2; diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/ClassAndMethodName.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/ClassAndMethodName.cs index 7e0b477f04d..3b43f33c6a2 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/ClassAndMethodName.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/ClassAndMethodName.cs @@ -114,7 +114,7 @@ private static void CheckTypeName(SonarSyntaxNodeReportingContext context) { var typeDeclaration = (BaseTypeDeclarationSyntax)context.Node; var identifier = typeDeclaration.Identifier; - var symbol = context.SemanticModel.GetDeclaredSymbol(typeDeclaration); + var symbol = context.Model.GetDeclaredSymbol(typeDeclaration); if (symbol.GetAttributes(ComRelatedTypes).Any()) { @@ -154,7 +154,7 @@ private static void CheckTypeName(SonarSyntaxNodeReportingContext context) private static void CheckMemberName(SonarSyntaxNodeReportingContext context, SyntaxToken identifier) { - var symbol = context.SemanticModel.GetDeclaredSymbol(context.Node); + var symbol = context.Model.GetDeclaredSymbol(context.Node); if (symbol == null) { return; diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/ClassWithEqualityShouldImplementIEquatable.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/ClassWithEqualityShouldImplementIEquatable.cs index eb9372cfb9c..dbd471ec7c0 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/ClassWithEqualityShouldImplementIEquatable.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/ClassWithEqualityShouldImplementIEquatable.cs @@ -34,7 +34,7 @@ protected override void Initialize(SonarAnalysisContext context) c => { var classDeclaration = (ClassDeclarationSyntax)c.Node; - var classSymbol = c.SemanticModel.GetDeclaredSymbol(classDeclaration); + var classSymbol = c.Model.GetDeclaredSymbol(classDeclaration); if (classSymbol == null || ImplementsIEquatableInterface(classSymbol) || classDeclaration.Identifier.IsMissing) diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/CloudNative/AzureFunctionsCatchExceptions.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/CloudNative/AzureFunctionsCatchExceptions.cs index b69044cc438..4d1a2b180fc 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/CloudNative/AzureFunctionsCatchExceptions.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/CloudNative/AzureFunctionsCatchExceptions.cs @@ -32,7 +32,7 @@ protected override void Initialize(SonarAnalysisContext context) => if (c.IsAzureFunction()) { var method = (MethodDeclarationSyntax)c.Node; - var walker = new Walker(c.SemanticModel); + var walker = new Walker(c.Model); if (walker.SafeVisit(method.GetBodyOrExpressionBody()) && walker.HasInvocationOutsideTryCatch) { c.ReportIssue(Rule, method.Identifier); diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/CloudNative/AzureFunctionsLogFailures.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/CloudNative/AzureFunctionsLogFailures.cs index 0190cf5ff7a..a64dc1de865 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/CloudNative/AzureFunctionsLogFailures.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/CloudNative/AzureFunctionsLogFailures.cs @@ -40,7 +40,7 @@ protected override void Initialize(SonarAnalysisContext context) => if (c.AzureFunctionMethod() is { } entryPoint && HasLoggerInScope(entryPoint)) { - var walker = new LoggerCallWalker(c.SemanticModel, c.Cancel); + var walker = new LoggerCallWalker(c.Model, c.Cancel); walker.SafeVisit(catchClause.Block); // Exception handling in the filter clause preserves log scopes and is therefore recommended // See https://blog.stephencleary.com/2020/06/a-new-pattern-for-exception-logging.html diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/CloudNative/AzureFunctionsStateless.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/CloudNative/AzureFunctionsStateless.cs index c91213f95a1..a6e1666143e 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/CloudNative/AzureFunctionsStateless.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/CloudNative/AzureFunctionsStateless.cs @@ -68,7 +68,7 @@ protected override void Initialize(SonarAnalysisContext context) private static void CheckTarget(SonarSyntaxNodeReportingContext context, ExpressionSyntax target) { if (context.IsAzureFunction() - && context.SemanticModel.GetSymbolInfo((target as ElementAccessExpressionSyntax)?.Expression ?? target).Symbol is { } symbol + && context.Model.GetSymbolInfo((target as ElementAccessExpressionSyntax)?.Expression ?? target).Symbol is { } symbol && symbol.IsStatic) { context.ReportIssue(Rule, target); diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/CloudNative/DurableEntityInterfaceRestrictions.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/CloudNative/DurableEntityInterfaceRestrictions.cs index b986389c7fa..a44908eb4e0 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/CloudNative/DurableEntityInterfaceRestrictions.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/CloudNative/DurableEntityInterfaceRestrictions.cs @@ -35,7 +35,7 @@ protected override void Initialize(SonarAnalysisContext context) => var name = (GenericNameSyntax)c.Node; if (name.Identifier.ValueText is SignalEntityName or SignalEntityAsyncName or CreateEntityProxyName && name.TypeArgumentList.Arguments.Count == 1 - && c.SemanticModel.GetSymbolInfo(name).Symbol is IMethodSymbol method + && c.Model.GetSymbolInfo(name).Symbol is IMethodSymbol method && IsRestrictedMethod(method) && method.TypeArguments.Single() is INamedTypeSymbol { TypeKind: not TypeKind.Error } entityInterface && InterfaceErrorMessage(entityInterface) is { } message) diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/CollectionPropertiesShouldBeReadOnly.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/CollectionPropertiesShouldBeReadOnly.cs index 285ff5991e9..d377ecfb3a3 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/CollectionPropertiesShouldBeReadOnly.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/CollectionPropertiesShouldBeReadOnly.cs @@ -47,7 +47,7 @@ protected override void Initialize(SonarAnalysisContext context) => c => { var propertyDeclaration = (PropertyDeclarationSyntax)c.Node; - var propertySymbol = c.SemanticModel.GetDeclaredSymbol(propertyDeclaration); + var propertySymbol = c.Model.GetDeclaredSymbol(propertyDeclaration); if (propertyDeclaration.AccessorList != null && !propertyDeclaration.AccessorList.Accessors.AnyOfKind(SyntaxKindEx.InitAccessorDeclaration) diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/CollectionQuerySimplification.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/CollectionQuerySimplification.cs index 1c8cff93c82..6d931a82ea7 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/CollectionQuerySimplification.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/CollectionQuerySimplification.cs @@ -87,9 +87,9 @@ private static void CheckCountCall(SonarSyntaxNodeReportingContext context) Expression: { } memberAccessExpression } } - && context.SemanticModel.GetSymbolInfo(invocation).Symbol is IMethodSymbol { Name: CountName } methodSymbol + && context.Model.GetSymbolInfo(invocation).Symbol is IMethodSymbol { Name: CountName } methodSymbol && methodSymbol.IsExtensionOn(KnownType.System_Collections_Generic_IEnumerable_T) - && HasCountProperty(memberAccessExpression, context.SemanticModel)) + && HasCountProperty(memberAccessExpression, context.Model)) { context.ReportIssue(Rule, GetReportLocation(invocation), string.Format(MessageUseInstead, $"'{CountName}' property")); } @@ -101,8 +101,8 @@ static bool HasCountProperty(ExpressionSyntax expression, SemanticModel semantic private static void CheckToCollectionCalls(SonarSyntaxNodeReportingContext context) { var outerInvocation = (InvocationExpressionSyntax)context.Node; - if (context.SemanticModel.GetSymbolInfo(outerInvocation).Symbol is not IMethodSymbol outerMethodSymbol - || !MethodExistsOnIEnumerable(outerMethodSymbol, context.SemanticModel)) + if (context.Model.GetSymbolInfo(outerInvocation).Symbol is not IMethodSymbol outerMethodSymbol + || !MethodExistsOnIEnumerable(outerMethodSymbol, context.Model)) { return; } @@ -113,7 +113,7 @@ private static void CheckToCollectionCalls(SonarSyntaxNodeReportingContext conte return; } - if (context.SemanticModel.GetSymbolInfo(innerInvocation).Symbol is IMethodSymbol innerMethodSymbol + if (context.Model.GetSymbolInfo(innerInvocation).Symbol is IMethodSymbol innerMethodSymbol && IsToCollectionCall(innerMethodSymbol)) { context.ReportIssue(Rule, GetReportLocation(innerInvocation), GetToCollectionCallsMessage(context, innerInvocation, innerMethodSymbol)); @@ -168,7 +168,7 @@ private static bool IsToCollectionCall(IMethodSymbol methodSymbol) => || methodSymbol.ContainingType.ConstructedFrom.Is(KnownType.System_Collections_Generic_List_T)); private static string GetToCollectionCallsMessage(SonarSyntaxNodeReportingContext context, InvocationExpressionSyntax invocation, IMethodSymbol methodSymbol) => - IsLinqDatabaseQuery(invocation, context.SemanticModel) + IsLinqDatabaseQuery(invocation, context.Model) ? string.Format(MessageUseInstead, "'AsEnumerable'") : string.Format(MessageDropFromMiddle, methodSymbol.Name); @@ -197,7 +197,7 @@ private static ITypeSymbol GetNodeTypeSymbol(SyntaxNode node, SemanticModel mode private static void CheckExtensionMethodsOnIEnumerable(SonarSyntaxNodeReportingContext context) { var outerInvocation = (InvocationExpressionSyntax)context.Node; - if (context.SemanticModel.GetSymbolInfo(outerInvocation).Symbol is not IMethodSymbol outerMethodSymbol + if (context.Model.GetSymbolInfo(outerInvocation).Symbol is not IMethodSymbol outerMethodSymbol || !outerMethodSymbol.IsExtensionOn(KnownType.System_Collections_Generic_IEnumerable_T)) { return; @@ -209,7 +209,7 @@ private static void CheckExtensionMethodsOnIEnumerable(SonarSyntaxNodeReportingC return; } - if (context.SemanticModel.GetSymbolInfo(innerInvocation).Symbol is not IMethodSymbol innerMethodSymbol + if (context.Model.GetSymbolInfo(innerInvocation).Symbol is not IMethodSymbol innerMethodSymbol || !innerMethodSymbol.IsExtensionOn(KnownType.System_Collections_Generic_IEnumerable_T)) { return; diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/ComparableInterfaceImplementation.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/ComparableInterfaceImplementation.cs index ffbf4f8dda7..45240fe678b 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/ComparableInterfaceImplementation.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/ComparableInterfaceImplementation.cs @@ -45,7 +45,7 @@ protected override void Initialize(SonarAnalysisContext context) => { var classDeclaration = (TypeDeclarationSyntax)c.Node; - var classSymbol = c.SemanticModel.GetDeclaredSymbol(classDeclaration); + var classSymbol = c.Model.GetDeclaredSymbol(classDeclaration); if (classSymbol == null) { return; diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/CompareNaN.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/CompareNaN.cs index 3d9b770593d..11d5110f8a8 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/CompareNaN.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/CompareNaN.cs @@ -39,8 +39,8 @@ protected override void Initialize(SonarAnalysisContext context) => { var binaryExpressionSyntax = (BinaryExpressionSyntax)c.Node; - if (TryGetFloatingPointType(binaryExpressionSyntax.Left, c.SemanticModel, out var floatingPointType) - || TryGetFloatingPointType(binaryExpressionSyntax.Right, c.SemanticModel, out floatingPointType)) + if (TryGetFloatingPointType(binaryExpressionSyntax.Left, c.Model, out var floatingPointType) + || TryGetFloatingPointType(binaryExpressionSyntax.Right, c.Model, out floatingPointType)) { var messageFormat = c.Node.Kind() is SyntaxKind.EqualsExpression or SyntaxKind.NotEqualsExpression ? MessageFormatEquality diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/ConditionalSimplification.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/ConditionalSimplification.cs index 0fd3db4e8ab..c71e7f5ea07 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/ConditionalSimplification.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/ConditionalSimplification.cs @@ -107,9 +107,9 @@ private static void CheckIfStatement(SonarSyntaxNodeReportingContext context) } var possiblyCoalescing = ifStatement.Condition.TryGetExpressionComparedToNull(out var comparedToNull, out var comparedIsNullInTrue) - && comparedToNull.CanBeNull(context.SemanticModel); + && comparedToNull.CanBeNull(context.Model); - if (CanBeSimplified(context, whenTrue, whenFalse, possiblyCoalescing ? comparedToNull : null, context.SemanticModel, comparedIsNullInTrue, out var simplifiedOperator)) + if (CanBeSimplified(context, whenTrue, whenFalse, possiblyCoalescing ? comparedToNull : null, context.Model, comparedIsNullInTrue, out var simplifiedOperator)) { context.ReportIssue(Rule, ifStatement.IfKeyword, BuildCodeFixProperties(context, simplifiedOperator), simplifiedOperator); } @@ -129,8 +129,8 @@ private static void CheckConditionalExpression(SonarSyntaxNodeReportingContext c } if (condition.TryGetExpressionComparedToNull(out var comparedToNull, out var comparedIsNullInTrue) - && comparedToNull.CanBeNull(context.SemanticModel) - && CanExpressionBeCoalescing(whenTrue, whenFalse, comparedToNull, context.SemanticModel, comparedIsNullInTrue)) + && comparedToNull.CanBeNull(context.Model) + && CanExpressionBeCoalescing(whenTrue, whenFalse, comparedToNull, context.Model, comparedIsNullInTrue)) { if (context.Compilation.IsCoalesceAssignmentSupported() && IsCoalesceAssignmentCandidate(conditional, comparedToNull)) { diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/ConditionalStructureSameImplementation.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/ConditionalStructureSameImplementation.cs index 758e3146e61..7a0ee6c0245 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/ConditionalStructureSameImplementation.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/ConditionalStructureSameImplementation.cs @@ -39,11 +39,11 @@ protected override void Initialize(SonarAnalysisContext context) var precedingStatements = ifStatement.PrecedingStatementsInConditionChain().ToList(); var hasElse = HasLeafElseClause(ifStatement); - CheckStatement(c, ifStatement.Statement, precedingStatements, c.SemanticModel, hasElse, "branch"); + CheckStatement(c, ifStatement.Statement, precedingStatements, c.Model, hasElse, "branch"); if (ifStatement.Else is not null) { - CheckStatement(c, ifStatement.Else.Statement, [..precedingStatements, ifStatement.Statement], c.SemanticModel, hasElse, "branch"); + CheckStatement(c, ifStatement.Else.Statement, [..precedingStatements, ifStatement.Statement], c.Model, hasElse, "branch"); } }, SyntaxKind.IfStatement); @@ -54,7 +54,7 @@ protected override void Initialize(SonarAnalysisContext context) var switchSection = (SwitchSectionSyntax)c.Node; var precedingSections = switchSection.PrecedingSections().ToList(); - CheckStatement(c, switchSection, precedingSections, c.SemanticModel, HasDefaultClause((SwitchStatementSyntax)switchSection.Parent), "case"); + CheckStatement(c, switchSection, precedingSections, c.Model, HasDefaultClause((SwitchStatementSyntax)switchSection.Parent), "case"); }, SyntaxKind.SwitchSection); } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/ConditionalsWithSameCondition.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/ConditionalsWithSameCondition.cs index bb94030ddd7..432a66b895e 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/ConditionalsWithSameCondition.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/ConditionalsWithSameCondition.cs @@ -45,7 +45,7 @@ private static void CheckMatchingExpressionsInSucceedingStatements(SonarSynta var currentExpression = expression(currentStatement); var previousExpression = expression(previousStatement); if (CSharpEquivalenceChecker.AreEquivalent(currentExpression, previousExpression) - && !ContainsPossibleUpdate(previousStatement, currentExpression, context.SemanticModel)) + && !ContainsPossibleUpdate(previousStatement, currentExpression, context.Model)) { context.ReportIssue(Rule, currentExpression, previousExpression.GetLineNumberToReport().ToString()); } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/ConstructorOverridableCall.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/ConstructorOverridableCall.cs index b31c185f525..3352707a0fa 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/ConstructorOverridableCall.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/ConstructorOverridableCall.cs @@ -45,14 +45,14 @@ private static void CheckOverridableCallInConstructor(SonarSyntaxNodeReportingCo return; } - var enclosingSymbol = context.SemanticModel.GetEnclosingSymbol(invocationExpression.SpanStart) as IMethodSymbol; + var enclosingSymbol = context.Model.GetEnclosingSymbol(invocationExpression.SpanStart) as IMethodSymbol; if (!IsMethodConstructor(enclosingSymbol)) { return; } - if (context.SemanticModel.GetSymbolInfo(invocationExpression.Expression).Symbol is IMethodSymbol methodSymbol && + if (context.Model.GetSymbolInfo(invocationExpression.Expression).Symbol is IMethodSymbol methodSymbol && IsMethodOverridable(methodSymbol) && enclosingSymbol.IsInType(methodSymbol.ContainingType)) { diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/ConsumeValueTaskCorrectly.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/ConsumeValueTaskCorrectly.cs index adc6ba21822..de11e173da2 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/ConsumeValueTaskCorrectly.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/ConsumeValueTaskCorrectly.cs @@ -44,7 +44,7 @@ public sealed class ConsumeValueTaskCorrectly : SonarDiagnosticAnalyzer protected override void Initialize(SonarAnalysisContext context) => context.RegisterNodeAction(c => { - var walker = new ConsumeValueTaskWalker(c.SemanticModel); + var walker = new ConsumeValueTaskWalker(c.Model); walker.SafeVisit(c.Node); foreach (var syntaxNodes in walker.SymbolUsages.Values) diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/CryptographicKeyShouldNotBeTooShort.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/CryptographicKeyShouldNotBeTooShort.cs index fa31416eb1f..0abb8186de4 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/CryptographicKeyShouldNotBeTooShort.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/CryptographicKeyShouldNotBeTooShort.cs @@ -60,7 +60,7 @@ protected override void Initialize(SonarAnalysisContext context) c => { var invocation = (InvocationExpressionSyntax)c.Node; - var containingType = new Lazy(() => c.SemanticModel.GetSymbolInfo(invocation).Symbol?.ContainingType); + var containingType = new Lazy(() => c.Model.GetSymbolInfo(invocation).Symbol?.ContainingType); switch (GetMethodName(invocation)) { @@ -87,7 +87,7 @@ protected override void Initialize(SonarAnalysisContext context) c => { var objectCreation = ObjectCreationFactory.Create(c.Node); - var containingType = objectCreation.TypeSymbol(c.SemanticModel); + var containingType = objectCreation.TypeSymbol(c.Model); CheckSystemSecurityEllipticCurve(c, containingType, objectCreation.Expression, objectCreation.ArgumentList); CheckSystemSecurityCryptographyAlgorithms(c, containingType, objectCreation); CheckBouncyCastleKeyGenerationParameters(c, containingType, objectCreation); @@ -100,7 +100,7 @@ protected override void Initialize(SonarAnalysisContext context) var assignment = (AssignmentExpressionSyntax)c.Node; if (GetPropertyName(assignment.Left) == nameof(AsymmetricAlgorithm.KeySize) && assignment.Left is MemberAccessExpressionSyntax { Expression: { } expression } - && c.SemanticModel.GetTypeInfo(expression).Type is ITypeSymbol containingType) + && c.Model.GetTypeInfo(expression).Type is ITypeSymbol containingType) { // Using the KeySize setter on DSACryptoServiceProvider/RSACryptoServiceProvider does not actually change the underlying key size // https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.dsacryptoserviceprovider.keysize @@ -144,7 +144,7 @@ private void CheckBouncyCastleEllipticCurve(SonarSyntaxNodeReportingContext c, I return; } - if (firstParam.FindStringConstant(c.SemanticModel) is { } curveId) + if (firstParam.FindStringConstant(c.Model) is { } curveId) { CheckCurveNameKeyLength(c, invocation, curveId); } @@ -158,7 +158,7 @@ private void CheckSystemSecurityEllipticCurve(SonarSyntaxNodeReportingContext c, return; } - if (c.SemanticModel.GetSymbolInfo(firstParam).Symbol is { } paramSymbol) + if (c.Model.GetSymbolInfo(firstParam).Symbol is { } paramSymbol) { CheckCurveNameKeyLength(c, syntaxElement, paramSymbol.Name); } @@ -193,7 +193,7 @@ private static bool HasDefaultSize(SonarSyntaxNodeReportingContext c, ArgumentLi argumentList == null || argumentList.Arguments.Count == 0 || (argumentList.Arguments.Count == 1 - && c.SemanticModel.GetTypeInfo(argumentList.Arguments[0].Expression).Type is ITypeSymbol type + && c.Model.GetTypeInfo(argumentList.Arguments[0].Expression).Type is ITypeSymbol type && type.Is(KnownType.System_Security_Cryptography_CspParameters)); private static void CheckGenericDsaRsaCryptographyAlgorithms(SonarSyntaxNodeReportingContext c, ITypeSymbol containingType, SyntaxNode syntaxElement, SyntaxNode keyLengthSyntax) @@ -227,7 +227,7 @@ private static void CheckBouncyCastleKeyGenerationParameters(SonarSyntaxNodeRepo } private static bool IsInvalidCommonKeyLength(SonarSyntaxNodeReportingContext c, SyntaxNode keyLengthSyntax) => - keyLengthSyntax.FindConstantValue(c.SemanticModel) is int keyLength && keyLength < MinimalCommonKeyLength; + keyLengthSyntax.FindConstantValue(c.Model) is int keyLength && keyLength < MinimalCommonKeyLength; private static string GetMethodName(InvocationExpressionSyntax invocationExpression) => invocationExpression.Expression.GetIdentifier()?.ValueText; diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/DeadStores.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/DeadStores.cs index ed75fcdfc81..ff097689b25 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/DeadStores.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/DeadStores.cs @@ -42,7 +42,7 @@ protected override void Initialize(SonarAnalysisContext context) { // No need to check for ExpressionBody as it can't contain variable assignment context.RegisterNodeAction( - c => CheckForDeadStores(c, c.SemanticModel.GetDeclaredSymbol(c.Node)), + c => CheckForDeadStores(c, c.Model.GetDeclaredSymbol(c.Node)), SyntaxKind.AddAccessorDeclaration, SyntaxKind.ConstructorDeclaration, SyntaxKind.ConversionOperatorDeclaration, @@ -57,7 +57,7 @@ protected override void Initialize(SonarAnalysisContext context) SyntaxKindEx.LocalFunctionStatement); context.RegisterNodeAction( - c => CheckForDeadStores(c, c.SemanticModel.GetSymbolInfo(c.Node).Symbol), + c => CheckForDeadStores(c, c.Model.GetSymbolInfo(c.Node).Symbol), SyntaxKind.AnonymousMethodExpression, SyntaxKind.ParenthesizedLambdaExpression, SyntaxKind.SimpleLambdaExpression); @@ -70,14 +70,14 @@ private void CheckForDeadStores(SonarSyntaxNodeReportingContext context, ISymbol if (useSonarCfg) { // Tuple expressions are not supported. See https://github.com/SonarSource/sonar-dotnet/issues/3094 - if (!context.Node.DescendantNodes().AnyOfKind(SyntaxKindEx.TupleExpression) && CSharpControlFlowGraph.TryGet(context.Node, context.SemanticModel, out var cfg)) + if (!context.Node.DescendantNodes().AnyOfKind(SyntaxKindEx.TupleExpression) && CSharpControlFlowGraph.TryGet(context.Node, context.Model, out var cfg)) { - var lva = new SonarCSharpLiveVariableAnalysis(cfg, symbol, context.SemanticModel, context.Cancel); + var lva = new SonarCSharpLiveVariableAnalysis(cfg, symbol, context.Model, context.Cancel); var checker = new SonarChecker(context, lva, context.Node); checker.Analyze(cfg.Blocks); } } - else if (context.Node.CreateCfg(context.SemanticModel, context.Cancel) is { } cfg) + else if (context.Node.CreateCfg(context.Model, context.Cancel) is { } cfg) { var lva = new RoslynLiveVariableAnalysis(cfg, CSharpSyntaxClassifier.Instance, context.Cancel); var checker = new RoslynChecker(context, lva); @@ -121,7 +121,7 @@ protected abstract class State public abstract void AnalyzeBlock(); - protected SemanticModel SemanticModel => owner.context.SemanticModel; + protected SemanticModel SemanticModel => owner.context.Model; protected State(CheckerBase owner, TBlock block) { diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/DebugAssertHasNoSideEffects.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/DebugAssertHasNoSideEffects.cs index d036d63eea7..aff0c57bcc4 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/DebugAssertHasNoSideEffects.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/DebugAssertHasNoSideEffects.cs @@ -62,7 +62,7 @@ private static string GetIdentifierName(InvocationExpressionSyntax invocation) private static bool IsDebugAssert(SonarSyntaxNodeReportingContext context, InvocationExpressionSyntax invocation) => invocation.Expression is MemberAccessExpressionSyntax memberAccess && memberAccess.Name.Identifier.ValueText == nameof(System.Diagnostics.Debug.Assert) - && context.SemanticModel.GetSymbolInfo(invocation).Symbol is IMethodSymbol symbol + && context.Model.GetSymbolInfo(invocation).Symbol is IMethodSymbol symbol && symbol.IsDebugAssert(); private static bool ContainsCallsWithSideEffects(InvocationExpressionSyntax invocation) => diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/DeclareEventHandlersCorrectly.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/DeclareEventHandlersCorrectly.cs index 529a025bb0c..37af7b0cadc 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/DeclareEventHandlersCorrectly.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/DeclareEventHandlersCorrectly.cs @@ -44,7 +44,7 @@ private static void AnalyzeEventType(SonarSyntaxNodeReportingContext analysisCon { if (!eventSymbol.IsOverride && eventSymbol.GetInterfaceMember() is null - && analysisContext.SemanticModel.GetSymbolInfo(typeSyntax).Symbol is INamedTypeSymbol eventHandlerType + && analysisContext.Model.GetSymbolInfo(typeSyntax).Symbol is INamedTypeSymbol eventHandlerType && eventHandlerType.DelegateInvokeMethod is { } methodSymbol && !IsCorrectEventHandlerSignature(methodSymbol)) { diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/DelegateSubtraction.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/DelegateSubtraction.cs index 7cbbeb49e81..fe88c747e4a 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/DelegateSubtraction.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/DelegateSubtraction.cs @@ -33,7 +33,7 @@ protected override void Initialize(SonarAnalysisContext context) c => { var assignment = (AssignmentExpressionSyntax)c.Node; - if (!ExpressionIsSimple(assignment.Right) && IsDelegateSubtraction(assignment, c.SemanticModel)) + if (!ExpressionIsSimple(assignment.Right) && IsDelegateSubtraction(assignment, c.Model)) { c.ReportIssue(Rule, assignment); } @@ -46,7 +46,7 @@ protected override void Initialize(SonarAnalysisContext context) var binary = (BinaryExpressionSyntax)c.Node; if (IsTopLevelSubtraction(binary) && !BinaryIsValidSubstraction(binary) - && IsDelegateSubtraction(binary, c.SemanticModel)) + && IsDelegateSubtraction(binary, c.Model)) { c.ReportIssue(Rule, binary); } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/DisposableReturnedFromUsing.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/DisposableReturnedFromUsing.cs index cc9b8816400..1ec3e219528 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/DisposableReturnedFromUsing.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/DisposableReturnedFromUsing.cs @@ -38,7 +38,7 @@ protected override void Initialize(SonarAnalysisContext context) if (declaration != null) { symbolsDeclaredInUsing = - declaration.Variables.Select(syntax => c.SemanticModel.GetDeclaredSymbol(syntax)) + declaration.Variables.Select(syntax => c.Model.GetDeclaredSymbol(syntax)) .WhereNotNull() .ToHashSet(); } @@ -48,7 +48,7 @@ protected override void Initialize(SonarAnalysisContext context) { return; } - var symbol = c.SemanticModel.GetSymbolInfo(identifierName).Symbol; + var symbol = c.Model.GetSymbolInfo(identifierName).Symbol; if (symbol == null) { return; @@ -71,7 +71,7 @@ protected override void Initialize(SonarAnalysisContext context) } var declaredSymbols = localDeclarationStatement.Declaration.Variables - .Select(syntax => c.SemanticModel.GetDeclaredSymbol(syntax)) + .Select(syntax => c.Model.GetDeclaredSymbol(syntax)) .WhereNotNull() .ToHashSet(); @@ -87,7 +87,7 @@ private static void CheckReturns(SonarSyntaxNodeReportingContext c, SyntaxToken return; } - var returnedSymbols = GetReturnedSymbols(body, c.SemanticModel); + var returnedSymbols = GetReturnedSymbols(body, c.Model); returnedSymbols.IntersectWith(declaredSymbols); if (returnedSymbols.Any()) diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/DisposableTypesNeedFinalizers.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/DisposableTypesNeedFinalizers.cs index c2e5ede2e37..17905338466 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/DisposableTypesNeedFinalizers.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/DisposableTypesNeedFinalizers.cs @@ -36,7 +36,7 @@ protected override void Initialize(SonarAnalysisContext context) => var declaration = (TypeDeclarationSyntax)c.Node; if (!c.IsRedundantPositionalRecordContext() && ((ITypeSymbol)c.ContainingSymbol).Implements(KnownType.System_IDisposable) - && HasNativeHandleFields(declaration, c.SemanticModel) + && HasNativeHandleFields(declaration, c.Model) && !HasFinalizer(declaration)) { c.ReportIssue(Rule, declaration.Identifier); diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/DisposeFromDispose.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/DisposeFromDispose.cs index b8d10b014a7..4e761fad6af 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/DisposeFromDispose.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/DisposeFromDispose.cs @@ -35,13 +35,13 @@ protected override void Initialize(SonarAnalysisContext context) => var invocation = (InvocationExpressionSyntax)c.Node; var languageVersion = c.Compilation.GetLanguageVersion(); if (InvocationTargetAndName(invocation, out var fieldCandidate, out var name) - && c.SemanticModel.GetSymbolInfo(fieldCandidate).Symbol is IFieldSymbol invocationTarget + && c.Model.GetSymbolInfo(fieldCandidate).Symbol is IFieldSymbol invocationTarget && invocationTarget.IsNonStaticNonPublicDisposableField(languageVersion) - && IsDisposeMethodCalled(invocation, c.SemanticModel, languageVersion) + && IsDisposeMethodCalled(invocation, c.Model, languageVersion) && IsDisposableClassOrStruct(invocationTarget.ContainingType, languageVersion) - && !IsCalledInsideDispose(invocation, c.SemanticModel) - && FieldDeclaredInType(c.SemanticModel, invocation, invocationTarget) - && !FieldDisposedInDispose(c.SemanticModel, invocationTarget)) + && !IsCalledInsideDispose(invocation, c.Model) + && FieldDeclaredInType(c.Model, invocation, invocationTarget) + && !FieldDisposedInDispose(c.Model, invocationTarget)) { c.ReportIssue(Rule, name); } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotCatchNullReferenceException.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotCatchNullReferenceException.cs index 38811e4bd52..5319be974e8 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotCatchNullReferenceException.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotCatchNullReferenceException.cs @@ -32,13 +32,13 @@ protected override void Initialize(SonarAnalysisContext context) c => { var catchClause = (CatchClauseSyntax)c.Node; - if (IsCatchingNullReferenceException(catchClause.Declaration, c.SemanticModel)) + if (IsCatchingNullReferenceException(catchClause.Declaration, c.Model)) { c.ReportIssue(rule, catchClause.Declaration.Type); return; } - if (HasIsNullReferenceExceptionFilter(catchClause.Filter, c.SemanticModel, out var locationToReportOn)) + if (HasIsNullReferenceExceptionFilter(catchClause.Filter, c.Model, out var locationToReportOn)) { c.ReportIssue(rule, locationToReportOn); } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotCatchSystemException.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotCatchSystemException.cs index 1572bd8f328..a901d8618e9 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotCatchSystemException.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotCatchSystemException.cs @@ -33,7 +33,7 @@ protected override void Initialize(SonarAnalysisContext context) => if (c.AzureFunctionMethod() is null && IsCatchClauseEmptyOrNotPattern(catchClause) - && IsSystemException(catchClause.Declaration, c.SemanticModel) + && IsSystemException(catchClause.Declaration, c.Model) && !IsThrowTheLastStatementInTheBlock(catchClause.Block)) { c.ReportIssue(Rule, GetLocation(catchClause)); diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotCheckZeroSizeCollection.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotCheckZeroSizeCollection.cs index 6ced89db2ea..3bf97c8419d 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotCheckZeroSizeCollection.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotCheckZeroSizeCollection.cs @@ -93,7 +93,7 @@ private void CheckPatternCondition(SonarSyntaxNodeReportingContext context, Synt && ((RelationalPatternSyntaxWrapper)relationalPatternNode) is var relationalPattern && ComparisonKind(relationalPattern.OperatorToken) is { } comparison && comparison != Comparison.None - && Language.ExpressionNumericConverter.TryGetConstantIntValue(context.SemanticModel, relationalPattern.Expression, out var constant)) + && Language.ExpressionNumericConverter.TryGetConstantIntValue(context.Model, relationalPattern.Expression, out var constant)) { CheckExpression(context, relationalPattern.SyntaxNode, expression, constant, comparison); } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotCopyArraysInProperties.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotCopyArraysInProperties.cs index e1d2cce8d08..755fba8589f 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotCopyArraysInProperties.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotCopyArraysInProperties.cs @@ -40,7 +40,7 @@ protected override void Initialize(SonarAnalysisContext context) return; } - var walker = new PropertyWalker(c.SemanticModel); + var walker = new PropertyWalker(c.Model); walker.SafeVisit(body); diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotDecreaseMemberVisibility.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotDecreaseMemberVisibility.cs index 2d7db77764b..aa26d3b2971 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotDecreaseMemberVisibility.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotDecreaseMemberVisibility.cs @@ -70,7 +70,7 @@ public IssueReporter(ITypeSymbol classSymbol, SonarSyntaxNodeReportingContext co public void ReportIssue(MemberDeclarationSyntax memberDeclaration) { - switch (context.SemanticModel.GetDeclaredSymbol(memberDeclaration)) + switch (context.Model.GetDeclaredSymbol(memberDeclaration)) { case IMethodSymbol methodSymbol: ReportMethodIssue(memberDeclaration, methodSymbol); diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotExposeListT.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotExposeListT.cs index ee4013cbf31..9f7cf12bc33 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotExposeListT.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotExposeListT.cs @@ -31,7 +31,7 @@ protected override void Initialize(SonarAnalysisContext context) c => { var baseMethodDeclaration = (BaseMethodDeclarationSyntax)c.Node; - var methodSymbol = c.SemanticModel.GetDeclaredSymbol(baseMethodDeclaration); + var methodSymbol = c.Model.GetDeclaredSymbol(baseMethodDeclaration); if (methodSymbol == null || !methodSymbol.IsPubliclyAccessible() @@ -61,7 +61,7 @@ protected override void Initialize(SonarAnalysisContext context) c => { var propertyDeclaration = (PropertyDeclarationSyntax)c.Node; - var propertySymbol = c.SemanticModel.GetDeclaredSymbol(propertyDeclaration); + var propertySymbol = c.Model.GetDeclaredSymbol(propertyDeclaration); if (propertySymbol != null && propertySymbol.IsPubliclyAccessible() @@ -84,7 +84,7 @@ protected override void Initialize(SonarAnalysisContext context) return; } - var fieldSymbol = c.SemanticModel.GetDeclaredSymbol(variableDeclaration); + var fieldSymbol = c.Model.GetDeclaredSymbol(variableDeclaration); if (fieldSymbol != null && fieldSymbol.IsPubliclyAccessible() @@ -98,7 +98,7 @@ protected override void Initialize(SonarAnalysisContext context) private static void ReportIfListT(SonarSyntaxNodeReportingContext context, TypeSyntax typeSyntax, string memberType) { - if (typeSyntax != null && typeSyntax.IsKnownType(KnownType.System_Collections_Generic_List_T, context.SemanticModel)) + if (typeSyntax != null && typeSyntax.IsKnownType(KnownType.System_Collections_Generic_List_T, context.Model)) { context.ReportIssue(Rule, typeSyntax, memberType); } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotHideBaseClassMethods.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotHideBaseClassMethods.cs index 4b71f36305a..1189ddb512a 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotHideBaseClassMethods.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotHideBaseClassMethods.cs @@ -31,7 +31,7 @@ protected override void Initialize(SonarAnalysisContext context) => var declarationSyntax = (TypeDeclarationSyntax)c.Node; if (declarationSyntax.Identifier.IsMissing || c.IsRedundantPositionalRecordContext() - || !(c.SemanticModel.GetDeclaredSymbol(declarationSyntax) is { } declaredSymbol)) + || !(c.Model.GetDeclaredSymbol(declarationSyntax) is { } declaredSymbol)) { return; } @@ -66,7 +66,7 @@ public IssueReporter(ITypeSymbol typeSymbol, SonarSyntaxNodeReportingContext con public void ReportIssue(MemberDeclarationSyntax memberDeclaration) { if (memberDeclaration is MethodDeclarationSyntax { Identifier: { } identifier } - && context.SemanticModel.GetDeclaredSymbol(memberDeclaration) is IMethodSymbol methodSymbol + && context.Model.GetDeclaredSymbol(memberDeclaration) is IMethodSymbol methodSymbol && FindBaseMethodHiddenByMethod(methodSymbol) is { } baseMethodHidden) { context.ReportIssue(Rule, identifier, baseMethodHidden.ToDisplayString()); diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotInstantiateSharedClasses.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotInstantiateSharedClasses.cs index 3347e9ecdeb..9613caa47e2 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotInstantiateSharedClasses.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotInstantiateSharedClasses.cs @@ -30,7 +30,7 @@ protected override void Initialize(SonarAnalysisContext context) { var creationSyntax = (ObjectCreationExpressionSyntax)c.Node; - var createdType = c.SemanticModel.GetTypeInfo(creationSyntax).Type; + var createdType = c.Model.GetTypeInfo(creationSyntax).Type; if (createdType != null && createdType.GetAttributes(KnownType.System_ComponentModel_Composition_PartCreationPolicyAttribute).Any(IsShared)) { diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotLockOnSharedResource.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotLockOnSharedResource.cs index 30fc260970f..d01d0afa597 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotLockOnSharedResource.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotLockOnSharedResource.cs @@ -32,7 +32,7 @@ protected override void Initialize(SonarAnalysisContext context) if (IsLockOnThis(lockStatement.Expression) || IsLockOnStringLiteral(lockStatement.Expression) || - IsLockOnForbiddenKnownType(lockStatement.Expression, c.SemanticModel)) + IsLockOnForbiddenKnownType(lockStatement.Expression, c.Model)) { c.ReportIssue(rule, lockStatement.Expression); } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotMarkEnumsWithFlags.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotMarkEnumsWithFlags.cs index 234941ebd0e..fd365577aa3 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotMarkEnumsWithFlags.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotMarkEnumsWithFlags.cs @@ -34,9 +34,9 @@ protected override void Initialize(SonarAnalysisContext context) => c => { var enumDeclaration = (EnumDeclarationSyntax)c.Node; - var enumSymbol = c.SemanticModel.GetDeclaredSymbol(enumDeclaration); + var enumSymbol = c.Model.GetDeclaredSymbol(enumDeclaration); - if (!enumDeclaration.HasFlagsAttribute(c.SemanticModel) + if (!enumDeclaration.HasFlagsAttribute(c.Model) || enumDeclaration.Identifier.IsMissing || enumSymbol is null) { diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotNestTypesInArguments.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotNestTypesInArguments.cs index efc90e7b542..1faa9e8bbdf 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotNestTypesInArguments.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotNestTypesInArguments.cs @@ -30,7 +30,7 @@ protected override void Initialize(SonarAnalysisContext context) => context.RegisterNodeAction( c => { - var argumentTypeSymbols = GetParametersSyntaxNodes(c.Node).Where(p => MaxDepthReached(p, c.SemanticModel)); + var argumentTypeSymbols = GetParametersSyntaxNodes(c.Node).Where(p => MaxDepthReached(p, c.Model)); foreach (var argument in argumentTypeSymbols) { diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotOverloadOperatorEqual.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotOverloadOperatorEqual.cs index 3f63838b631..bd01af69aae 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotOverloadOperatorEqual.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotOverloadOperatorEqual.cs @@ -47,7 +47,7 @@ private static void CheckForIssue(SonarSyntaxNodeReportingContext analysisContex .OfType() .Any(op => op.OperatorToken.IsKind(SyntaxKind.PlusToken) || op.OperatorToken.IsKind(SyntaxKind.MinusToken)) - && analysisContext.SemanticModel.GetDeclaredSymbol(classDeclaration) is { } namedTypeSymbol + && analysisContext.Model.GetDeclaredSymbol(classDeclaration) is { } namedTypeSymbol && !namedTypeSymbol.ImplementsAny(InterfacesRelyingOnOperatorEqualOverload)) { analysisContext.ReportIssue(Rule, declaration.OperatorToken); diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotShiftByZeroOrIntSize.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotShiftByZeroOrIntSize.cs index 8dd0ffd151c..3647c4a9371 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotShiftByZeroOrIntSize.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotShiftByZeroOrIntSize.cs @@ -57,7 +57,7 @@ protected override void Initialize(SonarAnalysisContext context) => { var shiftInstances = ((MemberDeclarationSyntax)c.Node) .DescendantNodes() - .Select(n => FindShiftInstance(n, c.SemanticModel)) + .Select(n => FindShiftInstance(n, c.Model)) .WhereNotNull(); var zeroShiftIssues = new List(); diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotUseCollectionInItsOwnMethodCalls.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotUseCollectionInItsOwnMethodCalls.cs index c288c7a44ec..17f11828a04 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotUseCollectionInItsOwnMethodCalls.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotUseCollectionInItsOwnMethodCalls.cs @@ -49,7 +49,7 @@ protected override void Initialize(SonarAnalysisContext context) return; } - var operands = GetOperandsToCheckIfTrackedMethod(invocation, c.SemanticModel); + var operands = GetOperandsToCheckIfTrackedMethod(invocation, c.Model); if (operands is not null && CSharpEquivalenceChecker.AreEquivalent(operands.Left, operands.Right)) { c.ReportIssue(rule, operands.Left, [operands.Right.ToSecondaryLocation()], operands.Right.ToString(), operands.ErrorMessage); diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotUseLiteralBoolInAssertions.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotUseLiteralBoolInAssertions.cs index 8ab795f2b17..db1b72ae1b0 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotUseLiteralBoolInAssertions.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotUseLiteralBoolInAssertions.cs @@ -67,9 +67,9 @@ protected override void Initialize(SonarAnalysisContext context) => var invocation = (InvocationExpressionSyntax)c.Node; if (invocation.ArgumentList != null && IsFirstOrSecondArgumentABoolLiteral(invocation.ArgumentList.Arguments) - && c.SemanticModel.GetSymbolOrCandidateSymbol(invocation) is IMethodSymbol methodSymbol + && c.Model.GetSymbolOrCandidateSymbol(invocation) is IMethodSymbol methodSymbol && IsTrackedMethod(methodSymbol) - && !IsWorkingWithNullableType(methodSymbol, invocation.ArgumentList.Arguments, c.SemanticModel)) + && !IsWorkingWithNullableType(methodSymbol, invocation.ArgumentList.Arguments, c.Model)) { c.ReportIssue(Rule, invocation); } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotUseOutRefParameters.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotUseOutRefParameters.cs index b5e4ed39924..097d760d10b 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotUseOutRefParameters.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotUseOutRefParameters.cs @@ -40,7 +40,7 @@ protected override void Initialize(SonarAnalysisContext context) => var modifier = parameter.Modifiers.First(IsRefOrOut); - var parameterSymbol = c.SemanticModel.GetDeclaredSymbol(parameter); + var parameterSymbol = c.Model.GetDeclaredSymbol(parameter); if (parameterSymbol?.ContainingSymbol is not IMethodSymbol containingMethod || containingMethod.IsOverride diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotWriteToStandardOutput.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotWriteToStandardOutput.cs index 796d1dcf074..0ab997f96db 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotWriteToStandardOutput.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/DoNotWriteToStandardOutput.cs @@ -36,10 +36,10 @@ protected sealed override void Initialize(SonarAnalysisContext context) => { var invocation = (InvocationExpressionSyntax)c.Node; if (c.Compilation.Options.OutputKind != OutputKind.ConsoleApplication - && c.SemanticModel.GetSymbolInfo(invocation.Expression).Symbol is IMethodSymbol method + && c.Model.GetSymbolInfo(invocation.Expression).Symbol is IMethodSymbol method && method.IsAny(KnownType.System_Console, BannedConsoleMembers) && !c.Node.IsInDebugBlock() - && !invocation.IsInConditionalDebug(c.SemanticModel)) + && !invocation.IsInConditionalDebug(c.Model)) { c.ReportIssue(Rule, invocation.Expression); } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/DontUseTraceSwitchLevels.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/DontUseTraceSwitchLevels.cs index c7006d255db..c3ff9ee7e17 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/DontUseTraceSwitchLevels.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/DontUseTraceSwitchLevels.cs @@ -39,9 +39,9 @@ protected override void Initialize(SonarAnalysisContext context) => var invocation = (InvocationExpressionSyntax)c.Node; if (invocation.GetName() is "WriteIf" or "WriteLineIf" && invocation.ArgumentList.Arguments.Count > 1 - && c.SemanticModel.GetSymbolInfo(invocation).Symbol is IMethodSymbol methodSymbol + && c.Model.GetSymbolInfo(invocation).Symbol is IMethodSymbol methodSymbol && methodSymbol.ContainingType.Is(KnownType.System_Diagnostics_Trace) - && UsesTraceSwitchAsCondition(c.SemanticModel, methodSymbol, invocation) is { } traceSwitchProperty) + && UsesTraceSwitchAsCondition(c.Model, methodSymbol, invocation) is { } traceSwitchProperty) { c.ReportIssue(Rule, traceSwitchProperty, invocation.GetName()); } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/EmptyMethod.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/EmptyMethod.cs index 6b8e794b5dc..f688ff4c7ad 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/EmptyMethod.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/EmptyMethod.cs @@ -44,7 +44,7 @@ protected override void CheckMethod(SonarSyntaxNodeReportingContext context) private static bool ShouldBeExcluded(SonarSyntaxNodeReportingContext context, SyntaxNode node, SyntaxTokenList modifiers) => modifiers.Any(SyntaxKind.VirtualKeyword) // This quick check only works for methods, for accessors we need to check the symbol - || (context.SemanticModel.GetDeclaredSymbol(node) is IMethodSymbol symbol + || (context.Model.GetDeclaredSymbol(node) is IMethodSymbol symbol && (symbol is { IsVirtual: true } || symbol is { IsOverride: true, OverriddenMethod.IsAbstract: true } || !symbol.ExplicitOrImplicitInterfaceImplementations().IsEmpty)) diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/EnumStorageNeedsToBeInt32.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/EnumStorageNeedsToBeInt32.cs index 27a1ad205c7..98fd2816ee7 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/EnumStorageNeedsToBeInt32.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/EnumStorageNeedsToBeInt32.cs @@ -35,7 +35,7 @@ protected override void Initialize(SonarAnalysisContext context) var enumBaseType = enumDeclaration?.BaseList?.Types.FirstOrDefault()?.Type; if (enumDeclaration != null && - !IsDefaultOrLarger(enumBaseType, c.SemanticModel)) + !IsDefaultOrLarger(enumBaseType, c.Model)) { c.ReportIssue(rule, enumDeclaration.Identifier); } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/EnumerableSumInUnchecked.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/EnumerableSumInUnchecked.cs index 708d59116da..5a8307ac131 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/EnumerableSumInUnchecked.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/EnumerableSumInUnchecked.cs @@ -37,7 +37,7 @@ protected override void Initialize(SonarAnalysisContext context) if (expression is MemberAccessExpressionSyntax memberAccess && memberAccess.Name.Identifier.ValueText == "Sum" && IsSumInsideUnchecked(invocation) && - c.SemanticModel.GetSymbolInfo(invocation).Symbol is IMethodSymbol methodSymbol && + c.Model.GetSymbolInfo(invocation).Symbol is IMethodSymbol methodSymbol && IsSumOnInteger(methodSymbol)) { c.ReportIssue(rule, memberAccess.Name); diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/EqualityOnFloatingPoint.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/EqualityOnFloatingPoint.cs index 43548cf8cbc..f77697cffe3 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/EqualityOnFloatingPoint.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/EqualityOnFloatingPoint.cs @@ -53,8 +53,8 @@ private static void CheckLogicalExpression(SonarSyntaxNodeReportingContext conte && TryGetBinaryExpression(binaryExpression.Right) is { } right && CSharpEquivalenceChecker.AreEquivalent(right.Right, left.Right) && CSharpEquivalenceChecker.AreEquivalent(right.Left, left.Left) - && IsIndirectEquality(context.SemanticModel, binaryExpression, left, right) is var isEquality - && IsIndirectInequality(context.SemanticModel, binaryExpression, left, right) is var isInequality + && IsIndirectEquality(context.Model, binaryExpression, left, right) is var isEquality + && IsIndirectInequality(context.Model, binaryExpression, left, right) is var isInequality && (isEquality || isInequality)) { context.ReportIssue(Rule, binaryExpression, MessageEqualityPart(isEquality), "a range"); @@ -67,7 +67,7 @@ private static string MessageEqualityPart(bool isEquality) => private static void CheckEquality(SonarSyntaxNodeReportingContext context) { var equals = (BinaryExpressionSyntax)context.Node; - if (context.SemanticModel.GetSymbolInfo(equals).Symbol is IMethodSymbol { ContainingType: { } container } method + if (context.Model.GetSymbolInfo(equals).Symbol is IMethodSymbol { ContainingType: { } container } method && IsFloatingPointType(container) && (method.IsOperatorEquals() || method.IsOperatorNotEquals())) { @@ -84,15 +84,15 @@ private static void CheckEquality(SonarSyntaxNodeReportingContext context) private static string ProposedMessageForMemberAccess(SonarSyntaxNodeReportingContext context, ExpressionSyntax expression) => expression is MemberAccessExpressionSyntax memberAccess && SpecialMembers.TryGetValue(memberAccess.GetName(), out var proposedMethod) - && context.SemanticModel.GetTypeInfo(memberAccess).ConvertedType is { } type + && context.Model.GetTypeInfo(memberAccess).ConvertedType is { } type && IsFloatingPointType(type) - ? $"'{type.ToMinimalDisplayString(context.SemanticModel, memberAccess.SpanStart)}.{proposedMethod}()'" + ? $"'{type.ToMinimalDisplayString(context.Model, memberAccess.SpanStart)}.{proposedMethod}()'" : null; private static string ProposedMessageForIdentifier(SonarSyntaxNodeReportingContext context, ExpressionSyntax expression) => expression is IdentifierNameSyntax identifier && SpecialMembers.TryGetValue(identifier.GetName(), out var proposedMethod) - && context.SemanticModel.GetSymbolInfo(identifier).Symbol is { ContainingType: { } type } + && context.Model.GetSymbolInfo(identifier).Symbol is { ContainingType: { } type } && IsFloatingPointType(type) ? $"'{proposedMethod}()'" : null; diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/EqualityOnModulus.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/EqualityOnModulus.cs index c15f89c1a17..d6d32533ec8 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/EqualityOnModulus.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/EqualityOnModulus.cs @@ -43,8 +43,8 @@ private static void VisitEquality(SonarSyntaxNodeReportingContext c) { var equalsExpression = (BinaryExpressionSyntax)c.Node; - if (CheckExpression(equalsExpression.Left, equalsExpression.Right, c.SemanticModel, out var constantValue) - || CheckExpression(equalsExpression.Right, equalsExpression.Left, c.SemanticModel, out constantValue)) + if (CheckExpression(equalsExpression.Left, equalsExpression.Right, c.Model, out var constantValue) + || CheckExpression(equalsExpression.Right, equalsExpression.Left, c.Model, out constantValue)) { c.ReportIssue(Rule, equalsExpression, constantValue < 0 ? "negative" : "positive"); } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/EquatableClassShouldBeSealed.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/EquatableClassShouldBeSealed.cs index 9e4a95d4340..06119616124 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/EquatableClassShouldBeSealed.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/EquatableClassShouldBeSealed.cs @@ -32,7 +32,7 @@ protected override void Initialize(SonarAnalysisContext context) => c => { var classDeclaration = (ClassDeclarationSyntax)c.Node; - var classSymbol = c.SemanticModel.GetDeclaredSymbol(classDeclaration); + var classSymbol = c.Model.GetDeclaredSymbol(classDeclaration); if (classSymbol != null && !classSymbol.IsSealed diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/EventHandlerDelegateShouldHaveProperArguments.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/EventHandlerDelegateShouldHaveProperArguments.cs index 275e3cb20b3..a8107548741 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/EventHandlerDelegateShouldHaveProperArguments.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/EventHandlerDelegateShouldHaveProperArguments.cs @@ -47,7 +47,7 @@ protected override void Initialize(SonarAnalysisContext context) return; } - if (!(c.SemanticModel.GetSymbolInfo(invocation).Symbol is IMethodSymbol methodSymbol) || + if (!(c.Model.GetSymbolInfo(invocation).Symbol is IMethodSymbol methodSymbol) || methodSymbol.MethodKind != MethodKind.DelegateInvoke || !methodSymbol.ContainingType.ConstructedFrom.IsAny(EventHandlerTypes)) { @@ -62,7 +62,7 @@ protected override void Initialize(SonarAnalysisContext context) c.ReportIssue(rule, invocation, NullEventArgsMessage); } - var eventSymbol = GetEventSymbol(invocation.Expression, c.SemanticModel); + var eventSymbol = GetEventSymbol(invocation.Expression, c.Model); if (eventSymbol == null) { return; diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/ExceptionRethrow.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/ExceptionRethrow.cs index 79d6aefd61c..fcdf1d69bfd 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/ExceptionRethrow.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/ExceptionRethrow.cs @@ -39,7 +39,7 @@ protected override void Initialize(SonarAnalysisContext context) return; } - var exceptionIdentifier = c.SemanticModel.GetDeclaredSymbol(catchClause.Declaration); + var exceptionIdentifier = c.Model.GetDeclaredSymbol(catchClause.Declaration); if (exceptionIdentifier == null) { return; @@ -53,7 +53,7 @@ protected override void Initialize(SonarAnalysisContext context) foreach (var @throw in throws) { - var thrown = c.SemanticModel.GetSymbolInfo(@throw.Expression).Symbol as ILocalSymbol; + var thrown = c.Model.GetSymbolInfo(@throw.Expression).Symbol as ILocalSymbol; if (Equals(thrown, exceptionIdentifier)) { c.ReportIssue(rule, @throw); diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/ExceptionShouldNotBeThrownFromUnexpectedMethods.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/ExceptionShouldNotBeThrownFromUnexpectedMethods.cs index 1fef851baa9..811761d0892 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/ExceptionShouldNotBeThrownFromUnexpectedMethods.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/ExceptionShouldNotBeThrownFromUnexpectedMethods.cs @@ -47,7 +47,7 @@ public sealed class ExceptionShouldNotBeThrownFromUnexpectedMethods : SonarDiagn protected override void Initialize(SonarAnalysisContext context) { context.RegisterNodeAction( - c => CheckForIssue(c, mds => IsTrackedMethod(mds, c.SemanticModel), DefaultAllowedExceptions), + c => CheckForIssue(c, mds => IsTrackedMethod(mds, c.Model), DefaultAllowedExceptions), SyntaxKind.MethodDeclaration); context.RegisterNodeAction( @@ -133,7 +133,7 @@ private static void ReportOnInvalidThrow(SonarSyntaxNodeReportingContext context // Because of the ShimLayer ThrowExpression implementation, we need to provide extra boilerplate as the wrappers to extract the node and the expression. // The location is returned only if an issue should be reported. Otherwise, null is returned. Location GetLocationToReport(IEnumerable throwNodes, Func getNode, Func getExpression) => - throwNodes.Select(x => new NodeAndSymbol(getNode(x), context.SemanticModel.GetSymbolInfo(getExpression(x)).Symbol)) + throwNodes.Select(x => new NodeAndSymbol(getNode(x), context.Model.GetSymbolInfo(getExpression(x)).Symbol)) .FirstOrDefault(x => x.Symbol is not null && ShouldReport(x.Symbol.ContainingType, allowedTypes))? .Node .GetLocation(); diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/ExceptionsNeedStandardConstructors.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/ExceptionsNeedStandardConstructors.cs index 2945a58b357..99d355f6f67 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/ExceptionsNeedStandardConstructors.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/ExceptionsNeedStandardConstructors.cs @@ -31,7 +31,7 @@ protected override void Initialize(SonarAnalysisContext context) context.RegisterNodeAction(c => { var classDeclaration = c.Node as ClassDeclarationSyntax; - var classSymbol = c.SemanticModel.GetDeclaredSymbol(classDeclaration); + var classSymbol = c.Model.GetDeclaredSymbol(classDeclaration); if (!classDeclaration.Identifier.IsMissing && classSymbol.DerivesFrom(KnownType.System_Exception) && diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/ExceptionsShouldBeLogged.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/ExceptionsShouldBeLogged.cs index 7b4c3ecdb5c..5b86baea91e 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/ExceptionsShouldBeLogged.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/ExceptionsShouldBeLogged.cs @@ -44,7 +44,7 @@ protected override void Initialize(SonarAnalysisContext context) => cc.RegisterNodeAction(c => { var catchClauseSyntax = (CatchClauseSyntax)c.Node; - var walker = new CatchLoggingInvocationWalker(c.SemanticModel); + var walker = new CatchLoggingInvocationWalker(c.Model); if (walker.SafeVisit(catchClauseSyntax) && !walker.IsExceptionLogged && walker.LoggingInvocationsWithoutException.Any()) { diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/ExceptionsShouldBeLoggedOrThrown.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/ExceptionsShouldBeLoggedOrThrown.cs index 8d82cd91456..2507ad70b73 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/ExceptionsShouldBeLoggedOrThrown.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/ExceptionsShouldBeLoggedOrThrown.cs @@ -45,7 +45,7 @@ protected override void Initialize(SonarAnalysisContext context) => cc.RegisterNodeAction(c => { var catchClauseSyntax = (CatchClauseSyntax)c.Node; - var walker = new LoggingInvocationWalker(c.SemanticModel); + var walker = new LoggingInvocationWalker(c.Model); if (catchClauseSyntax.Declaration?.Identifier is { } exceptionIdentifier // there is an exception to log && catchClauseSyntax.DescendantNodes().Any(x => x.Kind() is SyntaxKind.ThrowStatement or SyntaxKindEx.ThrowExpression) // and a throw statement (preliminary check) && walker.SafeVisit(catchClauseSyntax) diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/ExceptionsShouldBeUsed.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/ExceptionsShouldBeUsed.cs index eb55ce970fc..c4ae0eedd4d 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/ExceptionsShouldBeUsed.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/ExceptionsShouldBeUsed.cs @@ -33,7 +33,7 @@ protected override void Initialize(SonarAnalysisContext context) => var objectCreation = (ObjectCreationExpressionSyntax)c.Node; var parent = objectCreation.GetFirstNonParenthesizedParent(); if (parent.IsKind(SyntaxKind.ExpressionStatement) - && c.SemanticModel.GetSymbolInfo(objectCreation.Type).Symbol is INamedTypeSymbol createdObjectType + && c.Model.GetSymbolInfo(objectCreation.Type).Symbol is INamedTypeSymbol createdObjectType && createdObjectType.DerivesFrom(KnownType.System_Exception)) { c.ReportIssue(Rule, objectCreation); diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/ExtensionMethodShouldBeInSeparateNamespace.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/ExtensionMethodShouldBeInSeparateNamespace.cs index 4cb931e8032..07f2884c9d7 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/ExtensionMethodShouldBeInSeparateNamespace.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/ExtensionMethodShouldBeInSeparateNamespace.cs @@ -32,7 +32,7 @@ protected override void Initialize(SonarAnalysisContext context) => var methodDeclaration = (MethodDeclarationSyntax)c.Node; if (methodDeclaration.IsExtensionMethod() - && c.SemanticModel.GetDeclaredSymbol(methodDeclaration) is { IsExtensionMethod: true, Parameters: { Length: > 0 } } methodSymbol + && c.Model.GetDeclaredSymbol(methodDeclaration) is { IsExtensionMethod: true, Parameters: { Length: > 0 } } methodSymbol && methodSymbol.Parameters[0].Type.Kind != SymbolKind.ErrorType && methodSymbol.Parameters[0].Type.IsClass() && methodSymbol.ContainingNamespace.Equals(methodSymbol.Parameters[0].Type.ContainingNamespace) diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/FieldShadowsParentField.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/FieldShadowsParentField.cs index d76558ab945..9abfab3e48e 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/FieldShadowsParentField.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/FieldShadowsParentField.cs @@ -27,7 +27,7 @@ protected override void Initialize(SonarAnalysisContext context) => var fieldDeclaration = (FieldDeclarationSyntax)c.Node; if (!fieldDeclaration.Modifiers.Any(x => x.IsKind(SyntaxKind.NewKeyword))) { - foreach (var diagnostics in fieldDeclaration.Declaration.Variables.SelectMany(x => CheckFields(c.SemanticModel, x))) + foreach (var diagnostics in fieldDeclaration.Declaration.Variables.SelectMany(x => CheckFields(c.Model, x))) { c.ReportIssue(diagnostics); } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/FieldsShouldBeEncapsulatedInProperties.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/FieldsShouldBeEncapsulatedInProperties.cs index f06862d1d70..dad7f306b40 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/FieldsShouldBeEncapsulatedInProperties.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/FieldsShouldBeEncapsulatedInProperties.cs @@ -50,8 +50,8 @@ protected override void Initialize(SonarAnalysisContext context) => } var firstVariable = fieldDeclaration.Declaration.Variables[0]; - var symbol = c.SemanticModel.GetDeclaredSymbol(firstVariable); - var parentSymbol = c.SemanticModel.GetDeclaredSymbol(fieldDeclaration.Parent); + var symbol = c.Model.GetDeclaredSymbol(firstVariable); + var parentSymbol = c.Model.GetDeclaredSymbol(fieldDeclaration.Parent); if (symbol.ContainingType.DerivesFromAny(IgnoredTypes) || parentSymbol.HasAttribute(KnownType.System_Runtime_InteropServices_StructLayoutAttribute) || Serializable(symbol, parentSymbol)) diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/ForLoopCounterChanged.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/ForLoopCounterChanged.cs index 26bd6f421e0..8f33dbdf701 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/ForLoopCounterChanged.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/ForLoopCounterChanged.cs @@ -65,11 +65,11 @@ protected override void Initialize(SonarAnalysisContext context) => c => { var forNode = (ForStatementSyntax)c.Node; - var loopCounters = LoopCounters(forNode, c.SemanticModel).ToList(); + var loopCounters = LoopCounters(forNode, c.Model).ToList(); foreach (var affectedExpression in ComputeAffectedExpressions(forNode.Statement)) { - var symbol = c.SemanticModel.GetSymbolInfo(affectedExpression).Symbol; + var symbol = c.Model.GetSymbolInfo(affectedExpression).Symbol; if (symbol != null && loopCounters.Contains(symbol)) { diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/ForLoopCounterCondition.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/ForLoopCounterCondition.cs index ee078909c09..ee2fb9dc74d 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/ForLoopCounterCondition.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/ForLoopCounterCondition.cs @@ -36,13 +36,13 @@ protected override void Initialize(SonarAnalysisContext context) => { var forNode = (ForStatementSyntax)c.Node; - var incrementedSymbols = GetIncrementorSymbols(forNode, c.SemanticModel).ToList(); + var incrementedSymbols = GetIncrementorSymbols(forNode, c.Model).ToList(); if (!incrementedSymbols.Any()) { return; } - var conditionSymbols = GetReadSymbolsCondition(forNode, c.SemanticModel).ToList(); + var conditionSymbols = GetReadSymbolsCondition(forNode, c.Model).ToList(); if (conditionSymbols.Intersect(incrementedSymbols).Any()) { return; diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/ForeachLoopExplicitConversion.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/ForeachLoopExplicitConversion.cs index 5358a4ac691..08df376d7cd 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/ForeachLoopExplicitConversion.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/ForeachLoopExplicitConversion.cs @@ -31,7 +31,7 @@ protected override void Initialize(SonarAnalysisContext context) => c => { var foreachStatement = (ForEachStatementSyntax)c.Node; - var foreachInfo = c.SemanticModel.GetForEachStatementInfo(foreachStatement); + var foreachInfo = c.Model.GetForEachStatementInfo(foreachStatement); if (foreachInfo.Equals(default(ForEachStatementInfo)) || foreachInfo.ElementConversion.IsImplicit @@ -46,7 +46,7 @@ protected override void Initialize(SonarAnalysisContext context) => Rule, foreachStatement.Type, foreachStatement.Identifier.ValueText, - foreachInfo.ElementType.ToMinimalDisplayString(c.SemanticModel, foreachStatement.Type.SpanStart), + foreachInfo.ElementType.ToMinimalDisplayString(c.Model, foreachStatement.Type.SpanStart), foreachStatement.Type.ToString()); }, SyntaxKind.ForEachStatement); diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/FrameworkTypeNaming.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/FrameworkTypeNaming.cs index 94ae1767133..6da086ef869 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/FrameworkTypeNaming.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/FrameworkTypeNaming.cs @@ -32,7 +32,7 @@ protected override void Initialize(SonarAnalysisContext context) => c => { var classDeclaration = (ClassDeclarationSyntax)c.Node; - var symbol = c.SemanticModel.GetDeclaredSymbol(classDeclaration); + var symbol = c.Model.GetDeclaredSymbol(classDeclaration); if (symbol == null) { return; diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/GenericLoggerInjectionShouldMatchEnclosingType.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/GenericLoggerInjectionShouldMatchEnclosingType.cs index c7988c3f9b8..258e1189a74 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/GenericLoggerInjectionShouldMatchEnclosingType.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/GenericLoggerInjectionShouldMatchEnclosingType.cs @@ -34,7 +34,7 @@ protected override void Initialize(SonarAnalysisContext context) => cc.RegisterNodeAction(c => { var constructor = (ConstructorDeclarationSyntax)c.Node; - foreach (var invalidType in InvalidTypeParameters(constructor, c.SemanticModel)) + foreach (var invalidType in InvalidTypeParameters(constructor, c.Model)) { c.ReportIssue(Rule, invalidType); } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/GenericReadonlyFieldPropertyAssignment.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/GenericReadonlyFieldPropertyAssignment.cs index 899e61b440d..f509b8d5ba2 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/GenericReadonlyFieldPropertyAssignment.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/GenericReadonlyFieldPropertyAssignment.cs @@ -33,7 +33,7 @@ protected override void Initialize(SonarAnalysisContext context) var assignment = (AssignmentExpressionSyntax)c.Node; var expression = assignment.Left; - ProcessPropertyChange(c, c.SemanticModel, expression); + ProcessPropertyChange(c, c.Model, expression); }, SyntaxKind.SimpleAssignmentExpression, SyntaxKind.AddAssignmentExpression, @@ -52,7 +52,7 @@ protected override void Initialize(SonarAnalysisContext context) context.RegisterNodeAction(c => { var unary = (PrefixUnaryExpressionSyntax)c.Node; - ProcessPropertyChange(c, c.SemanticModel, unary.Operand); + ProcessPropertyChange(c, c.Model, unary.Operand); }, SyntaxKind.PreDecrementExpression, SyntaxKind.PreIncrementExpression); @@ -60,7 +60,7 @@ protected override void Initialize(SonarAnalysisContext context) context.RegisterNodeAction(c => { var unary = (PostfixUnaryExpressionSyntax)c.Node; - ProcessPropertyChange(c, c.SemanticModel, unary.Operand); + ProcessPropertyChange(c, c.Model, unary.Operand); }, SyntaxKind.PostDecrementExpression, SyntaxKind.PostIncrementExpression); diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/GenericTypeParameterEmptinessChecking.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/GenericTypeParameterEmptinessChecking.cs index 72c6675a18c..9276119757b 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/GenericTypeParameterEmptinessChecking.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/GenericTypeParameterEmptinessChecking.cs @@ -41,7 +41,7 @@ protected override void Initialize(SonarAnalysisContext context) => } var expressionToTypeCheck = leftIsNull ? equalsExpression.Right : equalsExpression.Left; - if (c.SemanticModel.GetTypeInfo(expressionToTypeCheck).Type is ITypeParameterSymbol { HasReferenceTypeConstraint: false } typeInfo + if (c.Model.GetTypeInfo(expressionToTypeCheck).Type is ITypeParameterSymbol { HasReferenceTypeConstraint: false } typeInfo && !typeInfo.ConstraintTypes.OfType().Any() && !typeInfo.ConstraintTypes.Any(typeSymbol => typeSymbol.IsReferenceType && typeSymbol.IsClass())) { diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/GenericTypeParameterInOut.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/GenericTypeParameterInOut.cs index 9190d2e11a3..26781568761 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/GenericTypeParameterInOut.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/GenericTypeParameterInOut.cs @@ -36,7 +36,7 @@ protected override void Initialize(SonarAnalysisContext context) private static void CheckInterfaceVariance(SonarSyntaxNodeReportingContext context, InterfaceDeclarationSyntax declaration) { - var interfaceType = context.SemanticModel.GetDeclaredSymbol(declaration); + var interfaceType = context.Model.GetDeclaredSymbol(declaration); if (interfaceType == null) { return; @@ -56,13 +56,13 @@ private static void CheckInterfaceVariance(SonarSyntaxNodeReportingContext conte } private static void CheckDelegateVariance(SonarSyntaxNodeReportingContext context, DelegateDeclarationSyntax declaration) { - var declaredSymbol = context.SemanticModel.GetDeclaredSymbol(declaration); + var declaredSymbol = context.Model.GetDeclaredSymbol(declaration); if (declaredSymbol == null) { return; } - var returnType = context.SemanticModel.GetTypeInfo(declaration.ReturnType).Type; + var returnType = context.Model.GetTypeInfo(declaration.ReturnType).Type; if (returnType == null) { return; @@ -71,7 +71,7 @@ private static void CheckDelegateVariance(SonarSyntaxNodeReportingContext contex var parameterSymbols = declaration.ParameterList == null ? ImmutableArray.Empty : declaration.ParameterList.Parameters - .Select(p => context.SemanticModel.GetDeclaredSymbol(p)) + .Select(p => context.Model.GetDeclaredSymbol(p)) .ToImmutableArray(); if (parameterSymbols.Any(parameter => parameter == null)) { diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/GenericTypeParameterUnused.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/GenericTypeParameterUnused.cs index fbf27a18e3c..ee410f5951e 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/GenericTypeParameterUnused.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/GenericTypeParameterUnused.cs @@ -36,7 +36,7 @@ protected override void Initialize(SonarAnalysisContext context) { context.RegisterNodeAction(c => { - if (c.SemanticModel.GetDeclaredSymbol(c.Node) is { } declarationSymbol) + if (c.Model.GetDeclaredSymbol(c.Node) is { } declarationSymbol) { CheckGenericTypeParameters(c, declarationSymbol); } @@ -79,7 +79,7 @@ private static ParametersInfo CreateParametersInfo(SonarSyntaxNodeReportingConte InterfaceDeclarationSyntax interfaceDeclaration => new ParametersInfo(interfaceDeclaration.TypeParameterList, "interface"), ClassDeclarationSyntax classDeclaration => new ParametersInfo(classDeclaration.TypeParameterList, "class"), StructDeclarationSyntax structDeclaration => new ParametersInfo(structDeclaration.TypeParameterList, "struct"), - MethodDeclarationSyntax methodDeclaration when IsMethodCandidate(methodDeclaration, c.SemanticModel) => new ParametersInfo(methodDeclaration.TypeParameterList, "method"), + MethodDeclarationSyntax methodDeclaration when IsMethodCandidate(methodDeclaration, c.Model) => new ParametersInfo(methodDeclaration.TypeParameterList, "method"), var wrapper when LocalFunctionStatementSyntaxWrapper.IsInstance(wrapper) => new ParametersInfo(((LocalFunctionStatementSyntaxWrapper)c.Node).TypeParameterList, "local function"), var wrapper when RecordDeclarationSyntaxWrapper.IsInstance(wrapper) => new ParametersInfo(((RecordDeclarationSyntaxWrapper)c.Node).TypeParameterList, "record"), _ => null @@ -96,7 +96,7 @@ private static List GetUsedTypeParameters(SonarSyntaxNodeReportingContex declarations.SelectMany(x => x.DescendantNodes()) .OfType() .Where(x => x.Parent is not TypeParameterConstraintClauseSyntax && typeParameterNames.Contains(x.Identifier.ValueText)) - .Select(x => x.EnsureCorrectSemanticModelOrDefault(context.SemanticModel)?.GetSymbolInfo(x).Symbol) + .Select(x => x.EnsureCorrectSemanticModelOrDefault(context.Model)?.GetSymbolInfo(x).Symbol) .Where(x => x is { Kind: SymbolKind.TypeParameter }) .Select(x => x.Name) .ToList(); diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/GenericTypeParametersRequired.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/GenericTypeParametersRequired.cs index f0363a40bde..624ee58b927 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/GenericTypeParametersRequired.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/GenericTypeParametersRequired.cs @@ -33,7 +33,7 @@ protected override void Initialize(SonarAnalysisContext context) => var typeParameters = methodDeclaration .TypeParameterList ?.Parameters - .Select(p => c.SemanticModel.GetDeclaredSymbol(p)); + .Select(p => c.Model.GetDeclaredSymbol(p)); if (typeParameters == null) { @@ -43,7 +43,7 @@ protected override void Initialize(SonarAnalysisContext context) => var argumentTypes = methodDeclaration .ParameterList .Parameters - .Select(p => c.SemanticModel.GetDeclaredSymbol(p)?.Type); + .Select(p => c.Model.GetDeclaredSymbol(p)?.Type); var typeParametersInArguments = new HashSet(); foreach (var argumentType in argumentTypes) diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/GetHashCodeEqualsOverride.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/GetHashCodeEqualsOverride.cs index 11726392485..16d5d4cbb8c 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/GetHashCodeEqualsOverride.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/GetHashCodeEqualsOverride.cs @@ -86,7 +86,7 @@ private static bool TryGetLocationFromInvocationInsideMethod(SonarSyntaxNodeRepo { location = null; var invocation = (InvocationExpressionSyntax)context.Node; - if (!(context.SemanticModel.GetSymbolInfo(invocation).Symbol is IMethodSymbol invokedMethod) + if (!(context.Model.GetSymbolInfo(invocation).Symbol is IMethodSymbol invokedMethod) || invokedMethod.Name != symbol.Name || !invocation.IsOnBase()) { diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/GetHashCodeMutable.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/GetHashCodeMutable.cs index 196fa78920d..5ccf702da6f 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/GetHashCodeMutable.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/GetHashCodeMutable.cs @@ -32,7 +32,7 @@ protected override void Initialize(SonarAnalysisContext context) => c => { var methodSyntax = (MethodDeclarationSyntax)c.Node; - var methodSymbol = c.SemanticModel.GetDeclaredSymbol(methodSyntax); + var methodSymbol = c.Model.GetDeclaredSymbol(methodSyntax); if (methodSymbol.ContainingType.IsValueType || !methodSymbol.IsObjectGetHashCode()) { @@ -42,7 +42,7 @@ protected override void Initialize(SonarAnalysisContext context) => ImmutableArray baseMembers; try { - baseMembers = c.SemanticModel.LookupBaseMembers(methodSyntax.SpanStart); + baseMembers = c.Model.LookupBaseMembers(methodSyntax.SpanStart); } catch (ArgumentException) { @@ -77,7 +77,7 @@ private static IEnumerable GetAllFirstMutableFieldsUsed(So foreach (var identifier in identifiers) { - if (context.SemanticModel.GetSymbolInfo(identifier).Symbol is not IFieldSymbol identifierSymbol) + if (context.Model.GetSymbolInfo(identifier).Symbol is not IFieldSymbol identifierSymbol) { continue; } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/GetTypeWithIsAssignableFrom.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/GetTypeWithIsAssignableFrom.cs index 98f7f6fa930..4e2b29acc25 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/GetTypeWithIsAssignableFrom.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/GetTypeWithIsAssignableFrom.cs @@ -40,7 +40,7 @@ protected override void Initialize(SonarAnalysisContext context) && invocation.HasExactlyNArguments(1) && memberAccess.Name.Identifier.ValueText is var methodName && (methodName == "IsInstanceOfType" || methodName == "IsAssignableFrom") - && c.SemanticModel.GetSymbolInfo(invocation).Symbol is IMethodSymbol methodSymbol + && c.Model.GetSymbolInfo(invocation).Symbol is IMethodSymbol methodSymbol && methodSymbol.IsInType(KnownType.System_Type)) { CheckForIsAssignableFrom(c, memberAccess, methodSymbol, invocation.ArgumentList.Arguments.First().Expression); @@ -65,9 +65,9 @@ protected override void Initialize(SonarAnalysisContext context) context.RegisterNodeAction(c => { var isExpression = (BinaryExpressionSyntax)c.Node; - if (c.SemanticModel.GetTypeInfo(isExpression.Left).Type is var objectToCast + if (c.Model.GetTypeInfo(isExpression.Left).Type is var objectToCast && objectToCast.IsClass() - && c.SemanticModel.GetSymbolInfo(isExpression.Right).Symbol is INamedTypeSymbol namedSymbol + && c.Model.GetSymbolInfo(isExpression.Right).Symbol is INamedTypeSymbol namedSymbol && namedSymbol.GetSymbolType() is var typeCastTo && typeCastTo.IsClass() && !typeCastTo.Is(KnownType.System_Object) @@ -101,8 +101,8 @@ private static void CheckGetTypeAndTypeOfEquality(SonarSyntaxNodeReportingContex { if (sideA.ToStringContains("GetType") && sideB is TypeOfExpressionSyntax sideBTypeOf - && (sideA as InvocationExpressionSyntax).IsGetTypeCall(context.SemanticModel) - && context.SemanticModel.GetTypeInfo(sideBTypeOf.Type).Type is { } typeSymbol // Can be null for empty identifier from 'typeof' unfinished syntax + && (sideA as InvocationExpressionSyntax).IsGetTypeCall(context.Model) + && context.Model.GetTypeInfo(sideBTypeOf.Type).Type is { } typeSymbol // Can be null for empty identifier from 'typeof' unfinished syntax && typeSymbol.IsSealed && !typeSymbol.OriginalDefinition.Is(KnownType.System_Nullable_T)) { @@ -122,7 +122,7 @@ private static void CheckForIsInstanceOfType(SonarSyntaxNodeReportingContext con private static void CheckForIsAssignableFrom(SonarSyntaxNodeReportingContext context, MemberAccessExpressionSyntax memberAccess, IMethodSymbol methodSymbol, ExpressionSyntax argument) { - if (methodSymbol.Name == nameof(Type.IsAssignableFrom) && (argument as InvocationExpressionSyntax).IsGetTypeCall(context.SemanticModel)) + if (methodSymbol.Name == nameof(Type.IsAssignableFrom) && (argument as InvocationExpressionSyntax).IsGetTypeCall(context.Model)) { if (memberAccess.Expression is TypeOfExpressionSyntax typeOf) { diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/GuardConditionOnEqualsOverride.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/GuardConditionOnEqualsOverride.cs index 67a376c030a..73c8921874e 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/GuardConditionOnEqualsOverride.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/GuardConditionOnEqualsOverride.cs @@ -45,7 +45,7 @@ protected override void Initialize(SonarAnalysisContext context) => private static void CheckInvocationInsideMethod(SonarSyntaxNodeReportingContext context, ISymbol symbol) { var invocation = (InvocationExpressionSyntax)context.Node; - if (!(context.SemanticModel.GetSymbolInfo(invocation).Symbol is IMethodSymbol invokedMethod) + if (!(context.Model.GetSymbolInfo(invocation).Symbol is IMethodSymbol invokedMethod) || invokedMethod.Name != symbol.Name || !invocation.IsOnBase()) { diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/Hotspots/ClearTextProtocolsAreSensitive.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/Hotspots/ClearTextProtocolsAreSensitive.cs index 6beedc14545..bf06081dd8a 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/Hotspots/ClearTextProtocolsAreSensitive.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/Hotspots/ClearTextProtocolsAreSensitive.cs @@ -138,11 +138,11 @@ private static void VisitObjectCreation(SonarSyntaxNodeReportingContext context) { var objectCreation = ObjectCreationFactory.Create(context.Node); - if (!IsServerSafe(objectCreation, context.SemanticModel) && ObjectInitializationTracker.ShouldBeReported(objectCreation, context.SemanticModel, false)) + if (!IsServerSafe(objectCreation, context.Model) && ObjectInitializationTracker.ShouldBeReported(objectCreation, context.Model, false)) { context.ReportIssue(EnableSslRule, objectCreation.Expression); } - else if (objectCreation.TypeAsString(context.SemanticModel) is { } typeAsString && TelnetRegexForIdentifier.SafeIsMatch(typeAsString)) + else if (objectCreation.TypeAsString(context.Model) is { } typeAsString && TelnetRegexForIdentifier.SafeIsMatch(typeAsString)) { context.ReportIssue(DefaultRule, objectCreation.Expression, TelnetKey, RecommendedProtocols[TelnetKey]); } @@ -161,8 +161,8 @@ private static void VisitAssignments(SonarSyntaxNodeReportingContext context) { var assignment = (AssignmentExpressionSyntax)context.Node; if (assignment.Left is MemberAccessExpressionSyntax memberAccess - && memberAccess.IsMemberAccessOnKnownType(EnableSslName, KnownType.System_Net_FtpWebRequest, context.SemanticModel) - && assignment.Right.FindConstantValue(context.SemanticModel) is bool enableSslValue + && memberAccess.IsMemberAccessOnKnownType(EnableSslName, KnownType.System_Net_FtpWebRequest, context.Model) + && assignment.Right.FindConstantValue(context.Model) is bool enableSslValue && !enableSslValue) { context.ReportIssue(EnableSslRule, assignment); @@ -171,7 +171,7 @@ private static void VisitAssignments(SonarSyntaxNodeReportingContext context) private static void VisitStringExpressions(SonarSyntaxNodeReportingContext c) { - if (GetUnsafeProtocol(c.Node, c.SemanticModel) is { } unsafeProtocol) + if (GetUnsafeProtocol(c.Node, c.Model) is { } unsafeProtocol) { c.ReportIssue(DefaultRule, c.Node, unsafeProtocol, RecommendedProtocols[unsafeProtocol]); } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/Hotspots/DisablingCsrfProtection.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/Hotspots/DisablingCsrfProtection.cs index 94866c9bbc5..bbe2a58a7e5 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/Hotspots/DisablingCsrfProtection.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/Hotspots/DisablingCsrfProtection.cs @@ -51,9 +51,9 @@ private static void CheckIgnoreAntiforgeryTokenAttribute(SonarSyntaxNodeReportin { var shouldReport = c.Node switch { - AttributeSyntax attributeSyntax => attributeSyntax.IsKnownType(KnownType.Microsoft_AspNetCore_Mvc_IgnoreAntiforgeryTokenAttribute, c.SemanticModel), - ObjectCreationExpressionSyntax objectCreation => objectCreation.IsKnownType(KnownType.Microsoft_AspNetCore_Mvc_IgnoreAntiforgeryTokenAttribute, c.SemanticModel), - _ => c.Node.IsKnownType(KnownType.Microsoft_AspNetCore_Mvc_IgnoreAntiforgeryTokenAttribute, c.SemanticModel) + AttributeSyntax attributeSyntax => attributeSyntax.IsKnownType(KnownType.Microsoft_AspNetCore_Mvc_IgnoreAntiforgeryTokenAttribute, c.Model), + ObjectCreationExpressionSyntax objectCreation => objectCreation.IsKnownType(KnownType.Microsoft_AspNetCore_Mvc_IgnoreAntiforgeryTokenAttribute, c.Model), + _ => c.Node.IsKnownType(KnownType.Microsoft_AspNetCore_Mvc_IgnoreAntiforgeryTokenAttribute, c.Model) }; if (shouldReport) diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/Hotspots/DoNotHardcodeSecrets.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/Hotspots/DoNotHardcodeSecrets.cs index 8f0bc22f033..8728f1131c0 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/Hotspots/DoNotHardcodeSecrets.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/Hotspots/DoNotHardcodeSecrets.cs @@ -70,7 +70,7 @@ protected override void Initialize(SonarParametrizedAnalysisContext context) var node = c.Node; if (FindIdentifier(node) is { } identifier && FindRightHandSide(node) is { } rhs - && rhs.FindStringConstant(c.SemanticModel) is { } secret) + && rhs.FindStringConstant(c.Model) is { } secret) { if (ShouldRaiseBinary(identifier.ValueText, secret)) { @@ -97,9 +97,9 @@ protected override void Initialize(SonarParametrizedAnalysisContext context) if (invocationExpression.Expression is MemberAccessExpressionSyntax memberAccessExpression && memberAccessExpression.Name.Identifier.ValueText == EqualsName && invocationExpression.TryGetFirstArgument(out var firstArgument) - && memberAccessExpression.IsMemberAccessOnKnownType(EqualsName, KnownType.System_String, c.SemanticModel) + && memberAccessExpression.IsMemberAccessOnKnownType(EqualsName, KnownType.System_String, c.Model) && GetIdentifierAndValue(memberAccessExpression.Expression, firstArgument, out var identifier, out var value) - && value.FindStringConstant(c.SemanticModel) is { } secret + && value.FindStringConstant(c.Model) is { } secret && ShouldRaiseBinary(identifier.Value.ValueText, secret)) { c.ReportIssue(rule, memberAccessExpression, identifier.Value.ValueText); diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/Hotspots/DoNotUseRandom.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/Hotspots/DoNotUseRandom.cs index a2c4622682e..ca0b2d17a7d 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/Hotspots/DoNotUseRandom.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/Hotspots/DoNotUseRandom.cs @@ -46,7 +46,7 @@ protected override void Initialize(SonarAnalysisContext context) => var argumentsCount = objectCreationSyntax.ArgumentList?.Arguments.Count; if (argumentsCount <= 1 // Random has two ctors - with zero and one parameter - && c.SemanticModel.GetSymbolInfo(objectCreationSyntax).Symbol is IMethodSymbol methodSymbol + && c.Model.GetSymbolInfo(objectCreationSyntax).Symbol is IMethodSymbol methodSymbol && methodSymbol.ContainingType.Is(KnownType.System_Random)) { c.ReportIssue(Rule, objectCreationSyntax); diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/Hotspots/InsecureDeserialization.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/Hotspots/InsecureDeserialization.cs index 359e0986142..55d420c83f9 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/Hotspots/InsecureDeserialization.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/Hotspots/InsecureDeserialization.cs @@ -36,7 +36,7 @@ protected override void Initialize(SonarAnalysisContext context) => if (!c.IsRedundantPositionalRecordContext() && IsEnabled(c.Options) && HasConstructorsWithParameters(declaration) // If there are no constructors, or if these don't have parameters, there is no validation done and the type is considered safe. - && c.SemanticModel.GetDeclaredSymbol(declaration) is { } typeSymbol + && c.Model.GetDeclaredSymbol(declaration) is { } typeSymbol && HasSerializableAttribute(typeSymbol)) { ReportOnInsecureDeserializations(c, declaration, typeSymbol); @@ -52,7 +52,7 @@ private static void ReportOnInsecureDeserializations(SonarSyntaxNodeReportingCon var implementsISerializable = ImplementsISerializable(typeSymbol); var implementsIDeserializationCallback = ImplementsIDeserializationCallback(typeSymbol); - var walker = new ConstructorDeclarationWalker(context.SemanticModel); + var walker = new ConstructorDeclarationWalker(context.Model); walker.SafeVisit(declaration); if (!implementsISerializable && !implementsIDeserializationCallback) @@ -71,7 +71,7 @@ private static void ReportOnInsecureDeserializations(SonarSyntaxNodeReportingCon } } - if (implementsIDeserializationCallback && !OnDeserializationHasConditions(declaration, context.SemanticModel)) + if (implementsIDeserializationCallback && !OnDeserializationHasConditions(declaration, context.Model)) { foreach (var constructor in walker.GetConstructorsInfo(x => x.HasConditionalConstructs)) { diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/Hotspots/LooseFilePermissions.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/Hotspots/LooseFilePermissions.cs index 8ee33a64ec5..e84d13ed850 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/Hotspots/LooseFilePermissions.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/Hotspots/LooseFilePermissions.cs @@ -28,7 +28,7 @@ internal LooseFilePermissions(IAnalyzerConfiguration configuration) : base(confi protected override void VisitAssignments(SonarSyntaxNodeReportingContext context) { var node = context.Node; - if (IsFileAccessPermissions(node, context.SemanticModel) && !node.IsPartOfBinaryNegationOrCondition()) + if (IsFileAccessPermissions(node, context.Model) && !node.IsPartOfBinaryNegationOrCondition()) { context.ReportIssue(Rule, node); } @@ -37,8 +37,8 @@ protected override void VisitAssignments(SonarSyntaxNodeReportingContext context protected override void VisitInvocations(SonarSyntaxNodeReportingContext context) { var invocation = (InvocationExpressionSyntax)context.Node; - if ((IsSetAccessRule(invocation, context.SemanticModel) || IsAddAccessRule(invocation, context.SemanticModel)) - && (GetObjectCreation(invocation, context.SemanticModel) is { } objectCreation)) + if ((IsSetAccessRule(invocation, context.Model) || IsAddAccessRule(invocation, context.Model)) + && (GetObjectCreation(invocation, context.Model) is { } objectCreation)) { var invocationLocation = invocation.GetLocation(); var secondaryLocation = objectCreation.Expression.GetLocation(); diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/Hotspots/PermissiveCors.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/Hotspots/PermissiveCors.cs index e936b63d0d1..aaf91f2fa8d 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/Hotspots/PermissiveCors.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/Hotspots/PermissiveCors.cs @@ -94,8 +94,8 @@ private static void SetupObjectCreationTracker(ObjectCreationTracker private void VisitAttribute(SonarSyntaxNodeReportingContext context) { var attribute = (AttributeSyntax)context.Node; - if (attribute.IsKnownType(KnownType.System_Web_Http_Cors_EnableCorsAttribute, context.SemanticModel) - && IsStar(attribute.ArgumentList.Arguments[0].Expression, context.SemanticModel)) + if (attribute.IsKnownType(KnownType.System_Web_Http_Cors_EnableCorsAttribute, context.Model) + && IsStar(attribute.ArgumentList.Arguments[0].Expression, context.Model)) { context.ReportIssue(Rule, attribute); } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/Hotspots/RequestsWithExcessiveLength.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/Hotspots/RequestsWithExcessiveLength.cs index e59f570f2e1..8a80097d2ad 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/Hotspots/RequestsWithExcessiveLength.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/Hotspots/RequestsWithExcessiveLength.cs @@ -36,9 +36,9 @@ protected override void Initialize(SonarParametrizedAnalysisContext context) if (body is not null && body.DescendantNodes() .OfType() - .Any(x => x.IsMethodInvocation(KnownType.Microsoft_AspNetCore_Components_Forms_IBrowserFile, "OpenReadStream", c.SemanticModel))) + .Any(x => x.IsMethodInvocation(KnownType.Microsoft_AspNetCore_Components_Forms_IBrowserFile, "OpenReadStream", c.Model))) { - var walker = new StreamReadSizeCheck(c.SemanticModel, FileUploadSizeLimit); + var walker = new StreamReadSizeCheck(c.Model, FileUploadSizeLimit); if (walker.SafeVisit(body)) { foreach (var location in walker.Locations) diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/ImplementIDisposableCorrectly.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/ImplementIDisposableCorrectly.cs index 7d45c4f7f0c..38ed1dab013 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/ImplementIDisposableCorrectly.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/ImplementIDisposableCorrectly.cs @@ -44,9 +44,9 @@ protected override void Initialize(SonarAnalysisContext context) => var declarationIdentifier = typeDeclarationSyntax.Identifier; var checker = new DisposableChecker(typeDeclarationSyntax.BaseList, declarationIdentifier, - c.SemanticModel.GetDeclaredSymbol(typeDeclarationSyntax), + c.Model.GetDeclaredSymbol(typeDeclarationSyntax), c.Node.GetDeclarationTypeName(), - c.SemanticModel); + c.Model); var locations = checker.GetIssueLocations(typeDeclarationSyntax); if (locations.Any()) diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/ImplementSerializationMethodsCorrectly.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/ImplementSerializationMethodsCorrectly.cs index 29549d8fe21..ce1ef2950ca 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/ImplementSerializationMethodsCorrectly.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/ImplementSerializationMethodsCorrectly.cs @@ -38,7 +38,7 @@ protected override void Initialize(SonarAnalysisContext context) context.RegisterNodeAction(c => { var wrapper = (LocalFunctionStatementSyntaxWrapper)c.Node; - var attributes = GetSerializationAttributes(wrapper.AttributeLists, c.SemanticModel); + var attributes = GetSerializationAttributes(wrapper.AttributeLists, c.Model); ReportOnAttributes(c, attributes, "local functions"); }, SyntaxKindEx.LocalFunctionStatement); @@ -46,7 +46,7 @@ protected override void Initialize(SonarAnalysisContext context) context.RegisterNodeAction(c => { var wrapper = (ParenthesizedLambdaExpressionSyntaxWrapper)c.Node; - var attributes = GetSerializationAttributes(wrapper.AttributeLists, c.SemanticModel); + var attributes = GetSerializationAttributes(wrapper.AttributeLists, c.Model); ReportOnAttributes(c, attributes, "lambdas"); }, SyntaxKind.ParenthesizedLambdaExpression); diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/InfiniteRecursion.RoslynCfg.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/InfiniteRecursion.RoslynCfg.cs index 7296a9e5c12..07525dcdd85 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/InfiniteRecursion.RoslynCfg.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/InfiniteRecursion.RoslynCfg.cs @@ -41,7 +41,7 @@ public void CheckForNoExitEvent(SonarSyntaxNodeReportingContext c, EventDeclarat { foreach (var accessor in eventDeclaration.AccessorList.Accessors.Where(x => x.HasBodyOrExpressionBody())) { - var cfg = ControlFlowGraph.Create(accessor, c.SemanticModel, c.Cancel); + var cfg = ControlFlowGraph.Create(accessor, c.Model, c.Cancel); var context = new RecursionContext(c, cfg, eventSymbol, accessor.Keyword.GetLocation(), "event accessor's recursion"); var walker = new RecursionSearcher(context); walker.CheckPaths(); @@ -51,7 +51,7 @@ public void CheckForNoExitEvent(SonarSyntaxNodeReportingContext c, EventDeclarat public void CheckForNoExitMethod(SonarSyntaxNodeReportingContext c, SyntaxNode body, SyntaxToken identifier, IMethodSymbol symbol) { - if (body.CreateCfg(c.SemanticModel, c.Cancel) is { } cfg) + if (body.CreateCfg(c.Model, c.Cancel) is { } cfg) { var context = new RecursionContext(c, cfg, symbol, identifier.GetLocation(), "method's recursion"); var walker = new RecursionSearcher(context); @@ -84,7 +84,7 @@ private static void CheckForNoExit(SonarSyntaxNodeReportingContext c, if (expressionBody?.Expression is not null) { - var cfg = ControlFlowGraph.Create(expressionBody, c.SemanticModel, c.Cancel); + var cfg = ControlFlowGraph.Create(expressionBody, c.Model, c.Cancel); var walker = new RecursionSearcher(new RecursionContext(c, cfg, propertySymbol, location, arrowExpressionMessageArg)); walker.CheckPaths(); } @@ -92,7 +92,7 @@ private static void CheckForNoExit(SonarSyntaxNodeReportingContext c, { foreach (var accessor in accessorList.Accessors.Where(x => x.HasBodyOrExpressionBody())) { - var cfg = ControlFlowGraph.Create(accessor, c.SemanticModel, c.Cancel); + var cfg = ControlFlowGraph.Create(accessor, c.Model, c.Cancel); var context = new RecursionContext(c, cfg, propertySymbol, accessor.Keyword.GetLocation(), accessorMessageArg); var walker = new RecursionSearcher(context, !accessor.Keyword.IsAnyKind(SyntaxKind.SetKeyword, SyntaxKindEx.InitKeyword)); walker.CheckPaths(); diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/InfiniteRecursion.SonarCfg.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/InfiniteRecursion.SonarCfg.cs index 1d004078df0..d079291edda 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/InfiniteRecursion.SonarCfg.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/InfiniteRecursion.SonarCfg.cs @@ -27,7 +27,7 @@ public void CheckForNoExitProperty(SonarSyntaxNodeReportingContext c, PropertyDe IControlFlowGraph cfg; if (property.ExpressionBody?.Expression != null) { - if (CSharpControlFlowGraph.TryGet(property, c.SemanticModel, out cfg)) + if (CSharpControlFlowGraph.TryGet(property, c.Model, out cfg)) { var walker = new RecursionSearcherForProperty( new RecursionContext(c, cfg, propertySymbol, property.Identifier.GetLocation(), "property's recursion"), @@ -43,7 +43,7 @@ public void CheckForNoExitProperty(SonarSyntaxNodeReportingContext c, PropertyDe { foreach (var accessor in accessors) { - if (CSharpControlFlowGraph.TryGet(accessor, c.SemanticModel, out cfg)) + if (CSharpControlFlowGraph.TryGet(accessor, c.Model, out cfg)) { var walker = new RecursionSearcherForProperty( new RecursionContext(c, cfg, propertySymbol, accessor.Keyword.GetLocation(), "property accessor's recursion"), @@ -68,7 +68,7 @@ public void CheckForNoExitEvent(SonarSyntaxNodeReportingContext c, EventDeclarat public void CheckForNoExitMethod(SonarSyntaxNodeReportingContext c, SyntaxNode body, SyntaxToken identifier, IMethodSymbol symbol) { - if (CSharpControlFlowGraph.TryGet(body, c.SemanticModel, out var cfg)) + if (CSharpControlFlowGraph.TryGet(body, c.Model, out var cfg)) { var walker = new RecursionSearcherForMethod(new RecursionContext(c, cfg, symbol, identifier.GetLocation(), "method's recursion")); walker.CheckPaths(); diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/InfiniteRecursion.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/InfiniteRecursion.cs index a220215dcb2..1cb0e5e96df 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/InfiniteRecursion.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/InfiniteRecursion.cs @@ -70,7 +70,7 @@ protected override void Initialize(SonarAnalysisContext context) c => { var property = (PropertyDeclarationSyntax)c.Node; - checker.CheckForNoExitProperty(c, property, c.SemanticModel.GetDeclaredSymbol(property)); + checker.CheckForNoExitProperty(c, property, c.Model.GetDeclaredSymbol(property)); }, SyntaxKind.PropertyDeclaration); @@ -78,7 +78,7 @@ protected override void Initialize(SonarAnalysisContext context) c => { var indexer = (IndexerDeclarationSyntax)c.Node; - checker.CheckForNoExitIndexer(c, indexer, c.SemanticModel.GetDeclaredSymbol(indexer)); + checker.CheckForNoExitIndexer(c, indexer, c.Model.GetDeclaredSymbol(indexer)); }, SyntaxKind.IndexerDeclaration); @@ -86,14 +86,14 @@ protected override void Initialize(SonarAnalysisContext context) c => { var eventDeclaration = (EventDeclarationSyntax)c.Node; - checker.CheckForNoExitEvent(c, eventDeclaration, c.SemanticModel.GetDeclaredSymbol(eventDeclaration)); + checker.CheckForNoExitEvent(c, eventDeclaration, c.Model.GetDeclaredSymbol(eventDeclaration)); }, SyntaxKind.EventDeclaration); } private void CheckForNoExitMethod(SonarSyntaxNodeReportingContext c, SyntaxToken identifier) { - if (c.SemanticModel.GetDeclaredSymbol(c.Node) is IMethodSymbol symbol) + if (c.Model.GetDeclaredSymbol(c.Node) is IMethodSymbol symbol) { checker.CheckForNoExitMethod(c, c.Node, identifier, symbol); } @@ -118,7 +118,7 @@ private sealed class RecursionContext public TControlFlowGraph ControlFlowGraph { get; } public ISymbol AnalyzedSymbol { get; } - public SemanticModel Model => analysisContext.SemanticModel; + public SemanticModel Model => analysisContext.Model; public RecursionContext(SonarSyntaxNodeReportingContext analysisContext, TControlFlowGraph controlFlowGraph, diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/InheritedCollidingInterfaceMembers.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/InheritedCollidingInterfaceMembers.cs index 4205a86d8a0..a81340b20d6 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/InheritedCollidingInterfaceMembers.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/InheritedCollidingInterfaceMembers.cs @@ -38,7 +38,7 @@ protected override void Initialize(SonarAnalysisContext context) => return; } - var interfaceSymbol = c.SemanticModel.GetDeclaredSymbol(interfaceDeclaration); + var interfaceSymbol = c.Model.GetDeclaredSymbol(interfaceDeclaration); if (interfaceSymbol == null) { return; @@ -47,7 +47,7 @@ protected override void Initialize(SonarAnalysisContext context) => var collidingMembers = GetCollidingMembers(interfaceSymbol).Take(MaxMemberDisplayCount + 1).ToList(); if (collidingMembers.Any()) { - var membersText = GetIssueMessageText(collidingMembers, c.SemanticModel, interfaceDeclaration.SpanStart); + var membersText = GetIssueMessageText(collidingMembers, c.Model, interfaceDeclaration.SpanStart); var pluralize = collidingMembers.Count > 1 ? "s" : string.Empty; var secondaryLocations = collidingMembers.SelectMany(x => x.Locations).Where(x => x.IsInSource).ToSecondary(); c.ReportIssue(Rule, interfaceDeclaration.Identifier, secondaryLocations, membersText, pluralize); diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/InitializeStaticFieldsInline.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/InitializeStaticFieldsInline.cs index 34312f4927c..73b93460475 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/InitializeStaticFieldsInline.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/InitializeStaticFieldsInline.cs @@ -35,7 +35,7 @@ protected override void Initialize(SonarAnalysisContext context) => { return; } - if (c.SemanticModel.GetDeclaredSymbol(constructor).ContainingType is { } currentType) + if (c.Model.GetDeclaredSymbol(constructor).ContainingType is { } currentType) { var bodyDescendantNodes = constructor.Body?.DescendantNodes().ToArray() ?? constructor.ExpressionBody()?.DescendantNodes().ToArray() @@ -43,13 +43,13 @@ protected override void Initialize(SonarAnalysisContext context) => var assignedFieldCount = bodyDescendantNodes .OfType() - .SelectMany(x => FieldSymbolsFromLeftSide(x, c.SemanticModel, currentType)) + .SelectMany(x => FieldSymbolsFromLeftSide(x, c.Model, currentType)) .Select(x => x.Name) .Distinct() .Count(); var hasIfOrSwitch = Array.Exists(bodyDescendantNodes, x => x.Kind() is SyntaxKind.IfStatement or SyntaxKind.SwitchStatement); if (((hasIfOrSwitch && assignedFieldCount == 1) || (!hasIfOrSwitch && assignedFieldCount > 0)) - && !HasTupleAssignmentForMultipleFields(bodyDescendantNodes, c.SemanticModel, currentType)) + && !HasTupleAssignmentForMultipleFields(bodyDescendantNodes, c.Model, currentType)) { c.ReportIssue(Rule, constructor.Identifier); } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/InterfaceMethodsShouldBeCallableByChildTypes.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/InterfaceMethodsShouldBeCallableByChildTypes.cs index 429e63d60bb..4252ea31ced 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/InterfaceMethodsShouldBeCallableByChildTypes.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/InterfaceMethodsShouldBeCallableByChildTypes.cs @@ -59,7 +59,7 @@ private static void ReportOnIssue(SonarSyntaxNodeReportingContext var declaration = (TypeDeclarationSyntax)memberDeclaration.FirstAncestorOrSelf(node => node is TypeDeclarationSyntax); if (declaration == null || declaration.Identifier.IsMissing - || !IsDeclarationTracked(declaration, analysisContext.SemanticModel)) + || !IsDeclarationTracked(declaration, analysisContext.Model)) { return; } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/InterfacesShouldNotBeEmpty.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/InterfacesShouldNotBeEmpty.cs index 20379c1ed37..bf932225c09 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/InterfacesShouldNotBeEmpty.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/InterfacesShouldNotBeEmpty.cs @@ -36,7 +36,7 @@ protected override void Initialize(SonarAnalysisContext context) => return; } - var interfaceSymbol = c.SemanticModel.GetDeclaredSymbol(interfaceDeclaration); + var interfaceSymbol = c.Model.GetDeclaredSymbol(interfaceDeclaration); if (interfaceSymbol is { DeclaredAccessibility: Accessibility.Public } && !IsAggregatingOtherInterfaces(interfaceSymbol) && !IsSpecializedGeneric(interfaceSymbol) diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/InvocationResolvesToOverrideWithParams.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/InvocationResolvesToOverrideWithParams.cs index 7aa9d05033a..0b49bee3c5b 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/InvocationResolvesToOverrideWithParams.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/InvocationResolvesToOverrideWithParams.cs @@ -40,25 +40,25 @@ protected override void Initialize(SonarAnalysisContext context) => private static void CheckCall(SonarSyntaxNodeReportingContext context, SyntaxNode node, ArgumentListSyntax argumentList) { if (argumentList is { Arguments.Count: > 0 } - && context.SemanticModel.GetSymbolInfo(node).Symbol is IMethodSymbol method + && context.Model.GetSymbolInfo(node).Symbol is IMethodSymbol method && method.Parameters.LastOrDefault() is { IsParams: true } - && !IsInvocationWithExplicitArray(argumentList, method, context.SemanticModel) + && !IsInvocationWithExplicitArray(argumentList, method, context.Model) && ArgumentTypes(context, argumentList) is var argumentTypes && Array.TrueForAll(argumentTypes, x => x is not IErrorTypeSymbol) && OtherOverloadsOf(method).FirstOrDefault(IsPossibleMatch) is { } otherMethod && method.IsGenericMethod == otherMethod.IsGenericMethod) { - context.ReportIssue(Rule, node, otherMethod.ToMinimalDisplayString(context.SemanticModel, node.SpanStart)); + context.ReportIssue(Rule, node, otherMethod.ToMinimalDisplayString(context.Model, node.SpanStart)); } bool IsPossibleMatch(IMethodSymbol method) => - ArgumentsMatchParameters(argumentList, argumentTypes, method, context.SemanticModel) + ArgumentsMatchParameters(argumentList, argumentTypes, method, context.Model) && MethodAccessibleWithinType(method, context.ContainingSymbol.ContainingType); } private static ITypeSymbol[] ArgumentTypes(SonarSyntaxNodeReportingContext context, ArgumentListSyntax argumentList) => argumentList.Arguments - .Select(x => context.SemanticModel.GetTypeInfo(x.Expression)) + .Select(x => context.Model.GetTypeInfo(x.Expression)) .Select(x => x.Type ?? x.ConvertedType) // Action and Func won't always resolve properly with Type .ToArray(); diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/IssueSuppression.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/IssueSuppression.cs index 09ad741578b..d4a7e13fed8 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/IssueSuppression.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/IssueSuppression.cs @@ -33,7 +33,7 @@ protected override void Initialize(SonarAnalysisContext context) { var attribute = (AttributeSyntax)c.Node; - if (!(c.SemanticModel.GetSymbolInfo(attribute).Symbol is IMethodSymbol attributeConstructor) || + if (!(c.Model.GetSymbolInfo(attribute).Symbol is IMethodSymbol attributeConstructor) || !attributeConstructor.ContainingType.Is(KnownType.System_Diagnostics_CodeAnalysis_SuppressMessageAttribute)) { return; diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/JSInvokableMethodsShouldBePublic.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/JSInvokableMethodsShouldBePublic.cs index 4d431c09dfb..38fbc700925 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/JSInvokableMethodsShouldBePublic.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/JSInvokableMethodsShouldBePublic.cs @@ -39,7 +39,7 @@ private static void CheckMethod(SonarSyntaxNodeReportingContext context) { var method = (MethodDeclarationSyntax)context.Node; if (!method.Modifiers.AnyOfKind(SyntaxKind.PublicKeyword) - && method.AttributeLists.SelectMany(x => x.Attributes).Any(x => x.IsKnownType(KnownType.Microsoft_JSInterop_JSInvokable, context.SemanticModel))) + && method.AttributeLists.SelectMany(x => x.Attributes).Any(x => x.IsKnownType(KnownType.Microsoft_JSInterop_JSInvokable, context.Model))) { context.ReportIssue(Rule, method.Identifier); } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/LiteralsShouldNotBePassedAsLocalizedParameters.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/LiteralsShouldNotBePassedAsLocalizedParameters.cs index 424bf72693b..5c05610f536 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/LiteralsShouldNotBePassedAsLocalizedParameters.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/LiteralsShouldNotBePassedAsLocalizedParameters.cs @@ -42,7 +42,7 @@ protected override void Initialize(SonarAnalysisContext context) private static void AnalyzeInvocations(SonarSyntaxNodeReportingContext context) { var invocationSyntax = (InvocationExpressionSyntax)context.Node; - if (!(context.SemanticModel.GetSymbolInfo(invocationSyntax).Symbol is IMethodSymbol methodSymbol) || invocationSyntax.ArgumentList is null) + if (!(context.Model.GetSymbolInfo(invocationSyntax).Symbol is IMethodSymbol methodSymbol) || invocationSyntax.ArgumentList is null) { return; } @@ -50,7 +50,7 @@ private static void AnalyzeInvocations(SonarSyntaxNodeReportingContext context) // Calling to/from debug-only code if (methodSymbol.IsDiagnosticDebugMethod() || methodSymbol.IsConditionalDebugMethod() - || invocationSyntax.IsInConditionalDebug(context.SemanticModel)) + || invocationSyntax.IsInConditionalDebug(context.Model)) { return; } @@ -58,7 +58,7 @@ private static void AnalyzeInvocations(SonarSyntaxNodeReportingContext context) if (methodSymbol.IsConsoleWrite() || methodSymbol.IsConsoleWriteLine()) { var firstArgument = invocationSyntax.ArgumentList.Arguments.FirstOrDefault(); - if (IsStringLiteral(firstArgument?.Expression, context.SemanticModel)) + if (IsStringLiteral(firstArgument?.Expression, context.Model)) { context.ReportIssue(Rule, firstArgument); } @@ -67,7 +67,7 @@ private static void AnalyzeInvocations(SonarSyntaxNodeReportingContext context) var nonCompliantParameters = methodSymbol.Parameters .Merge(invocationSyntax.ArgumentList.Arguments, (parameter, syntax) => new { parameter, syntax }) - .Where(x => IsLocalizableStringLiteral(x.parameter, x.syntax, context.SemanticModel)); + .Where(x => IsLocalizableStringLiteral(x.parameter, x.syntax, context.Model)); foreach (var nonCompliantParameter in nonCompliantParameters) { @@ -78,7 +78,7 @@ private static void AnalyzeInvocations(SonarSyntaxNodeReportingContext context) private static void AnalyzeAssignments(SonarSyntaxNodeReportingContext context) { var assignmentSyntax = (AssignmentExpressionSyntax)context.Node; - if (assignmentSyntax.IsInConditionalDebug(context.SemanticModel)) + if (assignmentSyntax.IsInConditionalDebug(context.Model)) { return; } @@ -86,9 +86,9 @@ private static void AnalyzeAssignments(SonarSyntaxNodeReportingContext context) var assignmentMappings = assignmentSyntax.MapAssignmentArguments(); foreach (var assignmentMapping in assignmentMappings) { - if (context.SemanticModel.GetSymbolInfo(assignmentMapping.Left).Symbol is IPropertySymbol propertySymbol + if (context.Model.GetSymbolInfo(assignmentMapping.Left).Symbol is IPropertySymbol propertySymbol && IsLocalizable(propertySymbol) - && IsStringLiteral(assignmentMapping.Right, context.SemanticModel)) + && IsStringLiteral(assignmentMapping.Right, context.Model)) { context.ReportIssue(Rule, assignmentMapping.Right); } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/LockedFieldShouldBeReadonly.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/LockedFieldShouldBeReadonly.cs index 2f278159d60..37371e7bda3 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/LockedFieldShouldBeReadonly.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/LockedFieldShouldBeReadonly.cs @@ -40,7 +40,7 @@ private static void CheckLockStatement(SonarSyntaxNodeReportingContext context) } else { - var lazySymbol = new Lazy(() => context.SemanticModel.GetSymbolInfo(expression).Symbol); + var lazySymbol = new Lazy(() => context.Model.GetSymbolInfo(expression).Symbol); if (IsOfTypeString(expression, lazySymbol)) { context.ReportIssue(LockedFieldRule, expression, "strings as they can be interned"); diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/LoggerFieldsShouldBePrivateStaticReadonly.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/LoggerFieldsShouldBePrivateStaticReadonly.cs index 45761d3a11c..afa557d991b 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/LoggerFieldsShouldBePrivateStaticReadonly.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/LoggerFieldsShouldBePrivateStaticReadonly.cs @@ -60,7 +60,7 @@ protected override void Initialize(SonarAnalysisContext context) => { cc.RegisterNodeAction(c => { - foreach (var invalid in InvalidFields((FieldDeclarationSyntax)c.Node, c.SemanticModel)) + foreach (var invalid in InvalidFields((FieldDeclarationSyntax)c.Node, c.Model)) { c.ReportIssue(Rule, invalid, invalid.ValueText); } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/LoggerMembersNamesShouldComply.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/LoggerMembersNamesShouldComply.cs index 895f97ed29e..43fadb09406 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/LoggerMembersNamesShouldComply.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/LoggerMembersNamesShouldComply.cs @@ -81,7 +81,7 @@ protected override void Initialize(SonarParametrizedAnalysisContext context) => foreach (var memberData in Declarations(c.Node)) { if (!MatchesFormat(memberData.Name) - && c.SemanticModel.GetDeclaredSymbol(memberData.Member).GetSymbolType() is { } type + && c.Model.GetDeclaredSymbol(memberData.Member).GetSymbolType() is { } type && type.DerivesOrImplementsAny(Loggers)) { c.ReportIssue(Rule, memberData.Location, memberData.MemberType, memberData.Name, Format); diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/LoggersShouldBeNamedForEnclosingType.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/LoggersShouldBeNamedForEnclosingType.cs index b3244a236db..71f792cefb9 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/LoggersShouldBeNamedForEnclosingType.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/LoggersShouldBeNamedForEnclosingType.cs @@ -57,9 +57,9 @@ private static void Process(SonarSyntaxNodeReportingContext context) if (invocation.GetName() is "GetLogger" or "CreateLogger" && EnclosingTypeNode(invocation) is { } enclosingType // filter out top-level statements, choose new() first and then enclosing type && ExtractArgument(invocation) is { } argument - && context.SemanticModel.GetSymbolInfo(invocation).Symbol is IMethodSymbol method + && context.Model.GetSymbolInfo(invocation).Symbol is IMethodSymbol method && IsValidMethod(method) - && !MatchesEnclosingType(argument, enclosingType, context.SemanticModel)) + && !MatchesEnclosingType(argument, enclosingType, context.Model)) { context.ReportIssue(Rule, argument); } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/LoggingArgumentsShouldBePassedCorrectly.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/LoggingArgumentsShouldBePassedCorrectly.cs index d694c2d2d62..13c920413bd 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/LoggingArgumentsShouldBePassedCorrectly.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/LoggingArgumentsShouldBePassedCorrectly.cs @@ -43,7 +43,7 @@ protected override void Initialize(SonarAnalysisContext context) => { var invocation = (InvocationExpressionSyntax)c.Node; if (!LoggingMethodNames.Contains(invocation.GetName()) - || c.SemanticModel.GetSymbolInfo(invocation).Symbol is not IMethodSymbol invocationSymbol) + || c.Model.GetSymbolInfo(invocation).Symbol is not IMethodSymbol invocationSymbol) { return; } @@ -77,7 +77,7 @@ private static void CheckInvalidParams(InvocationExpressionSyntax invocation, IM var paramsIndex = invocationSymbol.Parameters.IndexOf(paramsParameter); var invalidArguments = invocation.ArgumentList.Arguments - .Where(x => x.GetArgumentIndex() >= paramsIndex && IsInvalidArgument(x, c.SemanticModel, knownTypes)) + .Where(x => x.GetArgumentIndex() >= paramsIndex && IsInvalidArgument(x, c.Model, knownTypes)) .ToSecondaryLocations() .ToArray(); if (invalidArguments.Length > 0) @@ -92,7 +92,7 @@ private static void CheckInvalidTypeParams(InvocationExpressionSyntax invocation { var typeParameterNames = methodSymbol.TypeParameters.Select(x => x.MetadataName).ToArray(); var positions = methodSymbol.ConstructedFrom.Parameters.Where(x => typeParameterNames.Contains(x.Type.MetadataName)).Select(x => methodSymbol.ConstructedFrom.Parameters.IndexOf(x)); - var invalidArguments = InvalidArguments(invocation, c.SemanticModel, positions, knownTypes).ToSecondaryLocations(); + var invalidArguments = InvalidArguments(invocation, c.Model, positions, knownTypes).ToSecondaryLocations(); c.ReportIssue(Rule, invocation.Expression, invalidArguments); } } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/LoopsAndLinq.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/LoopsAndLinq.cs index 212c63265df..549ecadf50a 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/LoopsAndLinq.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/LoopsAndLinq.cs @@ -90,11 +90,11 @@ bool ConditionValidInvocation() => ifStatementSyntax.Condition is InvocationExpr /// private static void CheckIfCanBeSimplifiedUsingSelect(SonarSyntaxNodeReportingContext c, ForEachStatementSyntax forEachStatementSyntax) { - var declaredSymbol = new Lazy(() => c.SemanticModel.GetDeclaredSymbol(forEachStatementSyntax)); + var declaredSymbol = new Lazy(() => c.Model.GetDeclaredSymbol(forEachStatementSyntax)); var expressionTypeIsOrImplementsIEnumerable = new Lazy( () => { - var expressionType = c.SemanticModel.GetTypeInfo(forEachStatementSyntax.Expression).Type; + var expressionType = c.Model.GetTypeInfo(forEachStatementSyntax.Expression).Type; return expressionType.Is(KnownType.System_Collections_Generic_IEnumerable_T) || expressionType.Implements(KnownType.System_Collections_Generic_IEnumerable_T); }); @@ -106,8 +106,8 @@ private static void CheckIfCanBeSimplifiedUsingSelect(SonarSyntaxNodeReportingCo if (identifierSyntax.Parent is MemberAccessExpressionSyntax { Parent: not InvocationExpressionSyntax } memberAccessExpressionSyntax && IsNotLeftSideOfAssignment(memberAccessExpressionSyntax) && expressionTypeIsOrImplementsIEnumerable.Value - && c.SemanticModel.GetSymbolInfo(identifierSyntax).Symbol.Equals(declaredSymbol.Value) - && c.SemanticModel.GetSymbolInfo(memberAccessExpressionSyntax.Name).Symbol is { } symbol) + && c.Model.GetSymbolInfo(identifierSyntax).Symbol.Equals(declaredSymbol.Value) + && c.Model.GetSymbolInfo(memberAccessExpressionSyntax.Name).Symbol is { } symbol) { var usageStats = accessedProperties.GetOrAdd(symbol, _ => new UsageStats()); diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/LossOfFractionInDivision.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/LossOfFractionInDivision.cs index dcf62426ea7..ca0f729c655 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/LossOfFractionInDivision.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/LossOfFractionInDivision.cs @@ -32,17 +32,17 @@ protected override void Initialize(SonarAnalysisContext context) => { var division = (BinaryExpressionSyntax)c.Node; - if (c.SemanticModel.GetSymbolInfo(division).Symbol as IMethodSymbol is not { } symbol + if (c.Model.GetSymbolInfo(division).Symbol as IMethodSymbol is not { } symbol || !symbol.ContainingType.IsAny(KnownType.IntegralNumbersIncludingNative)) { return; } - if (DivisionIsInAssignmentAndTypeIsNonIntegral(division, c.SemanticModel, out var divisionResultType) - || DivisionIsArgumentAndTypeIsNonIntegral(division, c.SemanticModel, out divisionResultType) - || DivisionIsInReturnAndTypeIsNonIntegral(division, c.SemanticModel, out divisionResultType)) + if (DivisionIsInAssignmentAndTypeIsNonIntegral(division, c.Model, out var divisionResultType) + || DivisionIsArgumentAndTypeIsNonIntegral(division, c.Model, out divisionResultType) + || DivisionIsInReturnAndTypeIsNonIntegral(division, c.Model, out divisionResultType)) { - c.ReportIssue(Rule, division, divisionResultType.ToMinimalDisplayString(c.SemanticModel, division.SpanStart)); + c.ReportIssue(Rule, division, divisionResultType.ToMinimalDisplayString(c.Model, division.SpanStart)); } }, SyntaxKind.DivideExpression); diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/MarkAssemblyWithNeutralResourcesLanguageAttribute.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/MarkAssemblyWithNeutralResourcesLanguageAttribute.cs index bc2462e2251..0c4c630a20c 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/MarkAssemblyWithNeutralResourcesLanguageAttribute.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/MarkAssemblyWithNeutralResourcesLanguageAttribute.cs @@ -31,7 +31,7 @@ protected override void Initialize(SonarAnalysisContext context) => { var hasResx = false; context.RegisterNodeActionInAllFiles(cc => - hasResx = hasResx || IsResxGeneratedFile(cc.SemanticModel, (ClassDeclarationSyntax)cc.Node), + hasResx = hasResx || IsResxGeneratedFile(cc.Model, (ClassDeclarationSyntax)cc.Node), SyntaxKind.ClassDeclaration); c.RegisterCompilationEndAction(cc => diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/MemberInitializedToDefault.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/MemberInitializedToDefault.cs index 3b8091b216a..587caf3ee5b 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/MemberInitializedToDefault.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/MemberInitializedToDefault.cs @@ -46,7 +46,7 @@ private static void CheckAutoProperty(SonarSyntaxNodeReportingContext context) return; } - var propertySymbol = context.SemanticModel.GetDeclaredSymbol(propertyDeclaration); + var propertySymbol = context.Model.GetDeclaredSymbol(propertyDeclaration); if (propertySymbol != null && IsDefaultValueInitializer(propertyDeclaration.Initializer, propertySymbol.Type)) @@ -61,7 +61,7 @@ private static void CheckEvent(SonarSyntaxNodeReportingContext context) foreach (var eventDeclaration in field.Declaration.Variables.Where(v => v.Initializer != null)) { - if (!(context.SemanticModel.GetDeclaredSymbol(eventDeclaration) is IEventSymbol eventSymbol)) + if (!(context.Model.GetDeclaredSymbol(eventDeclaration) is IEventSymbol eventSymbol)) { continue; } @@ -80,7 +80,7 @@ private static void CheckField(SonarSyntaxNodeReportingContext context) foreach (var variableDeclarator in field.Declaration.Variables.Where(v => v.Initializer != null)) { - if (context.SemanticModel.GetDeclaredSymbol(variableDeclarator) is IFieldSymbol {IsConst: false} fieldSymbol + if (context.Model.GetDeclaredSymbol(variableDeclarator) is IFieldSymbol {IsConst: false} fieldSymbol && IsDefaultValueInitializer(variableDeclarator.Initializer, fieldSymbol.Type)) { context.ReportIssue(Rule, variableDeclarator.Initializer, fieldSymbol.Name); diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/MemberInitializerRedundant.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/MemberInitializerRedundant.cs index 5c07b6d0d08..4420290e106 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/MemberInitializerRedundant.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/MemberInitializerRedundant.cs @@ -43,7 +43,7 @@ protected override void Initialize(SonarAnalysisContext context) => c => { var declaration = (TypeDeclarationSyntax)c.Node; - if (c.SemanticModel.GetDeclaredSymbol(declaration)?.GetMembers() is { Length: > 0 } members) + if (c.Model.GetDeclaredSymbol(declaration)?.GetMembers() is { Length: > 0 } members) { // structs cannot initialize fields/properties at declaration time // interfaces cannot have instance fields and instance properties cannot have initializers @@ -71,7 +71,7 @@ private void CheckInstanceMembers(SonarSyntaxNodeReportingContext c, TypeDeclara } // only retrieve the member symbols (an expensive call) if there are explicit class initializers - var initializedMembers = GetInitializedMembers(c.SemanticModel, declaration, IsNotStaticOrConst); + var initializedMembers = GetInitializedMembers(c.Model, declaration, IsNotStaticOrConst); if (initializedMembers.Count == 0) { return; @@ -101,7 +101,7 @@ private void CheckStaticMembers(SonarSyntaxNodeReportingContext c, TypeDeclarati } // only retrieve the member symbols (an expensive call) if there are explicit class initializers - var initializedMembers = GetInitializedMembers(c.SemanticModel, declaration, IsStatic); + var initializedMembers = GetInitializedMembers(c.Model, declaration, IsStatic); if (initializedMembers.Count == 0) { return; @@ -168,7 +168,7 @@ private static List> GetConstructorDe where TSyntax : SyntaxNode => (from constructorSymbol in constructorSymbols from declarationNode in constructorSymbol.DeclaringSyntaxReferences.Select(x => x.GetSyntax()).OfType() - let model = declarationNode.EnsureCorrectSemanticModelOrDefault(context.SemanticModel) + let model = declarationNode.EnsureCorrectSemanticModelOrDefault(context.Model) where model != null select new NodeSymbolAndModel(model, declarationNode, constructorSymbol)).ToList(); diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/MemberOverrideCallsBaseMember.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/MemberOverrideCallsBaseMember.cs index e49cabbc055..5f3255af6a8 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/MemberOverrideCallsBaseMember.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/MemberOverrideCallsBaseMember.cs @@ -35,7 +35,7 @@ protected override void Initialize(SonarAnalysisContext context) c => { var method = (MethodDeclarationSyntax)c.Node; - if (IsMethodCandidate(method, c.SemanticModel)) + if (IsMethodCandidate(method, c.Model)) { c.ReportIssue(Rule, method, method.Identifier.ValueText, "method"); } @@ -46,7 +46,7 @@ protected override void Initialize(SonarAnalysisContext context) c => { var property = (PropertyDeclarationSyntax)c.Node; - if (IsPropertyCandidate(property, c.SemanticModel)) + if (IsPropertyCandidate(property, c.Model)) { c.ReportIssue(Rule, property, property.Identifier.ValueText, "property"); } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/MemberShouldBeStatic.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/MemberShouldBeStatic.cs index 971d27aa335..250535f1780 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/MemberShouldBeStatic.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/MemberShouldBeStatic.cs @@ -83,7 +83,7 @@ private static void CheckIssue(SonarSyntaxNodeReportingConte return; } - if (context.SemanticModel.GetDeclaredSymbol(declaration) is not { } methodOrPropertySymbol + if (context.Model.GetDeclaredSymbol(declaration) is not { } methodOrPropertySymbol || IsStaticVirtualAbstractOrOverride() || MethodNameWhitelist.Contains(methodOrPropertySymbol.Name) || IsOverrideInterfaceOrNew() @@ -97,7 +97,7 @@ private static void CheckIssue(SonarSyntaxNodeReportingConte } var descendants = getDescendants(declaration); - if (descendants is null || HasInstanceReferences(descendants, context.SemanticModel)) + if (descendants is null || HasInstanceReferences(descendants, context.Model)) { return; } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/MemberShouldNotHaveConflictingTransparencyAttributes.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/MemberShouldNotHaveConflictingTransparencyAttributes.cs index f96c93e6b6f..b1540faeffc 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/MemberShouldNotHaveConflictingTransparencyAttributes.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/MemberShouldNotHaveConflictingTransparencyAttributes.cs @@ -44,7 +44,7 @@ private static void CollectSecurityAttributes(SonarSyntaxNodeReportingContext sy Dictionary nodesWithSecurityCritical) { var attribute = (AttributeSyntax)syntaxNodeAnalysisContext.Node; - if (!(syntaxNodeAnalysisContext.SemanticModel.GetSymbolInfo(attribute).Symbol is IMethodSymbol attributeConstructor)) + if (!(syntaxNodeAnalysisContext.Model.GetSymbolInfo(attribute).Symbol is IMethodSymbol attributeConstructor)) { return; } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/MessageTemplates/LoggingTemplatePlaceHoldersShouldBeInOrder.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/MessageTemplates/LoggingTemplatePlaceHoldersShouldBeInOrder.cs index b8d0c54627a..e4010348af9 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/MessageTemplates/LoggingTemplatePlaceHoldersShouldBeInOrder.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/MessageTemplates/LoggingTemplatePlaceHoldersShouldBeInOrder.cs @@ -30,7 +30,7 @@ public sealed class LoggingTemplatePlaceHoldersShouldBeInOrder : IMessageTemplat public void Execute(SonarSyntaxNodeReportingContext context, InvocationExpressionSyntax invocation, ArgumentSyntax templateArgument, MessageTemplatesParser.Placeholder[] placeholders) { - var methodSymbol = (IMethodSymbol)context.SemanticModel.GetSymbolInfo(invocation).Symbol; + var methodSymbol = (IMethodSymbol)context.Model.GetSymbolInfo(invocation).Symbol; var placeholderValues = PlaceholderValues(invocation, methodSymbol).ToImmutableArray(); for (var i = 0; i < placeholders.Length; i++) { diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/MessageTemplates/MessageTemplateAnalyzer.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/MessageTemplates/MessageTemplateAnalyzer.cs index 2475749c7d5..c542ec9cf4c 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/MessageTemplates/MessageTemplateAnalyzer.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/MessageTemplates/MessageTemplateAnalyzer.cs @@ -39,7 +39,7 @@ protected override void Initialize(SonarAnalysisContext context) => var invocation = (InvocationExpressionSyntax)c.Node; var enabledChecks = Checks.Where(x => x.Rule.IsEnabled(c)).ToArray(); if (enabledChecks.Length > 0 - && MessageTemplateExtractor.TemplateArgument(invocation, c.SemanticModel) is { } argument + && MessageTemplateExtractor.TemplateArgument(invocation, c.Model) is { } argument && HasValidExpression(argument) && MessageTemplatesParser.Parse(argument.Expression.ToString()) is { Success: true } result) { diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/MessageTemplates/MessageTemplatesShouldBeCorrect.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/MessageTemplates/MessageTemplatesShouldBeCorrect.cs index c99c6561bde..df965cfa85b 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/MessageTemplates/MessageTemplatesShouldBeCorrect.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/MessageTemplates/MessageTemplatesShouldBeCorrect.cs @@ -37,7 +37,7 @@ protected override void Initialize(SonarAnalysisContext context) => cc.RegisterNodeAction(c => { var invocation = (InvocationExpressionSyntax)c.Node; - if (MessageTemplateExtractor.TemplateArgument(invocation, c.SemanticModel) is { } argument + if (MessageTemplateExtractor.TemplateArgument(invocation, c.Model) is { } argument && argument.Expression.IsKind(SyntaxKind.StringLiteralExpression) && TemplateValidator.ContainsErrors(argument.Expression.ToString(), out var errors)) { diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/MethodOverrideAddsParams.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/MethodOverrideAddsParams.cs index d797db8a709..5c83190850b 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/MethodOverrideAddsParams.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/MethodOverrideAddsParams.cs @@ -31,7 +31,7 @@ protected override void Initialize(SonarAnalysisContext context) => c => { var method = (MethodDeclarationSyntax)c.Node; - var methodSymbol = c.SemanticModel.GetDeclaredSymbol(method); + var methodSymbol = c.Model.GetDeclaredSymbol(method); if (methodSymbol is not { IsOverride: true } || methodSymbol.OverriddenMethod == null) @@ -47,7 +47,7 @@ protected override void Initialize(SonarAnalysisContext context) => var paramsKeyword = lastParameter.Modifiers.FirstOrDefault(modifier => modifier.IsKind(SyntaxKind.ParamsKeyword)); if (paramsKeyword != default - && IsNotSemanticallyParams(lastParameter, c.SemanticModel)) + && IsNotSemanticallyParams(lastParameter, c.Model)) { c.ReportIssue(Rule, paramsKeyword); } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/MethodOverrideChangedDefaultValue.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/MethodOverrideChangedDefaultValue.cs index 814de623f12..5ff5394d8d1 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/MethodOverrideChangedDefaultValue.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/MethodOverrideChangedDefaultValue.cs @@ -37,7 +37,7 @@ protected override void Initialize(SonarAnalysisContext context) c => { var method = (MethodDeclarationSyntax)c.Node; - var methodSymbol = c.SemanticModel.GetDeclaredSymbol(method); + var methodSymbol = c.Model.GetDeclaredSymbol(method); var overriddenMember = methodSymbol.GetOverriddenMember() ?? methodSymbol.GetInterfaceMember(); if (methodSymbol == null || diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/MethodOverrideNoParams.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/MethodOverrideNoParams.cs index 8bcc303d287..7cbbfcb11cf 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/MethodOverrideNoParams.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/MethodOverrideNoParams.cs @@ -32,7 +32,7 @@ protected override void Initialize(SonarAnalysisContext context) => c => { var method = (MethodDeclarationSyntax)c.Node; - var methodSymbol = c.SemanticModel.GetDeclaredSymbol(method); + var methodSymbol = c.Model.GetDeclaredSymbol(method); if (methodSymbol is not null && methodSymbol.IsOverride diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/MethodParameterMissingOptional.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/MethodParameterMissingOptional.cs index 70b2e03b11f..69ced8813dc 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/MethodParameterMissingOptional.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/MethodParameterMissingOptional.cs @@ -36,7 +36,7 @@ protected override void Initialize(SonarAnalysisContext context) => return; } - var attributes = AttributeSyntaxSymbolMapping.GetAttributesForParameter(parameter, c.SemanticModel).ToList(); + var attributes = AttributeSyntaxSymbolMapping.GetAttributesForParameter(parameter, c.Model).ToList(); var defaultParameterValueAttribute = attributes.FirstOrDefault(a => a.Symbol.IsInType(KnownType.System_Runtime_InteropServices_DefaultParameterValueAttribute)); if (defaultParameterValueAttribute == null) diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/MethodParameterUnused.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/MethodParameterUnused.cs index fca590d43b3..65d0e540831 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/MethodParameterUnused.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/MethodParameterUnused.cs @@ -98,7 +98,7 @@ private static bool OnlyThrowsNotImplementedException(MethodContext declaration) return throwExpressions .OfType() - .Select(x => declaration.Context.SemanticModel.GetSymbolInfo(x).Symbol) + .Select(x => declaration.Context.Model.GetSymbolInfo(x).Symbol) .OfType() .Any(x => x is not null && x.ContainingType.Is(KnownType.System_NotImplementedException)); } @@ -146,13 +146,13 @@ private LvaResult ComputeLva(MethodContext declaration) { if (useSonarCfg) { - return CSharpControlFlowGraph.TryGet(declaration.Context.Node, declaration.Context.SemanticModel, out var cfg) + return CSharpControlFlowGraph.TryGet(declaration.Context.Node, declaration.Context.Model, out var cfg) ? new LvaResult(declaration, cfg) : null; } else { - return declaration.Context.Node.CreateCfg(declaration.Context.SemanticModel, declaration.Context.Cancel) is { } cfg + return declaration.Context.Node.CreateCfg(declaration.Context.Model, declaration.Context.Cancel) is { } cfg ? new LvaResult(cfg, declaration.Context.Cancel) : null; } @@ -166,7 +166,7 @@ private static void ReportOnUnusedParameters(MethodContext declaration, IEnumera } var parameters = declaration.ParameterList.Parameters - .Select(x => new NodeAndSymbol(x, declaration.Context.SemanticModel.GetDeclaredSymbol(x))) + .Select(x => new NodeAndSymbol(x, declaration.Context.Model.GetDeclaredSymbol(x))) .Where(x => x.Symbol is not null); foreach (var parameter in parameters.Where(x => parametersToReportOn.Contains(x.Symbol))) @@ -194,7 +194,7 @@ private static IImmutableList GetUnusedParameters(MethodContex foreach (var body in bodies.WhereNotNull()) { - usedParameters.UnionWith(GetUsedParameters(declaration.Symbol.Parameters, body, declaration.Context.SemanticModel)); + usedParameters.UnionWith(GetUsedParameters(declaration.Symbol.Parameters, body, declaration.Context.Model)); } var unusedParameter = declaration.Symbol.Parameters.Except(usedParameters); @@ -215,7 +215,7 @@ private static ISet GetUsedParameters(ImmutableArray declaration.Symbol.ContainingType.DeclaringSyntaxReferences.Select(x => x.GetSyntax()) - .Any(x => IsMethodUsedAsEventHandlerFunctionOrActionWithinNode(declaration.Symbol, x, x.EnsureCorrectSemanticModelOrDefault(declaration.Context.SemanticModel))); + .Any(x => IsMethodUsedAsEventHandlerFunctionOrActionWithinNode(declaration.Symbol, x, x.EnsureCorrectSemanticModelOrDefault(declaration.Context.Model))); private static bool IsMethodUsedAsEventHandlerFunctionOrActionWithinNode(IMethodSymbol methodSymbol, SyntaxNode typeDeclaration, SemanticModel model) => typeDeclaration.DescendantNodes() @@ -264,7 +264,7 @@ public MethodContext(SonarSyntaxNodeReportingContext context, LocalFunctionState public MethodContext(SonarSyntaxNodeReportingContext context, SyntaxTokenList modifiers, ParameterListSyntax parameterList, BlockSyntax body, ArrowExpressionClauseSyntax expressionBody) { Context = context; - Symbol = context.SemanticModel.GetDeclaredSymbol(context.Node) as IMethodSymbol; + Symbol = context.Model.GetDeclaredSymbol(context.Node) as IMethodSymbol; Modifiers = modifiers; ParameterList = parameterList; Body = body; @@ -279,7 +279,7 @@ private sealed class LvaResult public LvaResult(MethodContext declaration, IControlFlowGraph cfg) { - var lva = new SonarCSharpLiveVariableAnalysis(cfg, declaration.Symbol, declaration.Context.SemanticModel, declaration.Context.Cancel); + var lva = new SonarCSharpLiveVariableAnalysis(cfg, declaration.Symbol, declaration.Context.Model, declaration.Context.Cancel); LiveInEntryBlock = lva.LiveIn(cfg.EntryBlock).OfType().ToImmutableArray(); CapturedVariables = lva.CapturedVariables; } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/MethodShouldBeNamedAccordingToSynchronicity.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/MethodShouldBeNamedAccordingToSynchronicity.cs index 47b153ac084..06f5e494bfd 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/MethodShouldBeNamedAccordingToSynchronicity.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/MethodShouldBeNamedAccordingToSynchronicity.cs @@ -48,7 +48,7 @@ protected override void Initialize(SonarAnalysisContext context) => return; } - var methodSymbol = c.SemanticModel.GetDeclaredSymbol(methodDeclaration); + var methodSymbol = c.Model.GetDeclaredSymbol(methodDeclaration); if (methodSymbol == null || methodSymbol.IsMainMethod() || methodSymbol.GetInterfaceMember() != null diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/MethodShouldNotOnlyReturnConstant.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/MethodShouldNotOnlyReturnConstant.cs index 511c1a4d4aa..4d8b6961ae9 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/MethodShouldNotOnlyReturnConstant.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/MethodShouldNotOnlyReturnConstant.cs @@ -37,12 +37,12 @@ protected override void Initialize(SonarAnalysisContext context) => } var expressionSyntax = GetSingleExpressionOrDefault(methodDeclaration); - if (!IsConstantExpression(expressionSyntax, c.SemanticModel)) + if (!IsConstantExpression(expressionSyntax, c.Model)) { return; } - if (c.SemanticModel.GetDeclaredSymbol(methodDeclaration) is { } methodSymbol + if (c.Model.GetDeclaredSymbol(methodDeclaration) is { } methodSymbol && !methodSymbol.ContainingType.IsInterface() && methodSymbol.GetInterfaceMember() == null && methodSymbol.GetOverriddenMember() == null) diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/MethodsShouldUseBaseTypes.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/MethodsShouldUseBaseTypes.cs index 7b60eca97df..64efe4ac9f9 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/MethodsShouldUseBaseTypes.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/MethodsShouldUseBaseTypes.cs @@ -27,7 +27,7 @@ public sealed class MethodsShouldUseBaseTypes : SonarDiagnosticAnalyzer protected override void Initialize(SonarAnalysisContext context) => context.RegisterNodeAction( - c => FindViolations((BaseMethodDeclarationSyntax)c.Node, c.SemanticModel).ForEach(d => c.ReportIssue(d)), + c => FindViolations((BaseMethodDeclarationSyntax)c.Node, c.Model).ForEach(d => c.ReportIssue(d)), SyntaxKind.MethodDeclaration); private static List FindViolations(BaseMethodDeclarationSyntax methodDeclaration, SemanticModel semanticModel) diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/MutableFieldsShouldNotBe.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/MutableFieldsShouldNotBe.cs index 12c6eb29d7e..8d163f45cfe 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/MutableFieldsShouldNotBe.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/MutableFieldsShouldNotBe.cs @@ -55,18 +55,18 @@ protected sealed override void Initialize(SonarAnalysisContext context) => } var typeDeclaration = (TypeDeclarationSyntax)c.Node; var fieldDeclarations = typeDeclaration.Members.OfType(); - var assignmentsImmutability = FieldAssignmentImmutability(typeDeclaration, fieldDeclarations, c.SemanticModel); + var assignmentsImmutability = FieldAssignmentImmutability(typeDeclaration, fieldDeclarations, c.Model); foreach (var fieldDeclaration in fieldDeclarations) { if (HasAllInvalidModifiers(fieldDeclaration) && fieldDeclaration.Declaration.Variables.Count > 0 - && c.SemanticModel.GetDeclaredSymbol(fieldDeclaration.Declaration.Variables[0]) is IFieldSymbol { Type: not null } fieldSymbol + && c.Model.GetDeclaredSymbol(fieldDeclaration.Declaration.Variables[0]) is IFieldSymbol { Type: not null } fieldSymbol && fieldSymbol.GetEffectiveAccessibility() == Accessibility.Public && !IsImmutableOrValidMutableType(fieldSymbol.Type) // The field seems to be violating the rule but we should exclude the cases where the field is read-only // and all initializations to this field are immutable - && CollectInvalidFieldVariables(fieldDeclaration, assignmentsImmutability, c.SemanticModel).ToList() is { Count: > 0 } incorrectFieldVariables) + && CollectInvalidFieldVariables(fieldDeclaration, assignmentsImmutability, c.Model).ToList() is { Count: > 0 } incorrectFieldVariables) { var pluralizeSuffix = incorrectFieldVariables.Count > 1 ? "s" : string.Empty; c.ReportIssue(rule, fieldDeclaration.Declaration.Type, pluralizeSuffix, incorrectFieldVariables.ToSentence(quoteWords: true)); diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/NativeMethodsShouldBeWrapped.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/NativeMethodsShouldBeWrapped.cs index 5ddba42f103..cbfdbb86fd4 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/NativeMethodsShouldBeWrapped.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/NativeMethodsShouldBeWrapped.cs @@ -69,7 +69,7 @@ private static void ReportTrivialWrappers(SonarSyntaxNodeReportingContext c) return; } - var methodSymbol = c.SemanticModel.GetDeclaredSymbol(methodDeclaration); + var methodSymbol = c.Model.GetDeclaredSymbol(methodDeclaration); if (methodSymbol == null || (methodSymbol.IsExtern && methodDeclaration.ParameterList == null)) { @@ -80,7 +80,7 @@ private static void ReportTrivialWrappers(SonarSyntaxNodeReportingContext c) descendants.OfType() .Where(ParametersMatchContainingMethodDeclaration) - .Select(i => c.SemanticModel.GetSymbolInfo(i).Symbol) + .Select(i => c.Model.GetSymbolInfo(i).Symbol) .OfType() .Where(externalMethodSymbols.Contains) .ToList() diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/NonAsyncTaskShouldNotReturnNull.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/NonAsyncTaskShouldNotReturnNull.cs index b2901e99624..6f8f9b2b6d6 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/NonAsyncTaskShouldNotReturnNull.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/NonAsyncTaskShouldNotReturnNull.cs @@ -48,7 +48,7 @@ protected override void Initialize(SonarAnalysisContext context) var enclosingMember = GetEnclosingMember(nullLiteral); if (enclosingMember != null && !enclosingMember.IsKind(SyntaxKind.VariableDeclaration) && - IsInvalidEnclosingSymbolContext(enclosingMember, c.SemanticModel)) + IsInvalidEnclosingSymbolContext(enclosingMember, c.Model)) { c.ReportIssue(rule, nullLiteral); } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/NonFlagsEnumInBitwiseOperation.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/NonFlagsEnumInBitwiseOperation.cs index 8d3994b7ff2..72ee5fe5cff 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/NonFlagsEnumInBitwiseOperation.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/NonFlagsEnumInBitwiseOperation.cs @@ -47,13 +47,13 @@ protected override void Initialize(SonarAnalysisContext context) private static void CheckExpressionWithOperator(SonarSyntaxNodeReportingContext context, Func operatorSelector) where T : SyntaxNode { - if (context.SemanticModel.GetSymbolInfo(context.Node).Symbol is not IMethodSymbol { MethodKind: MethodKind.BuiltinOperator, ReturnType.TypeKind: TypeKind.Enum } operation + if (context.Model.GetSymbolInfo(context.Node).Symbol is not IMethodSymbol { MethodKind: MethodKind.BuiltinOperator, ReturnType.TypeKind: TypeKind.Enum } operation || operation.ReturnType.HasAttribute(KnownType.System_FlagsAttribute)) { return; } - var friendlyTypeName = operation.ReturnType.ToMinimalDisplayString(context.SemanticModel, context.Node.SpanStart); + var friendlyTypeName = operation.ReturnType.ToMinimalDisplayString(context.Model, context.Node.SpanStart); var messageFormat = operation.ReturnType.DeclaringSyntaxReferences.Any() ? MessageChangeOrRemove : MessageRemove; diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/ObjectShouldBeInitializedCorrectlyBase.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/ObjectShouldBeInitializedCorrectlyBase.cs index bb047bb042b..e1fdea951d2 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/ObjectShouldBeInitializedCorrectlyBase.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/ObjectShouldBeInitializedCorrectlyBase.cs @@ -54,7 +54,7 @@ protected override void Initialize(SonarAnalysisContext context) c => { var objectCreation = ObjectCreationFactory.Create(c.Node); - if (ObjectInitializationTracker.ShouldBeReported(objectCreation, c.SemanticModel, isDefaultConstructorSafe )) + if (ObjectInitializationTracker.ShouldBeReported(objectCreation, c.Model, isDefaultConstructorSafe )) { c.ReportIssue(SupportedDiagnostics[0], objectCreation.Expression); } @@ -65,7 +65,7 @@ protected override void Initialize(SonarAnalysisContext context) c => { var assignment = (AssignmentExpressionSyntax)c.Node; - if (ObjectInitializationTracker.ShouldBeReported(assignment, c.SemanticModel)) + if (ObjectInitializationTracker.ShouldBeReported(assignment, c.Model)) { c.ReportIssue(SupportedDiagnostics[0], assignment); } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/OperatorOverloadsShouldHaveNamedAlternatives.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/OperatorOverloadsShouldHaveNamedAlternatives.cs index e15383bb2f0..31d2967a211 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/OperatorOverloadsShouldHaveNamedAlternatives.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/OperatorOverloadsShouldHaveNamedAlternatives.cs @@ -92,7 +92,7 @@ protected override void Initialize(SonarAnalysisContext context) context.RegisterNodeAction(c => { var operatorDeclaration = (OperatorDeclarationSyntax)c.Node; - var operatorSymbol = c.SemanticModel.GetDeclaredSymbol(operatorDeclaration); + var operatorSymbol = c.Model.GetDeclaredSymbol(operatorDeclaration); if (operatorSymbol == null || operatorSymbol.MethodKind != MethodKind.UserDefinedOperator) { diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/OptionalParameterWithDefaultValue.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/OptionalParameterWithDefaultValue.cs index 6f0d685cb77..a963bdac1a0 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/OptionalParameterWithDefaultValue.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/OptionalParameterWithDefaultValue.cs @@ -36,7 +36,7 @@ protected override void Initialize(SonarAnalysisContext context) => return; } - var attributes = AttributeSyntaxSymbolMapping.GetAttributesForParameter(parameter, c.SemanticModel).ToList(); + var attributes = AttributeSyntaxSymbolMapping.GetAttributesForParameter(parameter, c.Model).ToList(); var hasNoOptional = attributes.All(attr => !attr.Symbol.IsInType(KnownType.System_Runtime_InteropServices_OptionalAttribute)); if (hasNoOptional) diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/OptionalRefOutParameter.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/OptionalRefOutParameter.cs index 7d9e369c123..4d67c893872 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/OptionalRefOutParameter.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/OptionalRefOutParameter.cs @@ -37,7 +37,7 @@ protected override void Initialize(SonarAnalysisContext context) => return; } - var optionalAttribute = AttributeSyntaxSymbolMapping.GetAttributesForParameter(parameter, c.SemanticModel) + var optionalAttribute = AttributeSyntaxSymbolMapping.GetAttributesForParameter(parameter, c.Model) .FirstOrDefault(a => a.Symbol.IsInType(KnownType.System_Runtime_InteropServices_OptionalAttribute)); if (optionalAttribute != null) diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/OrderByRepeated.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/OrderByRepeated.cs index 5a02d95d373..c9bf49d49f8 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/OrderByRepeated.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/OrderByRepeated.cs @@ -35,8 +35,8 @@ protected override void Initialize(SonarAnalysisContext context) var outerInvocation = (InvocationExpressionSyntax)c.Node; if (outerInvocation.Expression is MemberAccessExpressionSyntax memberAccess && memberAccess.Expression is InvocationExpressionSyntax innerInvocation && - IsMethodOrderByExtension(outerInvocation, c.SemanticModel) && - IsOrderByOrThenBy(innerInvocation, c.SemanticModel)) + IsMethodOrderByExtension(outerInvocation, c.Model) && + IsOrderByOrThenBy(innerInvocation, c.Model)) { c.ReportIssue(rule, memberAccess.Name); } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/OverrideGetHashCodeOnOverridingEquals.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/OverrideGetHashCodeOnOverridingEquals.cs index 2f5e1322848..6e306901d5d 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/OverrideGetHashCodeOnOverridingEquals.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/OverrideGetHashCodeOnOverridingEquals.cs @@ -32,7 +32,7 @@ protected override void Initialize(SonarAnalysisContext context) c => { var declaration = (TypeDeclarationSyntax)c.Node; - var typeSymbol = c.SemanticModel.GetDeclaredSymbol(declaration); + var typeSymbol = c.Model.GetDeclaredSymbol(declaration); if (typeSymbol == null) { return; diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/PInvokesShouldNotBeVisible.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/PInvokesShouldNotBeVisible.cs index 14893c13b91..f06772cd09f 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/PInvokesShouldNotBeVisible.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/PInvokesShouldNotBeVisible.cs @@ -32,7 +32,7 @@ protected override void Initialize(SonarAnalysisContext context) c => { var methodDeclaration = (MethodDeclarationSyntax)c.Node; - var methodSymbol = c.SemanticModel.GetDeclaredSymbol(methodDeclaration); + var methodSymbol = c.Model.GetDeclaredSymbol(methodDeclaration); if (methodSymbol != null && methodSymbol.IsExtern && diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/ParameterValidationInAsyncShouldBeWrapped.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/ParameterValidationInAsyncShouldBeWrapped.cs index d16833ecfe1..03e83aee9c4 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/ParameterValidationInAsyncShouldBeWrapped.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/ParameterValidationInAsyncShouldBeWrapped.cs @@ -36,12 +36,12 @@ protected override void Initialize(SonarAnalysisContext context) => var method = (MethodDeclarationSyntax)c.Node; if (!method.Modifiers.Any(SyntaxKind.AsyncKeyword) || method.HasReturnTypeVoid() - || (method.Identifier.ValueText == "Main" && c.SemanticModel.GetDeclaredSymbol(method).IsMainMethod())) + || (method.Identifier.ValueText == "Main" && c.Model.GetDeclaredSymbol(method).IsMainMethod())) { return; } - var walker = new ParameterValidationInAsyncWalker(c.SemanticModel); + var walker = new ParameterValidationInAsyncWalker(c.Model); walker.SafeVisit(method); if (walker.ArgumentExceptionLocations.Any()) { diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/ParameterValidationInYieldShouldBeWrapped.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/ParameterValidationInYieldShouldBeWrapped.cs index 089f56e8868..2e010fdeb52 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/ParameterValidationInYieldShouldBeWrapped.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/ParameterValidationInYieldShouldBeWrapped.cs @@ -34,7 +34,7 @@ protected override void Initialize(SonarAnalysisContext context) => { var methodDeclaration = (MethodDeclarationSyntax)c.Node; - var walker = new ParameterValidationInYieldWalker(c.SemanticModel); + var walker = new ParameterValidationInYieldWalker(c.Model); walker.SafeVisit(methodDeclaration); if (walker.HasYieldStatement && diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/PartialMethodNoImplementation.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/PartialMethodNoImplementation.cs index a1810c17810..c01f4ce737f 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/PartialMethodNoImplementation.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/PartialMethodNoImplementation.cs @@ -41,7 +41,7 @@ private static void CheckForCandidatePartialDeclaration(SonarSyntaxNodeReporting if (partialKeyword != default && !declaration.HasBodyOrExpressionBody() && !declaration.Modifiers.Any(HasAccessModifier) - && context.SemanticModel.GetDeclaredSymbol(declaration) is { } methodSymbol + && context.Model.GetDeclaredSymbol(declaration) is { } methodSymbol && methodSymbol.PartialImplementationPart == null) { context.ReportIssue(Rule, partialKeyword, "this", string.Empty); @@ -53,7 +53,7 @@ private static void CheckForCandidatePartialInvocation(SonarSyntaxNodeReportingC var invocation = (InvocationExpressionSyntax)context.Node; if (invocation.Parent is StatementSyntax statement - && context.SemanticModel.GetSymbolInfo(invocation).Symbol is IMethodSymbol methodSymbol + && context.Model.GetSymbolInfo(invocation).Symbol is IMethodSymbol methodSymbol && methodSymbol.PartialImplementationPart == null && PartialMethodsWithoutAccessModifier(methodSymbol).Any()) { diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/PointersShouldBePrivate.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/PointersShouldBePrivate.cs index c2b1cb84694..fecd731d824 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/PointersShouldBePrivate.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/PointersShouldBePrivate.cs @@ -39,7 +39,7 @@ protected override void Initialize(SonarAnalysisContext context) => foreach (var variable in fieldDeclaration.Declaration.Variables) { - if (SymbolIfPointerType(fieldDeclaration.Declaration, variable, c.SemanticModel) is { } variableSymbol + if (SymbolIfPointerType(fieldDeclaration.Declaration, variable, c.Model) is { } variableSymbol && variableSymbol.GetEffectiveAccessibility() is var accessibility && accessibility != Accessibility.Private && accessibility != Accessibility.Internal diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/PreferJaggedArraysOverMultidimensional.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/PreferJaggedArraysOverMultidimensional.cs index efc148eb76e..25e627f2d65 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/PreferJaggedArraysOverMultidimensional.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/PreferJaggedArraysOverMultidimensional.cs @@ -58,7 +58,7 @@ private static void AnalyzeNode(SonarSyntaxNodeReportingContext context where TSyntax : SyntaxNode { var syntax = (TSyntax)context.Node; - var typeSymbol = getTypeSymbol(context.SemanticModel, syntax); + var typeSymbol = getTypeSymbol(context.Model, syntax); if (typeSymbol == null) { return; diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/PrivateFieldUsedAsLocalVariable.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/PrivateFieldUsedAsLocalVariable.cs index b94a51d690b..850dafd8d66 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/PrivateFieldUsedAsLocalVariable.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/PrivateFieldUsedAsLocalVariable.cs @@ -43,8 +43,8 @@ protected override void Initialize(SonarAnalysisContext context) => } var methodNames = typeDeclaration.Members.OfType().Select(x => x.Identifier.ValueText).ToHashSet(); - var privateFields = GetPrivateFields(c.SemanticModel, typeDeclaration); - var collector = new FieldAccessCollector(c.SemanticModel, privateFields, methodNames); + var privateFields = GetPrivateFields(c.Model, typeDeclaration); + var collector = new FieldAccessCollector(c.Model, privateFields, methodNames); if (!collector.SafeVisit(typeDeclaration)) { // We couldn't finish the exploration so we cannot take any decision diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/PrivateStaticMethodUsedOnlyByNestedClass.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/PrivateStaticMethodUsedOnlyByNestedClass.cs index 1b1613178c6..8e8122d9887 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/PrivateStaticMethodUsedOnlyByNestedClass.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/PrivateStaticMethodUsedOnlyByNestedClass.cs @@ -44,7 +44,7 @@ protected override void Initialize(SonarAnalysisContext context) => && HasNestedTypeDeclarations(outerType) && PrivateStaticMethodsOf(outerType) is { Length: > 0 } candidates) { - var methodReferences = TypesWhichUseTheMethods(candidates, outerType, c.SemanticModel); + var methodReferences = TypesWhichUseTheMethods(candidates, outerType, c.Model); foreach (var reference in methodReferences) { diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/PropertiesShouldBePreferred.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/PropertiesShouldBePreferred.cs index 1cec3a8b0b4..642b8418f85 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/PropertiesShouldBePreferred.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/PropertiesShouldBePreferred.cs @@ -33,7 +33,7 @@ protected override void Initialize(SonarAnalysisContext context) => context.RegisterNodeAction(c => { if (c.IsRedundantPositionalRecordContext() - || c.SemanticModel.GetDeclaredSymbol(c.Node) is not INamedTypeSymbol typeSymbol) + || c.Model.GetDeclaredSymbol(c.Node) is not INamedTypeSymbol typeSymbol) { return; } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/PropertyToAutoProperty.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/PropertyToAutoProperty.cs index 2f8556eeedf..e0212a26c07 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/PropertyToAutoProperty.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/PropertyToAutoProperty.cs @@ -39,12 +39,12 @@ protected override void Initialize(SonarAnalysisContext context) => && !propertyDeclaration.Modifiers.Any(SyntaxKind.PartialKeyword) && accessors.FirstOrDefault(x => x.IsKind(SyntaxKind.GetAccessorDeclaration)) is { } getter && accessors.FirstOrDefault(x => x.Kind() is SyntaxKind.SetAccessorDeclaration or SyntaxKindEx.InitAccessorDeclaration) is { } setter - && FieldFromGetter(getter, c.SemanticModel) is { } getterField - && FieldFromSetter(setter, c.SemanticModel) is { } setterField + && FieldFromGetter(getter, c.Model) is { } getterField + && FieldFromSetter(setter, c.Model) is { } setterField && getterField.Equals(setterField) && !getterField.GetAttributes().Any() && !getterField.IsVolatile - && c.SemanticModel.GetDeclaredSymbol(propertyDeclaration) is { } propertySymbol + && c.Model.GetDeclaredSymbol(propertyDeclaration) is { } propertySymbol && getterField.IsStatic == propertySymbol.IsStatic && getterField.Type.Equals(propertySymbol.Type)) { diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/PureAttributeOnVoidMethod.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/PureAttributeOnVoidMethod.cs index 7e376615929..0fe417ba3e8 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/PureAttributeOnVoidMethod.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/PureAttributeOnVoidMethod.cs @@ -29,7 +29,7 @@ protected override void Initialize(SonarAnalysisContext context) { if ((LocalFunctionStatementSyntaxWrapper)c.Node is var localFunction && localFunction.AttributeLists.SelectMany(x => x.Attributes).Any(IsPureAttribute) - && InvalidPureDataAttributeUsage((IMethodSymbol)c.SemanticModel.GetDeclaredSymbol(c.Node)) is { } pureAttribute) + && InvalidPureDataAttributeUsage((IMethodSymbol)c.Model.GetDeclaredSymbol(c.Node)) is { } pureAttribute) { c.ReportIssue(Rule, pureAttribute.ApplicationSyntaxReference.GetSyntax()); } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/RedundancyInConstructorDestructorDeclaration.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/RedundancyInConstructorDestructorDeclaration.cs index 4fbfdc29d27..10c95143f8a 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/RedundancyInConstructorDestructorDeclaration.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/RedundancyInConstructorDestructorDeclaration.cs @@ -46,7 +46,7 @@ private static void CheckTypesWithPrimaryConstructor(SonarSyntaxNodeReportingCon var typeDeclaration = (TypeDeclarationSyntax)context.Node; if (!IsInheritingFromTypeWithValueInPrimaryConstructor(typeDeclaration) && typeDeclaration.ParameterList() is { Parameters.Count: 0 } parameterList - && !IsStructWithInitializedFieldOrProperty(typeDeclaration, context.SemanticModel)) + && !IsStructWithInitializedFieldOrProperty(typeDeclaration, context.Model)) { context.ReportIssue(Rule, parameterList, "primary constructor"); } @@ -70,7 +70,7 @@ private static void CheckConstructorDeclaration(SonarSyntaxNodeReportingContext { var constructorDeclaration = (ConstructorDeclarationSyntax)context.Node; - if (IsConstructorRedundant(constructorDeclaration, context.SemanticModel)) + if (IsConstructorRedundant(constructorDeclaration, context.Model)) { context.ReportIssue(Rule, constructorDeclaration, "constructor"); return; diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/RedundantArgument.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/RedundantArgument.cs index e1475c02560..6f942969dc1 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/RedundantArgument.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/RedundantArgument.cs @@ -33,9 +33,9 @@ protected override void Initialize(SonarAnalysisContext context) => if (c.Node.ArgumentList() is { Arguments.Count: > 0 } argumentList && !c.IsRedundantPrimaryConstructorBaseTypeContext() && !c.IsInExpressionTree() // Can't use optional arguments in expression trees (CS0584), so skip those - && new CSharpMethodParameterLookup(argumentList, c.SemanticModel) is { MethodSymbol: { } } methodParameterLookup) + && new CSharpMethodParameterLookup(argumentList, c.Model) is { MethodSymbol: { } } methodParameterLookup) { - foreach (var argumentMapping in methodParameterLookup.GetAllArgumentParameterMappings().Reverse().Where(x => ArgumentHasDefaultValue(x, c.SemanticModel))) + foreach (var argumentMapping in methodParameterLookup.GetAllArgumentParameterMappings().Reverse().Where(x => ArgumentHasDefaultValue(x, c.Model))) { c.ReportIssue(Rule, argumentMapping.Node, argumentMapping.Symbol.Name); } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/RedundantCast.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/RedundantCast.cs index d1f9f29e67f..346168d9367 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/RedundantCast.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/RedundantCast.cs @@ -56,8 +56,8 @@ protected override void Initialize(SonarAnalysisContext context) private static void CheckCastExpression(SonarSyntaxNodeReportingContext context, ExpressionSyntax expression, ExpressionSyntax type, Location location) { if (!expression.IsKind(SyntaxKindEx.DefaultLiteralExpression) - && context.SemanticModel.GetTypeInfo(expression) is { Type: { } expressionType } expressionTypeInfo - && context.SemanticModel.GetTypeInfo(type) is { Type: { } castType } + && context.Model.GetTypeInfo(expression) is { Type: { } expressionType } expressionTypeInfo + && context.Model.GetTypeInfo(type) is { Type: { } castType } && expressionType.Equals(castType) && FlowStateEquals(expressionTypeInfo, type)) { @@ -80,7 +80,7 @@ private static bool FlowStateEquals(TypeInfo expressionTypeInfo, ExpressionSynta private static void CheckExtensionMethodInvocation(SonarSyntaxNodeReportingContext context) { var invocation = (InvocationExpressionSyntax)context.Node; - if (GetEnumerableExtensionSymbol(invocation, context.SemanticModel) is { } methodSymbol) + if (GetEnumerableExtensionSymbol(invocation, context.Model) is { } methodSymbol) { var returnType = methodSymbol.ReturnType; if (GetGenericTypeArgument(returnType) is { } castType) @@ -91,7 +91,7 @@ private static void CheckExtensionMethodInvocation(SonarSyntaxNodeReportingConte return; } - var elementType = GetElementType(invocation, methodSymbol, context.SemanticModel); + var elementType = GetElementType(invocation, methodSymbol, context.Model); if (elementType != null && elementType.Equals(castType) && elementType.NullableAnnotation() == castType.NullableAnnotation()) { var methodCalledAsStatic = methodSymbol.MethodKind == MethodKind.Ordinary; @@ -102,7 +102,7 @@ private static void CheckExtensionMethodInvocation(SonarSyntaxNodeReportingConte } private static void ReportIssue(SonarSyntaxNodeReportingContext context, ExpressionSyntax expression, ITypeSymbol castType, Location location) => - context.ReportIssue(Rule, location, castType.ToMinimalDisplayString(context.SemanticModel, expression.SpanStart)); + context.ReportIssue(Rule, location, castType.ToMinimalDisplayString(context.Model, expression.SpanStart)); /// If the invocation one of the extensions, returns the method symbol. private static IMethodSymbol GetEnumerableExtensionSymbol(InvocationExpressionSyntax invocation, SemanticModel semanticModel) => diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/RedundantConditionalAroundAssignment.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/RedundantConditionalAroundAssignment.cs index 2bb3d65fe1e..0411efd5c44 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/RedundantConditionalAroundAssignment.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/RedundantConditionalAroundAssignment.cs @@ -56,7 +56,7 @@ private static void UselessConditionIfStatement(SonarSyntaxNodeReportingContext return; } - if (c.SemanticModel.GetSymbolInfo(assignment.Left).Symbol is not IPropertySymbol) + if (c.Model.GetSymbolInfo(assignment.Left).Symbol is not IPropertySymbol) { c.ReportIssue(Rule, condition); } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/RedundantDeclaration.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/RedundantDeclaration.cs index 450450fbc3b..5c3f7e90a64 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/RedundantDeclaration.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/RedundantDeclaration.cs @@ -83,7 +83,7 @@ private static void CheckTypeSpecifications(SonarSyntaxNodeReportingContext cont return; } - if (!(context.SemanticModel.GetSymbolInfo(lambda).Symbol is IMethodSymbol symbol)) + if (!(context.Model.GetSymbolInfo(lambda).Symbol is IMethodSymbol symbol)) { return; } @@ -91,7 +91,7 @@ private static void CheckTypeSpecifications(SonarSyntaxNodeReportingContext cont var newParameterList = SyntaxFactory.ParameterList(SyntaxFactory.SeparatedList(lambda.ParameterList.Parameters.Select(p => SyntaxFactory.Parameter(p.Identifier)))); var newLambda = lambda.WithParameterList(newParameterList); - newLambda = ChangeSyntaxElement(lambda, newLambda, context.SemanticModel, out var newSemanticModel); + newLambda = ChangeSyntaxElement(lambda, newLambda, context.Model, out var newSemanticModel); if (!(newSemanticModel.GetSymbolInfo(newLambda).Symbol is IMethodSymbol newSymbol) || ParameterTypesDoNotMatch(symbol, newSymbol)) { @@ -154,14 +154,14 @@ private static bool ParameterTypesDoNotMatch(IMethodSymbol method1, IMethodSymbo private static void ReportRedundantNullableConstructorCall(SonarSyntaxNodeReportingContext context) { var objectCreation = ObjectCreationFactory.Create(context.Node); - if (!IsNullableCreation(objectCreation, context.SemanticModel)) + if (!IsNullableCreation(objectCreation, context.Model)) { return; } if (IsInNotVarDeclaration(objectCreation.Expression) || IsInAssignmentOrReturnValue(objectCreation.Expression) - || IsInArgumentAndCanBeChanged(objectCreation, context.SemanticModel)) + || IsInArgumentAndCanBeChanged(objectCreation, context.Model)) { ReportIssueOnRedundantObjectCreation(context, objectCreation.Expression, "explicit nullable type creation", RedundancyType.ExplicitNullable); } @@ -237,13 +237,13 @@ private static void ReportRedundantArrayTypeSpecifier(SonarSyntaxNodeReportingCo return; } - if (!(context.SemanticModel.GetTypeInfo(array.Type).Type is IArrayTypeSymbol arrayType)) + if (!(context.Model.GetTypeInfo(array.Type).Type is IArrayTypeSymbol arrayType)) { return; } var canBeSimplified = array.Initializer.Expressions - .Select(exp => context.SemanticModel.GetTypeInfo(exp).Type) + .Select(exp => context.Model.GetTypeInfo(exp).Type) .All(type => Equals(type, arrayType.ElementType)); if (canBeSimplified) @@ -280,16 +280,16 @@ private static void ReportOnExplicitDelegateCreation(SonarSyntaxNodeReportingCon return; } - if (!IsDelegateCreation(objectCreation, context.SemanticModel)) + if (!IsDelegateCreation(objectCreation, context.Model)) { return; } - if (IsInDeclarationNotVarNotDelegate(objectCreation.Expression, context.SemanticModel) - || IsAssignmentNotDelegate(objectCreation.Expression, context.SemanticModel) - || IsReturnValueNotDelegate(objectCreation.Expression, context.SemanticModel) - || IsInArgumentAndCanBeChanged(objectCreation, context.SemanticModel, - invocation => invocation.ArgumentList.Arguments.Any(a => IsDynamic(a, context.SemanticModel)))) + if (IsInDeclarationNotVarNotDelegate(objectCreation.Expression, context.Model) + || IsAssignmentNotDelegate(objectCreation.Expression, context.Model) + || IsReturnValueNotDelegate(objectCreation.Expression, context.Model) + || IsInArgumentAndCanBeChanged(objectCreation, context.Model, + invocation => invocation.ArgumentList.Arguments.Any(a => IsDynamic(a, context.Model)))) { ReportIssueOnRedundantObjectCreation(context, objectCreation.Expression, "explicit delegate creation", RedundancyType.ExplicitDelegate); } @@ -360,7 +360,7 @@ private static void ReportOnRedundantParameterList(SonarSyntaxNodeReportingConte return; } - if (!(context.SemanticModel.GetSymbolInfo(anonymousMethod).Symbol is IMethodSymbol methodSymbol)) + if (!(context.Model.GetSymbolInfo(anonymousMethod).Symbol is IMethodSymbol methodSymbol)) { return; } @@ -370,7 +370,7 @@ private static void ReportOnRedundantParameterList(SonarSyntaxNodeReportingConte var usedParameters = anonymousMethod.Body.DescendantNodes() .OfType() .Where(id => parameterNames.Contains(id.Identifier.ValueText)) - .Select(id => context.SemanticModel.GetSymbolInfo(id).Symbol as IParameterSymbol) + .Select(id => context.Model.GetSymbolInfo(id).Symbol as IParameterSymbol) .WhereNotNull() .ToHashSet(); diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/RedundantInheritanceList.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/RedundantInheritanceList.cs index cf5af3c206a..55b368e06d4 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/RedundantInheritanceList.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/RedundantInheritanceList.cs @@ -63,7 +63,7 @@ protected override void Initialize(SonarAnalysisContext context) => private static void ReportRedundantBaseType(SonarSyntaxNodeReportingContext context, BaseTypeDeclarationSyntax typeDeclaration, KnownType redundantType, string message) { var baseTypeSyntax = typeDeclaration.BaseList.Types.First().Type; - if (context.SemanticModel.GetSymbolInfo(baseTypeSyntax).Symbol is ITypeSymbol baseTypeSymbol + if (context.Model.GetSymbolInfo(baseTypeSyntax).Symbol is ITypeSymbol baseTypeSymbol && baseTypeSymbol.Is(redundantType)) { var location = GetLocationWithToken(baseTypeSyntax, typeDeclaration.BaseList.Types); @@ -73,26 +73,26 @@ private static void ReportRedundantBaseType(SonarSyntaxNodeReportingContext cont private static void ReportRedundantInterfaces(SonarSyntaxNodeReportingContext context, BaseTypeDeclarationSyntax typeDeclaration) { - var declaredType = context.SemanticModel.GetDeclaredSymbol(typeDeclaration); + var declaredType = context.Model.GetDeclaredSymbol(typeDeclaration); if (declaredType is null) { return; } var baseList = typeDeclaration.BaseList; - var interfaceTypesWithAllInterfaces = GetImplementedInterfaceMappings(baseList, context.SemanticModel); + var interfaceTypesWithAllInterfaces = GetImplementedInterfaceMappings(baseList, context.Model); for (var i = 0; i < baseList.Types.Count; i++) { var baseType = baseList.Types[i]; - if (context.SemanticModel.GetSymbolInfo(baseType.Type).Symbol is INamedTypeSymbol interfaceType + if (context.Model.GetSymbolInfo(baseType.Type).Symbol is INamedTypeSymbol interfaceType && interfaceType.IsInterface() && CollidingDeclaration(declaredType, interfaceType, interfaceTypesWithAllInterfaces) is { } collidingDeclaration) { var location = GetLocationWithToken(baseType.Type, baseList.Types); var message = string.Format(MessageAlreadyImplements, - collidingDeclaration.ToMinimalDisplayString(context.SemanticModel, baseType.Type.SpanStart), - interfaceType.ToMinimalDisplayString(context.SemanticModel, baseType.Type.SpanStart)); + collidingDeclaration.ToMinimalDisplayString(context.Model, baseType.Type.SpanStart), + interfaceType.ToMinimalDisplayString(context.Model, baseType.Type.SpanStart)); context.ReportIssue(Rule, location, DiagnosticsProperties(i), message); } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/RedundantJumpStatement.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/RedundantJumpStatement.cs index bca58ef0104..2bef96a81e2 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/RedundantJumpStatement.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/RedundantJumpStatement.cs @@ -59,7 +59,7 @@ protected override void Initialize(SonarAnalysisContext context) private static void CheckForRedundantJumps(SonarSyntaxNodeReportingContext context) { - if (!CSharpControlFlowGraph.TryGet(context.Node, context.SemanticModel, out var cfg)) + if (!CSharpControlFlowGraph.TryGet(context.Node, context.Model, out var cfg)) { return; } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/RedundantModifier.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/RedundantModifier.cs index ec30ff52d66..85ab6d09100 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/RedundantModifier.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/RedundantModifier.cs @@ -100,7 +100,7 @@ private static void CheckForUnnecessaryUnsafeBlocksBelow(SonarSyntaxNodeReportin else { MarkAllUnsafeBlockInside(context, typeDeclaration); - if (!HasUnsafeConstructInside(typeDeclaration, context.SemanticModel)) + if (!HasUnsafeConstructInside(typeDeclaration, context.Model)) { ReportOnUnsafeBlock(context, unsafeKeyword.GetLocation()); } @@ -113,7 +113,7 @@ private static void CheckForUnnecessaryUnsafeBlocksInMember(SonarSyntaxNodeRepor if (unsafeKeyword != default) { MarkAllUnsafeBlockInside(context, member); - if (!HasUnsafeConstructInside(member, context.SemanticModel)) + if (!HasUnsafeConstructInside(member, context.Model)) { ReportOnUnsafeBlock(context, unsafeKeyword.GetLocation()); } @@ -128,7 +128,7 @@ private static void CheckForUnnecessaryUnsafeBlocksInMember(SonarSyntaxNodeRepor foreach (var topLevelUnsafeBlock in topLevelUnsafeBlocks) { MarkAllUnsafeBlockInside(context, topLevelUnsafeBlock); - if (!HasUnsafeConstructInside(member, context.SemanticModel)) + if (!HasUnsafeConstructInside(member, context.Model)) { ReportOnUnsafeBlock(context, topLevelUnsafeBlock.UnsafeKeyword.GetLocation()); } @@ -190,7 +190,7 @@ private static void CheckTypeDeclarationForRedundantPartial(SonarSyntaxNodeRepor var typeDeclaration = (TypeDeclarationSyntax)context.Node; if (!context.IsRedundantPositionalRecordContext() && typeDeclaration.Modifiers.Any(SyntaxKind.PartialKeyword) - && context.SemanticModel.GetDeclaredSymbol(typeDeclaration) is { DeclaringSyntaxReferences.Length: <= 1 }) + && context.Model.GetDeclaredSymbol(typeDeclaration) is { DeclaringSyntaxReferences.Length: <= 1 }) { var keyword = typeDeclaration.Modifiers.First(m => m.IsKind(SyntaxKind.PartialKeyword)); context.ReportIssue(Rule, keyword, "partial", "gratuitous"); @@ -331,15 +331,15 @@ private void SetHasIntegralOperation(CastExpressionSyntax node) { if (!currentContextHasIntegralOperation) { - var expressionType = context.SemanticModel.GetTypeInfo(node.Expression).Type; - var castedToType = context.SemanticModel.GetTypeInfo(node.Type).Type; + var expressionType = context.Model.GetTypeInfo(node.Expression).Type; + var castedToType = context.Model.GetTypeInfo(node.Type).Type; currentContextHasIntegralOperation = castedToType is not null && expressionType is not null && castedToType.IsAny(KnownType.IntegralNumbers); } } private void SetHasIntegralOperation(ExpressionSyntax node) => currentContextHasIntegralOperation = currentContextHasIntegralOperation - || (context.SemanticModel.GetSymbolInfo(node).Symbol is IMethodSymbol methodSymbol && methodSymbol.ReceiverType.IsAny(KnownType.IntegralNumbers)); + || (context.Model.GetSymbolInfo(node).Symbol is IMethodSymbol methodSymbol && methodSymbol.ReceiverType.IsAny(KnownType.IntegralNumbers)); } } } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/RedundantNullableTypeComparison.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/RedundantNullableTypeComparison.cs index 17796bb503a..39b270103bf 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/RedundantNullableTypeComparison.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/RedundantNullableTypeComparison.cs @@ -42,7 +42,7 @@ protected override void Initialize(SonarAnalysisContext context) private static void CheckGetTypeAndTypeOfEquality(SonarSyntaxNodeReportingContext context, ExpressionSyntax sideA, ExpressionSyntax sideB, Location location) { - if (!(sideA as InvocationExpressionSyntax).IsGetTypeCall(context.SemanticModel)) + if (!(sideA as InvocationExpressionSyntax).IsGetTypeCall(context.Model)) { return; } @@ -53,7 +53,7 @@ private static void CheckGetTypeAndTypeOfEquality(SonarSyntaxNodeReportingContex return; } - var typeSymbol = context.SemanticModel.GetTypeInfo(typeSyntax).Type; + var typeSymbol = context.Model.GetTypeInfo(typeSyntax).Type; if (typeSymbol != null && typeSymbol.OriginalDefinition.Is(KnownType.System_Nullable_T)) { diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/RedundantToArrayCall.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/RedundantToArrayCall.cs index cb2686046ba..acac75fcc8e 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/RedundantToArrayCall.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/RedundantToArrayCall.cs @@ -55,7 +55,7 @@ private static MemberAccessExpressionSyntax GetRedundantMemberAccess(SonarSyntax bool IsTargetMethod(MemberAccessExpressionSyntax memberAccess) => memberAccess.Name.Identifier.ValueText == targetMethodName - && context.SemanticModel.GetSymbolInfo(invocation).Symbol is IMethodSymbol methodSymbol + && context.Model.GetSymbolInfo(invocation).Symbol is IMethodSymbol methodSymbol && methodSymbol.IsInType(targetKnownType) && methodSymbol.Parameters.Length == 0; } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/RedundantToStringCall.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/RedundantToStringCall.cs index cf5b8e5f79d..e5b28e35789 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/RedundantToStringCall.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/RedundantToStringCall.cs @@ -44,7 +44,7 @@ private static void CheckRightSideOfAddAssignmentsForToStringCall(SonarAnalysisC c => { var assignment = (AssignmentExpressionSyntax)c.Node; - var operation = c.SemanticModel.GetSymbolInfo(assignment).Symbol as IMethodSymbol; + var operation = c.Model.GetSymbolInfo(assignment).Symbol as IMethodSymbol; if (!IsOperationAddOnString(operation)) { return; @@ -61,7 +61,7 @@ private static void CheckSidesOfAddExpressionsForToStringCall(SonarAnalysisConte c => { var binary = (BinaryExpressionSyntax)c.Node; - var operation = c.SemanticModel.GetSymbolInfo(binary).Symbol as IMethodSymbol; + var operation = c.Model.GetSymbolInfo(binary).Symbol as IMethodSymbol; if (!IsOperationAddOnString(operation)) { return; @@ -79,7 +79,7 @@ private static void CheckToStringInvocationsOnStringAndInStringFormat(SonarAnaly c => { var invocation = (InvocationExpressionSyntax)c.Node; - if (!IsArgumentlessToStringCallNotOnBaseExpression(invocation, c.SemanticModel, out var location, out var methodSymbol)) + if (!IsArgumentlessToStringCallNotOnBaseExpression(invocation, c.Model, out var location, out var methodSymbol)) { return; } @@ -90,7 +90,7 @@ private static void CheckToStringInvocationsOnStringAndInStringFormat(SonarAnaly return; } - if (!TryGetExpressionTypeOfOwner(invocation, c.SemanticModel, out var subExpressionType) || + if (!TryGetExpressionTypeOfOwner(invocation, c.Model, out var subExpressionType) || subExpressionType.IsValueType) { return; @@ -98,12 +98,12 @@ private static void CheckToStringInvocationsOnStringAndInStringFormat(SonarAnaly var stringFormatArgument = invocation?.Parent as ArgumentSyntax; if (!(stringFormatArgument?.Parent?.Parent is InvocationExpressionSyntax stringFormatInvocation) || - !IsStringFormatCall(c.SemanticModel.GetSymbolInfo(stringFormatInvocation).Symbol as IMethodSymbol)) + !IsStringFormatCall(c.Model.GetSymbolInfo(stringFormatInvocation).Symbol as IMethodSymbol)) { return; } - var parameterLookup = new CSharpMethodParameterLookup(stringFormatInvocation, c.SemanticModel); + var parameterLookup = new CSharpMethodParameterLookup(stringFormatInvocation, c.Model); if (parameterLookup.TryGetSymbol(stringFormatArgument, out var argParameter) && argParameter.Name.StartsWith("arg", StringComparison.Ordinal)) { @@ -132,19 +132,19 @@ private static void CheckRightExpressionForRemovableToStringCall(SonarSyntaxNode private static void CheckExpressionForRemovableToStringCall(SonarSyntaxNodeReportingContext context, ExpressionSyntax expressionWithToStringCall, ExpressionSyntax otherOperandOfAddition, int checkedSideIndex) { - if (!IsArgumentlessToStringCallNotOnBaseExpression(expressionWithToStringCall, context.SemanticModel, out var location, out var methodSymbol) || + if (!IsArgumentlessToStringCallNotOnBaseExpression(expressionWithToStringCall, context.Model, out var location, out var methodSymbol) || methodSymbol.IsInType(KnownType.System_String)) { return; } - var sideBType = context.SemanticModel.GetTypeInfo(otherOperandOfAddition).Type; + var sideBType = context.Model.GetTypeInfo(otherOperandOfAddition).Type; if (!sideBType.Is(KnownType.System_String)) { return; } - if (!TryGetExpressionTypeOfOwner((InvocationExpressionSyntax)expressionWithToStringCall, context.SemanticModel, out var subExpressionType) || + if (!TryGetExpressionTypeOfOwner((InvocationExpressionSyntax)expressionWithToStringCall, context.Model, out var subExpressionType) || subExpressionType.IsValueType) { return; diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/ReferenceEqualityCheckWhenEqualsExists.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/ReferenceEqualityCheckWhenEqualsExists.cs index 0f10c5301db..b24473a04c1 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/ReferenceEqualityCheckWhenEqualsExists.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/ReferenceEqualityCheckWhenEqualsExists.cs @@ -55,13 +55,13 @@ protected override void Initialize(SonarAnalysisContext context) => c => { var binary = (BinaryExpressionSyntax)c.Node; - if (!IsBinaryCandidateForReporting(binary, c.SemanticModel)) + if (!IsBinaryCandidateForReporting(binary, c.Model)) { return; } - var typeLeft = c.SemanticModel.GetTypeInfo(binary.Left).Type; - var typeRight = c.SemanticModel.GetTypeInfo(binary.Right).Type; + var typeLeft = c.Model.GetTypeInfo(binary.Left).Type; + var typeRight = c.Model.GetTypeInfo(binary.Right).Type; if (IsAllowedTypeOrNull(typeLeft) || IsAllowedTypeOrNull(typeRight)) { return; diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/ReferenceEqualsOnValueType.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/ReferenceEqualsOnValueType.cs index c87fd1d7b88..91408dc5786 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/ReferenceEqualsOnValueType.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/ReferenceEqualsOnValueType.cs @@ -36,10 +36,10 @@ protected override void Initialize(SonarAnalysisContext context) { var invocation = (InvocationExpressionSyntax) c.Node; - var methodSymbol = c.SemanticModel.GetSymbolInfo(invocation).Symbol as IMethodSymbol; + var methodSymbol = c.Model.GetSymbolInfo(invocation).Symbol as IMethodSymbol; if (methodSymbol.IsInType(KnownType.System_Object) && methodSymbol.Name == ReferenceEqualsName && - AnyArgumentIsValueType(invocation.ArgumentList, c.SemanticModel)) + AnyArgumentIsValueType(invocation.ArgumentList, c.Model)) { c.ReportIssue(rule, invocation.Expression); } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/RequireAttributeUsageAttribute.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/RequireAttributeUsageAttribute.cs index 6779f7bfb7d..d0439d20d05 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/RequireAttributeUsageAttribute.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/RequireAttributeUsageAttribute.cs @@ -32,7 +32,7 @@ protected override void Initialize(SonarAnalysisContext context) => { var classDeclaration = (ClassDeclarationSyntax)c.Node; - if (c.SemanticModel.GetDeclaredSymbol(classDeclaration) is { IsAbstract: false } classSymbol + if (c.Model.GetDeclaredSymbol(classDeclaration) is { IsAbstract: false } classSymbol && classSymbol.DerivesFrom(KnownType.System_Attribute) && !classSymbol.HasAttribute(KnownType.System_AttributeUsageAttribute)) { diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/ReturnEmptyCollectionInsteadOfNull.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/ReturnEmptyCollectionInsteadOfNull.cs index 9692eba0946..df23d9bfce7 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/ReturnEmptyCollectionInsteadOfNull.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/ReturnEmptyCollectionInsteadOfNull.cs @@ -76,7 +76,7 @@ private static bool IsReturningCollection(SonarSyntaxNodeReportingContext contex private static ITypeSymbol GetType(SonarSyntaxNodeReportingContext context) { - var symbol = context.SemanticModel.GetDeclaredSymbol(context.Node); + var symbol = context.Model.GetDeclaredSymbol(context.Node); return symbol is IPropertySymbol property ? property.Type : ((IMethodSymbol)symbol).ReturnType; } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/ReturnValueIgnored.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/ReturnValueIgnored.cs index 7e515059a81..013e832b687 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/ReturnValueIgnored.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/ReturnValueIgnored.cs @@ -78,7 +78,7 @@ protected override void Initialize(SonarAnalysisContext context) { var lambda = (LambdaExpressionSyntax)c.Node; - if (c.SemanticModel.GetSymbolInfo(lambda).Symbol is not IMethodSymbol { ReturnsVoid: true } symbol) + if (c.Model.GetSymbolInfo(lambda).Symbol is not IMethodSymbol { ReturnsVoid: true } symbol) { return; } @@ -93,7 +93,7 @@ protected override void Initialize(SonarAnalysisContext context) private static void CheckExpressionForPureMethod(SonarSyntaxNodeReportingContext context, ExpressionSyntax expression) { if (expression is InvocationExpressionSyntax invocation - && context.SemanticModel.GetSymbolInfo(invocation).Symbol is IMethodSymbol { ReturnsVoid: false } invokedMethodSymbol + && context.Model.GetSymbolInfo(invocation).Symbol is IMethodSymbol { ReturnsVoid: false } invokedMethodSymbol && invokedMethodSymbol.Parameters.All(p => p.RefKind == RefKind.None) && IsSideEffectFreeOrPure(invokedMethodSymbol)) { diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/ReuseClientBase.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/ReuseClientBase.cs index 2546d20d388..dfb168df19a 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/ReuseClientBase.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/ReuseClientBase.cs @@ -36,7 +36,7 @@ protected static bool IsAssignedForReuse(SonarSyntaxNodeReportingContext context protected bool IsReusableClient(SonarSyntaxNodeReportingContext context) { var objectCreation = ObjectCreationFactory.Create(context.Node); - return ReusableClients.Any(x => objectCreation.IsKnownType(x, context.SemanticModel)); + return ReusableClients.Any(x => objectCreation.IsKnownType(x, context.Model)); } private static bool IsInVariableDeclaration(SyntaxNode node) => @@ -52,5 +52,5 @@ private static bool IsInConditionalCode(SyntaxNode node) => private static bool IsAssignedToStaticFieldOrProperty(SonarSyntaxNodeReportingContext context) => context.Node.Parent.WalkUpParentheses() is AssignmentExpressionSyntax assignment - && context.SemanticModel.GetSymbolInfo(assignment.Left, context.Cancel).Symbol is { IsStatic: true, Kind: SymbolKind.Field or SymbolKind.Property }; + && context.Model.GetSymbolInfo(assignment.Left, context.Cancel).Symbol is { IsStatic: true, Kind: SymbolKind.Field or SymbolKind.Property }; } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/SerializationConstructorsShouldBeSecured.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/SerializationConstructorsShouldBeSecured.cs index 60fc488b699..e6c0cfa3b30 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/SerializationConstructorsShouldBeSecured.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/SerializationConstructorsShouldBeSecured.cs @@ -43,7 +43,7 @@ private static void FindPossibleViolations(SonarSyntaxNodeReportingContext c) return; } - var serializationConstructor = c.SemanticModel.GetDeclaredSymbol(constructorSyntax); + var serializationConstructor = c.Model.GetDeclaredSymbol(constructorSyntax); if (!serializationConstructor.IsSerializationConstructor()) { return; @@ -55,7 +55,7 @@ private static void FindPossibleViolations(SonarSyntaxNodeReportingContext c) return; } - var isAssemblyIsPartiallyTrusted = c.SemanticModel.Compilation.Assembly + var isAssemblyIsPartiallyTrusted = c.Model.Compilation.Assembly .HasAttribute(KnownType.System_Security_AllowPartiallyTrustedCallersAttribute); if (!isAssemblyIsPartiallyTrusted) { diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/SetLocaleForDataTypes.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/SetLocaleForDataTypes.cs index 7936432eaab..0a35c55996b 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/SetLocaleForDataTypes.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/SetLocaleForDataTypes.cs @@ -47,7 +47,7 @@ protected override void Initialize(SonarAnalysisContext context) => private static void ProcessObjectCreations(SonarSyntaxNodeReportingContext c, IDictionary symbolsWhereTypeIsCreated) { - if (GetSymbolFromConstructorInvocation(c.Node, c.SemanticModel) is ITypeSymbol objectType + if (GetSymbolFromConstructorInvocation(c.Node, c.Model) is ITypeSymbol objectType && objectType.IsAny(CheckedTypes) && GetAssignmentTargetVariable(c.Node) is { } variableSyntax) { @@ -57,8 +57,8 @@ private static void ProcessObjectCreations(SonarSyntaxNodeReportingContext c, ID } var variableSymbol = variableSyntax is IdentifierNameSyntax - ? c.SemanticModel.GetSymbolInfo(variableSyntax).Symbol - : c.SemanticModel.GetDeclaredSymbol(variableSyntax); + ? c.Model.GetSymbolInfo(variableSyntax).Symbol + : c.Model.GetDeclaredSymbol(variableSyntax); if (variableSymbol != null && !symbolsWhereTypeIsCreated.ContainsKey(variableSymbol)) { @@ -71,10 +71,10 @@ private static void ProcessSimpleAssignments(SonarSyntaxNodeReportingContext c, { var assignmentExpression = (AssignmentExpressionSyntax)c.Node; var variableSymbols = assignmentExpression.AssignmentTargets() - .Where(x => c.SemanticModel.GetSymbolInfo(x).Symbol is IPropertySymbol propertySymbol + .Where(x => c.Model.GetSymbolInfo(x).Symbol is IPropertySymbol propertySymbol && propertySymbol.Name == "Locale" && propertySymbol.ContainingType.IsAny(CheckedTypes)) - .Select(x => GetAccessedVariable(x, c.SemanticModel)) + .Select(x => GetAccessedVariable(x, c.Model)) .WhereNotNull(); symbolsWhereLocaleIsSet.UnionWith(variableSymbols); } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/SpecifyIFormatProviderOrCultureInfo.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/SpecifyIFormatProviderOrCultureInfo.cs index 2071da4915d..93a2acb2064 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/SpecifyIFormatProviderOrCultureInfo.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/SpecifyIFormatProviderOrCultureInfo.cs @@ -60,10 +60,10 @@ protected override void Initialize(SonarAnalysisContext context) { var invocation = (InvocationExpressionSyntax)c.Node; if (invocation.Expression != null && - c.SemanticModel.GetSymbolInfo(invocation.Expression).Symbol is IMethodSymbol methodSymbol && + c.Model.GetSymbolInfo(invocation.Expression).Symbol is IMethodSymbol methodSymbol && !IsIgnored(methodSymbol) && CanPotentiallyRaise(methodSymbol) && - SonarAnalyzer.CSharp.Syntax.Extensions.InvocationExpressionSyntaxExtensions.HasOverloadWithType(invocation, c.SemanticModel, formatAndCultureType)) + SonarAnalyzer.CSharp.Syntax.Extensions.InvocationExpressionSyntaxExtensions.HasOverloadWithType(invocation, c.Model, formatAndCultureType)) { c.ReportIssue(rule, invocation, invocation.Expression.ToString()); } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/SpecifyStringComparison.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/SpecifyStringComparison.cs index 1d928765077..7e8385961b1 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/SpecifyStringComparison.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/SpecifyStringComparison.cs @@ -37,8 +37,8 @@ protected override void Initialize(SonarAnalysisContext context) var invocation = (InvocationExpressionSyntax)c.Node; if (invocation.Expression != null && - IsInvalidCall(invocation.Expression, c.SemanticModel) && - SonarAnalyzer.CSharp.Syntax.Extensions.InvocationExpressionSyntaxExtensions.HasOverloadWithType(invocation, c.SemanticModel, stringComparisonType)) + IsInvalidCall(invocation.Expression, c.Model) && + SonarAnalyzer.CSharp.Syntax.Extensions.InvocationExpressionSyntaxExtensions.HasOverloadWithType(invocation, c.Model, stringComparisonType)) { c.ReportIssue(rule, invocation, invocation.Expression.ToString()); } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/SqlKeywordsDelimitedBySpace.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/SqlKeywordsDelimitedBySpace.cs index b5f2aae07e8..de703b5617c 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/SqlKeywordsDelimitedBySpace.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/SqlKeywordsDelimitedBySpace.cs @@ -192,7 +192,7 @@ private bool TryGetStringWrapper(ExpressionSyntax expression, out StringWrapper // if this is a nested binary, we skip it so that we can raise when we visit it. // Otherwise, FindConstantValue will merge it into one value. else if (expression.RemoveParentheses() is not BinaryExpressionSyntax - && expression.FindConstantValue(context.SemanticModel) is string constantValue) + && expression.FindConstantValue(context.Model) is string constantValue) { stringWrapper = new StringWrapper(expression, constantValue); return true; @@ -238,7 +238,7 @@ private bool TryGetConstantValues(InterpolatedStringExpressionSyntax interpolate foreach (var content in interpolatedStringExpression.Contents) { if (content is InterpolationSyntax interpolation - && interpolation.Expression.FindConstantValue(context.SemanticModel) is string constantValue) + && interpolation.Expression.FindConstantValue(context.Model) is string constantValue) { parts.Add(new StringWrapper(content, constantValue)); } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/StaticFieldInGenericClass.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/StaticFieldInGenericClass.cs index 46814a81b39..cd171fd5f38 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/StaticFieldInGenericClass.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/StaticFieldInGenericClass.cs @@ -81,7 +81,7 @@ private static string[] CollectTypeParameterNames(SyntaxNode current) private static bool HasGenericType(SonarSyntaxNodeReportingContext context, SyntaxNode root, string[] typeParameterNames) => root.DescendantNodesAndSelf() .OfType() - .Any(x => typeParameterNames.Contains(x.Identifier.Value) && context.SemanticModel.GetSymbolInfo(x).Symbol is { Kind: SymbolKind.TypeParameter }); + .Any(x => typeParameterNames.Contains(x.Identifier.Value) && context.Model.GetSymbolInfo(x).Symbol is { Kind: SymbolKind.TypeParameter }); private static bool BaseTypeHasGenericTypeArgument(TypeDeclarationSyntax typeDeclaration, string[] typeParameterNames) => typeDeclaration.BaseList is { } baseList && baseList.Types.Any(x => x.Type is GenericNameSyntax genericType && HasGenericTypeArgument(genericType, typeParameterNames)); diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/StaticFieldInitializerOrder.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/StaticFieldInitializerOrder.cs index f4a1668bb8f..8ac24283c2c 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/StaticFieldInitializerOrder.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/StaticFieldInitializerOrder.cs @@ -48,12 +48,12 @@ protected override void Initialize(SonarAnalysisContext context) => { return; } - var containingType = c.SemanticModel.GetDeclaredSymbol(variables[0]).ContainingType; + var containingType = c.Model.GetDeclaredSymbol(variables[0]).ContainingType; var typeDeclaration = fieldDeclaration.FirstAncestorOrSelf(x => x.IsAnyKind(EnclosingTypes)); foreach (var variable in variables) { - if (IdentifierFields(variable, containingType, c.SemanticModel) + if (IdentifierFields(variable, containingType, c.Model) .Select(x => new IdentifierTypeDeclarationMapping(x, GetTypeDeclaration(x))) .Any(x => x.TypeDeclaration is not null && (x.TypeDeclaration != typeDeclaration || x.Field.DeclaringSyntaxReferences.First().Span.Start > variable.SpanStart))) { diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/StaticFieldVisible.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/StaticFieldVisible.cs index 3d8f68e76c6..16b8fb885af 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/StaticFieldVisible.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/StaticFieldVisible.cs @@ -30,7 +30,7 @@ protected override void Initialize(SonarAnalysisContext context) => context.RegisterNodeAction( c => { - foreach (var diagnostic in GetDiagnostics(c.SemanticModel, (FieldDeclarationSyntax)c.Node)) + foreach (var diagnostic in GetDiagnostics(c.Model, (FieldDeclarationSyntax)c.Node)) { c.ReportIssue(diagnostic); } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/StaticFieldWrittenFrom.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/StaticFieldWrittenFrom.cs index 4d3234e9de0..c8b2bb35703 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/StaticFieldWrittenFrom.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/StaticFieldWrittenFrom.cs @@ -41,7 +41,7 @@ protected sealed override void Initialize(SonarAnalysisContext context) => foreach (var target in assignment.AssignmentTargets()) { - if (GetStaticFieldSymbol(c.SemanticModel, target) is { } fieldSymbol) + if (GetStaticFieldSymbol(c.Model, target) is { } fieldSymbol) { locationsForFields.Add(fieldSymbol, target.CreateLocation(to: assignment.OperatorToken)); } @@ -64,7 +64,7 @@ protected sealed override void Initialize(SonarAnalysisContext context) => cbc.RegisterNodeAction(c => { var unary = (PrefixUnaryExpressionSyntax)c.Node; - CollectLocationOfStaticField(c.SemanticModel, locationsForFields, unary.Operand); + CollectLocationOfStaticField(c.Model, locationsForFields, unary.Operand); }, SyntaxKind.PreDecrementExpression, SyntaxKind.PreIncrementExpression); @@ -72,7 +72,7 @@ protected sealed override void Initialize(SonarAnalysisContext context) => cbc.RegisterNodeAction(c => { var unary = (PostfixUnaryExpressionSyntax)c.Node; - CollectLocationOfStaticField(c.SemanticModel, locationsForFields, unary.Operand); + CollectLocationOfStaticField(c.Model, locationsForFields, unary.Operand); }, SyntaxKind.PostDecrementExpression, SyntaxKind.PostIncrementExpression); diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/StaticSealedClassProtectedMembers.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/StaticSealedClassProtectedMembers.cs index 7fabf4f194f..4d698a2783b 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/StaticSealedClassProtectedMembers.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/StaticSealedClassProtectedMembers.cs @@ -56,7 +56,7 @@ protected override void Initialize(SonarAnalysisContext context) private static void ReportDiagnostics(SonarSyntaxNodeReportingContext context, SyntaxNode declaration, IEnumerable modifiers) { - var symbol = context.SemanticModel.GetDeclaredSymbol(declaration); + var symbol = context.Model.GetDeclaredSymbol(declaration); if (symbol == null || symbol.IsOverride || !symbol.ContainingType.IsSealed) { return; diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/StreamReadStatement.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/StreamReadStatement.cs index 104dcf6c419..4eba17745a7 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/StreamReadStatement.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/StreamReadStatement.cs @@ -49,7 +49,7 @@ protected override void Initialize(SonarAnalysisContext context) => if (expression is InvocationExpressionSyntax invocation && invocation.GetMethodCallIdentifier() is { } methodIdentifier && ReadMethodNames.Contains(methodIdentifier.Text) - && c.SemanticModel.GetSymbolInfo(expression).Symbol is IMethodSymbol method + && c.Model.GetSymbolInfo(expression).Symbol is IMethodSymbol method && (method.ContainingType.Is(KnownType.System_IO_Stream) || (method.IsOverride && method.ContainingType.DerivesOrImplements(KnownType.System_IO_Stream)))) { diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/StringFormatValidator.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/StringFormatValidator.cs index 0ac4a516eab..78ff1291574 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/StringFormatValidator.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/StringFormatValidator.cs @@ -81,7 +81,7 @@ private static void CheckForFormatStringIssues(SonarSyntaxNodeReportingContext a { var invocation = (InvocationExpressionSyntax)analysisContext.Node; - if (!(analysisContext.SemanticModel.GetSymbolInfo(invocation).Symbol is IMethodSymbol methodSymbol) + if (!(analysisContext.Model.GetSymbolInfo(invocation).Symbol is IMethodSymbol methodSymbol) || !methodSymbol.Parameters.Any() || methodSymbol.Parameters.All(x => x.Name != "format")) { @@ -100,7 +100,7 @@ private static void CheckForFormatStringIssues(SonarSyntaxNodeReportingContext a var formatStringExpression = invocation.ArgumentList.Arguments[formatArgumentIndex].Expression; var failure = formatStringExpression.IsNullLiteral() ? new ValidationFailureWithAdditionalData(ValidationFailure.NullFormatString) - : TryParseAndValidate(formatStringExpression.FindStringConstant(analysisContext.SemanticModel), invocation.ArgumentList, formatArgumentIndex, analysisContext.SemanticModel); + : TryParseAndValidate(formatStringExpression.FindStringConstant(analysisContext.Model), invocation.ArgumentList, formatArgumentIndex, analysisContext.Model); if (failure == null || CanIgnoreFailure(failure, currentMethodSignature.Name, invocation.ArgumentList.Arguments.Count)) { return; diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/StringOffsetMethods.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/StringOffsetMethods.cs index 5d163fbfc03..32d61072aa0 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/StringOffsetMethods.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/StringOffsetMethods.cs @@ -40,7 +40,7 @@ protected override void Initialize(SonarAnalysisContext context) context.RegisterNodeAction(analysisContext => { var invocationExpression = (InvocationExpressionSyntax)analysisContext.Node; - var semanticModel = analysisContext.SemanticModel; + var semanticModel = analysisContext.Model; if (IsTargetMethodInvocation(invocationExpression, semanticModel) && HasSubstringMethodInvocationChild(invocationExpression, semanticModel)) diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/StringOperationWithoutCulture.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/StringOperationWithoutCulture.cs index 0b7d0c9d754..318e51553ed 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/StringOperationWithoutCulture.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/StringOperationWithoutCulture.cs @@ -45,7 +45,7 @@ private static void ReportOnViolation(SonarSyntaxNodeReportingContext context) return; } - if (!(context.SemanticModel.GetSymbolInfo(invocation).Symbol is IMethodSymbol calledMethod)) + if (!(context.Model.GetSymbolInfo(invocation).Symbol is IMethodSymbol calledMethod)) { return; } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/StringOrIntegralTypesForIndexers.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/StringOrIntegralTypesForIndexers.cs index 74e72add803..7d3ddf704c9 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/StringOrIntegralTypesForIndexers.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/StringOrIntegralTypesForIndexers.cs @@ -42,7 +42,7 @@ protected override void Initialize(SonarAnalysisContext context) => var parameter = indexerDeclaration.ParameterList.Parameters.First(); - var parameterSymbol = c.SemanticModel.GetDeclaredSymbol(parameter); + var parameterSymbol = c.Model.GetDeclaredSymbol(parameter); if (parameterSymbol.Type == null || parameterSymbol.Type.TypeKind == TypeKind.Dynamic || parameterSymbol.Type.IsAny(AllowedIndexerTypes) diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/SuppressFinalizeUseless.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/SuppressFinalizeUseless.cs index b2b29480e8d..3514d457e80 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/SuppressFinalizeUseless.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/SuppressFinalizeUseless.cs @@ -33,7 +33,7 @@ protected override void Initialize(SonarAnalysisContext context) c => { var invocation = (InvocationExpressionSyntax)c.Node; - var suppressFinalizeSymbol = c.SemanticModel.GetSymbolInfo(invocation.Expression).Symbol as IMethodSymbol; + var suppressFinalizeSymbol = c.Model.GetSymbolInfo(invocation.Expression).Symbol as IMethodSymbol; if (suppressFinalizeSymbol?.Name != "SuppressFinalize" || !invocation.HasExactlyNArguments(1) || @@ -43,7 +43,7 @@ protected override void Initialize(SonarAnalysisContext context) } var argument = invocation.ArgumentList.Arguments.First(); - var argumentType = c.SemanticModel.GetTypeInfo(argument.Expression).Type as INamedTypeSymbol; + var argumentType = c.Model.GetTypeInfo(argument.Expression).Type as INamedTypeSymbol; if (!argumentType.IsClass() || !argumentType.IsSealed) diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/SwaggerActionReturnType.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/SwaggerActionReturnType.cs index 3b6da567117..80e1f03a980 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/SwaggerActionReturnType.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/SwaggerActionReturnType.cs @@ -77,9 +77,9 @@ protected override void Initialize(SonarAnalysisContext context) => private static InvalidMethodResult InvalidMethod(BaseMethodDeclarationSyntax methodDeclaration, SonarSyntaxNodeReportingContext nodeContext) { - var responseInvocations = FindSuccessResponses(methodDeclaration, nodeContext.SemanticModel); + var responseInvocations = FindSuccessResponses(methodDeclaration, nodeContext.Model); return responseInvocations.Length == 0 - || nodeContext.SemanticModel.GetDeclaredSymbol(methodDeclaration, nodeContext.Cancel) is not { } method + || nodeContext.Model.GetDeclaredSymbol(methodDeclaration, nodeContext.Cancel) is not { } method || !method.IsControllerActionMethod() || !method.ReturnType.DerivesOrImplementsAny(ControllerActionReturnTypes) || method.GetAttributesWithInherited().Any(x => x.AttributeClass.DerivesFrom(KnownType.Microsoft_AspNetCore_Mvc_ApiConventionMethodAttribute) diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/TaskConfigureAwait.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/TaskConfigureAwait.cs index ea405000847..c9ed0a220db 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/TaskConfigureAwait.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/TaskConfigureAwait.cs @@ -38,7 +38,7 @@ protected override void Initialize(SonarAnalysisContext context) => } if (((AwaitExpressionSyntax)c.Node).Expression is { } expression - && c.SemanticModel.GetTypeInfo(expression).Type is { } type + && c.Model.GetTypeInfo(expression).Type is { } type && type.DerivesFrom(KnownType.System_Threading_Tasks_Task)) { c.ReportIssue(rule, expression); diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/TestClassShouldHaveTestMethod.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/TestClassShouldHaveTestMethod.cs index ae8ee311103..0e74b630f0c 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/TestClassShouldHaveTestMethod.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/TestClassShouldHaveTestMethod.cs @@ -41,7 +41,7 @@ protected override void Initialize(SonarAnalysisContext context) => var typeDeclaration = (TypeDeclarationSyntax)c.Node; if (!c.IsRedundantPositionalRecordContext() && !typeDeclaration.Identifier.IsMissing - && c.SemanticModel.GetDeclaredSymbol(typeDeclaration) is { } typeSymbol + && c.Model.GetDeclaredSymbol(typeDeclaration) is { } typeSymbol && IsViolatingRule(typeSymbol) && !IsExceptionToTheRule(typeSymbol)) { diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/TestMethodShouldContainAssertion.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/TestMethodShouldContainAssertion.cs index 53e663a3e86..7b89958ceda 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/TestMethodShouldContainAssertion.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/TestMethodShouldContainAssertion.cs @@ -63,12 +63,12 @@ protected override void Initialize(SonarAnalysisContext context) => var methodDeclaration = MethodDeclarationFactory.Create(c.Node); if (!methodDeclaration.Identifier.IsMissing && methodDeclaration.HasImplementation - && c.SemanticModel.GetDeclaredSymbol(c.Node) is IMethodSymbol methodSymbol + && c.Model.GetDeclaredSymbol(c.Node) is IMethodSymbol methodSymbol && IsTestMethod(methodSymbol, methodDeclaration.IsLocal) && !methodSymbol.HasExpectedExceptionAttribute() && !methodSymbol.HasAssertionInAttribute() && !IsTestIgnored(methodSymbol) - && !ContainsAssertion(c.Node, c.SemanticModel, new HashSet(), 0)) + && !ContainsAssertion(c.Node, c.Model, new HashSet(), 0)) { c.ReportIssue(Rule, methodDeclaration.Identifier); } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/TestMethodShouldHaveCorrectSignature.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/TestMethodShouldHaveCorrectSignature.cs index b4fb8f2038d..5c491261bd5 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/TestMethodShouldHaveCorrectSignature.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/TestMethodShouldHaveCorrectSignature.cs @@ -94,7 +94,7 @@ protected override void Initialize(SonarAnalysisContext context) => private static void AnalyzeMethod(SonarSyntaxNodeReportingContext c) { - if (HasAttributes(c.Node) && c.SemanticModel.GetDeclaredSymbol(c.Node) is IMethodSymbol methodSymbol) + if (HasAttributes(c.Node) && c.Model.GetDeclaredSymbol(c.Node) is IMethodSymbol methodSymbol) { var validator = GetValidator(methodSymbol); var message = validator(c.Node, methodSymbol); diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/TestMethodShouldNotBeIgnored.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/TestMethodShouldNotBeIgnored.cs index dfbb1a0e700..4ce6ad8aae0 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/TestMethodShouldNotBeIgnored.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/TestMethodShouldNotBeIgnored.cs @@ -40,13 +40,13 @@ protected override void Initialize(SonarAnalysisContext context) => var attribute = (AttributeSyntax)c.Node; if (HasReasonPhrase(attribute) || HasTrailingComment(attribute) - || !IsKnownIgnoreAttribute(attribute, c.SemanticModel) + || !IsKnownIgnoreAttribute(attribute, c.Model) || attribute.Parent?.Parent is not { } attributeTarget) { return; } - var attributes = GetAllAttributes(attributeTarget, c.SemanticModel); + var attributes = GetAllAttributes(attributeTarget, c.Model); if (attributes.Any(IsTestOrTestClassAttribute) && !attributes.Any(IsWorkItemAttribute)) diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/ThisShouldNotBeExposedFromConstructors.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/ThisShouldNotBeExposedFromConstructors.cs index 6462808cc81..a3700a87620 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/ThisShouldNotBeExposedFromConstructors.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/ThisShouldNotBeExposedFromConstructors.cs @@ -52,7 +52,7 @@ protected override void Initialize(SonarAnalysisContext context) if (thisExpression != null && !IsClassMember(invocation.Expression) && - c.SemanticModel.GetSymbolInfo(invocation.Expression).Symbol is IMethodSymbol) + c.Model.GetSymbolInfo(invocation.Expression).Symbol is IMethodSymbol) { c.ReportIssue(rule, thisExpression); } @@ -67,7 +67,7 @@ protected override void Initialize(SonarAnalysisContext context) if (IsThisExpression(right) && !IsClassMember(assignment.Left) && - c.SemanticModel.GetSymbolInfo(assignment.Left).Symbol is IPropertySymbol) + c.Model.GetSymbolInfo(assignment.Left).Symbol is IPropertySymbol) { c.ReportIssue(rule, right); } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/ThreadStaticNonStaticField.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/ThreadStaticNonStaticField.cs index 817d58c5d6f..bf6c2df7333 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/ThreadStaticNonStaticField.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/ThreadStaticNonStaticField.cs @@ -33,7 +33,7 @@ protected override void Initialize(SonarAnalysisContext context) => { if ((FieldDeclarationSyntax)c.Node is var fieldDeclaration && !fieldDeclaration.Modifiers.Any(SyntaxKind.StaticKeyword) - && fieldDeclaration.AttributeLists.GetAttributes(KnownType.System_ThreadStaticAttribute, c.SemanticModel).FirstOrDefault() is { } threadStaticAttribute) + && fieldDeclaration.AttributeLists.GetAttributes(KnownType.System_ThreadStaticAttribute, c.Model).FirstOrDefault() is { } threadStaticAttribute) { c.ReportIssue(Rule, threadStaticAttribute.Name); } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/ThreadStaticWithInitializer.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/ThreadStaticWithInitializer.cs index 4b1fac80ec1..d81a25f9cf0 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/ThreadStaticWithInitializer.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/ThreadStaticWithInitializer.cs @@ -34,7 +34,7 @@ protected override void Initialize(SonarAnalysisContext context) => var fieldDeclaration = (FieldDeclarationSyntax)c.Node; if (!fieldDeclaration.Modifiers.Any(SyntaxKind.StaticKeyword) - || !HasThreadStaticAttribute(fieldDeclaration.AttributeLists, c.SemanticModel)) + || !HasThreadStaticAttribute(fieldDeclaration.AttributeLists, c.Model)) { return; } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/TooManyLoggingCalls.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/TooManyLoggingCalls.cs index fe4832c4482..6b277866602 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/TooManyLoggingCalls.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/TooManyLoggingCalls.cs @@ -79,7 +79,7 @@ private void Process(SonarSyntaxNodeReportingContext context) var node = context.Node; if (IsBlockNodeSupported(node)) { - var logCallCollector = new LoggingCallCollector(context.SemanticModel, node); + var logCallCollector = new LoggingCallCollector(context.Model, node); logCallCollector.Visit(node); foreach (var group in logCallCollector.GroupedLoggingInvocations) { diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/TrackNotImplementedException.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/TrackNotImplementedException.cs index 5615b56ebe2..c704a6f8180 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/TrackNotImplementedException.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/TrackNotImplementedException.cs @@ -52,7 +52,7 @@ protected override void Initialize(SonarAnalysisContext context) private static void ReportDiagnostic(SonarSyntaxNodeReportingContext c, ExpressionSyntax newExceptionExpression, SyntaxNode throwExpression) { - if (c.SemanticModel.GetTypeInfo(newExceptionExpression).Type.Is(KnownType.System_NotImplementedException)) + if (c.Model.GetTypeInfo(newExceptionExpression).Type.Is(KnownType.System_NotImplementedException)) { c.ReportIssue(rule, throwExpression); } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/TypeExaminationOnSystemType.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/TypeExaminationOnSystemType.cs index ada20ff1f33..586b1733f7b 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/TypeExaminationOnSystemType.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/TypeExaminationOnSystemType.cs @@ -35,7 +35,7 @@ protected override void Initialize(SonarAnalysisContext context) => var invocation = (InvocationExpressionSyntax)c.Node; if (invocation.Expression.ToStringContainsEitherOr(nameof(Type.IsInstanceOfType), nameof(Type.GetType)) - && c.SemanticModel.GetSymbolInfo(invocation).Symbol is IMethodSymbol methodSymbol) + && c.Model.GetSymbolInfo(invocation).Symbol is IMethodSymbol methodSymbol) { CheckGetTypeCallOnType(c, invocation, methodSymbol); CheckIsInstanceOfTypeCallWithTypeArgument(c, invocation, methodSymbol); @@ -52,14 +52,14 @@ private static void CheckIsInstanceOfTypeCallWithTypeArgument(SonarSyntaxNodeRep var argument = invocation.ArgumentList.Arguments.First().Expression; - var typeInfo = context.SemanticModel.GetTypeInfo(argument).Type; + var typeInfo = context.Model.GetTypeInfo(argument).Type; if (!typeInfo.Is(KnownType.System_Type)) { return; } var invocationInArgument = argument as InvocationExpressionSyntax; - var message = invocationInArgument.IsGetTypeCall(context.SemanticModel) + var message = invocationInArgument.IsGetTypeCall(context.Model) ? MessageIsInstanceOfTypeWithGetType : MessageIsInstanceOfType; @@ -69,13 +69,13 @@ private static void CheckIsInstanceOfTypeCallWithTypeArgument(SonarSyntaxNodeRep private static void CheckGetTypeCallOnType(SonarSyntaxNodeReportingContext context, InvocationExpressionSyntax invocation, IMethodSymbol invokedMethod) { if (!(invocation.Expression is MemberAccessExpressionSyntax memberCall) - || IsException(memberCall, context.SemanticModel) + || IsException(memberCall, context.Model) || !invokedMethod.IsGetTypeCall()) { return; } - var expressionType = context.SemanticModel.GetTypeInfo(memberCall.Expression).Type; + var expressionType = context.Model.GetTypeInfo(memberCall.Expression).Type; if (!expressionType.Is(KnownType.System_Type)) { return; diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/TypeMemberVisibility.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/TypeMemberVisibility.cs index 5b57d57312e..911fdc39fdb 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/TypeMemberVisibility.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/TypeMemberVisibility.cs @@ -42,7 +42,7 @@ protected override void Initialize(SonarAnalysisContext context) => return; } var typeDeclaration = (BaseTypeDeclarationSyntax)c.Node; - var secondaryLocations = GetInvalidMemberLocations(c.SemanticModel, typeDeclaration); + var secondaryLocations = GetInvalidMemberLocations(c.Model, typeDeclaration); if (secondaryLocations.Any()) { c.ReportIssue(Rule, typeDeclaration.Identifier, secondaryLocations); diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/TypeNamesShouldNotMatchNamespaces.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/TypeNamesShouldNotMatchNamespaces.cs index 5c46cdb9bb4..50fd8e3fa63 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/TypeNamesShouldNotMatchNamespaces.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/TypeNamesShouldNotMatchNamespaces.cs @@ -46,7 +46,7 @@ protected override void Initialize(SonarAnalysisContext context) => if (!c.IsRedundantPositionalRecordContext() && c.Node.GetIdentifier() is { } identifier && FrameworkNamespaces.Contains(identifier.ValueText) - && c.SemanticModel.GetDeclaredSymbol(c.Node)?.DeclaredAccessibility == Accessibility.Public) + && c.Model.GetDeclaredSymbol(c.Node)?.DeclaredAccessibility == Accessibility.Public) { c.ReportIssue(Rule, identifier, identifier.ValueText); } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/UnchangedLocalVariablesShouldBeConst.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/UnchangedLocalVariablesShouldBeConst.cs index df3496baafa..a6efa1f2139 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/UnchangedLocalVariablesShouldBeConst.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/UnchangedLocalVariablesShouldBeConst.cs @@ -44,7 +44,7 @@ protected override void Initialize(SonarAnalysisContext context) => return; } - var declaredType = FindDeclarationType(localDeclaration, c.SemanticModel); + var declaredType = FindDeclarationType(localDeclaration, c.Model); if (declaredType == DeclarationType.CannotBeConst) { return; @@ -53,9 +53,9 @@ protected override void Initialize(SonarAnalysisContext context) => localDeclaration.Declaration?.Variables .Where(v => v is { Identifier: { } } // constant string interpolation is only valid in C# 10 and above - && (c.SemanticModel.Compilation.IsAtLeastLanguageVersion(LanguageVersionEx.CSharp10) || !ContainsInterpolation(v)) - && IsInitializedWithCompatibleConstant(v, c.SemanticModel, declaredType) - && !HasMutableUsagesInMethod(c.SemanticModel, v)) + && (c.Model.Compilation.IsAtLeastLanguageVersion(LanguageVersionEx.CSharp10) || !ContainsInterpolation(v)) + && IsInitializedWithCompatibleConstant(v, c.Model, declaredType) + && !HasMutableUsagesInMethod(c.Model, v)) .ToList() .ForEach(x => Report(c, x)); }, @@ -172,7 +172,7 @@ private static void Report(SonarSyntaxNodeReportingContext c, VariableDeclarator Rule, declaratorSyntax.Identifier, declaratorSyntax.Identifier.ValueText, - AdditionalMessageHints(c.SemanticModel, declaratorSyntax)); + AdditionalMessageHints(c.Model, declaratorSyntax)); private static string AdditionalMessageHints(SemanticModel model, VariableDeclaratorSyntax declaratorSyntax) => declaratorSyntax is { Parent: VariableDeclarationSyntax { Type: { IsVar: true } typeSyntax } } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/UnnecessaryBitwiseOperation.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/UnnecessaryBitwiseOperation.cs index 06250b628be..6bd2837cf4f 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/UnnecessaryBitwiseOperation.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/UnnecessaryBitwiseOperation.cs @@ -45,7 +45,7 @@ protected override void Initialize(SonarAnalysisContext context) private void CheckAssignment(SonarSyntaxNodeReportingContext context, int constValueToLookFor) { var assignment = (AssignmentExpressionSyntax)context.Node; - if (FindIntConstant(context.SemanticModel, assignment.Right) is { } constValue + if (FindIntConstant(context.Model, assignment.Right) is { } constValue && constValue == constValueToLookFor) { var location = assignment.Parent is StatementSyntax diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/UnnecessaryMathematicalComparison.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/UnnecessaryMathematicalComparison.cs index c854335b0ee..fe3216e7359 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/UnnecessaryMathematicalComparison.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/UnnecessaryMathematicalComparison.cs @@ -33,12 +33,12 @@ protected override void Initialize(SonarAnalysisContext context) => private static void CheckComparisonOutOfRange(SonarSyntaxNodeReportingContext context) { - if (TryGetConstantValue(context.SemanticModel, (BinaryExpressionSyntax)context.Node, out var constant, out var other) - && context.SemanticModel.GetTypeInfo(other).Type is { } typeSymbolOfOther + if (TryGetConstantValue(context.Model, (BinaryExpressionSyntax)context.Node, out var constant, out var other) + && context.Model.GetTypeInfo(other).Type is { } typeSymbolOfOther && TryGetRange(typeSymbolOfOther) is { } range && range.IsOutOfRange(constant)) { - var typeName = typeSymbolOfOther.ToMinimalDisplayString(context.SemanticModel, other.GetLocation().SourceSpan.Start); + var typeName = typeSymbolOfOther.ToMinimalDisplayString(context.Model, other.GetLocation().SourceSpan.Start); context.ReportIssue(MathComparisonRule, other.Parent, typeName); } } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/UnnecessaryUsings.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/UnnecessaryUsings.cs index c1a73fe2f68..c7feb4b43ba 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/UnnecessaryUsings.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/UnnecessaryUsings.cs @@ -86,7 +86,7 @@ private static void CheckUnnecessaryUsings(SonarSyntaxNodeReportingContext conte { continue; } - if (context.SemanticModel.GetSymbolInfo(usingDirective.Name).Symbol is INamespaceSymbol namespaceSymbol + if (context.Model.GetSymbolInfo(usingDirective.Name).Symbol is INamespaceSymbol namespaceSymbol && !necessaryNamespaces.Any(usedNamespace => usedNamespace.IsSameNamespace(namespaceSymbol))) { context.ReportIssue(Rule, usingDirective); @@ -121,7 +121,7 @@ public override void VisitInitializerExpression(InitializerExpressionSyntax node { foreach (var addExpression in node.Expressions) { - VisitSymbol(context.SemanticModel.GetCollectionInitializerSymbolInfo(addExpression).Symbol); + VisitSymbol(context.Model.GetCollectionInitializerSymbolInfo(addExpression).Symbol); } } base.VisitInitializerExpression(node); @@ -138,7 +138,7 @@ public override void VisitGenericName(GenericNameSyntax node) public override void VisitAwaitExpression(AwaitExpressionSyntax node) { - VisitSymbol(context.SemanticModel.GetAwaitExpressionInfo(node).GetAwaiterMethod); + VisitSymbol(context.Model.GetAwaitExpressionInfo(node).GetAwaiterMethod); base.VisitAwaitExpression(node); } @@ -178,7 +178,7 @@ private void VisitNamespace(SyntaxNode node, SyntaxList us newUsingDirectives.UnionWith(simpleNamespaces.Select(x => new EquivalentNameSyntax(x.Name))); // We visit the namespace declaration with the updated set of parent 'usings', this is needed in case of nested namespaces - var visitingNamespace = context.SemanticModel.GetSymbolInfo(name).Symbol as INamespaceSymbol; + var visitingNamespace = context.Model.GetSymbolInfo(name).Symbol as INamespaceSymbol; var visitor = new CSharpRemovableUsingWalker(context, newUsingDirectives.ToImmutableHashSet(), visitingNamespace); VisitContent(visitor, members, node.DescendantTrivia()); @@ -191,7 +191,7 @@ private bool TryGetSystemLinkNamespace(out INamespaceSymbol systemLinqNamespace) { foreach (var usingDirective in usingDirectivesFromParent) { - if (context.SemanticModel.GetSymbolInfo(usingDirective.Name).Symbol is INamespaceSymbol namespaceSymbol + if (context.Model.GetSymbolInfo(usingDirective.Name).Symbol is INamespaceSymbol namespaceSymbol && namespaceSymbol.ToDisplayString() == "System.Linq") { systemLinqNamespace = namespaceSymbol; @@ -208,7 +208,7 @@ private bool TryGetSystemLinkNamespace(out INamespaceSymbol systemLinqNamespace) /// importing that namespace is indeed necessary. /// private void VisitNameNode(ExpressionSyntax node) => - VisitSymbol(context.SemanticModel.GetSymbolInfo(node).Symbol); + VisitSymbol(context.Model.GetSymbolInfo(node).Symbol); private void VisitSymbol(ISymbol symbol) { diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/UnusedReturnValue.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/UnusedReturnValue.cs index 19e3b4eb68e..e5485998ac4 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/UnusedReturnValue.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/UnusedReturnValue.cs @@ -78,13 +78,13 @@ private static void AnalyzeLocalFunctionStatements(SonarSyntaxNodeReportingConte return; } - var localFunctionSymbol = (IMethodSymbol)context.SemanticModel.GetDeclaredSymbol(localFunctionSyntax); + var localFunctionSymbol = (IMethodSymbol)context.Model.GetDeclaredSymbol(localFunctionSyntax); if (localFunctionSymbol.ReturnsVoid || localFunctionSymbol.IsAsync) { return; } - var matchingInvocations = GetLocalMatchingInvocations(topMostContainingMethod, localFunctionSymbol, context.SemanticModel).ToList(); + var matchingInvocations = GetLocalMatchingInvocations(topMostContainingMethod, localFunctionSymbol, context.Model).ToList(); // Method invocation is noncompliant when there is at least 1 invocation of the method, and no invocation is using the return value. The case of 0 invocation is handled by S1144. if (matchingInvocations.Any() && !matchingInvocations.Any(IsReturnValueUsed)) { diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/UseAwaitableMethod.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/UseAwaitableMethod.cs index 1fa3e721f1e..be7f4b92074 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/UseAwaitableMethod.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/UseAwaitableMethod.cs @@ -49,7 +49,7 @@ protected override void Initialize(SonarAnalysisContext context) => var invocationExpression = (InvocationExpressionSyntax)nodeContext.Node; var awaitableAlternatives = FindAwaitableAlternatives(wellKnownExtensionMethodContainer, exclusions, invocationExpression, - nodeContext.SemanticModel, nodeContext.ContainingSymbol, nodeContext.Cancel); + nodeContext.Model, nodeContext.ContainingSymbol, nodeContext.Cancel); if (awaitableAlternatives.FirstOrDefault() is { Name: { } alternative }) { nodeContext.ReportIssue(Rule, invocationExpression, alternative); diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/UseConstantLoggingTemplate.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/UseConstantLoggingTemplate.cs index d7c51069bdf..bb44366eb55 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/UseConstantLoggingTemplate.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/UseConstantLoggingTemplate.cs @@ -84,12 +84,12 @@ protected override void Initialize(SonarAnalysisContext context) => { var invocation = (InvocationExpressionSyntax)c.Node; if (LoggerMethodNames.Contains(invocation.GetName()) - && c.SemanticModel.GetSymbolInfo(invocation).Symbol is IMethodSymbol method + && c.Model.GetSymbolInfo(invocation).Symbol is IMethodSymbol method && !IsLog4NetExceptionMethod(method) && LoggerTypes.Any(x => x.Matches(method.ContainingType)) && method.Parameters.FirstOrDefault(x => LogMessageParameterNames.Contains(x.Name)) is { } messageParameter && ArgumentValue(invocation, method, messageParameter) is { } argumentValue - && InvalidSyntaxNode(argumentValue, c.SemanticModel) is { } invalidNode) + && InvalidSyntaxNode(argumentValue, c.Model) is { } invalidNode) { c.ReportIssue(Rule, invalidNode, Messages[invalidNode.Kind()]); } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/UseConstantsWhereAppropriate.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/UseConstantsWhereAppropriate.cs index e27347c59c0..876bf161cac 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/UseConstantsWhereAppropriate.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/UseConstantsWhereAppropriate.cs @@ -57,14 +57,14 @@ protected override void Initialize(SonarAnalysisContext context) return; } - var fieldSymbol = c.SemanticModel.GetDeclaredSymbol(firstVariableWithInitialization) + var fieldSymbol = c.Model.GetDeclaredSymbol(firstVariableWithInitialization) as IFieldSymbol; if (!IsFieldRelevant(fieldSymbol)) { return; } - var constValue = c.SemanticModel.GetConstantValue( + var constValue = c.Model.GetConstantValue( firstVariableWithInitialization.Initializer.Value); if (!constValue.HasValue) { diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/UseGenericEventHandlerInstances.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/UseGenericEventHandlerInstances.cs index 123c89669ed..d2dd51e28c0 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/UseGenericEventHandlerInstances.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/UseGenericEventHandlerInstances.cs @@ -58,7 +58,7 @@ private static void AnalyzeEventType(SonarSyntaxNodeReportingContext analysisCon Func getLocationToReportOn) { - if (analysisContext.SemanticModel.GetDeclaredSymbol(eventNode) is IEventSymbol eventSymbol && + if (analysisContext.Model.GetDeclaredSymbol(eventNode) is IEventSymbol eventSymbol && !eventSymbol.IsOverride && eventSymbol.GetInterfaceMember() == null && (eventSymbol.Type as INamedTypeSymbol)?.ConstructedFrom.IsAny(allowedTypes) == false) diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/UseGenericWithRefParameters.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/UseGenericWithRefParameters.cs index 84101c70e83..5102df1ac10 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/UseGenericWithRefParameters.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/UseGenericWithRefParameters.cs @@ -31,7 +31,7 @@ protected override void Initialize(SonarAnalysisContext context) => context.RegisterNodeAction(c => { var methodDeclaration = (MethodDeclarationSyntax)c.Node; - var methodSymbol = c.SemanticModel.GetDeclaredSymbol(methodDeclaration); + var methodSymbol = c.Model.GetDeclaredSymbol(methodDeclaration); if (methodSymbol is null || methodDeclaration.Identifier.IsMissing) diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/UseParamsForVariableArguments.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/UseParamsForVariableArguments.cs index 0addb4d3dbe..b4456cfe295 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/UseParamsForVariableArguments.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/UseParamsForVariableArguments.cs @@ -35,7 +35,7 @@ protected override void Initialize(SonarAnalysisContext context) => && parameters[count - 1].Identifier.IsKind(SyntaxKind.ArgListKeyword) && CheckModifiers(c.Node) && c.Node.GetIdentifier() is { IsMissing: false } identifier - && MethodSymbol(c.Node, c.SemanticModel) is { } methodSymbol + && MethodSymbol(c.Node, c.Model) is { } methodSymbol && !methodSymbol.IsOverride && methodSymbol.IsPubliclyAccessible() && methodSymbol.GetInterfaceMember() == null) diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/UseStringCreate.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/UseStringCreate.cs index a56e6b9f6d2..c38795f5de3 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/UseStringCreate.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/UseStringCreate.cs @@ -51,7 +51,7 @@ protected override void Initialize(SonarAnalysisContext context) => && NameIsEqual(left, nameof(FormattableString)) && node.HasExactlyNArguments(1) && node.ArgumentList.Arguments[0].Expression is InterpolatedStringExpressionSyntax - && c.SemanticModel.GetTypeInfo(left).Type.Is(KnownType.System_FormattableString)) + && c.Model.GetTypeInfo(left).Type.Is(KnownType.System_FormattableString)) { c.ReportIssue(Rule, node.GetIdentifier()?.GetLocation()); } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/UseStringIsNullOrEmpty.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/UseStringIsNullOrEmpty.cs index 4505b35a31e..f9a169d3db6 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/UseStringIsNullOrEmpty.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/UseStringIsNullOrEmpty.cs @@ -40,19 +40,19 @@ protected override void Initialize(SonarAnalysisContext context) if (invocationExpression.Expression is MemberAccessExpressionSyntax memberAccessExpression && memberAccessExpression.Name.Identifier.ValueText == EqualsName && invocationExpression.TryGetFirstArgument(out var firstArgument) - && memberAccessExpression.IsMemberAccessOnKnownType(EqualsName, KnownType.System_String, c.SemanticModel)) + && memberAccessExpression.IsMemberAccessOnKnownType(EqualsName, KnownType.System_String, c.Model)) { // x.Equals(value), where x is string.Empty, "" or const "", and value is some string - if (IsStringIdentifier(firstArgument.Expression, c.SemanticModel) - && IsConstantEmptyString(memberAccessExpression.Expression, c.SemanticModel)) + if (IsStringIdentifier(firstArgument.Expression, c.Model) + && IsConstantEmptyString(memberAccessExpression.Expression, c.Model)) { c.ReportIssue(rule, invocationExpression, MessageFormat); return; } // value.Equals(x), where x is string.Empty, "" or const "", and value is some string - if (IsStringIdentifier(memberAccessExpression.Expression, c.SemanticModel) - && IsConstantEmptyString(firstArgument.Expression, c.SemanticModel)) + if (IsStringIdentifier(memberAccessExpression.Expression, c.Model) + && IsConstantEmptyString(firstArgument.Expression, c.Model)) { c.ReportIssue(rule, invocationExpression, MessageFormat); } diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/UseUriInsteadOfString.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/UseUriInsteadOfString.cs index 342d3d3b0f1..821e97ada05 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/UseUriInsteadOfString.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/UseUriInsteadOfString.cs @@ -62,7 +62,7 @@ protected override void Initialize(SonarAnalysisContext context) private static void VerifyMethodDeclaration(SonarSyntaxNodeReportingContext context) { var methodDeclaration = (BaseMethodDeclarationSyntax)context.Node; - var methodSymbol = context.SemanticModel.GetDeclaredSymbol(methodDeclaration); + var methodSymbol = context.Model.GetDeclaredSymbol(methodDeclaration); if (methodSymbol == null || methodSymbol.IsOverride) { return; @@ -79,7 +79,7 @@ private static void VerifyMethodDeclaration(SonarSyntaxNodeReportingContext cont if (methodOverloads.Any()) { if (!methodDeclaration.IsKind(SyntaxKind.ConstructorDeclaration) - && !methodDeclaration.ContainsMethodInvocation(context.SemanticModel, x => true, x => methodOverloads.Contains(x))) + && !methodDeclaration.ContainsMethodInvocation(context.Model, x => true, x => methodOverloads.Contains(x))) { context.ReportIssue(RuleS3997, methodDeclaration.FindIdentifierLocation()); } @@ -96,7 +96,7 @@ private static void VerifyMethodDeclaration(SonarSyntaxNodeReportingContext cont private static void VerifyPropertyDeclaration(SonarSyntaxNodeReportingContext context) { var propertyDeclaration = (PropertyDeclarationSyntax)context.Node; - var propertySymbol = context.SemanticModel.GetDeclaredSymbol(propertyDeclaration); + var propertySymbol = context.Model.GetDeclaredSymbol(propertyDeclaration); if (propertySymbol.Type.Is(KnownType.System_String) && !propertySymbol.IsOverride && NameContainsUri(propertySymbol.Name)) @@ -108,7 +108,7 @@ private static void VerifyPropertyDeclaration(SonarSyntaxNodeReportingContext co private static void VerifyRecordDeclaration(SonarSyntaxNodeReportingContext context) { var declaration = (RecordDeclarationSyntaxWrapper)context.Node; - if (!context.IsRedundantPositionalRecordContext() && HasStringUriParams(declaration.ParameterList, context.SemanticModel)) + if (!context.IsRedundantPositionalRecordContext() && HasStringUriParams(declaration.ParameterList, context.Model)) { context.ReportIssue(RuleS3996, declaration.SyntaxNode); } @@ -120,7 +120,7 @@ private static bool HasStringUriParams(BaseParameterListSyntax parameterList, Se private static void VerifyInvocationAndCreation(SonarSyntaxNodeReportingContext context) { - if (context.SemanticModel.GetSymbolInfo(context.Node).Symbol is IMethodSymbol invokedMethodSymbol + if (context.Model.GetSymbolInfo(context.Node).Symbol is IMethodSymbol invokedMethodSymbol && !invokedMethodSymbol.IsInType(KnownType.System_Uri) && StringUrlParamIndexes(invokedMethodSymbol) is { Count: not 0 } stringUrlParams && FindOverloadsThatUseUriTypeInPlaceOfString(invokedMethodSymbol, stringUrlParams).Any()) diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/UseValueParameter.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/UseValueParameter.cs index 48361e95eee..57241f4175f 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/UseValueParameter.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/UseValueParameter.cs @@ -34,12 +34,12 @@ protected override void Initialize(SonarAnalysisContext context) => if ((accessor.Body == null && accessor.ExpressionBody() == null) || OnlyThrows(accessor) - || accessor.DescendantNodes().OfType().Any(x => IsAccessorValue(x, c.SemanticModel))) + || accessor.DescendantNodes().OfType().Any(x => IsAccessorValue(x, c.Model))) { return; } - var interfaceMember = c.SemanticModel.GetDeclaredSymbol(accessor).GetInterfaceMember(); + var interfaceMember = c.Model.GetDeclaredSymbol(accessor).GetInterfaceMember(); if (interfaceMember != null && accessor.Body?.Statements.Count == 0) // No need to check ExpressionBody, it can't be empty { return; diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/ValuesUselesslyIncremented.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/ValuesUselesslyIncremented.cs index 24fc4aa8bd6..a3a8167d984 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/ValuesUselesslyIncremented.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/ValuesUselesslyIncremented.cs @@ -31,7 +31,7 @@ protected override void Initialize(SonarAnalysisContext context) => c => { var increment = (PostfixUnaryExpressionSyntax)c.Node; - var symbol = c.SemanticModel.GetSymbolInfo(increment.Operand).Symbol; + var symbol = c.Model.GetSymbolInfo(increment.Operand).Symbol; if (symbol is ILocalSymbol || symbol is IParameterSymbol { RefKind: RefKind.None }) { diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/VariableUnused.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/VariableUnused.cs index 2f9b0b97748..f2d8b07393d 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/VariableUnused.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/VariableUnused.cs @@ -27,7 +27,7 @@ protected override void Initialize(SonarAnalysisContext context) => context.RegisterCodeBlockStartAction(cbc => { var collector = new UnusedLocalsCollector(); - var walker = new QueryExpressionWalker(cbc.SemanticModel); + var walker = new QueryExpressionWalker(cbc.Model); cbc.RegisterNodeAction(collector.CollectDeclarations, SyntaxKind.LocalDeclarationStatement, diff --git a/analyzers/src/SonarAnalyzer.CSharp/Rules/XmlExternalEntityShouldNotBeParsed.cs b/analyzers/src/SonarAnalyzer.CSharp/Rules/XmlExternalEntityShouldNotBeParsed.cs index 0f498413f10..43f2aaac8d2 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/Rules/XmlExternalEntityShouldNotBeParsed.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/Rules/XmlExternalEntityShouldNotBeParsed.cs @@ -53,8 +53,8 @@ protected override void Initialize(SonarAnalysisContext context) => var constructorIsSafe = ConstructorIsSafe(netFrameworkVersion); var trackers = TrackerFactory.Create(); - if (trackers.XmlDocumentTracker.ShouldBeReported(objectCreation, c.SemanticModel, constructorIsSafe) - || trackers.XmlTextReaderTracker.ShouldBeReported(objectCreation, c.SemanticModel, constructorIsSafe)) + if (trackers.XmlDocumentTracker.ShouldBeReported(objectCreation, c.Model, constructorIsSafe) + || trackers.XmlTextReaderTracker.ShouldBeReported(objectCreation, c.Model, constructorIsSafe)) { c.ReportIssue(Rule, objectCreation.Expression); } @@ -69,8 +69,8 @@ protected override void Initialize(SonarAnalysisContext context) => var assignment = (AssignmentExpressionSyntax)c.Node; var trackers = TrackerFactory.Create(); - if (trackers.XmlDocumentTracker.ShouldBeReported(assignment, c.SemanticModel) - || trackers.XmlTextReaderTracker.ShouldBeReported(assignment, c.SemanticModel)) + if (trackers.XmlDocumentTracker.ShouldBeReported(assignment, c.Model) + || trackers.XmlTextReaderTracker.ShouldBeReported(assignment, c.Model)) { c.ReportIssue(Rule, assignment); } @@ -83,18 +83,18 @@ protected override void Initialize(SonarAnalysisContext context) => private void VerifyXmlReaderInvocations(SonarSyntaxNodeReportingContext context) { var invocation = (InvocationExpressionSyntax)context.Node; - if (!invocation.IsMemberAccessOnKnownType("Create", KnownType.System_Xml_XmlReader, context.SemanticModel)) + if (!invocation.IsMemberAccessOnKnownType("Create", KnownType.System_Xml_XmlReader, context.Model)) { return; } - var settings = invocation.GetArgumentSymbolsOfKnownType(KnownType.System_Xml_XmlReaderSettings, context.SemanticModel).FirstOrDefault(); + var settings = invocation.GetArgumentSymbolsOfKnownType(KnownType.System_Xml_XmlReaderSettings, context.Model).FirstOrDefault(); if (settings == null) { return; // safe by default } - var xmlReaderSettingsValidator = new XmlReaderSettingsValidator(context.SemanticModel, versionProvider.GetDotNetFrameworkVersion(context.Compilation)); + var xmlReaderSettingsValidator = new XmlReaderSettingsValidator(context.Model, versionProvider.GetDotNetFrameworkVersion(context.Compilation)); if (xmlReaderSettingsValidator.GetUnsafeAssignmentLocations(invocation, settings, SecondaryMessage) is { } secondaryLocations && secondaryLocations.Any()) { context.ReportIssue(Rule, invocation, secondaryLocations); @@ -103,10 +103,10 @@ private void VerifyXmlReaderInvocations(SonarSyntaxNodeReportingContext context) private void VerifyXPathDocumentConstructor(SonarSyntaxNodeReportingContext context, IObjectCreation objectCreation) { - if (!context.SemanticModel.GetTypeInfo(objectCreation.Expression).Type.Is(KnownType.System_Xml_XPath_XPathDocument) + if (!context.Model.GetTypeInfo(objectCreation.Expression).Type.Is(KnownType.System_Xml_XPath_XPathDocument) // If a XmlReader is provided in the constructor, XPathDocument will be as safe as the received reader. // In this case we don't raise a warning since the XmlReader has it's own checks. - || objectCreation.ArgumentList.Arguments.GetArgumentsOfKnownType(KnownType.System_Xml_XmlReader, context.SemanticModel).Any()) + || objectCreation.ArgumentList.Arguments.GetArgumentsOfKnownType(KnownType.System_Xml_XmlReader, context.Model).Any()) { return; } diff --git a/analyzers/src/SonarAnalyzer.Core/AnalysisContext/SonarCodeBlockReportingContext.cs b/analyzers/src/SonarAnalyzer.Core/AnalysisContext/SonarCodeBlockReportingContext.cs index cc3e880950a..46b40b29465 100644 --- a/analyzers/src/SonarAnalyzer.Core/AnalysisContext/SonarCodeBlockReportingContext.cs +++ b/analyzers/src/SonarAnalyzer.Core/AnalysisContext/SonarCodeBlockReportingContext.cs @@ -24,7 +24,7 @@ public readonly record struct SonarCodeBlockReportingContext(SonarAnalysisContex public CancellationToken Cancel => Context.CancellationToken; public SyntaxNode CodeBlock => Context.CodeBlock; public ISymbol OwningSymbol => Context.OwningSymbol; - public SemanticModel SemanticModel => Context.SemanticModel; + public SemanticModel Model => Context.SemanticModel; public ReportingContext CreateReportingContext(Diagnostic diagnostic) => new(this, diagnostic); diff --git a/analyzers/src/SonarAnalyzer.Core/AnalysisContext/SonarCodeBlockStartAnalysisContext.cs b/analyzers/src/SonarAnalyzer.Core/AnalysisContext/SonarCodeBlockStartAnalysisContext.cs index 7f15871eceb..c88d2fcf607 100644 --- a/analyzers/src/SonarAnalyzer.Core/AnalysisContext/SonarCodeBlockStartAnalysisContext.cs +++ b/analyzers/src/SonarAnalyzer.Core/AnalysisContext/SonarCodeBlockStartAnalysisContext.cs @@ -23,7 +23,7 @@ public sealed class SonarCodeBlockStartAnalysisContext : SonarAnaly public override CancellationToken Cancel => Context.CancellationToken; public SyntaxNode CodeBlock => Context.CodeBlock; public ISymbol OwningSymbol => Context.OwningSymbol; - public SemanticModel SemanticModel => Context.SemanticModel; + public SemanticModel Model => Context.SemanticModel; internal SonarCodeBlockStartAnalysisContext(SonarAnalysisContext analysisContext, CodeBlockStartAnalysisContext context) : base(analysisContext, context) { } diff --git a/analyzers/src/SonarAnalyzer.Core/AnalysisContext/SonarSemanticModelReportingContext.cs b/analyzers/src/SonarAnalyzer.Core/AnalysisContext/SonarSemanticModelReportingContext.cs index 16e075c2e97..8c7e125a454 100644 --- a/analyzers/src/SonarAnalyzer.Core/AnalysisContext/SonarSemanticModelReportingContext.cs +++ b/analyzers/src/SonarAnalyzer.Core/AnalysisContext/SonarSemanticModelReportingContext.cs @@ -18,11 +18,11 @@ namespace SonarAnalyzer.Core.AnalysisContext; public readonly record struct SonarSemanticModelReportingContext(SonarAnalysisContext AnalysisContext, SemanticModelAnalysisContext Context) : ITreeReport, IAnalysisContext { - public SyntaxTree Tree => SemanticModel.SyntaxTree; + public SyntaxTree Tree => Model.SyntaxTree; public Compilation Compilation => Context.SemanticModel.Compilation; public AnalyzerOptions Options => Context.Options; public CancellationToken Cancel => Context.CancellationToken; - public SemanticModel SemanticModel => Context.SemanticModel; + public SemanticModel Model => Context.SemanticModel; public ReportingContext CreateReportingContext(Diagnostic diagnostic) => new(this, diagnostic); diff --git a/analyzers/src/SonarAnalyzer.Core/AnalysisContext/SonarSyntaxNodeReportingContext.cs b/analyzers/src/SonarAnalyzer.Core/AnalysisContext/SonarSyntaxNodeReportingContext.cs index d797c3f6d55..1044d9eb487 100644 --- a/analyzers/src/SonarAnalyzer.Core/AnalysisContext/SonarSyntaxNodeReportingContext.cs +++ b/analyzers/src/SonarAnalyzer.Core/AnalysisContext/SonarSyntaxNodeReportingContext.cs @@ -23,7 +23,7 @@ public readonly record struct SonarSyntaxNodeReportingContext(SonarAnalysisConte public AnalyzerOptions Options => Context.Options; public CancellationToken Cancel => Context.CancellationToken; public SyntaxNode Node => Context.Node; - public SemanticModel SemanticModel => Context.SemanticModel; + public SemanticModel Model => Context.SemanticModel; public ISymbol ContainingSymbol => Context.ContainingSymbol; /// diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/AlwaysSetDateTimeKindBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/AlwaysSetDateTimeKindBase.cs index faa11f7595d..9cddd32c2f6 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/AlwaysSetDateTimeKindBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/AlwaysSetDateTimeKindBase.cs @@ -33,7 +33,7 @@ protected override void Initialize(SonarAnalysisContext context) => { if (Language.Syntax.ObjectCreationTypeIdentifier(c.Node) is { IsMissing: false } identifier && Array.Exists(ValidNames, x => x.Equals(identifier.ValueText, Language.NameComparison)) - && IsDateTimeConstructorWithoutKindParameter(c.Node, c.SemanticModel)) + && IsDateTimeConstructorWithoutKindParameter(c.Node, c.Model)) { c.ReportIssue(Rule, c.Node); } diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/ArrayPassedAsParamsBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/ArrayPassedAsParamsBase.cs index 6267987fd17..010241c1f4d 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/ArrayPassedAsParamsBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/ArrayPassedAsParamsBase.cs @@ -34,11 +34,11 @@ protected sealed override void Initialize(SonarAnalysisContext context) => context.RegisterNodeAction(Language.GeneratedCodeRecognizer, c => { if (LastArgumentIfArrayCreation(c.Node) is { } lastArgument - && c.SemanticModel.GetSymbolInfo(c.Node).Symbol is IMethodSymbol methodSymbol + && c.Model.GetSymbolInfo(c.Node).Symbol is IMethodSymbol methodSymbol && Language.MethodParameterLookup(c.Node, methodSymbol) is { } parameterLookup && parameterLookup.TryGetSymbol(lastArgument, out var param) && param is { IsParams: true } - && !IsArrayOfCandidateTypes(lastArgument, parameterLookup, param, c.SemanticModel) + && !IsArrayOfCandidateTypes(lastArgument, parameterLookup, param, c.Model) && !IsJaggedArrayParam(param)) { c.ReportIssue(Rule, lastArgument.GetLocation()); diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/AspNet/BackslashShouldBeAvoidedInAspNetRoutesBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/AspNet/BackslashShouldBeAvoidedInAspNetRoutesBase.cs index 825d1e1eccb..f4b3e19ddb8 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/AspNet/BackslashShouldBeAvoidedInAspNetRoutesBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/AspNet/BackslashShouldBeAvoidedInAspNetRoutesBase.cs @@ -42,9 +42,9 @@ protected void Check(SonarSyntaxNodeReportingContext c) { if (!IsNamedAttributeArgument(c.Node) && Language.Syntax.NodeExpression(c.Node) is { } expression - && Language.FindConstantValue(c.SemanticModel, expression) is string constantRouteTemplate + && Language.FindConstantValue(c.Model, expression) is string constantRouteTemplate && ContainsBackslash(constantRouteTemplate) - && IsRouteTemplate(c.SemanticModel, c.Node)) + && IsRouteTemplate(c.Model, c.Node)) { c.ReportIssue(Rule, expression); } diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/AspNet/RouteTemplateShouldNotStartWithSlashBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/AspNet/RouteTemplateShouldNotStartWithSlashBase.cs index 802cb5bbbd1..4bd0fcf003c 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/AspNet/RouteTemplateShouldNotStartWithSlashBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/AspNet/RouteTemplateShouldNotStartWithSlashBase.cs @@ -46,7 +46,7 @@ protected override void Initialize(SonarAnalysisContext context) => var controllerActionInfo = new ConcurrentStack(); symbolStartContext.RegisterSyntaxNodeAction(nodeContext => { - if (nodeContext.SemanticModel.GetDeclaredSymbol(nodeContext.Node) is IMethodSymbol methodSymbol && methodSymbol.IsControllerActionMethod()) + if (nodeContext.Model.GetDeclaredSymbol(nodeContext.Node) is IMethodSymbol methodSymbol && methodSymbol.IsControllerActionMethod()) { controllerActionInfo.Push(new ActionParametersInfo(RouteAttributeTemplateArguments(methodSymbol.GetAttributes()))); } diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/AvoidDateTimeNowForBenchmarkingBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/AvoidDateTimeNowForBenchmarkingBase.cs index a3a51d4a872..d39074b8fae 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/AvoidDateTimeNowForBenchmarkingBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/AvoidDateTimeNowForBenchmarkingBase.cs @@ -37,9 +37,9 @@ protected sealed override void Initialize(SonarAnalysisContext context) private void CheckBinaryExpression(SonarSyntaxNodeReportingContext context) { if (Language.Syntax.BinaryExpressionLeft(context.Node) is TMemberAccess memberAccess - && IsDateTimeNow(memberAccess, context.SemanticModel) + && IsDateTimeNow(memberAccess, context.Model) && Language.Syntax.BinaryExpressionRight(context.Node) is var right - && context.SemanticModel.GetTypeInfo(right).Type.Is(KnownType.System_DateTime)) + && context.Model.GetTypeInfo(right).Type.Is(KnownType.System_DateTime)) { context.ReportIssue(Rule, context.Node); } @@ -51,10 +51,10 @@ private void CheckInvocation(SonarSyntaxNodeReportingContext context) if (Language.Syntax.NodeExpression(invocation) is TMemberAccess subtract && Language.Syntax.NodeExpression(subtract) is TMemberAccess now - && Language.Syntax.IsMemberAccessOnKnownType(subtract, "Subtract", KnownType.System_DateTime, context.SemanticModel) - && IsDateTimeNow(now, context.SemanticModel) + && Language.Syntax.IsMemberAccessOnKnownType(subtract, "Subtract", KnownType.System_DateTime, context.Model) + && IsDateTimeNow(now, context.Model) && Language.Syntax.HasExactlyNArguments(invocation, 1) - && ContainsDateTimeArgument(invocation, context.SemanticModel)) + && ContainsDateTimeArgument(invocation, context.Model)) { context.ReportIssue(Rule, subtract); } diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/AvoidUnsealedAttributesBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/AvoidUnsealedAttributesBase.cs index 9b81f034c15..567330c2f25 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/AvoidUnsealedAttributesBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/AvoidUnsealedAttributesBase.cs @@ -31,7 +31,7 @@ protected sealed override void Initialize(SonarAnalysisContext context) => c => { if (Language.Syntax.NodeIdentifier(c.Node) is { IsMissing: false } identifier - && c.SemanticModel.GetDeclaredSymbol(c.Node) is INamedTypeSymbol { IsAbstract: false, IsSealed: false } symbol + && c.Model.GetDeclaredSymbol(c.Node) is INamedTypeSymbol { IsAbstract: false, IsSealed: false } symbol && symbol.DerivesFrom(KnownType.System_Attribute) && symbol.IsPubliclyAccessible()) { diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/BeginInvokePairedWithEndInvokeBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/BeginInvokePairedWithEndInvokeBase.cs index 8d1536c417a..923915e1f85 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/BeginInvokePairedWithEndInvokeBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/BeginInvokePairedWithEndInvokeBase.cs @@ -45,13 +45,13 @@ protected override void Initialize(SonarAnalysisContext context) => var invocation = (TInvocationExpressionSyntax)c.Node; if (Language.Syntax.NodeExpression(invocation) is { } expression && expression.ToStringContains(BeginInvoke) - && c.SemanticModel.GetSymbolInfo(invocation).Symbol is IMethodSymbol methodSymbol + && c.Model.GetSymbolInfo(invocation).Symbol is IMethodSymbol methodSymbol && methodSymbol.Name == BeginInvoke && IsDelegate(methodSymbol) && methodSymbol.Parameters.SingleOrDefault(x => x.Name == CallbackParameterName) is { } parameter && Language.MethodParameterLookup(invocation, methodSymbol).TryGetNonParamsSyntax(parameter, out var callbackArg) - && IsInvalidCallback(callbackArg, c.SemanticModel) - && !ParentMethodContainsEndInvoke(invocation, c.SemanticModel)) + && IsInvalidCallback(callbackArg, c.Model) + && !ParentMethodContainsEndInvoke(invocation, c.Model)) { c.ReportIssue(Rule, Language.Syntax.InvocationIdentifier(invocation).Value); } diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/BooleanCheckInvertedBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/BooleanCheckInvertedBase.cs index 3e38ce49e51..3c2e5a4b0fd 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/BooleanCheckInvertedBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/BooleanCheckInvertedBase.cs @@ -34,8 +34,8 @@ protected Action GetAnalysisAction(DiagnosticDe { var expression = (TBinaryExpression)c.Node; - if (IsUserDefinedOperator(expression, c.SemanticModel) || - IsIgnoredNullableOperation(expression, c.SemanticModel)) + if (IsUserDefinedOperator(expression, c.Model) || + IsIgnoredNullableOperation(expression, c.Model)) { return; } diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/BooleanLiteralUnnecessaryBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/BooleanLiteralUnnecessaryBase.cs index 916fb22c42a..5b3871d03fc 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/BooleanLiteralUnnecessaryBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/BooleanLiteralUnnecessaryBase.cs @@ -150,8 +150,8 @@ protected bool CheckForNullabilityAndBooleanConstantsReport(SonarSyntaxNodeRepor var right = Language.Syntax.RemoveParentheses(GetRightNode(node)); if (right is null // Avoids DeclarationPattern or RecursivePattern - || TypeShouldBeIgnored(left, context.SemanticModel) - || TypeShouldBeIgnored(right, context.SemanticModel)) + || TypeShouldBeIgnored(left, context.Model) + || TypeShouldBeIgnored(right, context.Model)) { return true; } diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/CatchRethrowBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/CatchRethrowBase.cs index 026baa34f41..ae3a09295e8 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/CatchRethrowBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/CatchRethrowBase.cs @@ -34,7 +34,7 @@ protected CatchRethrowBase() : base(DiagnosticId) { } protected void RaiseOnInvalidCatch(SonarSyntaxNodeReportingContext context) { var catches = AllCatches(context.Node); - var caughtExceptionTypes = new Lazy(() => ComputeExceptionTypes(catches, context.SemanticModel)); + var caughtExceptionTypes = new Lazy(() => ComputeExceptionTypes(catches, context.Model)); var redundantCatches = new HashSet(); // We handle differently redundant catch clauses (just throw inside) that are followed by a non-redundant catch clause, because if they are removed, the method behavior will change. var followingCatchesOnlyThrow = true; diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/CertificateValidationCheckBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/CertificateValidationCheckBase.cs index b45f8eb74dd..3f17306a3d3 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/CertificateValidationCheckBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/CertificateValidationCheckBase.cs @@ -63,7 +63,7 @@ protected void CheckAssignmentSyntax(SonarSyntaxNodeReportingContext c) { SplitAssignment((TAssignmentExpressionSyntax)c.Node, out var leftIdentifier, out var right); if (leftIdentifier != null && right != null - && c.SemanticModel.GetSymbolInfo(leftIdentifier).Symbol is IPropertySymbol left + && c.Model.GetSymbolInfo(leftIdentifier).Symbol is IPropertySymbol left && IsValidationDelegateType(left.Type)) { TryReportLocations(new InspectionContext(c), leftIdentifier.GetLocation(), right); @@ -72,7 +72,7 @@ protected void CheckAssignmentSyntax(SonarSyntaxNodeReportingContext c) protected void CheckConstructorParameterSyntax(SonarSyntaxNodeReportingContext c) { - if (c.SemanticModel.GetSymbolInfo(c.Node).Symbol is IMethodSymbol ctor) + if (c.Model.GetSymbolInfo(c.Node).Symbol is IMethodSymbol ctor) { MethodParameterLookupBase methodParamLookup = null; // Cache, there might be more of them // Validation for TryGetNonParamsSyntax, ParamArray/params and therefore array arguments are not inspected @@ -94,7 +94,7 @@ protected ImmutableArray ParamLocations(InspectionContext c, TParamete if (containingMethodDeclaration != null && !c.VisitedMethods.Contains(containingMethodDeclaration)) { c.VisitedMethods.Add(containingMethodDeclaration); - var containingMethod = c.Context.SemanticModel.GetDeclaredSymbol(containingMethodDeclaration) as IMethodSymbol; + var containingMethod = c.Context.Model.GetDeclaredSymbol(containingMethodDeclaration) as IMethodSymbol; var identText = Language.Syntax.NodeIdentifier(param)?.ValueText; var paramSymbol = containingMethod?.Parameters.Single(x => x.Name == identText); if (paramSymbol is {IsParams: false}) // Validation for TryGetNonParamsSyntax, ParamArray/params and therefore array arguments are not inspected @@ -177,7 +177,7 @@ private ImmutableArray ArgumentLocations(InspectionContext c, SyntaxNo switch (ExtractArgumentExpressionNode(expression)) { case TIdentifierNameSyntax identifier: - if (c.Context.SemanticModel.GetSymbolInfo(identifier).Symbol is {DeclaringSyntaxReferences: {Length: 1}} identSymbol) + if (c.Context.Model.GetSymbolInfo(identifier).Symbol is {DeclaringSyntaxReferences: {Length: 1}} identSymbol) { return IdentifierLocations(c, SyntaxFromReference(identSymbol.DeclaringSyntaxReferences.Single())); } @@ -187,7 +187,7 @@ private ImmutableArray ArgumentLocations(InspectionContext c, SyntaxNo case TInvocationExpressionSyntax invocation: return VisitInvocation(invocation, c); case TMemberAccessSyntax memberAccess: - if (c.Context.SemanticModel.GetSymbolInfo(memberAccess).Symbol is { } maSymbol + if (c.Context.Model.GetSymbolInfo(memberAccess).Symbol is { } maSymbol && maSymbol.IsInType(KnownType.System_Net_Http_HttpClientHandler) && maSymbol.Name == "DangerousAcceptAnyServerCertificateValidator") { @@ -200,7 +200,7 @@ private ImmutableArray ArgumentLocations(InspectionContext c, SyntaxNo private ImmutableArray VisitInvocation(TInvocationExpressionSyntax invocation, InspectionContext c) { - var invSymbol = (IMethodSymbol)c.Context.SemanticModel.GetSymbolInfo(invocation).Symbol; + var invSymbol = (IMethodSymbol)c.Context.Model.GetSymbolInfo(invocation).Symbol; var references = invSymbol.PartialImplementationPart?.DeclaringSyntaxReferences ?? invSymbol.DeclaringSyntaxReferences; if (references.Length == 0) { @@ -256,7 +256,7 @@ private ImmutableArray InvocationLocations(InspectionContext c, Syntax private bool IsVisited(InspectionContext c, SyntaxNode expression) => expression is TInvocationExpressionSyntax invocation - && c.Context.SemanticModel.GetSymbolInfo(invocation).Symbol is { } symbol + && c.Context.Model.GetSymbolInfo(invocation).Symbol is { } symbol && symbol.DeclaringSyntaxReferences.Select(SyntaxFromReference).Any(x => c.VisitedMethods.Contains(x)); private ImmutableArray MultiExpressionSublocations(InspectionContext c, IEnumerable expressions) @@ -298,7 +298,7 @@ private ImmutableArray FindInvocationList(SonarSynt { if (Language.Syntax.InvocationIdentifier(invocation) is { } invocationIdentifier && invocationIdentifier.ValueText.Equals(method.Name, Language.NameComparison) - && c.SemanticModel.GetSymbolInfo(invocation).Symbol is { } symbol + && c.Model.GetSymbolInfo(invocation).Symbol is { } symbol && symbol.Equals(method)) { ret.Add(invocation); diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/ClassNamedExceptionBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/ClassNamedExceptionBase.cs index c77c0135c63..a4304e09a98 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/ClassNamedExceptionBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/ClassNamedExceptionBase.cs @@ -32,7 +32,7 @@ protected override void Initialize(SonarAnalysisContext context) => { if (Language.Syntax.NodeIdentifier(c.Node) is { IsMissing: false } classIdentifier && classIdentifier.ValueText.EndsWith("Exception", StringComparison.InvariantCultureIgnoreCase) - && c.SemanticModel.GetDeclaredSymbol(c.Node) is INamedTypeSymbol { } classSymbol + && c.Model.GetDeclaredSymbol(c.Node) is INamedTypeSymbol { } classSymbol && !classSymbol.DerivesFrom(KnownType.System_Exception) && !classSymbol.Implements(KnownType.System_Runtime_InteropServices_Exception)) { diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/ClassShouldNotBeEmptyBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/ClassShouldNotBeEmptyBase.cs index c81095e3a3b..760c01c569a 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/ClassShouldNotBeEmptyBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/ClassShouldNotBeEmptyBase.cs @@ -52,7 +52,7 @@ protected override void Initialize(SonarAnalysisContext context) => && !HasAnyAttribute(c.Node) && !HasConditionalCompilationDirectives(c.Node) && !ShouldIgnoreBecauseOfName(identifier) - && !ShouldIgnoreBecauseOfBaseClassOrInterface(c.Node, c.SemanticModel)) + && !ShouldIgnoreBecauseOfBaseClassOrInterface(c.Node, c.Model)) { c.ReportIssue(Rule, identifier, DeclarationTypeKeyword(c.Node)); } diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/CollectionEmptinessCheckingBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/CollectionEmptinessCheckingBase.cs index 3c2eb8604dc..666673ec154 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/CollectionEmptinessCheckingBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/CollectionEmptinessCheckingBase.cs @@ -44,7 +44,7 @@ protected override void Initialize(SonarAnalysisContext context) => private void CheckExpression(SonarSyntaxNodeReportingContext context, SyntaxNode expression, int constant, ComparisonKind comparison) { if (comparison.Compare(constant).IsEmptyOrNotEmpty() - && TryGetCountCall(expression, context.SemanticModel, out var location, out var typeArgument)) + && TryGetCountCall(expression, context.Model, out var location, out var typeArgument)) { context.ReportIssue(Rule, location, typeArgument); } diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/ConstructorArgumentValueShouldExistBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/ConstructorArgumentValueShouldExistBase.cs index 7ffefe9dac6..385a76d147d 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/ConstructorArgumentValueShouldExistBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/ConstructorArgumentValueShouldExistBase.cs @@ -33,9 +33,9 @@ protected override void Initialize(SonarAnalysisContext context) => c => { var attribute = (TAttribute)c.Node; - if (Language.Syntax.IsKnownAttributeType(c.SemanticModel, c.Node, KnownType.System_Windows_Markup_ConstructorArgumentAttribute) + if (Language.Syntax.IsKnownAttributeType(c.Model, c.Node, KnownType.System_Windows_Markup_ConstructorArgumentAttribute) && GetFirstAttributeArgument(attribute) is { } firstAttribute - && c.SemanticModel.GetConstantValue(Language.Syntax.NodeExpression(firstAttribute)) is { HasValue: true, Value: string constructorParameterName } + && c.Model.GetConstantValue(Language.Syntax.NodeExpression(firstAttribute)) is { HasValue: true, Value: string constructorParameterName } && c.ContainingSymbol is IPropertySymbol { ContainingType: { } containingType } && !GetConstructorParameterNames(containingType).Contains(constructorParameterName)) { diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/DateTimeFormatShouldNotBeHardcodedBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/DateTimeFormatShouldNotBeHardcodedBase.cs index 002b7692052..28ea0968960 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/DateTimeFormatShouldNotBeHardcodedBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/DateTimeFormatShouldNotBeHardcodedBase.cs @@ -46,8 +46,8 @@ private void AnalyzeInvocation(SonarSyntaxNodeReportingContext analysisContext) if ((TInvocation)analysisContext.Node is var invocation && Language.Syntax.InvocationIdentifier(invocation) is { } identifier && identifier.ValueText.Equals("ToString", Language.NameComparison) - && HasInvalidFirstArgument(invocation, analysisContext.SemanticModel) // Standard date and time format strings are 1 char long and they are allowed - && analysisContext.SemanticModel.GetSymbolInfo(identifier.Parent).Symbol is { } methodCallSymbol + && HasInvalidFirstArgument(invocation, analysisContext.Model) // Standard date and time format strings are 1 char long and they are allowed + && analysisContext.Model.GetSymbolInfo(identifier.Parent).Symbol is { } methodCallSymbol && CheckedTypes.Any(x => methodCallSymbol.ContainingType.ConstructedFrom.Is(x))) { analysisContext.ReportIssue(SupportedDiagnostics[0], HardCodedArgumentLocation(invocation)); diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/DebuggerDisplayUsesExistingMembersBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/DebuggerDisplayUsesExistingMembersBase.cs index 71249835594..c7644df087a 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/DebuggerDisplayUsesExistingMembersBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/DebuggerDisplayUsesExistingMembersBase.cs @@ -45,14 +45,14 @@ protected override void Initialize(SonarAnalysisContext context) => c => { var attributeArgument = (TAttributeArgumentSyntax)c.Node; - var trackingContext = new ArgumentContext(attributeArgument, c.SemanticModel); + var trackingContext = new ArgumentContext(attributeArgument, c.Model); var argumentMatcher = Language.Tracker.Argument; if (argumentMatcher.Or( argumentMatcher.MatchArgument(ConstructorDescriptor), argumentMatcher.MatchArgument(NameDescriptor), argumentMatcher.MatchArgument(TypeDescriptor))(trackingContext) && Language.Syntax.NodeExpression(attributeArgument) is { } formatString - && Language.FindConstantValue(c.SemanticModel, formatString) is string formatStringText + && Language.FindConstantValue(c.Model, formatString) is string formatStringText && FirstInvalidExpression(c, formatStringText, attributeArgument) is { } firstInvalidMember) { c.ReportIssue(Rule, formatString, firstInvalidMember); @@ -63,7 +63,7 @@ protected override void Initialize(SonarAnalysisContext context) => private string FirstInvalidExpression(SonarSyntaxNodeReportingContext context, string formatString, TAttributeArgumentSyntax attributeSyntax) { return (AttributeTarget(attributeSyntax) is { } targetSyntax - && context.SemanticModel.GetDeclaredSymbol(targetSyntax) is { } targetSymbol + && context.Model.GetDeclaredSymbol(targetSyntax) is { } targetSymbol && TypeContainingReferencedMembers(targetSymbol) is { } typeSymbol) ? FirstInvalidMemberName(typeSymbol) : null; diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/DeclareTypesInNamespacesBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/DeclareTypesInNamespacesBase.cs index a32c4bfbe66..59e85c50a6a 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/DeclareTypesInNamespacesBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/DeclareTypesInNamespacesBase.cs @@ -35,7 +35,7 @@ protected override void Initialize(SonarAnalysisContext context) => c => { var declaration = c.Node; - if (c.IsRedundantPositionalRecordContext() || IsInnerTypeOrWithinNamespace(declaration, c.SemanticModel) || IsException(c.Node)) + if (c.IsRedundantPositionalRecordContext() || IsInnerTypeOrWithinNamespace(declaration, c.Model) || IsException(c.Node)) { return; } diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/DoNotCallInsecureSecurityAlgorithmBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/DoNotCallInsecureSecurityAlgorithmBase.cs index d4ea6421648..6e624e88f26 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/DoNotCallInsecureSecurityAlgorithmBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/DoNotCallInsecureSecurityAlgorithmBase.cs @@ -46,7 +46,7 @@ private void CheckInvocation(SonarSyntaxNodeReportingContext context) var invocation = (TInvocationExpressionSyntax)context.Node; if (Language.Syntax.NodeExpression(invocation) is { } expression - && (context.SemanticModel.GetSymbolInfo(expression).Symbol is IMethodSymbol methodSymbol) + && (context.Model.GetSymbolInfo(expression).Symbol is IMethodSymbol methodSymbol) && (methodSymbol.ReturnType.DerivesFromAny(AlgorithmTypes) || IsInsecureBaseAlgorithmCreationFactoryCall(methodSymbol, invocation))) { ReportAllDiagnostics(context, invocation.GetLocation()); @@ -57,7 +57,7 @@ private void CheckObjectCreation(SonarSyntaxNodeReportingContext context) { var objectCreation = context.Node; - var typeInfo = context.SemanticModel.GetTypeInfo(objectCreation); + var typeInfo = context.Model.GetTypeInfo(objectCreation); if (typeInfo.Type == null || typeInfo.Type is IErrorTypeSymbol) { return; diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/DoNotCallMethodsBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/DoNotCallMethodsBase.cs index ede6fbb66ed..b6fa69178ea 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/DoNotCallMethodsBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/DoNotCallMethodsBase.cs @@ -48,10 +48,10 @@ private void AnalyzeInvocation(SonarSyntaxNodeReportingContext analysisContext) && Language.Syntax.InvocationIdentifier(invocation) is { } identifier && CheckedMethods.Where(x => x.Name.Equals(identifier.ValueText)) is var nameMatch && nameMatch.Any() - && analysisContext.SemanticModel.GetSymbolInfo(identifier.Parent).Symbol is { } methodCallSymbol + && analysisContext.Model.GetSymbolInfo(identifier.Parent).Symbol is { } methodCallSymbol && nameMatch.FirstOrDefault(x => methodCallSymbol.ContainingType.ConstructedFrom.Is(x.ContainingType)) is { } disallowedMethodSignature - && IsInValidContext(invocation, analysisContext.SemanticModel) - && ShouldReportOnMethodCall(invocation, analysisContext.SemanticModel, disallowedMethodSignature)) + && IsInValidContext(invocation, analysisContext.Model) + && ShouldReportOnMethodCall(invocation, analysisContext.Model, disallowedMethodSignature)) { analysisContext.ReportIssue(SupportedDiagnostics[0], identifier.GetLocation(), disallowedMethodSignature.ToString()); } diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/DoNotCheckZeroSizeCollectionBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/DoNotCheckZeroSizeCollectionBase.cs index e45ce16eb23..139213a8fcb 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/DoNotCheckZeroSizeCollectionBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/DoNotCheckZeroSizeCollectionBase.cs @@ -38,11 +38,11 @@ protected override void Initialize(SonarAnalysisContext context) => var binaryLeft = Language.Syntax.BinaryExpressionLeft(binary); var binaryRight = Language.Syntax.BinaryExpressionRight(binary); - if (Language.ExpressionNumericConverter.TryGetConstantIntValue(c.SemanticModel, binaryLeft, out var left)) + if (Language.ExpressionNumericConverter.TryGetConstantIntValue(c.Model, binaryLeft, out var left)) { CheckExpression(c, binary, binaryRight, left, Language.Syntax.ComparisonKind(binary).Mirror()); } - else if (Language.ExpressionNumericConverter.TryGetConstantIntValue(c.SemanticModel, binaryRight, out var right)) + else if (Language.ExpressionNumericConverter.TryGetConstantIntValue(c.Model, binaryRight, out var right)) { CheckExpression(c, binary, binaryLeft, right, Language.Syntax.ComparisonKind(binary)); } @@ -55,7 +55,7 @@ protected void CheckExpression(SonarSyntaxNodeReportingContext context, SyntaxNo var result = comparison.Compare(constant); if (result.IsInvalid() && HasCandidateName(Language.Syntax.NodeIdentifier(expression)?.ValueText) - && context.SemanticModel.GetSymbolInfo(expression).Symbol is ISymbol symbol + && context.Model.GetSymbolInfo(expression).Symbol is ISymbol symbol && CollecionSizeTypeName(symbol) is { } symbolType) { context.ReportIssue(Rule, issue, symbol.Name, symbolType, (result == CountComparisonResult.AlwaysTrue).ToString()); diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/DoNotLockWeakIdentityObjectsBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/DoNotLockWeakIdentityObjectsBase.cs index 4eb31bbeb0f..df76e5d5169 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/DoNotLockWeakIdentityObjectsBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/DoNotLockWeakIdentityObjectsBase.cs @@ -44,7 +44,7 @@ protected override void Initialize(SonarAnalysisContext context) => context.RegisterNodeAction(Language.GeneratedCodeRecognizer, c => { var lockExpression = Language.Syntax.NodeExpression(c.Node); - if (c.SemanticModel.GetSymbolInfo(lockExpression).Symbol?.GetSymbolType() is { } lockExpressionType && lockExpressionType.DerivesFromAny(weakIdentityTypes)) + if (c.Model.GetSymbolInfo(lockExpression).Symbol?.GetSymbolType() is { } lockExpressionType && lockExpressionType.DerivesFromAny(weakIdentityTypes)) { c.ReportIssue(Rule, lockExpression, lockExpressionType.Name); } diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/DoNotOverwriteCollectionElementsBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/DoNotOverwriteCollectionElementsBase.cs index 475e0736e02..dc6ba454ae3 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/DoNotOverwriteCollectionElementsBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/DoNotOverwriteCollectionElementsBase.cs @@ -57,7 +57,7 @@ protected void AnalysisAction(SonarSyntaxNodeReportingContext context) if (collectionIdentifier is null || indexOrKey is null || !IsIdentifierOrLiteral(indexOrKey) - || !IsDictionaryOrCollection(collectionIdentifier, context.SemanticModel)) + || !IsDictionaryOrCollection(collectionIdentifier, context.Model)) { return; } diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/DoNotUseDateTimeNowBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/DoNotUseDateTimeNowBase.cs index caf97309cdd..e0692a43490 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/DoNotUseDateTimeNowBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/DoNotUseDateTimeNowBase.cs @@ -38,7 +38,7 @@ protected DoNotUseDateTimeNowBase() : base(DiagnosticId) { } protected override void Initialize(SonarAnalysisContext context) => context.RegisterNodeAction(Language.GeneratedCodeRecognizer, c => { - if ((IsDateTimeNowOrToday(c.Node, c.SemanticModel) || IsDateTimeOffsetNowDateTime(c.Node, c.SemanticModel)) + if ((IsDateTimeNowOrToday(c.Node, c.Model) || IsDateTimeOffsetNowDateTime(c.Node, c.Model)) && !IsInsideNameOf(c.Node)) { c.ReportIssue(Rule, c.Node); diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/EnumNameShouldFollowRegexBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/EnumNameShouldFollowRegexBase.cs index 7df3bd698c2..a9783226207 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/EnumNameShouldFollowRegexBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/EnumNameShouldFollowRegexBase.cs @@ -41,7 +41,7 @@ protected EnumNameShouldFollowRegexBase() => protected sealed override void Initialize(SonarParametrizedAnalysisContext context) => context.RegisterNodeAction(Language.GeneratedCodeRecognizer, c => { - var pattern = c.Node.HasFlagsAttribute(c.SemanticModel) ? FlagsEnumNamePattern : EnumNamePattern; + var pattern = c.Node.HasFlagsAttribute(c.Model) ? FlagsEnumNamePattern : EnumNamePattern; if (Language.Syntax.NodeIdentifier(c.Node) is { } identifier && !NamingHelper.IsRegexMatch(identifier.ValueText, pattern)) { c.ReportIssue(SupportedDiagnostics[0], identifier, pattern); diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/ExceptionsShouldBePublicBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/ExceptionsShouldBePublicBase.cs index 41acaab5d07..e9ae81cd927 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/ExceptionsShouldBePublicBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/ExceptionsShouldBePublicBase.cs @@ -35,7 +35,7 @@ protected override void Initialize(SonarAnalysisContext context) => Language.GeneratedCodeRecognizer, c => { - if (c.SemanticModel.GetDeclaredSymbol(c.Node) is INamedTypeSymbol classSymbol + if (c.Model.GetDeclaredSymbol(c.Node) is INamedTypeSymbol classSymbol && classSymbol.GetEffectiveAccessibility() != Accessibility.Public && classSymbol.BaseType.IsAny(BaseTypes)) { diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/ExcludeFromCodeCoverageAttributesNeedJustificationBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/ExcludeFromCodeCoverageAttributesNeedJustificationBase.cs index 5d1589bfaa1..6580c8382b0 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/ExcludeFromCodeCoverageAttributesNeedJustificationBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/ExcludeFromCodeCoverageAttributesNeedJustificationBase.cs @@ -34,8 +34,8 @@ protected sealed override void Initialize(SonarAnalysisContext context) => Language.GeneratedCodeRecognizer, c => { - if (NoJustification(c.Node, c.SemanticModel) - && c.SemanticModel.GetSymbolInfo(c.Node).Symbol is IMethodSymbol attribute + if (NoJustification(c.Node, c.Model) + && c.Model.GetSymbolInfo(c.Node).Symbol is IMethodSymbol attribute && attribute.IsInType(KnownType.System_Diagnostics_CodeAnalysis_ExcludeFromCodeCoverageAttribute) && HasJustificationProperty(attribute.ContainingType)) { diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/ExtensionMethodShouldNotExtendObjectBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/ExtensionMethodShouldNotExtendObjectBase.cs index 69c5196ed13..2e2a126c558 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/ExtensionMethodShouldNotExtendObjectBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/ExtensionMethodShouldNotExtendObjectBase.cs @@ -33,8 +33,8 @@ protected override void Initialize(SonarAnalysisContext context) => Language.GeneratedCodeRecognizer, c => { - if (IsExtensionMethod((TMethodDeclaration)c.Node, c.SemanticModel) - && c.SemanticModel.GetDeclaredSymbol(c.Node) is IMethodSymbol method + if (IsExtensionMethod((TMethodDeclaration)c.Node, c.Model) + && c.Model.GetDeclaredSymbol(c.Node) is IMethodSymbol method && method.IsExtensionMethod && method.Parameters.Length > 0 && method.Parameters[0].Type.Is(KnownType.System_Object)) diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/FieldShouldNotBePublicBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/FieldShouldNotBePublicBase.cs index 1861db4a0ad..6cde63ec459 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/FieldShouldNotBePublicBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/FieldShouldNotBePublicBase.cs @@ -42,7 +42,7 @@ protected sealed override void Initialize(SonarAnalysisContext context) => var fieldDeclaration = (TFieldDeclarationSyntax)c.Node; var variables = Variables(fieldDeclaration); - foreach (var variable in variables.Select(x => new Pair(x, c.SemanticModel.GetDeclaredSymbol(x) as IFieldSymbol)).Where(x => FieldIsRelevant(x.Symbol))) + foreach (var variable in variables.Select(x => new Pair(x, c.Model.GetDeclaredSymbol(x) as IFieldSymbol)).Where(x => FieldIsRelevant(x.Symbol))) { var identifier = Language.Syntax.NodeIdentifier(variable.Node); c.ReportIssue(Rule, identifier.Value, identifier.Value.ValueText); diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/FindInsteadOfFirstOrDefaultBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/FindInsteadOfFirstOrDefaultBase.cs index 354a883aa63..9cee950086e 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/FindInsteadOfFirstOrDefaultBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/FindInsteadOfFirstOrDefaultBase.cs @@ -41,9 +41,9 @@ protected sealed override void Initialize(SonarAnalysisContext context) => if (Language.GetName(invocation).Equals(nameof(Enumerable.FirstOrDefault), Language.NameComparison) && Language.Syntax.HasExactlyNArguments(invocation, NumberOfArgument) && Language.Syntax.TryGetOperands(invocation, out var left, out var right) - && IsCorrectCall(right, c.SemanticModel) - && IsCorrectType(left, c.SemanticModel, out var isArray) - && !Language.Syntax.IsInExpressionTree(c.SemanticModel, invocation)) + && IsCorrectCall(right, c.Model) + && IsCorrectType(left, c.Model, out var isArray) + && !Language.Syntax.IsInExpressionTree(c.Model, invocation)) { c.ReportIssue(Rule, Language.Syntax.NodeIdentifier(invocation)?.GetLocation(), isArray ? ArrayMessage : GenericMessage); } diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/FlagsEnumWithoutInitializerBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/FlagsEnumWithoutInitializerBase.cs index 03cc8415d2c..685c8db46d3 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/FlagsEnumWithoutInitializerBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/FlagsEnumWithoutInitializerBase.cs @@ -32,7 +32,7 @@ protected FlagsEnumWithoutInitializerBase() : base(DiagnosticId) { } protected sealed override void Initialize(SonarAnalysisContext context) => context.RegisterNodeAction(Language.GeneratedCodeRecognizer, c => { - if (c.Node.HasFlagsAttribute(c.SemanticModel) && !AreAllRequiredMembersInitialized(c.Node) && Language.Syntax.NodeIdentifier(c.Node) is { } identifier) + if (c.Node.HasFlagsAttribute(c.Model) && !AreAllRequiredMembersInitialized(c.Node) && Language.Syntax.NodeIdentifier(c.Node) is { } identifier) { c.ReportIssue(Rule, identifier); } diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/FlagsEnumZeroMemberBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/FlagsEnumZeroMemberBase.cs index bdd0e67f98f..c128835163b 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/FlagsEnumZeroMemberBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/FlagsEnumZeroMemberBase.cs @@ -27,8 +27,8 @@ protected FlagsEnumZeroMemberBase() : base(DiagnosticId) { } protected sealed override void Initialize(SonarAnalysisContext context) => context.RegisterNodeAction(Language.GeneratedCodeRecognizer, c => { - if (c.Node.HasFlagsAttribute(c.SemanticModel) - && ZeroMember(c.Node, c.SemanticModel) is { } zeroMember + if (c.Node.HasFlagsAttribute(c.Model) + && ZeroMember(c.Node, c.Model) is { } zeroMember && Language.Syntax.NodeIdentifier(zeroMember) is { } identifier && identifier.ValueText != "None") { diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/FunctionComplexityBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/FunctionComplexityBase.cs index e231bdf7de2..02df0a0c83a 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/FunctionComplexityBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/FunctionComplexityBase.cs @@ -41,7 +41,7 @@ protected void CheckComplexity(SonarSyntaxNodeReportingContext context, return; } - var complexity = GetComplexity(nodeToAnalyze, context.SemanticModel); + var complexity = GetComplexity(nodeToAnalyze, context.Model); if (complexity > Maximum) { context.ReportIssue(SupportedDiagnostics[0], location(syntax), Maximum.ToString(), complexity.ToString(), declarationType); diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/GenericInheritanceShouldNotBeRecursiveBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/GenericInheritanceShouldNotBeRecursiveBase.cs index 34f856a34d2..ba6640ee927 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/GenericInheritanceShouldNotBeRecursiveBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/GenericInheritanceShouldNotBeRecursiveBase.cs @@ -39,7 +39,7 @@ protected override void Initialize(SonarAnalysisContext context) => var declaration = (TDeclaration)c.Node; if (!c.IsRedundantPositionalRecordContext() - && IsRecursiveInheritance(GetNamedTypeSymbol(declaration, c.SemanticModel))) + && IsRecursiveInheritance(GetNamedTypeSymbol(declaration, c.Model))) { c.ReportIssue(Rule, GetLocation(declaration), GetKeyword(declaration).ValueText); } diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/Hotspots/DoNotHardcodeCredentialsBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/Hotspots/DoNotHardcodeCredentialsBase.cs index 38826e29cc4..38c414bb05f 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/Hotspots/DoNotHardcodeCredentialsBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/Hotspots/DoNotHardcodeCredentialsBase.cs @@ -173,8 +173,8 @@ public Action AnalysisAction() => context => { var declarator = (TSyntaxNode)context.Node; - if (ShouldHandle(declarator, context.SemanticModel) - && GetAssignedValue(declarator, context.SemanticModel) is { } variableValue + if (ShouldHandle(declarator, context.Model) + && GetAssignedValue(declarator, context.Model) is { } variableValue && analyzer.ShouldRaise(GetVariableName(declarator), variableValue, out string message)) { context.ReportIssue(analyzer.rule, declarator, message); diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/Hotspots/HardcodedIpAddressBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/Hotspots/HardcodedIpAddressBase.cs index 30ef13eb607..7fdcdc02150 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/Hotspots/HardcodedIpAddressBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/Hotspots/HardcodedIpAddressBase.cs @@ -88,7 +88,7 @@ private void CheckForHardcodedIpAddressesInStringLiteral(SonarSyntaxNodeReportin private void CheckForHardcodedIpAddressesInStringInterpolation(SonarSyntaxNodeReportingContext context) { if (IsEnabled(context.Options) - && Language.Syntax.InterpolatedTextValue(context.Node, context.SemanticModel) is { } stringContent + && Language.Syntax.InterpolatedTextValue(context.Node, context.Model) is { } stringContent && IsHardcodedIp(stringContent, context.Node)) { context.ReportIssue(Rule, context.Node, stringContent); diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/Hotspots/PubliclyWritableDirectoriesBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/Hotspots/PubliclyWritableDirectoriesBase.cs index 550a6ef3adb..6b353174db8 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/Hotspots/PubliclyWritableDirectoriesBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/Hotspots/PubliclyWritableDirectoriesBase.cs @@ -69,7 +69,7 @@ protected override void Initialize(SonarAnalysisContext context) c => { if (IsEnabled(c.Options) - && Language.Syntax.StringValue(c.Node, c.SemanticModel) is { } stringValue + && Language.Syntax.StringValue(c.Node, c.Model) is { } stringValue && IsSensitiveDirectoryUsage(stringValue)) { c.ReportIssue(rule, c.Node); @@ -83,8 +83,8 @@ protected override void Initialize(SonarAnalysisContext context) { if (IsEnabled(c.Options) && c.Node is TInvocationExpression invocation - && (IsGetTempPathAssignment(invocation, KnownType.System_IO_Path, "GetTempPath", c.SemanticModel) - || IsInsecureEnvironmentVariableRetrieval(invocation, KnownType.System_Environment, "GetEnvironmentVariable", c.SemanticModel))) + && (IsGetTempPathAssignment(invocation, KnownType.System_IO_Path, "GetTempPath", c.Model) + || IsInsecureEnvironmentVariableRetrieval(invocation, KnownType.System_Environment, "GetEnvironmentVariable", c.Model))) { c.ReportIssue(rule, c.Node); } diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/Hotspots/RequestsWithExcessiveLengthBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/Hotspots/RequestsWithExcessiveLengthBase.cs index 84abbfb0669..7bd5b2cf225 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/Hotspots/RequestsWithExcessiveLengthBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/Hotspots/RequestsWithExcessiveLengthBase.cs @@ -94,14 +94,14 @@ private void CollectAttributesOverTheLimit(SonarSyntaxNodeReportingContext conte var attribute = (TAttributeSyntax)context.Node; if (IsDisableRequestSizeLimit(AttributeName(attribute)) - && attribute.IsKnownType(KnownType.Microsoft_AspNetCore_Mvc_DisableRequestSizeLimitAttribute, context.SemanticModel)) + && attribute.IsKnownType(KnownType.Microsoft_AspNetCore_Mvc_DisableRequestSizeLimitAttribute, context.Model)) { context.ReportIssue(Rule, attribute); return; } - var requestSizeLimit = IsInvalidRequestSizeLimit(attribute, context.SemanticModel); - var requestFormLimits = IsInvalidRequestFormLimits(attribute, context.SemanticModel); + var requestSizeLimit = IsInvalidRequestSizeLimit(attribute, context.Model); + var requestFormLimits = IsInvalidRequestFormLimits(attribute, context.Model); if ((requestSizeLimit != null || requestFormLimits != null) && GetMethodLocalFunctionOrClassDeclaration(attribute) is { } declaration) diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/Hotspots/SpecifyTimeoutOnRegexBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/Hotspots/SpecifyTimeoutOnRegexBase.cs index 72c0d4e2b17..8a65a489f71 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/Hotspots/SpecifyTimeoutOnRegexBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/Hotspots/SpecifyTimeoutOnRegexBase.cs @@ -60,7 +60,7 @@ protected override void Initialize(SonarAnalysisContext context) } if (IsCandidateCtor(c.Node) - && RegexMethodLacksTimeout(c.Node, c.SemanticModel)) + && RegexMethodLacksTimeout(c.Node, c.Model)) { c.ReportIssue(Rule, c.Node); } @@ -77,7 +77,7 @@ protected override void Initialize(SonarAnalysisContext context) } if (IsRegexMatchMethod(Language.Syntax.NodeIdentifier(c.Node).GetValueOrDefault().Text) - && RegexMethodLacksTimeout(c.Node, c.SemanticModel)) + && RegexMethodLacksTimeout(c.Node, c.Model)) { c.ReportIssue(Rule, c.Node); } diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/Hotspots/UsingNonstandardCryptographyBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/Hotspots/UsingNonstandardCryptographyBase.cs index bf870f5f286..ce9ac140a2a 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/Hotspots/UsingNonstandardCryptographyBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/Hotspots/UsingNonstandardCryptographyBase.cs @@ -53,7 +53,7 @@ protected override void Initialize(SonarAnalysisContext context) => if (!c.IsRedundantPositionalRecordContext() && IsEnabled(c.Options) && DerivesOrImplementsAny(declaration) - && DeclaredSymbol(declaration, c.SemanticModel).DerivesOrImplementsAny(nonInheritableClassesAndInterfaces)) + && DeclaredSymbol(declaration, c.Model).DerivesOrImplementsAny(nonInheritableClassesAndInterfaces)) { c.ReportIssue(rule, Location(declaration)); } diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/IndexOfCheckAgainstZeroBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/IndexOfCheckAgainstZeroBase.cs index d7171932638..71ee2145f10 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/IndexOfCheckAgainstZeroBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/IndexOfCheckAgainstZeroBase.cs @@ -55,7 +55,7 @@ protected override void Initialize(SonarAnalysisContext context) c => { var lessThan = (TBinaryExpressionSyntax)c.Node; - if (IsInvalidComparison(Left(lessThan), Right(lessThan), c.SemanticModel)) + if (IsInvalidComparison(Left(lessThan), Right(lessThan), c.Model)) { c.ReportIssue(Rule, Left(lessThan).CreateLocation(OperatorToken(lessThan))); } @@ -67,7 +67,7 @@ protected override void Initialize(SonarAnalysisContext context) c => { var greaterThan = (TBinaryExpressionSyntax)c.Node; - if (IsInvalidComparison(Right(greaterThan), Left(greaterThan), c.SemanticModel)) + if (IsInvalidComparison(Right(greaterThan), Left(greaterThan), c.Model)) { c.ReportIssue(Rule, OperatorToken(greaterThan).CreateLocation(Right(greaterThan))); } diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/InsecureTemporaryFilesCreationBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/InsecureTemporaryFilesCreationBase.cs index bd85788c953..499a44de2e5 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/InsecureTemporaryFilesCreationBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/InsecureTemporaryFilesCreationBase.cs @@ -33,7 +33,7 @@ protected override void Initialize(SonarAnalysisContext context) => private void Visit(SonarSyntaxNodeReportingContext context) { var memberAccess = (TMemberAccessSyntax)context.Node; - if (Language.Syntax.IsMemberAccessOnKnownType(memberAccess, VulnerableApiName, KnownType.System_IO_Path, context.SemanticModel)) + if (Language.Syntax.IsMemberAccessOnKnownType(memberAccess, VulnerableApiName, KnownType.System_IO_Path, context.Model)) { context.ReportIssue(Rule, memberAccess); } diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/InsteadOfAnyBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/InsteadOfAnyBase.cs index 1f859c29938..1bcabc87a09 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/InsteadOfAnyBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/InsteadOfAnyBase.cs @@ -57,21 +57,21 @@ protected override void Initialize(SonarAnalysisContext context) => if (IsNameEqualTo(invocation, nameof(Enumerable.Any)) && Language.Syntax.HasExactlyNArguments(invocation, 1) && Language.Syntax.TryGetOperands(invocation, out var left, out var right) - && IsCorrectCall(right, c.SemanticModel) - && c.SemanticModel.GetTypeInfo(left).Type is { } type - && !Language.Syntax.IsInExpressionTree(c.SemanticModel, invocation)) + && IsCorrectCall(right, c.Model) + && c.Model.GetTypeInfo(left).Type is { } type + && !Language.Syntax.IsInExpressionTree(c.Model, invocation)) { if (ExistsTypes.Any(x => type.DerivesFrom(x))) { RaiseIssue(c, invocation, existsRule, "Exists"); } - else if (ContainsTypes.Any(x => type.DerivesFrom(x) && IsSimpleEqualityCheck(invocation, c.SemanticModel))) + else if (ContainsTypes.Any(x => type.DerivesFrom(x) && IsSimpleEqualityCheck(invocation, c.Model))) { RaiseIssue(c, invocation, containsRule, "Contains"); } else if (type.DerivesFrom(KnownType.System_Collections_Generic_List_T)) { - if (IsSimpleEqualityCheck(invocation, c.SemanticModel)) + if (IsSimpleEqualityCheck(invocation, c.Model)) { RaiseIssue(c, invocation, containsRule, "Contains"); } diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/InvalidCastToInterfaceBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/InvalidCastToInterfaceBase.cs index 7a5da85b6e3..36479441cd4 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/InvalidCastToInterfaceBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/InvalidCastToInterfaceBase.cs @@ -39,13 +39,13 @@ protected override void Initialize(SonarAnalysisContext context) => compilationStartContext.RegisterNodeAction(Language.GeneratedCodeRecognizer, c => { var type = Language.Syntax.CastType(c.Node); - var interfaceType = c.SemanticModel.GetTypeInfo(type).Type as INamedTypeSymbol; - var expressionType = c.SemanticModel.GetTypeInfo(Language.Syntax.CastExpression(c.Node)).Type as INamedTypeSymbol; + var interfaceType = c.Model.GetTypeInfo(type).Type as INamedTypeSymbol; + var expressionType = c.Model.GetTypeInfo(Language.Syntax.CastExpression(c.Node)).Type as INamedTypeSymbol; if (IsImpossibleCast(interfaceImplementers, interfaceType, expressionType)) { var location = type.GetLocation(); - var interfaceTypeName = interfaceType.ToMinimalDisplayString(c.SemanticModel, location.SourceSpan.Start); - var expressionTypeName = expressionType.ToMinimalDisplayString(c.SemanticModel, location.SourceSpan.Start); + var interfaceTypeName = interfaceType.ToMinimalDisplayString(c.Model, location.SourceSpan.Start); + var expressionTypeName = expressionType.ToMinimalDisplayString(c.Model, location.SourceSpan.Start); var message = expressionType.IsInterface() ? MessageInterface : MessageClass; c.ReportIssue(Rule, location, string.Format(message, expressionTypeName, interfaceTypeName)); } diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/LinkedListPropertiesInsteadOfMethodsBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/LinkedListPropertiesInsteadOfMethodsBase.cs index 3290aec342d..0577fdf3897 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/LinkedListPropertiesInsteadOfMethodsBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/LinkedListPropertiesInsteadOfMethodsBase.cs @@ -34,7 +34,7 @@ protected sealed override void Initialize(SonarAnalysisContext context) => var invocation = (TInvocationExpression)c.Node; var methodName = Language.GetName(invocation); - if (IsFirstOrLast(methodName) && IsRelevantCallAndType(invocation, c.SemanticModel)) + if (IsFirstOrLast(methodName) && IsRelevantCallAndType(invocation, c.Model)) { c.ReportIssue(Rule, Language.Syntax.NodeIdentifier(invocation)?.GetLocation(), methodName); } diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/MarkWindowsFormsMainWithStaThreadBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/MarkWindowsFormsMainWithStaThreadBase.cs index 1f0283e8f81..73462ee5ae6 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/MarkWindowsFormsMainWithStaThreadBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/MarkWindowsFormsMainWithStaThreadBase.cs @@ -39,11 +39,11 @@ private void Action(SonarSyntaxNodeReportingContext c) { var methodDeclaration = (TMethodSyntax)c.Node; - if (c.SemanticModel.GetDeclaredSymbol(methodDeclaration) is IMethodSymbol methodSymbol + if (c.Model.GetDeclaredSymbol(methodDeclaration) is IMethodSymbol methodSymbol && methodSymbol.IsMainMethod() && !methodSymbol.IsAsync && !methodSymbol.HasAttribute(KnownType.System_STAThreadAttribute) - && IsAssemblyReferencingWindowsForms(c.SemanticModel.Compilation) + && IsAssemblyReferencingWindowsForms(c.Model.Compilation) && c.Compilation.Options.OutputKind == OutputKind.WindowsApplication) { var message = methodSymbol.HasAttribute(KnownType.System_MTAThreadAttribute) diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/MethodOverloadsShouldBeGroupedBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/MethodOverloadsShouldBeGroupedBase.cs index 4aa0612d698..469a4cd38d1 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/MethodOverloadsShouldBeGroupedBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/MethodOverloadsShouldBeGroupedBase.cs @@ -81,7 +81,7 @@ bool IsMisplacedCandidate(TMemberDeclarationSyntax member, List othe { if (membersGroupedByInterface.TryGetValue(member, out var interfaces)) { - return interfaces.Length == 1 && others.Any(other => FindInterfaces(c.SemanticModel, other.Member).Contains(interfaces.Single())); + return interfaces.Length == 1 && others.Any(other => FindInterfaces(c.Model, other.Member).Contains(interfaces.Single())); } return true; // Not member of an interface => process } @@ -102,7 +102,7 @@ private static Dictionary { var method = methodsToHandle.First.Value; methodsToHandle.RemoveFirst(); - var duplicates = methodsToHandle.Where(x => AreDuplicates(c.SemanticModel, method, x)).ToList(); + var duplicates = methodsToHandle.Where(x => AreDuplicates(c.Model, method, x)).ToList(); foreach (var duplicate in duplicates) { diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/ObsoleteAttributesBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/ObsoleteAttributesBase.cs index 4cbcddd9919..c1db93f3967 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/ObsoleteAttributesBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/ObsoleteAttributesBase.cs @@ -46,13 +46,13 @@ protected sealed override void Initialize(SonarAnalysisContext context) => Language.GeneratedCodeRecognizer, c => { - if (c.SemanticModel.GetSymbolInfo(c.Node).Symbol is { } attribute + if (c.Model.GetSymbolInfo(c.Node).Symbol is { } attribute && attribute.IsInType(KnownType.System_ObsoleteAttribute)) { var location = c.Node.GetLocation(); c.ReportIssue(RemoveRule, location); - if (NoExplanation(c.Node, c.SemanticModel)) + if (NoExplanation(c.Node, c.Model)) { c.ReportIssue(ExplanationNeededRule, location); } diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/OptionalParameterBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/OptionalParameterBase.cs index 2f8faaa4a82..0b606fbfcef 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/OptionalParameterBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/OptionalParameterBase.cs @@ -36,7 +36,7 @@ protected sealed override void Initialize(SonarAnalysisContext context) c => { var method = (TMethodSyntax)c.Node; - var symbol = c.SemanticModel.GetDeclaredSymbol(method); + var symbol = c.Model.GetDeclaredSymbol(method); if (symbol == null || !symbol.IsPubliclyAccessible() || @@ -48,7 +48,7 @@ protected sealed override void Initialize(SonarAnalysisContext context) var parameters = GetParameters(method); - foreach (var parameter in parameters.Where(p => IsOptional(p) && !HasAllowedAttribute(p, c.SemanticModel))) + foreach (var parameter in parameters.Where(p => IsOptional(p) && !HasAllowedAttribute(p, c.Model))) { var location = GetReportLocation(parameter); c.ReportIssue(SupportedDiagnostics[0], location); diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/OptionalParameterNotPassedToBaseCallBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/OptionalParameterNotPassedToBaseCallBase.cs index 6150bcc1549..39e90334478 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/OptionalParameterNotPassedToBaseCallBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/OptionalParameterNotPassedToBaseCallBase.cs @@ -25,7 +25,7 @@ public abstract class OptionalParameterNotPassedToBaseCallBase { foreach (var target in Language.Syntax.AssignmentTargets(c.Node)) { - if (c.SemanticModel.GetSymbolInfo(target).Symbol is { } symbol + if (c.Model.GetSymbolInfo(target).Symbol is { } symbol && (symbol is IParameterSymbol { RefKind: RefKind.None } || IsAssignmentToCatchVariable(symbol, target)) - && !IsReadBefore(c.SemanticModel, symbol, c.Node)) + && !IsReadBefore(c.Model, symbol, c.Node)) { c.ReportIssue(Rule, target, target.ToString()); } diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/ParameterNameMatchesOriginalBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/ParameterNameMatchesOriginalBase.cs index 4e9c27cb3b0..d7e3857c087 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/ParameterNameMatchesOriginalBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/ParameterNameMatchesOriginalBase.cs @@ -33,7 +33,7 @@ protected override void Initialize(SonarAnalysisContext context) => context.RegisterNodeAction(Language.GeneratedCodeRecognizer, c => { var methodSyntax = (TMethodDeclarationSyntax)c.Node; - if (c.SemanticModel.GetDeclaredSymbol(methodSyntax) is IMethodSymbol methodSymbol && methodSymbol.Parameters.Any()) + if (c.Model.GetDeclaredSymbol(methodSyntax) is IMethodSymbol methodSymbol && methodSymbol.Parameters.Any()) { if (methodSymbol.PartialImplementationPart != null) { diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/ParametersCorrectOrderBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/ParametersCorrectOrderBase.cs index 843de6ef498..1f23c6c10f4 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/ParametersCorrectOrderBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/ParametersCorrectOrderBase.cs @@ -33,7 +33,7 @@ protected sealed override void Initialize(SonarAnalysisContext context) => if (!c.IsRedundantPrimaryConstructorBaseTypeContext() && Language.Syntax.ArgumentList(c.Node) is { Count: >= MinNumberOfNameableArguments } argumentList // there must be at least two arguments to be able to swap, and further && argumentList.Select(ArgumentName).WhereNotNull().Take(MinNumberOfNameableArguments).Count() == MinNumberOfNameableArguments // at least two arguments with a "name" - && Language.MethodParameterLookup(c.Node, c.SemanticModel) is var methodParameterLookup) + && Language.MethodParameterLookup(c.Node, c.Model) is var methodParameterLookup) { foreach (var argument in argumentList) { diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/PartCreationPolicyShouldBeUsedWithExportAttributeBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/PartCreationPolicyShouldBeUsedWithExportAttributeBase.cs index f398e7b4be1..81e81b7dac2 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/PartCreationPolicyShouldBeUsedWithExportAttributeBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/PartCreationPolicyShouldBeUsedWithExportAttributeBase.cs @@ -40,7 +40,7 @@ protected void AnalyzeNode(SonarSyntaxNodeReportingContext c) return; } - if (!(c.SemanticModel.GetDeclaredSymbol(declaration) is ITypeSymbol symbol) + if (!(c.Model.GetDeclaredSymbol(declaration) is ITypeSymbol symbol) || symbol.AnyAttributeDerivesFrom(KnownType.System_ComponentModel_Composition_ExportAttribute) || symbol.GetSelfAndBaseTypes() .Union(symbol.AllInterfaces) @@ -52,7 +52,7 @@ protected void AnalyzeNode(SonarSyntaxNodeReportingContext c) c.ReportIssue(SupportedDiagnostics[0], attribute); bool IsPartCreationPolicyAttribute(TAttributeSyntax attributeSyntax) => - c.SemanticModel.GetSymbolInfo(attributeSyntax).Symbol is IMethodSymbol attributeSymbol + c.Model.GetSymbolInfo(attributeSyntax).Symbol is IMethodSymbol attributeSymbol && attributeSymbol.ContainingType.Is(KnownType.System_ComponentModel_Composition_PartCreationPolicyAttribute); } } diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/PreferGuidEmptyBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/PreferGuidEmptyBase.cs index b681dbea093..baecc2afd28 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/PreferGuidEmptyBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/PreferGuidEmptyBase.cs @@ -31,8 +31,8 @@ protected override void Initialize(SonarAnalysisContext context) Language.GeneratedCodeRecognizer, c => { - if (IsInvalidCtor(c.Node, c.SemanticModel) - && c.SemanticModel.GetSymbolInfo(c.Node).Symbol is IMethodSymbol methodSymbol + if (IsInvalidCtor(c.Node, c.Model) + && c.Model.GetSymbolInfo(c.Node).Symbol is IMethodSymbol methodSymbol && methodSymbol.ContainingType.Is(KnownType.System_Guid)) { c.ReportIssue(Rule, c.Node); @@ -45,7 +45,7 @@ protected override void Initialize(SonarAnalysisContext context) c => { if (!IsInParameter(c.Node) - && c.SemanticModel.GetTypeInfo(c.Node).ConvertedType.Is(KnownType.System_Guid)) + && c.Model.GetTypeInfo(c.Node).ConvertedType.Is(KnownType.System_Guid)) { c.ReportIssue(Rule, c.Node); } diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/PropertyGetterWithThrowBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/PropertyGetterWithThrowBase.cs index 8211bea2e71..d0c6b3979ac 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/PropertyGetterWithThrowBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/PropertyGetterWithThrowBase.cs @@ -62,7 +62,7 @@ protected sealed override void Initialize(SonarAnalysisContext context) return; } - var type = c.SemanticModel.GetTypeInfo(throwExpression).Type; + var type = c.Model.GetTypeInfo(throwExpression).Type; if (type == null || type.DerivesFromAny(AllowedExceptionBaseTypes)) { return; diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/PublicConstantFieldBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/PublicConstantFieldBase.cs index c291dbcdf24..14a139f78c9 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/PublicConstantFieldBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/PublicConstantFieldBase.cs @@ -45,7 +45,7 @@ protected sealed override void Initialize(SonarAnalysisContext context) } var anyVariable = variables.First(); - if (!(c.SemanticModel.GetDeclaredSymbol(anyVariable) is IFieldSymbol symbol) || + if (!(c.Model.GetDeclaredSymbol(anyVariable) is IFieldSymbol symbol) || !symbol.IsConst || symbol.GetEffectiveAccessibility() != Accessibility.Public) { diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/PublicMethodWithMultidimensionalArrayBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/PublicMethodWithMultidimensionalArrayBase.cs index fc056cede99..085645c5bd2 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/PublicMethodWithMultidimensionalArrayBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/PublicMethodWithMultidimensionalArrayBase.cs @@ -32,7 +32,7 @@ protected sealed override void Initialize(SonarAnalysisContext context) => context.RegisterNodeAction(Language.GeneratedCodeRecognizer, c => { - if (MethodSymbolOfNode(c.SemanticModel, c.Node) is { } methodSymbol + if (MethodSymbolOfNode(c.Model, c.Node) is { } methodSymbol && methodSymbol.GetInterfaceMember() == null && !methodSymbol.IsOverride && methodSymbol.IsPubliclyAccessible() diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/RegularExpressions/RegexMustHaveValidSyntaxBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/RegularExpressions/RegexMustHaveValidSyntaxBase.cs index 29dec71ac1d..5da8fa457e3 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/RegularExpressions/RegexMustHaveValidSyntaxBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/RegularExpressions/RegexMustHaveValidSyntaxBase.cs @@ -31,17 +31,17 @@ protected override void Initialize(SonarAnalysisContext context) { context.RegisterNodeAction( Language.GeneratedCodeRecognizer, - c => Analyze(c, RegexContext.FromCtor(Language, c.SemanticModel, c.Node)), + c => Analyze(c, RegexContext.FromCtor(Language, c.Model, c.Node)), Language.SyntaxKind.ObjectCreationExpressions); context.RegisterNodeAction( Language.GeneratedCodeRecognizer, - c => Analyze(c, RegexContext.FromMethod(Language, c.SemanticModel, c.Node)), + c => Analyze(c, RegexContext.FromMethod(Language, c.Model, c.Node)), Language.SyntaxKind.InvocationExpression); context.RegisterNodeAction( Language.GeneratedCodeRecognizer, - c => Analyze(c, RegexContext.FromAttribute(Language, c.SemanticModel, c.Node)), + c => Analyze(c, RegexContext.FromAttribute(Language, c.Model, c.Node)), Language.SyntaxKind.Attribute); } diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/SecurityPInvokeMethodShouldNotBeCalledBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/SecurityPInvokeMethodShouldNotBeCalledBase.cs index 3a525bd285f..8fa2290daad 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/SecurityPInvokeMethodShouldNotBeCalledBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/SecurityPInvokeMethodShouldNotBeCalledBase.cs @@ -58,11 +58,11 @@ private void CheckForIssue(SonarSyntaxNodeReportingContext analysisContext) { if (analysisContext.Node is TInvocationExpressionSyntax invocation && Language.Syntax.NodeExpression(invocation) is { } directMethodCall - && MethodSymbolForInvalidInvocation(directMethodCall, analysisContext.SemanticModel) is IMethodSymbol methodSymbol + && MethodSymbolForInvalidInvocation(directMethodCall, analysisContext.Model) is IMethodSymbol methodSymbol && methodSymbol.IsStatic - && IsImportFromInteropDll(methodSymbol, analysisContext.SemanticModel)) + && IsImportFromInteropDll(methodSymbol, analysisContext.Model)) { - analysisContext.ReportIssue(Rule, Language.Syntax.NodeIdentifier(directMethodCall).Value, GetMethodName(methodSymbol, analysisContext.SemanticModel)); + analysisContext.ReportIssue(Rule, Language.Syntax.NodeIdentifier(directMethodCall).Value, GetMethodName(methodSymbol, analysisContext.Model)); } } } diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/SetPropertiesInsteadOfMethodsBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/SetPropertiesInsteadOfMethodsBase.cs index 75c77ccd1cb..1c984d32bc9 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/SetPropertiesInsteadOfMethodsBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/SetPropertiesInsteadOfMethodsBase.cs @@ -41,8 +41,8 @@ protected override void Initialize(SonarAnalysisContext context) => if (HasCorrectName(methodName) && HasCorrectArgumentCount(invocation) && TryGetOperands(invocation, out var typeNode, out var methodNode) - && IsCorrectType(typeNode, c.SemanticModel) - && IsCorrectCall(methodNode, c.SemanticModel)) + && IsCorrectType(typeNode, c.Model) + && IsCorrectCall(methodNode, c.Model)) { c.ReportIssue(Rule, Language.Syntax.NodeIdentifier(invocation)?.GetLocation(), methodName); } diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/ShiftDynamicNotIntegerBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/ShiftDynamicNotIntegerBase.cs index 9e3e592d8e2..2028fca459a 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/ShiftDynamicNotIntegerBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/ShiftDynamicNotIntegerBase.cs @@ -49,10 +49,10 @@ protected void CheckExpressionWithTwoParts(SonarSyntaxNodeReportingContext conte var left = getLeft(expression); var right = getRight(expression); - if (!IsErrorType(right, context.SemanticModel, out var typeOfRight) - && ShouldRaise(context.SemanticModel, left, right)) + if (!IsErrorType(right, context.Model, out var typeOfRight) + && ShouldRaise(context.Model, left, right)) { - var typeInMessage = GetTypeNameForMessage(right, typeOfRight, context.SemanticModel); + var typeInMessage = GetTypeNameForMessage(right, typeOfRight, context.Model); context.ReportIssue(Rule, right, typeInMessage); } } diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/ShouldImplementExportedInterfacesBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/ShouldImplementExportedInterfacesBase.cs index e588bb5f0d7..fe21873ea09 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/ShouldImplementExportedInterfacesBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/ShouldImplementExportedInterfacesBase.cs @@ -46,14 +46,14 @@ protected override void Initialize(SonarAnalysisContext context) => c => { var attributeSyntax = (TAttributeSyntax)c.Node; - if (c.SemanticModel.GetSymbolInfo(GetAttributeName(attributeSyntax)).Symbol is not IMethodSymbol attributeCtorSymbol + if (c.Model.GetSymbolInfo(GetAttributeName(attributeSyntax)).Symbol is not IMethodSymbol attributeCtorSymbol || !attributeCtorSymbol.ContainingType.IsAny(exportAttributes)) { return; } - var exportedType = GetExportedTypeSymbol(GetAttributeArguments(attributeSyntax), c.SemanticModel); - var attributeTargetType = GetAttributeTargetSymbol(attributeSyntax, c.SemanticModel); + var exportedType = GetExportedTypeSymbol(GetAttributeArguments(attributeSyntax), c.Model); + var attributeTargetType = GetAttributeTargetSymbol(attributeSyntax, c.Model); if (exportedType is null || attributeTargetType is null || IsOfExportType(attributeTargetType, exportedType)) diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/StringConcatenationInLoopBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/StringConcatenationInLoopBase.cs index 2e3316c3010..0af7cc1016a 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/StringConcatenationInLoopBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/StringConcatenationInLoopBase.cs @@ -43,9 +43,9 @@ private void CheckSimpleAssignment(SonarSyntaxNodeReportingContext context) && Language.Syntax.IsAnyKind(rightExpression, ExpressionConcatenationKinds) && Language.Syntax.AssignmentLeft(assignment) is var assigned && IsIdentifierOnTheRight(assigned, rightExpression) - && IsSystemString(assigned, context.SemanticModel) - && context.SemanticModel.GetSymbolInfo(assigned).Symbol is ILocalSymbol - && AreNotDefinedInTheSameLoop(assigned, assignment, context.SemanticModel)) + && IsSystemString(assigned, context.Model) + && context.Model.GetSymbolInfo(assigned).Symbol is ILocalSymbol + && AreNotDefinedInTheSameLoop(assigned, assignment, context.Model)) { context.ReportIssue(SupportedDiagnostics[0], assignment); } @@ -56,9 +56,9 @@ private void CheckCompoundAssignment(SonarSyntaxNodeReportingContext context) var addAssignment = (TAssignmentExpression)context.Node; if (Language.Syntax.AssignmentLeft(addAssignment) is var expression - && IsSystemString(expression, context.SemanticModel) - && context.SemanticModel.GetSymbolInfo(expression).Symbol is ILocalSymbol - && AreNotDefinedInTheSameLoop(expression, addAssignment, context.SemanticModel)) + && IsSystemString(expression, context.Model) + && context.Model.GetSymbolInfo(expression).Symbol is ILocalSymbol + && AreNotDefinedInTheSameLoop(expression, addAssignment, context.Model)) { context.ReportIssue(SupportedDiagnostics[0], addAssignment); } diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/TestsShouldNotUseThreadSleepBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/TestsShouldNotUseThreadSleepBase.cs index 72e88098427..4991755b7f2 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/TestsShouldNotUseThreadSleepBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/TestsShouldNotUseThreadSleepBase.cs @@ -32,9 +32,9 @@ protected sealed override void Initialize(SonarAnalysisContext context) => context.RegisterNodeAction(Language.GeneratedCodeRecognizer, c => { if (c.Node.ToStringContains(nameof(Thread.Sleep), Language.NameComparison) - && c.SemanticModel.GetSymbolInfo(c.Node).Symbol is IMethodSymbol method + && c.Model.GetSymbolInfo(c.Node).Symbol is IMethodSymbol method && method.Is(KnownType.System_Threading_Thread, nameof(Thread.Sleep)) - && IsInTestMethod(c.Node, c.SemanticModel)) + && IsInTestMethod(c.Node, c.Model)) { c.ReportIssue(Rule, c.Node); } diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/ThrowReservedExceptionsBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/ThrowReservedExceptionsBase.cs index d137ec7d2da..9740c32b665 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/ThrowReservedExceptionsBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/ThrowReservedExceptionsBase.cs @@ -38,7 +38,7 @@ protected void Process(SonarSyntaxNodeReportingContext context, SyntaxNode throw { if (thrownExpression is not null && Language.Syntax.IsAnyKind(thrownExpression, Language.SyntaxKind.ObjectCreationExpressions)) { - var expressionType = context.SemanticModel.GetTypeInfo(thrownExpression).Type; + var expressionType = context.Model.GetTypeInfo(thrownExpression).Type; if (expressionType.IsAny(reservedExceptions)) { context.ReportIssue(Rule, thrownExpression, expressionType.ToDisplayString()); diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/TooManyLabelsInSwitchBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/TooManyLabelsInSwitchBase.cs index 8313d3411ee..2aa1ddd04b5 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/TooManyLabelsInSwitchBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/TooManyLabelsInSwitchBase.cs @@ -51,7 +51,7 @@ protected override void Initialize(SonarParametrizedAnalysisContext context) => { var switchNode = (TSwitchStatementSyntax)c.Node; - if (c.SemanticModel.GetTypeInfo(GetExpression(switchNode)).Type is { TypeKind: not TypeKind.Enum } + if (c.Model.GetTypeInfo(GetExpression(switchNode)).Type is { TypeKind: not TypeKind.Enum } && GetSectionsCount(switchNode) > Maximum && !AllSectionsAreOneLiners(switchNode)) { diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/TooManyParametersBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/TooManyParametersBase.cs index 5f157b293b0..398e8e39d6e 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/TooManyParametersBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/TooManyParametersBase.cs @@ -50,7 +50,7 @@ protected override void Initialize(SonarParametrizedAnalysisContext context) => if (parametersCount - baseCount > Maximum && c.Node.Parent is { } parent && !IsExtern(parent) - && CanBeChanged(parent, c.SemanticModel)) + && CanBeChanged(parent, c.Model)) { var valueText = baseCount == 0 ? parametersCount.ToString() : $"{parametersCount - baseCount} new"; c.ReportIssue(SupportedDiagnostics[0], c.Node, UserFriendlyNameForNode(c.Node.Parent), valueText, Maximum.ToString()); diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/UnconditionalJumpStatementBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/UnconditionalJumpStatementBase.cs index 4de0ac6c280..ad4a6523e81 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/UnconditionalJumpStatementBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/UnconditionalJumpStatementBase.cs @@ -72,7 +72,7 @@ public abstract class LoopWalkerBase protected LoopWalkerBase(SonarSyntaxNodeReportingContext context, ISet loopStatements) { rootExpression = context.Node; - semanticModel = context.SemanticModel; + semanticModel = context.Model; ignoredSyntaxesKind = LambdaSyntaxes.Union(LocalFunctionSyntaxes).Union(loopStatements).ToHashSet(); } diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/UnnecessaryBitwiseOperationBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/UnnecessaryBitwiseOperationBase.cs index 0abd5e33fb6..257568542c3 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/UnnecessaryBitwiseOperationBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/UnnecessaryBitwiseOperationBase.cs @@ -34,12 +34,12 @@ protected void CheckBinary(SonarSyntaxNodeReportingContext context, SyntaxNode l { Location location; bool isReportingOnLeftKey; - if (FindIntConstant(context.SemanticModel, left) is { } valueLeft && valueLeft == constValueToLookFor) + if (FindIntConstant(context.Model, left) is { } valueLeft && valueLeft == constValueToLookFor) { location = left.CreateLocation(@operator); isReportingOnLeftKey = true; } - else if (FindIntConstant(context.SemanticModel, right) is { } valueRight && valueRight == constValueToLookFor) + else if (FindIntConstant(context.Model, right) is { } valueRight && valueRight == constValueToLookFor) { location = @operator.CreateLocation(right); isReportingOnLeftKey = false; diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/UnusedStringBuilderBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/UnusedStringBuilderBase.cs index f7b26223979..a903727b6a2 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/UnusedStringBuilderBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/UnusedStringBuilderBase.cs @@ -40,9 +40,9 @@ protected sealed override void Initialize(SonarAnalysisContext context) => { var variableDeclarator = (TVariableDeclarator)c.Node; - if (RetrieveStringBuilderObject(c.SemanticModel, variableDeclarator) is { } symbol + if (RetrieveStringBuilderObject(c.Model, variableDeclarator) is { } symbol && GetScope(variableDeclarator) is { } scope - && !IsStringBuilderAccessed(c.SemanticModel, symbol, scope)) + && !IsStringBuilderAccessed(c.Model, symbol, scope)) { c.ReportIssue(Rule, variableDeclarator); } diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/UriShouldNotBeHardcodedBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/UriShouldNotBeHardcodedBase.cs index 238a1baf229..e56a7ce539e 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/UriShouldNotBeHardcodedBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/UriShouldNotBeHardcodedBase.cs @@ -72,7 +72,7 @@ protected override void Initialize(SonarAnalysisContext context) GeneratedCodeRecognizer, c => { - if (UriRegex.SafeIsMatch(Language.Syntax.LiteralText(c.Node)) && IsInCheckedContext(c.Node, c.SemanticModel)) + if (UriRegex.SafeIsMatch(Language.Syntax.LiteralText(c.Node)) && IsInCheckedContext(c.Node, c.Model)) { c.ReportIssue(SupportedDiagnostics[0], c.Node, AbsoluteUriMessage); } @@ -83,7 +83,7 @@ protected override void Initialize(SonarAnalysisContext context) GeneratedCodeRecognizer, c => { - var isInCheckedContext = new Lazy(() => IsInCheckedContext(c.Node, c.SemanticModel)); + var isInCheckedContext = new Lazy(() => IsInCheckedContext(c.Node, c.Model)); var leftNode = Language.Syntax.BinaryExpressionLeft(c.Node); if (IsPathDelimiter(leftNode) && isInCheckedContext.Value) diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/UseCharOverloadOfStringMethodsBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/UseCharOverloadOfStringMethodsBase.cs index e9c3a2840bb..e27000e51fe 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/UseCharOverloadOfStringMethodsBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/UseCharOverloadOfStringMethodsBase.cs @@ -44,7 +44,7 @@ protected override void Initialize(SonarAnalysisContext context) => if (HasCorrectName(methodName) && HasCorrectArguments(invocation) && Language.Syntax.TryGetOperands(invocation, out var left, out _) - && IsCorrectType(left, c.SemanticModel)) + && IsCorrectType(left, c.Model)) { c.ReportIssue(Rule, Language.Syntax.NodeIdentifier(invocation)?.GetLocation(), methodName); } diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/UseDateTimeOffsetInsteadOfDateTimeBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/UseDateTimeOffsetInsteadOfDateTimeBase.cs index ca57e88e0d5..db400da5542 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/UseDateTimeOffsetInsteadOfDateTimeBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/UseDateTimeOffsetInsteadOfDateTimeBase.cs @@ -42,7 +42,7 @@ protected sealed override void Initialize(SonarAnalysisContext context) c => { if ((c.Node.RawKind == (int)SyntaxKindEx.ImplicitObjectCreationExpression || IsNamedDateTime(GetTypeName(c.Node))) - && IsDateTimeType(c.Node, c.SemanticModel)) + && IsDateTimeType(c.Node, c.Model)) { c.ReportIssue(Rule, c.Node); } @@ -56,7 +56,7 @@ protected sealed override void Initialize(SonarAnalysisContext context) if (Language.Syntax.NodeExpression(c.Node) is var expression && IsNamedDateTime(Language.GetName(expression)) && TargetMemberAccess.Contains(Language.GetName(c.Node)) - && IsDateTimeType(expression, c.SemanticModel)) + && IsDateTimeType(expression, c.Model)) { c.ReportIssue(Rule, Language.Syntax.NodeExpression(c.Node)); } diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/UseIFormatProviderForParsingDateAndTimeBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/UseIFormatProviderForParsingDateAndTimeBase.cs index cd63846372a..53a94d34051 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/UseIFormatProviderForParsingDateAndTimeBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/UseIFormatProviderForParsingDateAndTimeBase.cs @@ -46,7 +46,7 @@ protected override void Initialize(SonarAnalysisContext context) => { if (Language.Syntax.NodeIdentifier(c.Node) is { IsMissing: false } identifier && Array.Exists(ParseMethodNames, x => identifier.ValueText.Equals(x, Language.NameComparison)) - && c.SemanticModel.GetSymbolInfo(c.Node) is { Symbol: IMethodSymbol methodSymbol } + && c.Model.GetSymbolInfo(c.Node) is { Symbol: IMethodSymbol methodSymbol } && TemporalTypes.Any(x => x.Matches(methodSymbol.ReceiverType)) && NotUsingFormatProvider(methodSymbol, c.Node)) { diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/UseIndexingInsteadOfLinqMethodsBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/UseIndexingInsteadOfLinqMethodsBase.cs index 962e5caa06a..90e59f538e4 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/UseIndexingInsteadOfLinqMethodsBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/UseIndexingInsteadOfLinqMethodsBase.cs @@ -39,8 +39,8 @@ protected override void Initialize(SonarAnalysisContext context) => if (HasValidSignature(invocation, out var methodName, out var indexDescriptor) && Language.Syntax.TryGetOperands(invocation, out var left, out var right) - && IsCorrectType(left, c.SemanticModel) - && IsCorrectCall(right, c.SemanticModel)) + && IsCorrectType(left, c.Model) + && IsCorrectCall(right, c.Model)) { c.ReportIssue( Rule, diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/UseLambdaParameterInConcurrentDictionaryBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/UseLambdaParameterInConcurrentDictionaryBase.cs index 837489de7dc..4982b827657 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/UseLambdaParameterInConcurrentDictionaryBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/UseLambdaParameterInConcurrentDictionaryBase.cs @@ -38,8 +38,8 @@ protected override void Initialize(SonarAnalysisContext context) => if (HasCorrectName(Language.GetName(invocation)) && Language.Syntax.TryGetOperands(invocation, out var left, out var right) - && IsCorrectType(left, c.SemanticModel) - && IsCorrectCall(right, c.SemanticModel) + && IsCorrectType(left, c.Model) + && IsCorrectCall(right, c.Model) && GetArguments(invocation) is { Count: > 1 } arguments && TryGetKeyName(arguments[0], out var keyName)) { diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/UseShortCircuitingOperatorBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/UseShortCircuitingOperatorBase.cs index 13e0d7ea922..c1b333336bc 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/UseShortCircuitingOperatorBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/UseShortCircuitingOperatorBase.cs @@ -37,11 +37,11 @@ protected sealed override void Initialize(SonarAnalysisContext context) => if (c.Node is TBinaryExpression node && Language.Syntax.BinaryExpressionLeft(node) is { } left && Language.Syntax.BinaryExpressionRight(node) is { } right - && IsBool(left, c.SemanticModel) - && IsBool(right, c.SemanticModel)) + && IsBool(left, c.Model) + && IsBool(right, c.Model)) { - var extractText = c.SemanticModel.GetConstantValue(right) is { HasValue: true } - || c.SemanticModel.GetSymbolInfo(right).Symbol is ILocalSymbol or IFieldSymbol or IPropertySymbol or IParameterSymbol + var extractText = c.Model.GetConstantValue(right) is { HasValue: true } + || c.Model.GetSymbolInfo(right).Symbol is ILocalSymbol or IFieldSymbol or IPropertySymbol or IParameterSymbol ? string.Empty : " and extract the right operand to a variable if it should always be evaluated"; c.ReportIssue(SupportedDiagnostics[0], GetOperator(node), GetCurrentOpName(node), GetSuggestedOpName(node), extractText); diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/UseTestableTimeProviderBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/UseTestableTimeProviderBase.cs index 3e62f891429..4dbd4483c5d 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/UseTestableTimeProviderBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/UseTestableTimeProviderBase.cs @@ -32,9 +32,9 @@ protected sealed override void Initialize(SonarAnalysisContext context) => context.RegisterNodeAction(Language.GeneratedCodeRecognizer, c => { if (IsDateTimeProviderProperty(Language.Syntax.NodeIdentifier(c.Node).Value.Text) - && c.SemanticModel.GetSymbolInfo(c.Node).Symbol is IPropertySymbol property + && c.Model.GetSymbolInfo(c.Node).Symbol is IPropertySymbol property && property.IsInType(trackedTypes) - && !c.Node.Ancestors().Any(x => Ignore(x, c.SemanticModel))) + && !c.Node.Ancestors().Any(x => Ignore(x, c.Model))) { c.ReportIssue(Rule, c.Node.Parent); } diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/UseTrueForAllBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/UseTrueForAllBase.cs index 7cf99c0d329..3035ee90bcd 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/UseTrueForAllBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/UseTrueForAllBase.cs @@ -34,8 +34,8 @@ protected override void Initialize(SonarAnalysisContext context) => { if (Language.GetName(c.Node).Equals(nameof(Enumerable.All), Language.NameComparison) && Language.Syntax.TryGetOperands(c.Node, out var left, out var right) - && IsCorrectType(left, c.SemanticModel) - && IsCorrectCall(right, c.SemanticModel)) + && IsCorrectType(left, c.Model) + && IsCorrectCall(right, c.Model)) { c.ReportIssue(Rule, Language.Syntax.NodeIdentifier(c.Node)?.GetLocation()); } diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/UseUnixEpochBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/UseUnixEpochBase.cs index 0670a5f7f75..9d8548a83db 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/UseUnixEpochBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/UseUnixEpochBase.cs @@ -59,15 +59,15 @@ protected sealed override void Initialize(SonarAnalysisContext context) => if (literalsArguments.Any(x => IsValueEqualTo(x, EpochYear) && literalsArguments.Count(x => IsValueEqualTo(x, EpochMonth)) == 2) - && CheckAndGetTypeName(cc.Node, cc.SemanticModel) is { } name - && IsEpochCtor(cc.Node, cc.SemanticModel)) + && CheckAndGetTypeName(cc.Node, cc.Model) is { } name + && IsEpochCtor(cc.Node, cc.Model)) { cc.ReportIssue(Rule, cc.Node, name); } else if (arguments.Count() == 1 && ((literalsArguments.Count() == 1 && IsValueEqualTo(literalsArguments.First(), EpochTicks)) - || (Language.FindConstantValue(cc.SemanticModel, arguments.First()) is long ticks && ticks == EpochTicks)) - && CheckAndGetTypeName(cc.Node, cc.SemanticModel) is { } typeName) + || (Language.FindConstantValue(cc.Model, arguments.First()) is long ticks && ticks == EpochTicks)) + && CheckAndGetTypeName(cc.Node, cc.Model) is { } typeName) { cc.ReportIssue(Rule, cc.Node, typeName); } diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/UseWhereBeforeOrderByBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/UseWhereBeforeOrderByBase.cs index b7c04c3ea9b..5542697f3d6 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/UseWhereBeforeOrderByBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/UseWhereBeforeOrderByBase.cs @@ -35,8 +35,8 @@ protected override void Initialize(SonarAnalysisContext context) => if (Language.GetName(invocation).Equals("Where", Language.NameComparison) && Language.Syntax.TryGetOperands(invocation, out var left, out var right) && LeftHasCorrectName(left, out var orderByMethodDescription) - && MethodIsLinqExtension(left, c.SemanticModel) - && MethodIsLinqExtension(right, c.SemanticModel) + && MethodIsLinqExtension(left, c.Model) + && MethodIsLinqExtension(right, c.Model) && Language.Syntax.NodeIdentifier(right) is { } rightIdentifier && Language.Syntax.NodeIdentifier(left) is { } leftIdentifier) { diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/Utilities/UtilityAnalyzerBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/Utilities/UtilityAnalyzerBase.cs index a6c81c93ce4..e92bd21031f 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/Utilities/UtilityAnalyzerBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/Utilities/UtilityAnalyzerBase.cs @@ -99,7 +99,7 @@ protected sealed override void Initialize(SonarAnalysisContext context) => { if (ShouldGenerateMetrics(parameters, modelContext)) { - var message = CreateMessage(parameters, modelContext.Tree, modelContext.SemanticModel); + var message = CreateMessage(parameters, modelContext.Tree, modelContext.Model); treeMessages.Push(message); } }); diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/ValueTypeShouldImplementIEquatableBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/ValueTypeShouldImplementIEquatableBase.cs index 9bfe13cfaad..88af40a5acd 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/ValueTypeShouldImplementIEquatableBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/ValueTypeShouldImplementIEquatableBase.cs @@ -32,7 +32,7 @@ protected sealed override void Initialize(SonarAnalysisContext context) => { var modifiers = Language.Syntax.ModifierKinds(c.Node); if (!modifiers.Any(x => x.Equals(Language.SyntaxKind.RefKeyword)) - && c.SemanticModel.GetDeclaredSymbol(c.Node) is INamedTypeSymbol structSymbol + && c.Model.GetDeclaredSymbol(c.Node) is INamedTypeSymbol structSymbol && !structSymbol.Implements(KnownType.System_IEquatable_T)) { var identifier = Language.Syntax.NodeIdentifier(c.Node).Value; diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/VariableUnusedBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/VariableUnusedBase.cs index 4fe4b341407..3d554b7ef21 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/VariableUnusedBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/VariableUnusedBase.cs @@ -32,11 +32,11 @@ protected abstract class UnusedLocalsCollectorBase public void CollectDeclarations(SonarSyntaxNodeReportingContext c) => declaredLocals.UnionWith( GetDeclaredVariables((TLocalDeclaration)c.Node) - .Select(variable => c.SemanticModel.GetDeclaredSymbol(variable) ?? c.SemanticModel.GetSymbolInfo(variable).Symbol) + .Select(variable => c.Model.GetDeclaredSymbol(variable) ?? c.Model.GetSymbolInfo(variable).Symbol) .WhereNotNull()); public void CollectUsages(SonarSyntaxNodeReportingContext c) => - usedLocals.UnionWith(GetUsedSymbols(c.Node, c.SemanticModel)); + usedLocals.UnionWith(GetUsedSymbols(c.Node, c.Model)); public void ReportUnusedVariables(SonarCodeBlockReportingContext c, DiagnosticDescriptor rule) { diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/WcfNonVoidOneWayBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/WcfNonVoidOneWayBase.cs index 0b093fdcd25..79aac2b32a9 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/WcfNonVoidOneWayBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/WcfNonVoidOneWayBase.cs @@ -30,7 +30,7 @@ protected sealed override void Initialize(SonarAnalysisContext context) c => { var methodDeclaration = (TMethodSyntax)c.Node; - var methodSymbol = c.SemanticModel.GetDeclaredSymbol(methodDeclaration) as IMethodSymbol; + var methodSymbol = c.Model.GetDeclaredSymbol(methodDeclaration) as IMethodSymbol; if (methodSymbol == null || methodSymbol.ReturnsVoid) { diff --git a/analyzers/src/SonarAnalyzer.Core/Rules/WeakSslTlsProtocolsBase.cs b/analyzers/src/SonarAnalyzer.Core/Rules/WeakSslTlsProtocolsBase.cs index a5d0d981d57..c18c22420ab 100644 --- a/analyzers/src/SonarAnalyzer.Core/Rules/WeakSslTlsProtocolsBase.cs +++ b/analyzers/src/SonarAnalyzer.Core/Rules/WeakSslTlsProtocolsBase.cs @@ -42,7 +42,7 @@ protected override void Initialize(SonarAnalysisContext context) => c => { var node = c.Node; - if (!IsPartOfBinaryNegationOrCondition(node) && IsWeakProtocol(node, c.SemanticModel)) + if (!IsPartOfBinaryNegationOrCondition(node) && IsWeakProtocol(node, c.Model)) { c.ReportIssue(Rule, node); } diff --git a/analyzers/src/SonarAnalyzer.Core/Trackers/ElementAccessContext.cs b/analyzers/src/SonarAnalyzer.Core/Trackers/ElementAccessContext.cs index aba260c2a4b..cb735a1125f 100644 --- a/analyzers/src/SonarAnalyzer.Core/Trackers/ElementAccessContext.cs +++ b/analyzers/src/SonarAnalyzer.Core/Trackers/ElementAccessContext.cs @@ -21,5 +21,5 @@ public class ElementAccessContext : SyntaxBaseContext public Lazy InvokedPropertySymbol { get; } public ElementAccessContext(SonarSyntaxNodeReportingContext context) : base(context) => - InvokedPropertySymbol = new Lazy(() => context.SemanticModel.GetSymbolInfo(context.Node).Symbol as IPropertySymbol); + InvokedPropertySymbol = new Lazy(() => context.Model.GetSymbolInfo(context.Node).Symbol as IPropertySymbol); } diff --git a/analyzers/src/SonarAnalyzer.Core/Trackers/InvocationContext.cs b/analyzers/src/SonarAnalyzer.Core/Trackers/InvocationContext.cs index f87e070200b..9e3b64bc490 100644 --- a/analyzers/src/SonarAnalyzer.Core/Trackers/InvocationContext.cs +++ b/analyzers/src/SonarAnalyzer.Core/Trackers/InvocationContext.cs @@ -21,7 +21,7 @@ public class InvocationContext : SyntaxBaseContext public string MethodName { get; } public Lazy MethodSymbol { get; } - public InvocationContext(SonarSyntaxNodeReportingContext context, string methodName) : this(context.Node, methodName, context.SemanticModel) { } + public InvocationContext(SonarSyntaxNodeReportingContext context, string methodName) : this(context.Node, methodName, context.Model) { } public InvocationContext(SyntaxNode node, string methodName, SemanticModel model) : base(node, model) { diff --git a/analyzers/src/SonarAnalyzer.Core/Trackers/ObjectCreationContext.cs b/analyzers/src/SonarAnalyzer.Core/Trackers/ObjectCreationContext.cs index cf07e8be906..39268f196a5 100644 --- a/analyzers/src/SonarAnalyzer.Core/Trackers/ObjectCreationContext.cs +++ b/analyzers/src/SonarAnalyzer.Core/Trackers/ObjectCreationContext.cs @@ -21,5 +21,5 @@ public class ObjectCreationContext : SyntaxBaseContext public Lazy InvokedConstructorSymbol { get; } public ObjectCreationContext(SonarSyntaxNodeReportingContext context) : base(context) => - InvokedConstructorSymbol = new Lazy(() => context.SemanticModel.GetSymbolInfo(context.Node).Symbol as IMethodSymbol); + InvokedConstructorSymbol = new Lazy(() => context.Model.GetSymbolInfo(context.Node).Symbol as IMethodSymbol); } diff --git a/analyzers/src/SonarAnalyzer.Core/Trackers/PropertyAccessContext.cs b/analyzers/src/SonarAnalyzer.Core/Trackers/PropertyAccessContext.cs index 1e2c079dbb0..61e58f92743 100644 --- a/analyzers/src/SonarAnalyzer.Core/Trackers/PropertyAccessContext.cs +++ b/analyzers/src/SonarAnalyzer.Core/Trackers/PropertyAccessContext.cs @@ -24,7 +24,7 @@ public class PropertyAccessContext : SyntaxBaseContext public PropertyAccessContext(SonarSyntaxNodeReportingContext context, string propertyName) : base(context) { PropertyName = propertyName; - PropertySymbol = new Lazy(() => context.SemanticModel.GetSymbolInfo(context.Node).Symbol as IPropertySymbol); + PropertySymbol = new Lazy(() => context.Model.GetSymbolInfo(context.Node).Symbol as IPropertySymbol); } public PropertyAccessContext(SyntaxNode node, SemanticModel model, string propertyName) : base(node, model) diff --git a/analyzers/src/SonarAnalyzer.Core/Trackers/SyntaxBaseContext.cs b/analyzers/src/SonarAnalyzer.Core/Trackers/SyntaxBaseContext.cs index 0ebdc7b7e49..9712a83fb18 100644 --- a/analyzers/src/SonarAnalyzer.Core/Trackers/SyntaxBaseContext.cs +++ b/analyzers/src/SonarAnalyzer.Core/Trackers/SyntaxBaseContext.cs @@ -22,7 +22,7 @@ public class SyntaxBaseContext : BaseContext public SyntaxNode Node { get; } public Location PrimaryLocation { get; set; } - public SyntaxBaseContext(SonarSyntaxNodeReportingContext context) : this(context.Node, context.SemanticModel) { } + public SyntaxBaseContext(SonarSyntaxNodeReportingContext context) : this(context.Node, context.Model) { } public SyntaxBaseContext(SyntaxNode node, SemanticModel model) { diff --git a/analyzers/src/SonarAnalyzer.VisualBasic.Core/Extensions/SonarSyntaxNodeAnalysisContextExtensions.cs b/analyzers/src/SonarAnalyzer.VisualBasic.Core/Extensions/SonarSyntaxNodeAnalysisContextExtensions.cs index 19e65c9442e..4006567b541 100644 --- a/analyzers/src/SonarAnalyzer.VisualBasic.Core/Extensions/SonarSyntaxNodeAnalysisContextExtensions.cs +++ b/analyzers/src/SonarAnalyzer.VisualBasic.Core/Extensions/SonarSyntaxNodeAnalysisContextExtensions.cs @@ -19,5 +19,5 @@ namespace SonarAnalyzer.VisualBasic.Core.Extensions; public static class SonarSyntaxNodeAnalysisContextExtensions { public static bool IsInExpressionTree(this SonarSyntaxNodeReportingContext context) => - context.Node.IsInExpressionTree(context.SemanticModel); + context.Node.IsInExpressionTree(context.Model); } diff --git a/analyzers/src/SonarAnalyzer.VisualBasic/Rules/ArrayCreationLongSyntax.cs b/analyzers/src/SonarAnalyzer.VisualBasic/Rules/ArrayCreationLongSyntax.cs index 1b75536e352..c213ce1ac7c 100644 --- a/analyzers/src/SonarAnalyzer.VisualBasic/Rules/ArrayCreationLongSyntax.cs +++ b/analyzers/src/SonarAnalyzer.VisualBasic/Rules/ArrayCreationLongSyntax.cs @@ -32,15 +32,15 @@ protected override void Initialize(SonarAnalysisContext context) => var arrayCreation = (ArrayCreationExpressionSyntax)c.Node; if (arrayCreation.Initializer == null || HasSizeSpecifier(arrayCreation) - || c.SemanticModel.GetTypeInfo(arrayCreation).Type is not IArrayTypeSymbol arrayType + || c.Model.GetTypeInfo(arrayCreation).Type is not IArrayTypeSymbol arrayType || arrayType.ElementType is null or IErrorTypeSymbol) { return; } if (arrayCreation.Initializer.Initializers.Any()) { - if (AtLeastOneExactTypeMatch(c.SemanticModel, arrayCreation, arrayType) - && AllTypesAreConvertible(c.SemanticModel, arrayCreation, arrayType)) + if (AtLeastOneExactTypeMatch(c.Model, arrayCreation, arrayType) + && AllTypesAreConvertible(c.Model, arrayCreation, arrayType)) { c.ReportIssue(Rule, arrayCreation); } diff --git a/analyzers/src/SonarAnalyzer.VisualBasic/Rules/ArrayInitializationMultipleStatements.cs b/analyzers/src/SonarAnalyzer.VisualBasic/Rules/ArrayInitializationMultipleStatements.cs index f67a2b5d84f..c938985e5ee 100644 --- a/analyzers/src/SonarAnalyzer.VisualBasic/Rules/ArrayInitializationMultipleStatements.cs +++ b/analyzers/src/SonarAnalyzer.VisualBasic/Rules/ArrayInitializationMultipleStatements.cs @@ -51,20 +51,20 @@ protected override void Initialize(SonarAnalysisContext context) return; } - var bound = GetConstantArgumentValue(name.ArrayBounds.Arguments.First(), c.SemanticModel); + var bound = GetConstantArgumentValue(name.ArrayBounds.Arguments.First(), c.Model); if (!bound.HasValue) { return; } - if (!(c.SemanticModel.GetDeclaredSymbol(name) is ILocalSymbol variableSymbol) || + if (!(c.Model.GetDeclaredSymbol(name) is ILocalSymbol variableSymbol) || !(variableSymbol.Type is IArrayTypeSymbol)) { return; } var statements = GetFollowingStatements(declaration); - var indexes = GetAssignedIndexes(statements, variableSymbol, c.SemanticModel).ToHashSet(); + var indexes = GetAssignedIndexes(statements, variableSymbol, c.Model).ToHashSet(); var upperBound = Math.Max(bound.Value, 0); diff --git a/analyzers/src/SonarAnalyzer.VisualBasic/Rules/BooleanLiteralUnnecessary.cs b/analyzers/src/SonarAnalyzer.VisualBasic/Rules/BooleanLiteralUnnecessary.cs index d0fdcfab754..33213d218b2 100644 --- a/analyzers/src/SonarAnalyzer.VisualBasic/Rules/BooleanLiteralUnnecessary.cs +++ b/analyzers/src/SonarAnalyzer.VisualBasic/Rules/BooleanLiteralUnnecessary.cs @@ -59,8 +59,8 @@ private void CheckConditional(SonarSyntaxNodeReportingContext context) var conditional = (TernaryConditionalExpressionSyntax)context.Node; var whenTrue = conditional.WhenTrue; var whenFalse = conditional.WhenFalse; - var typeLeft = context.SemanticModel.GetTypeInfo(whenTrue).Type; - var typeRight = context.SemanticModel.GetTypeInfo(whenFalse).Type; + var typeLeft = context.Model.GetTypeInfo(whenTrue).Type; + var typeRight = context.Model.GetTypeInfo(whenFalse).Type; if (typeLeft.IsNullableBoolean() || typeRight.IsNullableBoolean() || typeLeft == null diff --git a/analyzers/src/SonarAnalyzer.VisualBasic/Rules/CertificateValidationCheck.cs b/analyzers/src/SonarAnalyzer.VisualBasic/Rules/CertificateValidationCheck.cs index b96de79865d..c28e26df7cd 100644 --- a/analyzers/src/SonarAnalyzer.VisualBasic/Rules/CertificateValidationCheck.cs +++ b/analyzers/src/SonarAnalyzer.VisualBasic/Rules/CertificateValidationCheck.cs @@ -80,7 +80,7 @@ protected override ExpressionSyntax[] FindReturnAndThrowExpressions(InspectionCo // Return value set by assignment to function variable/value var assignments = block.DescendantNodes() .OfType() - .Where(x => c.Context.SemanticModel.GetSymbolInfo(x.Left).Symbol is ILocalSymbol {IsFunctionValue: true}); + .Where(x => c.Context.Model.GetSymbolInfo(x.Left).Symbol is ILocalSymbol {IsFunctionValue: true}); // And normal Return statements and throws return block.DescendantNodes().OfType().Select(x => x.Expression) // Throw statements #2825. x.Expression can be NULL for standalone Throw and we need that one as well. diff --git a/analyzers/src/SonarAnalyzer.VisualBasic/Rules/DoNotInstantiateSharedClasses.cs b/analyzers/src/SonarAnalyzer.VisualBasic/Rules/DoNotInstantiateSharedClasses.cs index 652dcbe5db7..41cd34183bc 100644 --- a/analyzers/src/SonarAnalyzer.VisualBasic/Rules/DoNotInstantiateSharedClasses.cs +++ b/analyzers/src/SonarAnalyzer.VisualBasic/Rules/DoNotInstantiateSharedClasses.cs @@ -30,7 +30,7 @@ protected override void Initialize(SonarAnalysisContext context) { var creationSyntax = (ObjectCreationExpressionSyntax)c.Node; - var createdType = c.SemanticModel.GetTypeInfo(creationSyntax).Type; + var createdType = c.Model.GetTypeInfo(creationSyntax).Type; if (createdType != null && createdType.GetAttributes(KnownType.System_ComponentModel_Composition_PartCreationPolicyAttribute).Any(IsShared)) { diff --git a/analyzers/src/SonarAnalyzer.VisualBasic/Rules/DoNotLockOnSharedResource.cs b/analyzers/src/SonarAnalyzer.VisualBasic/Rules/DoNotLockOnSharedResource.cs index 3cbaaec8694..dce8003c442 100644 --- a/analyzers/src/SonarAnalyzer.VisualBasic/Rules/DoNotLockOnSharedResource.cs +++ b/analyzers/src/SonarAnalyzer.VisualBasic/Rules/DoNotLockOnSharedResource.cs @@ -32,7 +32,7 @@ protected override void Initialize(SonarAnalysisContext context) if (IsLockOnThis(lockStatement.Expression) || IsLockOnStringLiteral(lockStatement.Expression) || - IsLockOnForbiddenKnownType(lockStatement.Expression, c.SemanticModel)) + IsLockOnForbiddenKnownType(lockStatement.Expression, c.Model)) { c.ReportIssue(rule, lockStatement.Expression); } diff --git a/analyzers/src/SonarAnalyzer.VisualBasic/Rules/DoNotUseIIf.cs b/analyzers/src/SonarAnalyzer.VisualBasic/Rules/DoNotUseIIf.cs index 7e07f19d842..509acd154a5 100644 --- a/analyzers/src/SonarAnalyzer.VisualBasic/Rules/DoNotUseIIf.cs +++ b/analyzers/src/SonarAnalyzer.VisualBasic/Rules/DoNotUseIIf.cs @@ -33,7 +33,7 @@ protected override void Initialize(SonarAnalysisContext context) => context.RegisterNodeAction(c => { var invocationExpression = (InvocationExpressionSyntax)c.Node; - var invokedMethod = c.SemanticModel.GetSymbolInfo(invocationExpression).Symbol as IMethodSymbol; + var invokedMethod = c.Model.GetSymbolInfo(invocationExpression).Symbol as IMethodSymbol; if (IsIIf(invokedMethod)) { diff --git a/analyzers/src/SonarAnalyzer.VisualBasic/Rules/EmptyMethod.cs b/analyzers/src/SonarAnalyzer.VisualBasic/Rules/EmptyMethod.cs index 031da9f3b74..1eaa75d7299 100644 --- a/analyzers/src/SonarAnalyzer.VisualBasic/Rules/EmptyMethod.cs +++ b/analyzers/src/SonarAnalyzer.VisualBasic/Rules/EmptyMethod.cs @@ -45,11 +45,11 @@ private static bool ShouldMethodBeExcluded(SonarSyntaxNodeReportingContext conte { if (methodStatement.Modifiers.Any(SyntaxKind.MustOverrideKeyword) || methodStatement.Modifiers.Any(SyntaxKind.OverridableKeyword) - || IsDllImport(context.SemanticModel, methodStatement)) + || IsDllImport(context.Model, methodStatement)) { return true; } - else if (context.SemanticModel.GetDeclaredSymbol(methodStatement) is { IsOverride: true } methodSymbol) + else if (context.Model.GetDeclaredSymbol(methodStatement) is { IsOverride: true } methodSymbol) { return methodSymbol.OverriddenMethod is { IsAbstract: true } || context.IsTestProject(); } diff --git a/analyzers/src/SonarAnalyzer.VisualBasic/Rules/FieldShadowsParentField.cs b/analyzers/src/SonarAnalyzer.VisualBasic/Rules/FieldShadowsParentField.cs index 10a028ae185..e47a1392611 100644 --- a/analyzers/src/SonarAnalyzer.VisualBasic/Rules/FieldShadowsParentField.cs +++ b/analyzers/src/SonarAnalyzer.VisualBasic/Rules/FieldShadowsParentField.cs @@ -27,7 +27,7 @@ protected override void Initialize(SonarAnalysisContext context) => var fieldDeclaration = (FieldDeclarationSyntax)c.Node; if (!fieldDeclaration.Modifiers.Any(x => x.IsKind(SyntaxKind.ShadowsKeyword))) { - foreach (var diagnostics in fieldDeclaration.Declarators.SelectMany(x => x.Names).SelectMany(x => CheckFields(c.SemanticModel, x))) + foreach (var diagnostics in fieldDeclaration.Declarators.SelectMany(x => x.Names).SelectMany(x => CheckFields(c.Model, x))) { c.ReportIssue(diagnostics); } diff --git a/analyzers/src/SonarAnalyzer.VisualBasic/Rules/LooseFilePermissions.cs b/analyzers/src/SonarAnalyzer.VisualBasic/Rules/LooseFilePermissions.cs index 745f2cb890a..637e0ee7911 100644 --- a/analyzers/src/SonarAnalyzer.VisualBasic/Rules/LooseFilePermissions.cs +++ b/analyzers/src/SonarAnalyzer.VisualBasic/Rules/LooseFilePermissions.cs @@ -28,7 +28,7 @@ internal LooseFilePermissions(IAnalyzerConfiguration configuration) : base(confi protected override void VisitAssignments(SonarSyntaxNodeReportingContext context) { var node = context.Node; - if (IsFileAccessPermissions(node, context.SemanticModel) && !node.IsPartOfBinaryNegationOrCondition()) + if (IsFileAccessPermissions(node, context.Model) && !node.IsPartOfBinaryNegationOrCondition()) { context.ReportIssue(Rule, node); } @@ -37,8 +37,8 @@ protected override void VisitAssignments(SonarSyntaxNodeReportingContext context protected override void VisitInvocations(SonarSyntaxNodeReportingContext context) { var invocation = (InvocationExpressionSyntax)context.Node; - if ((IsSetAccessRule(invocation, context.SemanticModel) || IsAddAccessRule(invocation, context.SemanticModel)) - && (GetObjectCreation(invocation, context.SemanticModel) is { } objectCreation)) + if ((IsSetAccessRule(invocation, context.Model) || IsAddAccessRule(invocation, context.Model)) + && (GetObjectCreation(invocation, context.Model) is { } objectCreation)) { var invocationLocation = invocation.GetLocation(); var secondaryLocation = objectCreation.GetLocation(); diff --git a/analyzers/src/SonarAnalyzer.VisualBasic/Rules/MethodParameterUnused.cs b/analyzers/src/SonarAnalyzer.VisualBasic/Rules/MethodParameterUnused.cs index 4e7527c708a..f62f8724d73 100644 --- a/analyzers/src/SonarAnalyzer.VisualBasic/Rules/MethodParameterUnused.cs +++ b/analyzers/src/SonarAnalyzer.VisualBasic/Rules/MethodParameterUnused.cs @@ -38,7 +38,7 @@ protected override void Initialize(SonarAnalysisContext context) => || IsInterfaceImplementation(methodBlock) || IsWithEventsHandler(methodBlock) || HasAnyAttribute(methodBlock) - || OnlyThrowsNotImplementedException(methodBlock, c.SemanticModel)) + || OnlyThrowsNotImplementedException(methodBlock, c.Model)) { return; } @@ -50,7 +50,7 @@ protected override void Initialize(SonarAnalysisContext context) => } // Bail-out if this is not a method we want to report on (only based on symbols checks) - var methodSymbol = c.SemanticModel.GetDeclaredSymbol(methodBlock); + var methodSymbol = c.Model.GetDeclaredSymbol(methodBlock); if (methodSymbol == null || methodSymbol.IsMainMethod() || methodSymbol.IsEventHandler() diff --git a/analyzers/src/SonarAnalyzer.VisualBasic/Rules/Naming/EventHandlerName.cs b/analyzers/src/SonarAnalyzer.VisualBasic/Rules/Naming/EventHandlerName.cs index ce79b0342b3..7e84bae6f72 100644 --- a/analyzers/src/SonarAnalyzer.VisualBasic/Rules/Naming/EventHandlerName.cs +++ b/analyzers/src/SonarAnalyzer.VisualBasic/Rules/Naming/EventHandlerName.cs @@ -37,7 +37,7 @@ protected override void Initialize(SonarParametrizedAnalysisContext context) => { var methodDeclaration = (MethodStatementSyntax)c.Node; if (!NamingHelper.IsRegexMatch(methodDeclaration.Identifier.ValueText, Pattern) - && IsEventHandler(methodDeclaration, c.SemanticModel)) + && IsEventHandler(methodDeclaration, c.Model)) { c.ReportIssue(Rule, methodDeclaration.Identifier, methodDeclaration.Identifier.ValueText, Pattern); } diff --git a/analyzers/src/SonarAnalyzer.VisualBasic/Rules/Naming/FieldNameChecker.cs b/analyzers/src/SonarAnalyzer.VisualBasic/Rules/Naming/FieldNameChecker.cs index e4754cfcd4b..db6f69ccbef 100644 --- a/analyzers/src/SonarAnalyzer.VisualBasic/Rules/Naming/FieldNameChecker.cs +++ b/analyzers/src/SonarAnalyzer.VisualBasic/Rules/Naming/FieldNameChecker.cs @@ -30,7 +30,7 @@ protected sealed override void Initialize(SonarParametrizedAnalysisContext conte var fieldDeclaration = (FieldDeclarationSyntax)c.Node; foreach (var name in fieldDeclaration.Declarators.SelectMany(v => v.Names).WhereNotNull()) { - if (c.SemanticModel.GetDeclaredSymbol(name) is IFieldSymbol symbol && + if (c.Model.GetDeclaredSymbol(name) is IFieldSymbol symbol && IsCandidateSymbol(symbol) && !NamingHelper.IsRegexMatch(symbol.Name, Pattern)) { diff --git a/analyzers/src/SonarAnalyzer.VisualBasic/Rules/Naming/FunctionName.cs b/analyzers/src/SonarAnalyzer.VisualBasic/Rules/Naming/FunctionName.cs index 48b34d1ff19..8bcef5685fd 100644 --- a/analyzers/src/SonarAnalyzer.VisualBasic/Rules/Naming/FunctionName.cs +++ b/analyzers/src/SonarAnalyzer.VisualBasic/Rules/Naming/FunctionName.cs @@ -50,7 +50,7 @@ protected override void Initialize(SonarParametrizedAnalysisContext context) var methodDeclaration = (MethodStatementSyntax)c.Node; if (ShouldBeChecked(methodDeclaration, c.ContainingSymbol) && !NamingHelper.IsRegexMatch(methodDeclaration.Identifier.ValueText, Pattern) - && !EventHandlerName.IsEventHandler(methodDeclaration, c.SemanticModel)) + && !EventHandlerName.IsEventHandler(methodDeclaration, c.Model)) { c.ReportIssue(Rule, methodDeclaration.Identifier, "procedure", methodDeclaration.Identifier.ValueText, Pattern); } diff --git a/analyzers/src/SonarAnalyzer.VisualBasic/Rules/Naming/LocalVariableName.cs b/analyzers/src/SonarAnalyzer.VisualBasic/Rules/Naming/LocalVariableName.cs index 5e09fd254a6..fc2fd0083e1 100644 --- a/analyzers/src/SonarAnalyzer.VisualBasic/Rules/Naming/LocalVariableName.cs +++ b/analyzers/src/SonarAnalyzer.VisualBasic/Rules/Naming/LocalVariableName.cs @@ -54,7 +54,7 @@ private void ProcessLoop(SonarSyntaxNodeReportingContext context, T loop, Fun return; } - if (!(context.SemanticModel.GetSymbolInfo(controlVar).Symbol is ILocalSymbol symbol) || + if (!(context.Model.GetSymbolInfo(controlVar).Symbol is ILocalSymbol symbol) || !isDeclaredInLoop(symbol) || NamingHelper.IsRegexMatch(symbol.Name, Pattern)) { @@ -76,7 +76,7 @@ private void ProcessVariableDeclarator(SonarSyntaxNodeReportingContext context) .Where(n => n != null && !NamingHelper.IsRegexMatch(n.Identifier.ValueText, Pattern))) { - if (!(context.SemanticModel.GetDeclaredSymbol(name) is ILocalSymbol symbol) || + if (!(context.Model.GetDeclaredSymbol(name) is ILocalSymbol symbol) || symbol.IsConst) { continue; diff --git a/analyzers/src/SonarAnalyzer.VisualBasic/Rules/NonAsyncTaskShouldNotReturnNull.cs b/analyzers/src/SonarAnalyzer.VisualBasic/Rules/NonAsyncTaskShouldNotReturnNull.cs index c07536ac43d..4964a6f57b5 100644 --- a/analyzers/src/SonarAnalyzer.VisualBasic/Rules/NonAsyncTaskShouldNotReturnNull.cs +++ b/analyzers/src/SonarAnalyzer.VisualBasic/Rules/NonAsyncTaskShouldNotReturnNull.cs @@ -41,7 +41,7 @@ protected override void Initialize(SonarAnalysisContext context) var enclosingMember = GetEnclosingMember(nullLiteral); if (enclosingMember != null && !enclosingMember.IsKind(SyntaxKind.VariableDeclarator) && - IsInvalidEnclosingSymbolContext(enclosingMember, c.SemanticModel)) + IsInvalidEnclosingSymbolContext(enclosingMember, c.Model)) { c.ReportIssue(rule, nullLiteral); } diff --git a/analyzers/src/SonarAnalyzer.VisualBasic/Rules/PropertyWithArrayType.cs b/analyzers/src/SonarAnalyzer.VisualBasic/Rules/PropertyWithArrayType.cs index 34189087afd..4084b8061a7 100644 --- a/analyzers/src/SonarAnalyzer.VisualBasic/Rules/PropertyWithArrayType.cs +++ b/analyzers/src/SonarAnalyzer.VisualBasic/Rules/PropertyWithArrayType.cs @@ -33,7 +33,7 @@ protected override void Initialize(SonarAnalysisContext context) => var property = (PropertyStatementSyntax)c.Node; if (property.ImplementsClause is null && !property.Modifiers.Any(x => x.IsKind(SyntaxKind.OverridesKeyword)) - && c.SemanticModel.GetDeclaredSymbol(property) is IPropertySymbol symbol + && c.Model.GetDeclaredSymbol(property) is IPropertySymbol symbol && !symbol.IsAutoProperty() && symbol.Type is IArrayTypeSymbol) { diff --git a/analyzers/src/SonarAnalyzer.VisualBasic/Rules/StringConcatenationWithPlus.cs b/analyzers/src/SonarAnalyzer.VisualBasic/Rules/StringConcatenationWithPlus.cs index 80a03467545..c20a161b11e 100644 --- a/analyzers/src/SonarAnalyzer.VisualBasic/Rules/StringConcatenationWithPlus.cs +++ b/analyzers/src/SonarAnalyzer.VisualBasic/Rules/StringConcatenationWithPlus.cs @@ -31,10 +31,10 @@ protected override void Initialize(SonarAnalysisContext context) => c => { var binary = (BinaryExpressionSyntax)c.Node; - var leftType = c.SemanticModel.GetTypeInfo(binary.Left).Type; + var leftType = c.Model.GetTypeInfo(binary.Left).Type; if (leftType.Is(KnownType.System_String) // If op_Addition exist, there's areason for it => don't raise. We don't care about type of op_Addition arguments, they match because it compiles. - || (leftType.GetMembers("op_Addition").IsEmpty && c.SemanticModel.GetTypeInfo(binary.Right).Type.Is(KnownType.System_String))) + || (leftType.GetMembers("op_Addition").IsEmpty && c.Model.GetTypeInfo(binary.Right).Type.Is(KnownType.System_String))) { c.ReportIssue(Rule, binary.OperatorToken); } diff --git a/analyzers/src/SonarAnalyzer.VisualBasic/Rules/UnsignedTypesUsage.cs b/analyzers/src/SonarAnalyzer.VisualBasic/Rules/UnsignedTypesUsage.cs index 01d401c94d7..075a5f2a3b9 100644 --- a/analyzers/src/SonarAnalyzer.VisualBasic/Rules/UnsignedTypesUsage.cs +++ b/analyzers/src/SonarAnalyzer.VisualBasic/Rules/UnsignedTypesUsage.cs @@ -38,7 +38,7 @@ protected override void Initialize(SonarAnalysisContext context) return; } - var typeSymbol = c.SemanticModel.GetSymbolInfo(typeSyntax).Symbol as ITypeSymbol; + var typeSymbol = c.Model.GetSymbolInfo(typeSyntax).Symbol as ITypeSymbol; if (typeSymbol.IsAny(KnownType.UnsignedIntegers)) { c.ReportIssue(rule, typeSyntax, SignedPairs[typeSymbol.SpecialType]); diff --git a/analyzers/src/SonarAnalyzer.VisualBasic/Rules/UseWithStatement.cs b/analyzers/src/SonarAnalyzer.VisualBasic/Rules/UseWithStatement.cs index 66eb25fe34a..317193895d2 100644 --- a/analyzers/src/SonarAnalyzer.VisualBasic/Rules/UseWithStatement.cs +++ b/analyzers/src/SonarAnalyzer.VisualBasic/Rules/UseWithStatement.cs @@ -115,7 +115,7 @@ private static bool IsCandidateForExtraction(SonarSyntaxNodeReportingContext con return currentMemberExpression != null && !currentMemberExpression.IsKind(SyntaxKind.IdentifierName) && !(currentMemberExpression is InstanceExpressionSyntax) && - !(context.SemanticModel.GetSymbolInfo(currentMemberExpression).Symbol is ITypeSymbol); + !(context.Model.GetSymbolInfo(currentMemberExpression).Symbol is ITypeSymbol); } private static ExecutableStatementSyntax GetParentStatement(ExpressionSyntax expression) diff --git a/analyzers/tests/SonarAnalyzer.Core.Test/AnalysisContext/SonarCodeBlockReportingContextTest.cs b/analyzers/tests/SonarAnalyzer.Core.Test/AnalysisContext/SonarCodeBlockReportingContextTest.cs index 3bea1f9a1b7..d98101bb10d 100644 --- a/analyzers/tests/SonarAnalyzer.Core.Test/AnalysisContext/SonarCodeBlockReportingContextTest.cs +++ b/analyzers/tests/SonarAnalyzer.Core.Test/AnalysisContext/SonarCodeBlockReportingContextTest.cs @@ -39,6 +39,6 @@ public void Properties_ArePropagated() sut.Cancel.Should().Be(cancel); sut.CodeBlock.Should().BeSameAs(codeBlock); sut.OwningSymbol.Should().BeSameAs(owningSymbol); - sut.SemanticModel.Should().BeSameAs(model); + sut.Model.Should().BeSameAs(model); } } diff --git a/analyzers/tests/SonarAnalyzer.Core.Test/AnalysisContext/SonarCodeBlockStartAnalysisContextTest.cs b/analyzers/tests/SonarAnalyzer.Core.Test/AnalysisContext/SonarCodeBlockStartAnalysisContextTest.cs index c59a9641d3e..39cfe00cc4f 100644 --- a/analyzers/tests/SonarAnalyzer.Core.Test/AnalysisContext/SonarCodeBlockStartAnalysisContextTest.cs +++ b/analyzers/tests/SonarAnalyzer.Core.Test/AnalysisContext/SonarCodeBlockStartAnalysisContextTest.cs @@ -38,6 +38,6 @@ public void Properties_ArePropagated() sut.Cancel.Should().Be(cancel); sut.CodeBlock.Should().BeSameAs(codeBlock); sut.OwningSymbol.Should().BeSameAs(owningSymbol); - sut.SemanticModel.Should().BeSameAs(model); + sut.Model.Should().BeSameAs(model); } } diff --git a/analyzers/tests/SonarAnalyzer.Core.Test/AnalysisContext/SonarSemanticModelReportingContextTest.cs b/analyzers/tests/SonarAnalyzer.Core.Test/AnalysisContext/SonarSemanticModelReportingContextTest.cs index 3de861727ea..1ca91415816 100644 --- a/analyzers/tests/SonarAnalyzer.Core.Test/AnalysisContext/SonarSemanticModelReportingContextTest.cs +++ b/analyzers/tests/SonarAnalyzer.Core.Test/AnalysisContext/SonarSemanticModelReportingContextTest.cs @@ -34,7 +34,7 @@ public void Properties_ArePropagated() sut.Tree.Should().BeSameAs(tree); sut.Compilation.Should().BeSameAs(model.Compilation); - sut.SemanticModel.Should().BeSameAs(model); + sut.Model.Should().BeSameAs(model); sut.Options.Should().BeSameAs(options); sut.Cancel.Should().Be(cancel); } diff --git a/analyzers/tests/SonarAnalyzer.Core.Test/AnalysisContext/SonarSyntaxNodeReportingContextTest.cs b/analyzers/tests/SonarAnalyzer.Core.Test/AnalysisContext/SonarSyntaxNodeReportingContextTest.cs index 3f9a0227b3f..c823466261a 100644 --- a/analyzers/tests/SonarAnalyzer.Core.Test/AnalysisContext/SonarSyntaxNodeReportingContextTest.cs +++ b/analyzers/tests/SonarAnalyzer.Core.Test/AnalysisContext/SonarSyntaxNodeReportingContextTest.cs @@ -39,7 +39,7 @@ public void Properties_ArePropagated() sut.Options.Should().BeSameAs(options); sut.Cancel.Should().Be(cancel); sut.Node.Should().BeSameAs(node); - sut.SemanticModel.Should().BeSameAs(model); + sut.Model.Should().BeSameAs(model); sut.ContainingSymbol.Should().BeSameAs(containingSymbol); } diff --git a/analyzers/tests/SonarAnalyzer.Test/AnalysisContext/SonarAnalysisContextTest.Register.cs b/analyzers/tests/SonarAnalyzer.Test/AnalysisContext/SonarAnalysisContextTest.Register.cs index 999b870a2bb..a96ed0e1c13 100644 --- a/analyzers/tests/SonarAnalyzer.Test/AnalysisContext/SonarAnalysisContextTest.Register.cs +++ b/analyzers/tests/SonarAnalyzer.Test/AnalysisContext/SonarAnalysisContextTest.Register.cs @@ -357,7 +357,7 @@ public void SonarCompilationStartAnalysisContext_RegisterCodeBlockStartAction_Re sut.RegisterCodeBlockStartAction(CSharpGeneratedCodeRecognizer.Instance, x => { registrationCalled = true; - x.SemanticModel.Should().Be(context.Model); + x.Model.Should().Be(context.Model); x.CodeBlock.Should().Be(context.ClassDeclarationNode); x.OwningSymbol.Should().Be(context.OwningSymbol); });