From 5266645a9cd03a62c7940c485be9abece4c32a6a Mon Sep 17 00:00:00 2001 From: ronimizy Date: Wed, 1 May 2024 21:58:37 +0300 Subject: [PATCH 1/7] refactor: solution structure --- .github/workflows/dotnet-build.yml | 25 +- .github/workflows/publish.yml | 20 +- Directory.Build.props | 23 +- Directory.Packages.props | 92 +-- NuGet.config | 23 +- SourceKit.Sample/.editorconfig | 11 - .../KeyTypeDoesNotImplementEquatable.cs | 8 - .../Dictionary/KeyTypeImplementsEquatable.cs | 8 - .../OnePublicField.cs | 6 - .../PublicProperty.cs | 6 - .../ReadonlyPublicField.cs | 6 - .../MustBePartial/NonPartialDerivative.cs | 6 - .../Analyzers/Nullable/NullableDisable.cs | 8 - .../Analyzers/Nullable/NullableEnable.cs | 8 - .../Generators/ArrayQueryUsage.cs | 52 -- .../Generators/ValidArrayQueryUsage.cs | 60 -- SourceKit.Sample/Models/Point.cs | 3 - SourceKit.Sample/Playground.cs | 24 - SourceKit.Sample/Program.cs | 5 - SourceKit.Sample/SourceKit.Sample.csproj | 33 - SourceKit.sln | 173 ++++- .../SourceKit.Reflect.Samples}/Class1.cs | 4 +- .../SourceKit.Reflect.Samples.csproj | 7 + .../.editorconfig | 4 + .../CustomKeyTypeImplementsEquatable.cs | 4 +- .../CustomKeyTypeImplementsOtherEquatable.cs | 2 +- .../Dictionary/EmptyKeyType.cs | 2 +- .../Dictionary/EnumKeyDictionary.cs | 2 +- .../Dictionary/EquatableType.cs | 2 +- ...heritedCustomKeyTypeImplementsEquatable.cs | 3 +- .../KeyTypeDoesNotImplementEquatable.cs | 8 + .../Dictionary/KeyTypeImplementsEquatable.cs | 8 + .../ListForEachStatementComplexExample.cs | 2 +- ...tForEachStatementWithLambdaBlockExample.cs | 2 +- ...achStatementWithLambdaExpressionExample.cs | 2 +- ...tementWithMemberAccessExpressionExample.cs | 2 +- ...stForEachStatementWithMethodLinkExample.cs | 2 +- .../NoListForEachStatementExample.cs | 2 +- ...ceKit.Analyzers.Collections.Samples.csproj | 11 + .../.editorconfig | 6 + .../CodeFixerTestCases.cs | 14 +- .../OfTypeMustUseDerivedType}/OfTypeSample.cs | 0 ...rceKit.Analyzers.Enumerable.Samples.csproj | 11 + .../.editorconfig | 3 + .../IPartialBase.cs | 2 +- .../NonPartialDerivative.cs | 3 + .../PartialDerivative.cs | 2 +- ...Kit.Analyzers.MustBePartial.Samples.csproj | 11 + .../.editorconfig | 4 + .../JokeExample.cs | 0 .../MultipleNestedNullableDisable.cs | 2 +- .../NullableDisable.cs | 8 + .../NullableEnable.cs | 8 + .../JokeExampleWithFieldAndProperties.cs | 4 +- .../JokeExampleWithVariableDeclarations.cs | 2 +- ...ourceKit.Analyzers.Nullable.Samples.csproj | 11 + .../.editorconfig | 6 + .../ExpressionBodyMethodsField.cs | 2 +- .../ManyPublicFields.cs | 2 +- .../OneField.cs | 2 +- .../OnePublicField.cs | 6 + .../PrivateFieldWithoutMethods.cs | 2 +- .../PublicProperty.cs | 6 + .../ReadonlyPublicField.cs | 6 + .../UnderscoreNameField.cs | 2 +- ...rceKit.Analyzers.Properties.Samples.csproj | 11 + .../.editorconfig | 5 + .../ArrayQuery.cs | 2 +- .../CustomModelQuery.cs | 4 +- .../Models/Point.cs | 3 + .../Program.cs | 5 + .../InitializedRequiredValueSample.cs | 18 + .../UninitializedRequiredValueSample.cs | 18 + .../RequiredValueFromParameterComponent.cs | 14 + .../SomeQuery.cs | 2 +- ...ourceKit.Generators.Builder.Samples.csproj | 12 + .../Program.cs | 4 +- .../SourceKit.Generators.Grpc.Samples.csproj | 13 +- .../protos/model.proto | 0 .../SourceKit.Reflect.csproj | 1 + .../Extensions/NamedTypeSymbolExtensions.cs | 2 +- .../Extensions/SyntaxTokenListExtensions.cs | 2 +- .../Extensions/TypeSymbolExtensions.cs | 12 +- src/SourceKit/SourceKit.csproj | 19 +- .../AnalyzerReleases.Shipped.md | 8 + .../AnalyzerReleases.Unshipped.md | 4 + .../Properties/launchSettings.json | 9 + .../SourceKit.Analyzers.Collections.csproj | 11 +- .../AnalyzerReleases.Shipped.md | 8 + .../AnalyzerReleases.Unshipped.md | 4 + ...EnumerateCollectionInLinqChainAnalyzer.cs} | 28 +- .../RemoveTerminalOperationCodeFixProvider.cs | 2 +- .../Properties/launchSettings.json | 9 + .../SourceKit.Analyzers.Enumerable.csproj | 11 +- .../AnalyzerReleases.Shipped.md | 6 + .../AnalyzerReleases.Unshipped.md | 6 + .../Properties/launchSettings.json | 9 + ...ceKit.Analyzers.MemberAccessibility.csproj | 11 +- ...Analyzers.MustBePartial.Annotations.csproj | 4 +- .../AnalyzerReleases.Shipped.md | 7 + .../AnalyzerReleases.Unshipped.md | 4 + .../Properties/launchSettings.json | 9 + .../SourceKit.Analyzers.MustBePartial.csproj | 10 +- .../AnalyzerReleases.Shipped.md | 8 + .../AnalyzerReleases.Unshipped.md | 4 + ...opagateNullableCorrectlyCodeFixProvider.cs | 2 +- .../Properties/launchSettings.json | 9 + .../SourceKit.Analyzers.Nullable.csproj | 11 +- .../AnalyzerReleases.Shipped.md | 7 + .../AnalyzerReleases.Unshipped.md | 4 + ...ationCouldBeConvertedToPropertyAnalyzer.cs | 2 +- .../Properties/launchSettings.json | 9 + .../SourceKit.Analyzers.Properties.csproj | 11 +- .../InitializesPropertyAttribute.cs | 4 +- ...eKit.Generators.Builder.Annotations.csproj | 15 +- .../AnalyzerReleases.Shipped.md | 7 + .../AnalyzerReleases.Unshipped.md | 4 + .../Builders/FileBuilders/TypeBuilder.cs | 2 +- .../Builders/FileBuilders/UsingBuilder.cs | 11 +- .../Properties/launchSettings.json | 9 + .../SourceKit.Generators.Builder.csproj | 26 +- .../Builders/FileBuilders/UsingBuilder.cs | 13 +- .../Properties/launchSettings.json | 9 + .../SourceKit.Generators.Grpc.csproj | 12 +- .../CollectionsTests.cs | 110 +++ .../ConvertListForEachIntoForEachLoop.cs | 186 +++++ .../ListForEachNotAllowedTests.cs | 130 ++++ ...urceKit.Analyzers.Collections.Tests.csproj | 30 + ...erateCollectionInLinqChainAnalyzerTests.cs | 152 ++++ .../OfTypeMustUseDerivedTypeTests.cs | 28 + ...veTerminalOperationCodeFixProviderTests.cs | 88 +++ ...ourceKit.Analyzers.Enumerable.Tests.csproj | 30 + .../MakeTypePartialCodeFixTests.cs | 40 + ...ceKit.Analyzers.MustBePartial.Tests.csproj | 30 + .../TypesMustBePartialAnalyzerTests.cs | 47 ++ .../NullForgivingOperatorNotAllowedTests.cs | 57 ++ .../NullableDisableNotAllowedTests.cs | 61 ++ .../PropagateNullableCorrectlyCodeFixTests.cs | 202 +++++ .../SourceKit.Analyzers.Nullable.Tests.csproj | 30 + ...vertDeclarationIntoPropertyCodeFixTests.cs | 253 ++++++ ...larationCouldBeConvertedToPropertyTests.cs | 199 +++++ ...ourceKit.Analyzers.Properties.Tests.csproj | 30 + .../BuilderSourceGeneratorTests.cs | 232 ++++++ .../RequiredValueAnalyzerTests.cs | 46 ++ .../SourceKit.Generators.Builder.Tests.csproj | 30 + .../ProtoMessageConstructorGeneratorTests.cs | 704 +++++++++++++++++ .../SourceKit.Generators.Grpc.Tests.csproj | 34 + .../InstanceReflectorTests.cs | 2 +- .../MethodReflectorTests.cs | 2 +- .../SourceKit.Reflect.Tests.csproj | 4 +- .../CompilationBuilder.cs | 63 +- tests/SourceKit.Tests.Common/SourceFile.cs | 20 + .../SourceKit.Tests.Common.csproj | 6 +- .../TestBases/AnalyzerTestBase.cs | 143 ++++ .../TestBases/CodeFixTestBase.cs | 90 +++ .../TestBases/GeneratorTestBase.cs | 64 ++ .../Analyzers/CollectionsTests.cs | 158 ---- ...larationCouldBeConvertedToPropertyTests.cs | 256 ------- ...oNotEnumerateCollectionInLinqChainTests.cs | 227 ------ .../OfTypeMustUseDerivedTypeTests.cs | 36 - .../Analyzers/ListForEachNotAllowedTests.cs | 198 ----- .../Analyzers/MustBePartialTests.cs | 92 --- .../NullForgivingOperatorNotAllowedTests.cs | 57 -- .../NullableDisableNotAllowedTests.cs | 80 -- .../ConvertDeclarationIntoPropertyTests.cs | 298 -------- .../ConvertListForEachIntoForEachLoop.cs | 251 ------ .../PropagateNullableCorrectlyCodeFixTests.cs | 214 ------ .../Generators/BuilderTests.cs | 212 ------ .../Generators/GrpcConstructorTests.cs | 718 ------------------ .../Generators/RequiredValueAnalyzerTests.cs | 61 -- tests/SourceKit.Tests/SourceKit.Tests.csproj | 51 -- tests/SourceKit.Tests/Startup.cs | 11 - tests/SourceKit.Tests/Tools/SourceFile.cs | 18 - 173 files changed, 3830 insertions(+), 3531 deletions(-) delete mode 100644 SourceKit.Sample/.editorconfig delete mode 100644 SourceKit.Sample/Analyzers/Collections/Dictionary/KeyTypeDoesNotImplementEquatable.cs delete mode 100644 SourceKit.Sample/Analyzers/Collections/Dictionary/KeyTypeImplementsEquatable.cs delete mode 100644 SourceKit.Sample/Analyzers/DeclarationCouldBeConvertedToProperty/OnePublicField.cs delete mode 100644 SourceKit.Sample/Analyzers/DeclarationCouldBeConvertedToProperty/PublicProperty.cs delete mode 100644 SourceKit.Sample/Analyzers/DeclarationCouldBeConvertedToProperty/ReadonlyPublicField.cs delete mode 100644 SourceKit.Sample/Analyzers/MustBePartial/NonPartialDerivative.cs delete mode 100644 SourceKit.Sample/Analyzers/Nullable/NullableDisable.cs delete mode 100644 SourceKit.Sample/Analyzers/Nullable/NullableEnable.cs delete mode 100644 SourceKit.Sample/Generators/ArrayQueryUsage.cs delete mode 100644 SourceKit.Sample/Generators/ValidArrayQueryUsage.cs delete mode 100644 SourceKit.Sample/Models/Point.cs delete mode 100644 SourceKit.Sample/Playground.cs delete mode 100644 SourceKit.Sample/Program.cs delete mode 100644 SourceKit.Sample/SourceKit.Sample.csproj rename {SourceKit.Sample => samples/SourceKit.Reflect.Samples}/Class1.cs (94%) create mode 100644 samples/SourceKit.Reflect.Samples/SourceKit.Reflect.Samples.csproj create mode 100644 samples/analyzers/SourceKit.Analyzers.Collections.Samples/.editorconfig rename {SourceKit.Sample/Analyzers/Collections => samples/analyzers/SourceKit.Analyzers.Collections.Samples}/Dictionary/CustomKeyTypeImplementsEquatable.cs (67%) rename {SourceKit.Sample/Analyzers/Collections => samples/analyzers/SourceKit.Analyzers.Collections.Samples}/Dictionary/CustomKeyTypeImplementsOtherEquatable.cs (85%) rename {SourceKit.Sample/Analyzers/Collections => samples/analyzers/SourceKit.Analyzers.Collections.Samples}/Dictionary/EmptyKeyType.cs (68%) rename {SourceKit.Sample/Analyzers/Collections => samples/analyzers/SourceKit.Analyzers.Collections.Samples}/Dictionary/EnumKeyDictionary.cs (82%) rename {SourceKit.Sample/Analyzers/Collections => samples/analyzers/SourceKit.Analyzers.Collections.Samples}/Dictionary/EquatableType.cs (87%) rename {SourceKit.Sample/Analyzers/Collections => samples/analyzers/SourceKit.Analyzers.Collections.Samples}/Dictionary/InheritedCustomKeyTypeImplementsEquatable.cs (77%) create mode 100644 samples/analyzers/SourceKit.Analyzers.Collections.Samples/Dictionary/KeyTypeDoesNotImplementEquatable.cs create mode 100644 samples/analyzers/SourceKit.Analyzers.Collections.Samples/Dictionary/KeyTypeImplementsEquatable.cs rename {SourceKit.Sample/Analyzers => samples/analyzers/SourceKit.Analyzers.Collections.Samples}/ListForEachNotAllowed/ListForEachStatementComplexExample.cs (90%) rename {SourceKit.Sample/Analyzers => samples/analyzers/SourceKit.Analyzers.Collections.Samples}/ListForEachNotAllowed/ListForEachStatementWithLambdaBlockExample.cs (82%) rename {SourceKit.Sample/Analyzers => samples/analyzers/SourceKit.Analyzers.Collections.Samples}/ListForEachNotAllowed/ListForEachStatementWithLambdaExpressionExample.cs (81%) rename {SourceKit.Sample/Analyzers => samples/analyzers/SourceKit.Analyzers.Collections.Samples}/ListForEachNotAllowed/ListForEachStatementWithMemberAccessExpressionExample.cs (77%) rename {SourceKit.Sample/Analyzers => samples/analyzers/SourceKit.Analyzers.Collections.Samples}/ListForEachNotAllowed/ListForEachStatementWithMethodLinkExample.cs (83%) rename {SourceKit.Sample/Analyzers => samples/analyzers/SourceKit.Analyzers.Collections.Samples}/ListForEachNotAllowed/NoListForEachStatementExample.cs (79%) create mode 100644 samples/analyzers/SourceKit.Analyzers.Collections.Samples/SourceKit.Analyzers.Collections.Samples.csproj create mode 100644 samples/analyzers/SourceKit.Analyzers.Enumerable.Samples/.editorconfig rename {SourceKit.Sample/Analyzers/CannotLinqChainAfterTerminalOperation => samples/analyzers/SourceKit.Analyzers.Enumerable.Samples/DoNotEnumerateCollectionsInLinqChain}/CodeFixerTestCases.cs (60%) rename {SourceKit.Sample/Analyzers/Enumerable => samples/analyzers/SourceKit.Analyzers.Enumerable.Samples/OfTypeMustUseDerivedType}/OfTypeSample.cs (100%) create mode 100644 samples/analyzers/SourceKit.Analyzers.Enumerable.Samples/SourceKit.Analyzers.Enumerable.Samples.csproj create mode 100644 samples/analyzers/SourceKit.Analyzers.MustBePartial.Samples/.editorconfig rename {SourceKit.Sample/Analyzers/MustBePartial => samples/analyzers/SourceKit.Analyzers.MustBePartial.Samples}/IPartialBase.cs (68%) create mode 100644 samples/analyzers/SourceKit.Analyzers.MustBePartial.Samples/NonPartialDerivative.cs rename {SourceKit.Sample/Analyzers/MustBePartial => samples/analyzers/SourceKit.Analyzers.MustBePartial.Samples}/PartialDerivative.cs (54%) create mode 100644 samples/analyzers/SourceKit.Analyzers.MustBePartial.Samples/SourceKit.Analyzers.MustBePartial.Samples.csproj create mode 100644 samples/analyzers/SourceKit.Analyzers.Nullable.Samples/.editorconfig rename {SourceKit.Sample/Analyzers => samples/analyzers/SourceKit.Analyzers.Nullable.Samples}/NullForgivingOperatorNotAllowed/JokeExample.cs (100%) rename {SourceKit.Sample/Analyzers/Nullable => samples/analyzers/SourceKit.Analyzers.Nullable.Samples/NullableDisableNotAllowed}/MultipleNestedNullableDisable.cs (86%) create mode 100644 samples/analyzers/SourceKit.Analyzers.Nullable.Samples/NullableDisableNotAllowed/NullableDisable.cs create mode 100644 samples/analyzers/SourceKit.Analyzers.Nullable.Samples/NullableDisableNotAllowed/NullableEnable.cs rename {SourceKit.Sample/CodeFixProviders => samples/analyzers/SourceKit.Analyzers.Nullable.Samples}/PropagateNullCorrectly/JokeExampleWithFieldAndProperties.cs (92%) rename {SourceKit.Sample/CodeFixProviders => samples/analyzers/SourceKit.Analyzers.Nullable.Samples}/PropagateNullCorrectly/JokeExampleWithVariableDeclarations.cs (95%) create mode 100644 samples/analyzers/SourceKit.Analyzers.Nullable.Samples/SourceKit.Analyzers.Nullable.Samples.csproj create mode 100644 samples/analyzers/SourceKit.Analyzers.Properties.Samples/.editorconfig rename {SourceKit.Sample/Analyzers => samples/analyzers/SourceKit.Analyzers.Properties.Samples}/DeclarationCouldBeConvertedToProperty/ExpressionBodyMethodsField.cs (66%) rename {SourceKit.Sample/Analyzers => samples/analyzers/SourceKit.Analyzers.Properties.Samples}/DeclarationCouldBeConvertedToProperty/ManyPublicFields.cs (55%) rename {SourceKit.Sample/Analyzers => samples/analyzers/SourceKit.Analyzers.Properties.Samples}/DeclarationCouldBeConvertedToProperty/OneField.cs (68%) create mode 100644 samples/analyzers/SourceKit.Analyzers.Properties.Samples/DeclarationCouldBeConvertedToProperty/OnePublicField.cs rename {SourceKit.Sample/Analyzers => samples/analyzers/SourceKit.Analyzers.Properties.Samples}/DeclarationCouldBeConvertedToProperty/PrivateFieldWithoutMethods.cs (59%) create mode 100644 samples/analyzers/SourceKit.Analyzers.Properties.Samples/DeclarationCouldBeConvertedToProperty/PublicProperty.cs create mode 100644 samples/analyzers/SourceKit.Analyzers.Properties.Samples/DeclarationCouldBeConvertedToProperty/ReadonlyPublicField.cs rename {SourceKit.Sample/Analyzers => samples/analyzers/SourceKit.Analyzers.Properties.Samples}/DeclarationCouldBeConvertedToProperty/UnderscoreNameField.cs (60%) create mode 100644 samples/analyzers/SourceKit.Analyzers.Properties.Samples/SourceKit.Analyzers.Properties.Samples.csproj create mode 100644 samples/generators/SourceKit.Generators.Builder.Samples/.editorconfig rename {SourceKit.Sample/Generators => samples/generators/SourceKit.Generators.Builder.Samples}/ArrayQuery.cs (72%) rename {SourceKit.Sample/Generators => samples/generators/SourceKit.Generators.Builder.Samples}/CustomModelQuery.cs (55%) create mode 100644 samples/generators/SourceKit.Generators.Builder.Samples/Models/Point.cs create mode 100644 samples/generators/SourceKit.Generators.Builder.Samples/Program.cs create mode 100644 samples/generators/SourceKit.Generators.Builder.Samples/RequiredValue/InitializedRequiredValueSample.cs create mode 100644 samples/generators/SourceKit.Generators.Builder.Samples/RequiredValue/UninitializedRequiredValueSample.cs create mode 100644 samples/generators/SourceKit.Generators.Builder.Samples/RequiredValueFromParameterComponent.cs rename {SourceKit.Sample/Generators => samples/generators/SourceKit.Generators.Builder.Samples}/SomeQuery.cs (84%) create mode 100644 samples/generators/SourceKit.Generators.Builder.Samples/SourceKit.Generators.Builder.Samples.csproj rename samples/{ => generators}/SourceKit.Generators.Grpc.Samples/Program.cs (83%) rename samples/{ => generators}/SourceKit.Generators.Grpc.Samples/SourceKit.Generators.Grpc.Samples.csproj (55%) rename samples/{ => generators}/SourceKit.Generators.Grpc.Samples/protos/model.proto (100%) create mode 100644 src/analyzers/SourceKit.Analyzers.Collections/AnalyzerReleases.Shipped.md create mode 100644 src/analyzers/SourceKit.Analyzers.Collections/AnalyzerReleases.Unshipped.md create mode 100644 src/analyzers/SourceKit.Analyzers.Collections/Properties/launchSettings.json create mode 100644 src/analyzers/SourceKit.Analyzers.Enumerable/AnalyzerReleases.Shipped.md create mode 100644 src/analyzers/SourceKit.Analyzers.Enumerable/AnalyzerReleases.Unshipped.md rename src/analyzers/SourceKit.Analyzers.Enumerable/Analyzers/{DoNotEnumerateCollectionInLinqChain.cs => DoNotEnumerateCollectionInLinqChainAnalyzer.cs} (89%) create mode 100644 src/analyzers/SourceKit.Analyzers.Enumerable/Properties/launchSettings.json create mode 100644 src/analyzers/SourceKit.Analyzers.MemberAccessibility/AnalyzerReleases.Shipped.md create mode 100644 src/analyzers/SourceKit.Analyzers.MemberAccessibility/AnalyzerReleases.Unshipped.md create mode 100644 src/analyzers/SourceKit.Analyzers.MemberAccessibility/Properties/launchSettings.json create mode 100644 src/analyzers/SourceKit.Analyzers.MustBePartial/AnalyzerReleases.Shipped.md create mode 100644 src/analyzers/SourceKit.Analyzers.MustBePartial/AnalyzerReleases.Unshipped.md create mode 100644 src/analyzers/SourceKit.Analyzers.MustBePartial/Properties/launchSettings.json create mode 100644 src/analyzers/SourceKit.Analyzers.Nullable/AnalyzerReleases.Shipped.md create mode 100644 src/analyzers/SourceKit.Analyzers.Nullable/AnalyzerReleases.Unshipped.md create mode 100644 src/analyzers/SourceKit.Analyzers.Nullable/Properties/launchSettings.json create mode 100644 src/analyzers/SourceKit.Analyzers.Properties/AnalyzerReleases.Shipped.md create mode 100644 src/analyzers/SourceKit.Analyzers.Properties/AnalyzerReleases.Unshipped.md create mode 100644 src/analyzers/SourceKit.Analyzers.Properties/Properties/launchSettings.json create mode 100644 src/generators/SourceKit.Generators.Builder/AnalyzerReleases.Shipped.md create mode 100644 src/generators/SourceKit.Generators.Builder/AnalyzerReleases.Unshipped.md create mode 100644 src/generators/SourceKit.Generators.Builder/Properties/launchSettings.json create mode 100644 src/generators/SourceKit.Generators.Grpc/Properties/launchSettings.json create mode 100644 tests/SourceKit.Analyzers.Collections.Tests/CollectionsTests.cs create mode 100644 tests/SourceKit.Analyzers.Collections.Tests/ConvertListForEachIntoForEachLoop.cs create mode 100644 tests/SourceKit.Analyzers.Collections.Tests/ListForEachNotAllowedTests.cs create mode 100644 tests/SourceKit.Analyzers.Collections.Tests/SourceKit.Analyzers.Collections.Tests.csproj create mode 100644 tests/SourceKit.Analyzers.Enumerable.Tests/DoNotEnumerateCollectionInLinqChainAnalyzerTests.cs create mode 100644 tests/SourceKit.Analyzers.Enumerable.Tests/OfTypeMustUseDerivedTypeTests.cs create mode 100644 tests/SourceKit.Analyzers.Enumerable.Tests/RemoveTerminalOperationCodeFixProviderTests.cs create mode 100644 tests/SourceKit.Analyzers.Enumerable.Tests/SourceKit.Analyzers.Enumerable.Tests.csproj create mode 100644 tests/SourceKit.Analyzers.MustBePartial.Tests/MakeTypePartialCodeFixTests.cs create mode 100644 tests/SourceKit.Analyzers.MustBePartial.Tests/SourceKit.Analyzers.MustBePartial.Tests.csproj create mode 100644 tests/SourceKit.Analyzers.MustBePartial.Tests/TypesMustBePartialAnalyzerTests.cs create mode 100644 tests/SourceKit.Analyzers.Nullable.Tests/NullForgivingOperatorNotAllowedTests.cs create mode 100644 tests/SourceKit.Analyzers.Nullable.Tests/NullableDisableNotAllowedTests.cs create mode 100644 tests/SourceKit.Analyzers.Nullable.Tests/PropagateNullableCorrectlyCodeFixTests.cs create mode 100644 tests/SourceKit.Analyzers.Nullable.Tests/SourceKit.Analyzers.Nullable.Tests.csproj create mode 100644 tests/SourceKit.Analyzers.Properties.Tests/ConvertDeclarationIntoPropertyCodeFixTests.cs create mode 100644 tests/SourceKit.Analyzers.Properties.Tests/DeclarationCouldBeConvertedToPropertyTests.cs create mode 100644 tests/SourceKit.Analyzers.Properties.Tests/SourceKit.Analyzers.Properties.Tests.csproj create mode 100644 tests/SourceKit.Generators.Builder.Tests/BuilderSourceGeneratorTests.cs create mode 100644 tests/SourceKit.Generators.Builder.Tests/RequiredValueAnalyzerTests.cs create mode 100644 tests/SourceKit.Generators.Builder.Tests/SourceKit.Generators.Builder.Tests.csproj create mode 100644 tests/SourceKit.Generators.Grpc.Tests/ProtoMessageConstructorGeneratorTests.cs create mode 100644 tests/SourceKit.Generators.Grpc.Tests/SourceKit.Generators.Grpc.Tests.csproj create mode 100644 tests/SourceKit.Tests.Common/SourceFile.cs create mode 100644 tests/SourceKit.Tests.Common/TestBases/AnalyzerTestBase.cs create mode 100644 tests/SourceKit.Tests.Common/TestBases/CodeFixTestBase.cs create mode 100644 tests/SourceKit.Tests.Common/TestBases/GeneratorTestBase.cs delete mode 100644 tests/SourceKit.Tests/Analyzers/CollectionsTests.cs delete mode 100644 tests/SourceKit.Tests/Analyzers/DeclarationCouldBeConvertedToPropertyTests.cs delete mode 100644 tests/SourceKit.Tests/Analyzers/DoNotEnumerateCollectionInLinqChainTests.cs delete mode 100644 tests/SourceKit.Tests/Analyzers/Enumerable/OfTypeMustUseDerivedTypeTests.cs delete mode 100644 tests/SourceKit.Tests/Analyzers/ListForEachNotAllowedTests.cs delete mode 100644 tests/SourceKit.Tests/Analyzers/MustBePartialTests.cs delete mode 100644 tests/SourceKit.Tests/Analyzers/NullForgivingOperatorNotAllowedTests.cs delete mode 100644 tests/SourceKit.Tests/Analyzers/NullableDisableNotAllowedTests.cs delete mode 100644 tests/SourceKit.Tests/CodeFixProviders/ConvertDeclarationIntoPropertyTests.cs delete mode 100644 tests/SourceKit.Tests/CodeFixProviders/ConvertListForEachIntoForEachLoop.cs delete mode 100644 tests/SourceKit.Tests/CodeFixProviders/PropagateNullableCorrectlyCodeFixTests.cs delete mode 100644 tests/SourceKit.Tests/Generators/BuilderTests.cs delete mode 100644 tests/SourceKit.Tests/Generators/GrpcConstructorTests.cs delete mode 100644 tests/SourceKit.Tests/Generators/RequiredValueAnalyzerTests.cs delete mode 100644 tests/SourceKit.Tests/SourceKit.Tests.csproj delete mode 100644 tests/SourceKit.Tests/Startup.cs delete mode 100644 tests/SourceKit.Tests/Tools/SourceFile.cs diff --git a/.github/workflows/dotnet-build.yml b/.github/workflows/dotnet-build.yml index ab771fc..01fc391 100644 --- a/.github/workflows/dotnet-build.yml +++ b/.github/workflows/dotnet-build.yml @@ -41,28 +41,15 @@ jobs: key: ${{ runner.os }}-${{ hashFiles('**/*.Packages.props', '**/*.csproj') }} restore-keys: | ${{ runner.os }}-nuget- - - - name: move nuget config - run: | - mkdir .tmp-nuget-config - mv NuGet.config .tmp-nuget-config - - - name: build sources - run: | - for csproj in $(find src | grep csproj$) - do - dotnet build -c Release "$csproj" - done - - - name: move nuget config back - run: | - mv .tmp-nuget-config/NuGet.config . - rm -rf .tmp-nuget-config + + - name: Restore + if: steps.cache-tests.output.cache-hit != 'true' + run: dotnet restore - name: Build if: steps.cache-tests.outputs.cache-hit != 'true' - run: dotnet build -c Release + run: dotnet build -c Debug - name: Test if: steps.cache-tests.outputs.cache-hit != 'true' - run: dotnet test -c Release --no-restore --no-build \ No newline at end of file + run: dotnet test -c Debug --no-restore --no-build \ No newline at end of file diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 5e04651..74d4040 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -50,15 +50,8 @@ jobs: - name: exclude redundant projects and files if: ${{ steps.cache-packages.outputs.cache-hit != 'true' }} run: | - dotnet sln SourceKit.sln remove tests/SourceKit.Tests/SourceKit.Tests.csproj dotnet sln SourceKit.sln remove tests/SourceKit.Reflect.Tests/SourceKit.Reflect.Tests.csproj - dotnet sln SourceKit.sln remove SourceKit.Sample/SourceKit.Sample.csproj - dotnet sln SourceKit.sln remove samples/SourceKit.Generators.Grpc.Samples/SourceKit.Generators.Grpc.Samples.csproj - rm -rf SourceKit.Sample - rm -rf tests/SourceKit.Tests rm -rf tests/SourceKit.Reflect.Tests - rm -rf samples/SourceKit.Generators.Grpc.Samples - rm NuGet.config -f - name: restore if: ${{ steps.cache-packages.outputs.cache-hit != 'true' }} @@ -74,18 +67,7 @@ jobs: if: ${{ steps.cache-packages.outputs.cache-hit != 'true' }} run: | rm -rf .packages - mkdir .packages - mv src/SourceKit/bin/Release/*.nupkg .packages/ - mv src/analyzers/SourceKit.Analyzers.MustBePartial/bin/Release/*.nupkg .packages/ - mv src/analyzers/SourceKit.Analyzers.MustBePartial.Annotations/bin/Release/*.nupkg .packages/ - mv src/analyzers/SourceKit.Analyzers.MemberAccessibility/bin/Release/*.nupkg .packages/ - mv src/analyzers/SourceKit.Analyzers.Nullable/bin/Release/*.nupkg .packages/ - mv src/analyzers/SourceKit.Analyzers.Enumerable/bin/Release/*.nupkg .packages/ - mv src/analyzers/SourceKit.Analyzers.Properties/bin/Release/*.nupkg .packages/ - mv src/analyzers/SourceKit.Analyzers.Collections/bin/Release/*.nupkg .packages/ - mv src/generators/SourceKit.Generators.Builder/bin/Release/*.nupkg .packages/ - mv src/generators/SourceKit.Generators.Builder.Annotations/bin/Release/*.nupkg .packages/ - mv src/generators/SourceKit.Generators.Grpc/bin/Release/*.nupkg .packages/ + cp bin/packages .packages publish: name: publish diff --git a/Directory.Build.props b/Directory.Build.props index 5d35fb2..17b15ad 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,8 +1,29 @@ + + net8.0 12 + enable + enable + - 0 + $(NoWarn);NU5128 + + + 0-local + + + + + $([System.IO.Path]::Combine($(SolutionDir), 'bin', 'packages')) + + + + + + + \ No newline at end of file diff --git a/Directory.Packages.props b/Directory.Packages.props index 8503447..648d8a3 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -1,46 +1,50 @@ - - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/NuGet.config b/NuGet.config index 4addf46..9204204 100644 --- a/NuGet.config +++ b/NuGet.config @@ -1,16 +1,15 @@ + - - - - - - - - - - - + - + + + + + + + + + \ No newline at end of file diff --git a/SourceKit.Sample/.editorconfig b/SourceKit.Sample/.editorconfig deleted file mode 100644 index c514901..0000000 --- a/SourceKit.Sample/.editorconfig +++ /dev/null @@ -1,11 +0,0 @@ -[*.cs] - -dotnet_diagnostic.SK1000.severity = warning -dotnet_diagnostic.SK1200.severity = warning -dotnet_diagnostic.SK1201.severity = warning -dotnet_diagnostic.SK1301.severity = warning -dotnet_diagnostic.SK1300.severity = warning -dotnet_diagnostic.SK1500.severity = warning -dotnet_diagnostic.SK2000.severity = warning -dotnet_diagnostic.SK2100.severity = warning - diff --git a/SourceKit.Sample/Analyzers/Collections/Dictionary/KeyTypeDoesNotImplementEquatable.cs b/SourceKit.Sample/Analyzers/Collections/Dictionary/KeyTypeDoesNotImplementEquatable.cs deleted file mode 100644 index 2900149..0000000 --- a/SourceKit.Sample/Analyzers/Collections/Dictionary/KeyTypeDoesNotImplementEquatable.cs +++ /dev/null @@ -1,8 +0,0 @@ -using System.Collections.Generic; - -namespace SourceKit.Sample.Analyzers.Collections.Dictionary; - -public class KeyTypeDoesNotImplementEquatable -{ - public Dictionary Sample { get; set; } -} \ No newline at end of file diff --git a/SourceKit.Sample/Analyzers/Collections/Dictionary/KeyTypeImplementsEquatable.cs b/SourceKit.Sample/Analyzers/Collections/Dictionary/KeyTypeImplementsEquatable.cs deleted file mode 100644 index f0a9e46..0000000 --- a/SourceKit.Sample/Analyzers/Collections/Dictionary/KeyTypeImplementsEquatable.cs +++ /dev/null @@ -1,8 +0,0 @@ -using System.Collections.Generic; - -namespace SourceKit.Sample.Analyzers.Collections.Dictionary; - -public class KeyTypeImplementsEquatable -{ - public Dictionary Sample { get; set; } -} \ No newline at end of file diff --git a/SourceKit.Sample/Analyzers/DeclarationCouldBeConvertedToProperty/OnePublicField.cs b/SourceKit.Sample/Analyzers/DeclarationCouldBeConvertedToProperty/OnePublicField.cs deleted file mode 100644 index 76229f3..0000000 --- a/SourceKit.Sample/Analyzers/DeclarationCouldBeConvertedToProperty/OnePublicField.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace SourceKit.Sample.Analyzers.DeclarationCouldBeConvertedToProperty; - -public class OnePublicField -{ - public string field; -} \ No newline at end of file diff --git a/SourceKit.Sample/Analyzers/DeclarationCouldBeConvertedToProperty/PublicProperty.cs b/SourceKit.Sample/Analyzers/DeclarationCouldBeConvertedToProperty/PublicProperty.cs deleted file mode 100644 index c9950bf..0000000 --- a/SourceKit.Sample/Analyzers/DeclarationCouldBeConvertedToProperty/PublicProperty.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace SourceKit.Sample.Analyzers.DeclarationCouldBeConvertedToProperty; - -public class PublicProperty -{ - public string Field { get; set; } -} \ No newline at end of file diff --git a/SourceKit.Sample/Analyzers/DeclarationCouldBeConvertedToProperty/ReadonlyPublicField.cs b/SourceKit.Sample/Analyzers/DeclarationCouldBeConvertedToProperty/ReadonlyPublicField.cs deleted file mode 100644 index fd89394..0000000 --- a/SourceKit.Sample/Analyzers/DeclarationCouldBeConvertedToProperty/ReadonlyPublicField.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace SourceKit.Sample.Analyzers.DeclarationCouldBeConvertedToProperty; - -public class ReadonlyPublicField -{ - public readonly string field; -} \ No newline at end of file diff --git a/SourceKit.Sample/Analyzers/MustBePartial/NonPartialDerivative.cs b/SourceKit.Sample/Analyzers/MustBePartial/NonPartialDerivative.cs deleted file mode 100644 index 4326933..0000000 --- a/SourceKit.Sample/Analyzers/MustBePartial/NonPartialDerivative.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace SourceKit.Sample.Analyzers.MustBePartial; - -public class NonPartialDerivative : IPartialBase -{ - -} \ No newline at end of file diff --git a/SourceKit.Sample/Analyzers/Nullable/NullableDisable.cs b/SourceKit.Sample/Analyzers/Nullable/NullableDisable.cs deleted file mode 100644 index 5f28d4d..0000000 --- a/SourceKit.Sample/Analyzers/Nullable/NullableDisable.cs +++ /dev/null @@ -1,8 +0,0 @@ -#nullable disable - -namespace SourceKit.Sample.Analyzers.Nullable; - -public class NullableDisable -{ - -} \ No newline at end of file diff --git a/SourceKit.Sample/Analyzers/Nullable/NullableEnable.cs b/SourceKit.Sample/Analyzers/Nullable/NullableEnable.cs deleted file mode 100644 index 03d9cad..0000000 --- a/SourceKit.Sample/Analyzers/Nullable/NullableEnable.cs +++ /dev/null @@ -1,8 +0,0 @@ -#nullable enable - -namespace SourceKit.Sample.Analyzers.Nullable; - -public class NullableEnable -{ - -} \ No newline at end of file diff --git a/SourceKit.Sample/Generators/ArrayQueryUsage.cs b/SourceKit.Sample/Generators/ArrayQueryUsage.cs deleted file mode 100644 index 2bab138..0000000 --- a/SourceKit.Sample/Generators/ArrayQueryUsage.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using SourceKit.Generators.Builder.Annotations; - -namespace SourceKit.Sample.Generators; - -public class ArrayQueryUsage -{ - public void A() - { - var query = ArrayQuery1.Build(x => x.WithId(Guid.NewGuid())); - } -} - -[GenerateBuilder] -public record ArrayQuery1(Guid[] Ids, [RequiredValue] string Value, string NotRequiredValue = "aboba") -{ - public static ArrayQuery1 Build(Func action) - { - return action(new Builder()).Build(); - } - - public sealed class Builder - { - private readonly List _ids; - - public Builder() - { - _ids = new List(); - } - - [InitializesProperty(nameof(Ids))] - public Builder WithId(Guid element) - { - _ids.Add(element); - return this; - } - - [InitializesPropertyAttribute(nameof(Ids))] - public Builder WithIds(IEnumerable elements) - { - _ids.AddRange(elements); - return this; - } - - public ArrayQuery1 Build() - { - return new ArrayQuery1(_ids.Distinct().ToArray(), string.Empty, string.Empty); - } - } -} \ No newline at end of file diff --git a/SourceKit.Sample/Generators/ValidArrayQueryUsage.cs b/SourceKit.Sample/Generators/ValidArrayQueryUsage.cs deleted file mode 100644 index 4e7c542..0000000 --- a/SourceKit.Sample/Generators/ValidArrayQueryUsage.cs +++ /dev/null @@ -1,60 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using SourceKit.Generators.Builder.Annotations; - -namespace SourceKit.Sample.Generators; - -file class ArrayQueryUsage -{ - public void A() - { - var query = ArrayQuery1.Build(x => x.WithValue("aboba")); - } -} - -[GenerateBuilder] -file record ArrayQuery1(Guid[] Ids, [RequiredValue] string Value, string NotRequiredValue = "aboba") -{ - public static ArrayQuery1 Build(Func action) - { - return action(new Builder()).Build(); - } - - public sealed class Builder - { - private readonly List _ids; - private string _value; - - public Builder() - { - _ids = new List(); - } - - [InitializesProperty(nameof(Ids))] - public Builder WithId(Guid element) - { - _ids.Add(element); - return this; - } - - [InitializesPropertyAttribute(nameof(Ids))] - public Builder WithIds(IEnumerable elements) - { - _ids.AddRange(elements); - return this; - } - - [InitializesPropertyAttribute(nameof(Value))] - public Builder WithValue(string value) - { - _value = value; - return this; - } - - public ArrayQuery1 Build() - { - return new ArrayQuery1(_ids.Distinct().ToArray(), string.Empty, string.Empty); - } - } -} \ No newline at end of file diff --git a/SourceKit.Sample/Models/Point.cs b/SourceKit.Sample/Models/Point.cs deleted file mode 100644 index 14594a3..0000000 --- a/SourceKit.Sample/Models/Point.cs +++ /dev/null @@ -1,3 +0,0 @@ -namespace SourceKit.Sample.Models; - -public record struct Point(int X, int Y); \ No newline at end of file diff --git a/SourceKit.Sample/Playground.cs b/SourceKit.Sample/Playground.cs deleted file mode 100644 index 059d672..0000000 --- a/SourceKit.Sample/Playground.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using SourceKit.Sample.Generators; -using SourceKit.Sample.Models; - -namespace SourceKit.Sample; - -public class Playground -{ - private static IEnumerable A(IEnumerable e) - => e.Where(x => new[] { x }.Where(y => y > 1).Any()); - - public static void X() - { - var temp = new List { "asd" }; - - var g = temp.FirstOrDefault(x => x == "asd")!.ToString(); - - /*SomeQuery.Build(x => x.WithOrderById(null)); - ArrayQuery.Build(x => x.WithId(Guid.NewGuid())); - CustomModelQuery.Build(x => x.WithPoint(new Point()));*/ - } -} \ No newline at end of file diff --git a/SourceKit.Sample/Program.cs b/SourceKit.Sample/Program.cs deleted file mode 100644 index 85900eb..0000000 --- a/SourceKit.Sample/Program.cs +++ /dev/null @@ -1,5 +0,0 @@ -// using System; -// using SourceKit.Sample.Generators; -// -// var query = SomeQuery.Build(x => x.WithCount(2)); -// Console.WriteLine(query.Count); \ No newline at end of file diff --git a/SourceKit.Sample/SourceKit.Sample.csproj b/SourceKit.Sample/SourceKit.Sample.csproj deleted file mode 100644 index 58d2cb8..0000000 --- a/SourceKit.Sample/SourceKit.Sample.csproj +++ /dev/null @@ -1,33 +0,0 @@ - - - - net7.0 - enable - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/SourceKit.sln b/SourceKit.sln index 653c8aa..643eede 100644 --- a/SourceKit.sln +++ b/SourceKit.sln @@ -8,10 +8,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SourceKit.Reflect", "src\So EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SourceKit", "src\SourceKit\SourceKit.csproj", "{8EED1912-BB7A-4C97-9032-08E3219724DE}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SourceKit.Sample", "SourceKit.Sample\SourceKit.Sample.csproj", "{701CE759-EAF3-439D-91BF-C158F5860B72}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SourceKit.Tests", "tests\SourceKit.Tests\SourceKit.Tests.csproj", "{EE7B76B2-A19F-4F9D-B091-9E6EF9151164}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "analyzers", "analyzers", "{0506CF17-3170-420E-B120-3BEB0BDE68CF}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SourceKit.Analyzers.MustBePartial.Annotations", "src\analyzers\SourceKit.Analyzers.MustBePartial.Annotations\SourceKit.Analyzers.MustBePartial.Annotations.csproj", "{B94E98ED-AD2A-4DE0-B405-2C38F75FA000}" @@ -38,6 +34,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "common", "common", "{1744B9 ProjectSection(SolutionItems) = preProject Directory.Packages.props = Directory.Packages.props Directory.Build.props = Directory.Build.props + NuGet.config = NuGet.config EndProjectSection EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SourceKit.Reflect.Tests", "tests\SourceKit.Reflect.Tests\SourceKit.Reflect.Tests.csproj", "{7A4C3CA4-A821-4BBF-9D33-C3B506684E1A}" @@ -54,7 +51,43 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SourceKit.Generators.Grpc", EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{68973D47-37E1-492E-8F62-E94B002349BB}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SourceKit.Generators.Grpc.Samples", "samples\SourceKit.Generators.Grpc.Samples\SourceKit.Generators.Grpc.Samples.csproj", "{40A67635-FA4B-4D71-AB8B-13BEDDE17E77}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SourceKit.Generators.Grpc.Samples", "samples\generators\SourceKit.Generators.Grpc.Samples\SourceKit.Generators.Grpc.Samples.csproj", "{40A67635-FA4B-4D71-AB8B-13BEDDE17E77}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "generators", "generators", "{84DBA1F6-2A81-452F-97EE-AEB57C0E7BC6}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SourceKit.Generators.Builder.Samples", "samples\generators\SourceKit.Generators.Builder.Samples\SourceKit.Generators.Builder.Samples.csproj", "{994FFED7-4AE4-4795-9612-9B3F65C334FC}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SourceKit.Generators.Builder.Tests", "tests\SourceKit.Generators.Builder.Tests\SourceKit.Generators.Builder.Tests.csproj", "{875C0BB6-CC18-49C5-8FC3-CEFD071A5F4F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SourceKit.Generators.Grpc.Tests", "tests\SourceKit.Generators.Grpc.Tests\SourceKit.Generators.Grpc.Tests.csproj", "{C2CD4423-7841-431D-AC65-2246983CF6F0}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "generators", "generators", "{D4C67B93-0E36-451B-B4CD-A036EDD288BE}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "analyzers", "analyzers", "{CB9AFB88-6DC1-436D-8F6F-398E065A07DE}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SourceKit.Analyzers.Enumerable.Tests", "tests\SourceKit.Analyzers.Enumerable.Tests\SourceKit.Analyzers.Enumerable.Tests.csproj", "{D848ABC7-B027-4E95-A98A-C71022BFDF79}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "analyzers", "analyzers", "{365210F4-5F33-49FD-9E14-552154E26285}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SourceKit.Analyzers.Enumerable.Samples", "samples\analyzers\SourceKit.Analyzers.Enumerable.Samples\SourceKit.Analyzers.Enumerable.Samples.csproj", "{4C8CEF9E-31D1-433B-8A2D-45312A1C5D81}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SourceKit.Analyzers.Collections.Tests", "tests\SourceKit.Analyzers.Collections.Tests\SourceKit.Analyzers.Collections.Tests.csproj", "{2A636AD6-8D81-4948-8B12-6AB842F50040}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SourceKit.Analyzers.Collections.Samples", "samples\analyzers\SourceKit.Analyzers.Collections.Samples\SourceKit.Analyzers.Collections.Samples.csproj", "{A2CF4A1C-73F5-4968-8335-D030D5F64A0B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SourceKit.Analyzers.MustBePartial.Samples", "samples\analyzers\SourceKit.Analyzers.MustBePartial.Samples\SourceKit.Analyzers.MustBePartial.Samples.csproj", "{C025F298-B242-4166-BC62-C03794CCE228}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SourceKit.Analyzers.MustBePartial.Tests", "tests\SourceKit.Analyzers.MustBePartial.Tests\SourceKit.Analyzers.MustBePartial.Tests.csproj", "{2DDC124E-8E7D-45F9-B2AD-7516DC065D23}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SourceKit.Analyzers.Nullable.Samples", "samples\analyzers\SourceKit.Analyzers.Nullable.Samples\SourceKit.Analyzers.Nullable.Samples.csproj", "{4019AF7B-3137-4EA4-AE05-E5D7A6F9AD66}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SourceKit.Analyzers.Nullable.Tests", "tests\SourceKit.Analyzers.Nullable.Tests\SourceKit.Analyzers.Nullable.Tests.csproj", "{79C8B98C-A75D-41F9-9873-FE30E88CB7BD}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SourceKit.Analyzers.Properties.Samples", "samples\analyzers\SourceKit.Analyzers.Properties.Samples\SourceKit.Analyzers.Properties.Samples.csproj", "{35F679FA-4F45-4870-B7C6-7B31A6CD014F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SourceKit.Analyzers.Properties.Tests", "tests\SourceKit.Analyzers.Properties.Tests\SourceKit.Analyzers.Properties.Tests.csproj", "{4B54BDA0-D16F-428F-97D2-03654311CE22}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SourceKit.Reflect.Samples", "samples\SourceKit.Reflect.Samples\SourceKit.Reflect.Samples.csproj", "{B3EEEF25-A90E-404F-9874-93A2E6990468}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -64,8 +97,6 @@ Global GlobalSection(NestedProjects) = preSolution {637C01C1-3A3C-4FC6-9874-6CFBA4319A79} = {BBA45AFB-5727-47BB-9BBB-B05559BE892E} {8EED1912-BB7A-4C97-9032-08E3219724DE} = {BBA45AFB-5727-47BB-9BBB-B05559BE892E} - {701CE759-EAF3-439D-91BF-C158F5860B72} = {4B7FE6F2-BF92-4698-A01F-4C1E111B62CF} - {EE7B76B2-A19F-4F9D-B091-9E6EF9151164} = {4B7FE6F2-BF92-4698-A01F-4C1E111B62CF} {0506CF17-3170-420E-B120-3BEB0BDE68CF} = {BBA45AFB-5727-47BB-9BBB-B05559BE892E} {B94E98ED-AD2A-4DE0-B405-2C38F75FA000} = {0506CF17-3170-420E-B120-3BEB0BDE68CF} {18E723E4-9DA2-49D3-9B08-0923BEC3FD9F} = {0506CF17-3170-420E-B120-3BEB0BDE68CF} @@ -81,53 +112,63 @@ Global {E2B94853-6782-4711-AF6F-7B619FC8CC82} = {4B7FE6F2-BF92-4698-A01F-4C1E111B62CF} {36BD473E-7C74-4E53-872A-9F6D4E822C70} = {1744B931-41D0-4099-902C-FEE41B009A09} {303F2F11-39B3-488A-8A93-8C7FEBDED5A5} = {7A8B3DC6-F194-45F6-8C23-151806809BE1} - {40A67635-FA4B-4D71-AB8B-13BEDDE17E77} = {68973D47-37E1-492E-8F62-E94B002349BB} + {84DBA1F6-2A81-452F-97EE-AEB57C0E7BC6} = {68973D47-37E1-492E-8F62-E94B002349BB} + {40A67635-FA4B-4D71-AB8B-13BEDDE17E77} = {84DBA1F6-2A81-452F-97EE-AEB57C0E7BC6} + {994FFED7-4AE4-4795-9612-9B3F65C334FC} = {84DBA1F6-2A81-452F-97EE-AEB57C0E7BC6} + {D4C67B93-0E36-451B-B4CD-A036EDD288BE} = {4B7FE6F2-BF92-4698-A01F-4C1E111B62CF} + {875C0BB6-CC18-49C5-8FC3-CEFD071A5F4F} = {D4C67B93-0E36-451B-B4CD-A036EDD288BE} + {C2CD4423-7841-431D-AC65-2246983CF6F0} = {D4C67B93-0E36-451B-B4CD-A036EDD288BE} + {CB9AFB88-6DC1-436D-8F6F-398E065A07DE} = {4B7FE6F2-BF92-4698-A01F-4C1E111B62CF} + {D848ABC7-B027-4E95-A98A-C71022BFDF79} = {CB9AFB88-6DC1-436D-8F6F-398E065A07DE} + {365210F4-5F33-49FD-9E14-552154E26285} = {68973D47-37E1-492E-8F62-E94B002349BB} + {4C8CEF9E-31D1-433B-8A2D-45312A1C5D81} = {365210F4-5F33-49FD-9E14-552154E26285} + {2A636AD6-8D81-4948-8B12-6AB842F50040} = {CB9AFB88-6DC1-436D-8F6F-398E065A07DE} + {A2CF4A1C-73F5-4968-8335-D030D5F64A0B} = {365210F4-5F33-49FD-9E14-552154E26285} + {C025F298-B242-4166-BC62-C03794CCE228} = {365210F4-5F33-49FD-9E14-552154E26285} + {2DDC124E-8E7D-45F9-B2AD-7516DC065D23} = {CB9AFB88-6DC1-436D-8F6F-398E065A07DE} + {4019AF7B-3137-4EA4-AE05-E5D7A6F9AD66} = {365210F4-5F33-49FD-9E14-552154E26285} + {79C8B98C-A75D-41F9-9873-FE30E88CB7BD} = {CB9AFB88-6DC1-436D-8F6F-398E065A07DE} + {35F679FA-4F45-4870-B7C6-7B31A6CD014F} = {365210F4-5F33-49FD-9E14-552154E26285} + {4B54BDA0-D16F-428F-97D2-03654311CE22} = {CB9AFB88-6DC1-436D-8F6F-398E065A07DE} + {B3EEEF25-A90E-404F-9874-93A2E6990468} = {68973D47-37E1-492E-8F62-E94B002349BB} EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {637C01C1-3A3C-4FC6-9874-6CFBA4319A79}.Release|Any CPU.ActiveCfg = Release|Any CPU {637C01C1-3A3C-4FC6-9874-6CFBA4319A79}.Release|Any CPU.Build.0 = Release|Any CPU {637C01C1-3A3C-4FC6-9874-6CFBA4319A79}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {637C01C1-3A3C-4FC6-9874-6CFBA4319A79}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8EED1912-BB7A-4C97-9032-08E3219724DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8EED1912-BB7A-4C97-9032-08E3219724DE}.Debug|Any CPU.Build.0 = Debug|Any CPU {8EED1912-BB7A-4C97-9032-08E3219724DE}.Release|Any CPU.ActiveCfg = Release|Any CPU {8EED1912-BB7A-4C97-9032-08E3219724DE}.Release|Any CPU.Build.0 = Release|Any CPU - {8EED1912-BB7A-4C97-9032-08E3219724DE}.Debug|Any CPU.ActiveCfg = Release|Any CPU - {8EED1912-BB7A-4C97-9032-08E3219724DE}.Debug|Any CPU.Build.0 = Release|Any CPU - {701CE759-EAF3-439D-91BF-C158F5860B72}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {701CE759-EAF3-439D-91BF-C158F5860B72}.Debug|Any CPU.Build.0 = Debug|Any CPU - {701CE759-EAF3-439D-91BF-C158F5860B72}.Release|Any CPU.ActiveCfg = Release|Any CPU - {701CE759-EAF3-439D-91BF-C158F5860B72}.Release|Any CPU.Build.0 = Release|Any CPU - {EE7B76B2-A19F-4F9D-B091-9E6EF9151164}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {EE7B76B2-A19F-4F9D-B091-9E6EF9151164}.Debug|Any CPU.Build.0 = Debug|Any CPU - {EE7B76B2-A19F-4F9D-B091-9E6EF9151164}.Release|Any CPU.ActiveCfg = Release|Any CPU - {EE7B76B2-A19F-4F9D-B091-9E6EF9151164}.Release|Any CPU.Build.0 = Release|Any CPU {B94E98ED-AD2A-4DE0-B405-2C38F75FA000}.Release|Any CPU.ActiveCfg = Release|Any CPU {B94E98ED-AD2A-4DE0-B405-2C38F75FA000}.Release|Any CPU.Build.0 = Release|Any CPU - {B94E98ED-AD2A-4DE0-B405-2C38F75FA000}.Debug|Any CPU.ActiveCfg = Release|Any CPU - {B94E98ED-AD2A-4DE0-B405-2C38F75FA000}.Debug|Any CPU.Build.0 = Release|Any CPU + {B94E98ED-AD2A-4DE0-B405-2C38F75FA000}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B94E98ED-AD2A-4DE0-B405-2C38F75FA000}.Debug|Any CPU.Build.0 = Debug|Any CPU {18E723E4-9DA2-49D3-9B08-0923BEC3FD9F}.Release|Any CPU.ActiveCfg = Release|Any CPU {18E723E4-9DA2-49D3-9B08-0923BEC3FD9F}.Release|Any CPU.Build.0 = Release|Any CPU - {18E723E4-9DA2-49D3-9B08-0923BEC3FD9F}.Debug|Any CPU.ActiveCfg = Release|Any CPU - {18E723E4-9DA2-49D3-9B08-0923BEC3FD9F}.Debug|Any CPU.Build.0 = Release|Any CPU + {18E723E4-9DA2-49D3-9B08-0923BEC3FD9F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {18E723E4-9DA2-49D3-9B08-0923BEC3FD9F}.Debug|Any CPU.Build.0 = Debug|Any CPU {C8BC0B4D-4FA2-4FB2-B384-A2ED37B0CFA9}.Release|Any CPU.ActiveCfg = Release|Any CPU {C8BC0B4D-4FA2-4FB2-B384-A2ED37B0CFA9}.Release|Any CPU.Build.0 = Release|Any CPU - {C8BC0B4D-4FA2-4FB2-B384-A2ED37B0CFA9}.Debug|Any CPU.ActiveCfg = Release|Any CPU - {C8BC0B4D-4FA2-4FB2-B384-A2ED37B0CFA9}.Debug|Any CPU.Build.0 = Release|Any CPU + {C8BC0B4D-4FA2-4FB2-B384-A2ED37B0CFA9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C8BC0B4D-4FA2-4FB2-B384-A2ED37B0CFA9}.Debug|Any CPU.Build.0 = Debug|Any CPU {5BD41F98-95D1-443A-9393-9D3DA2AD6B06}.Release|Any CPU.ActiveCfg = Release|Any CPU {5BD41F98-95D1-443A-9393-9D3DA2AD6B06}.Release|Any CPU.Build.0 = Release|Any CPU - {5BD41F98-95D1-443A-9393-9D3DA2AD6B06}.Debug|Any CPU.ActiveCfg = Release|Any CPU - {5BD41F98-95D1-443A-9393-9D3DA2AD6B06}.Debug|Any CPU.Build.0 = Release|Any CPU + {5BD41F98-95D1-443A-9393-9D3DA2AD6B06}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5BD41F98-95D1-443A-9393-9D3DA2AD6B06}.Debug|Any CPU.Build.0 = Debug|Any CPU {AABC159C-061A-46B6-A09B-16B24679CF7D}.Release|Any CPU.ActiveCfg = Release|Any CPU {AABC159C-061A-46B6-A09B-16B24679CF7D}.Release|Any CPU.Build.0 = Release|Any CPU - {AABC159C-061A-46B6-A09B-16B24679CF7D}.Debug|Any CPU.ActiveCfg = Release|Any CPU - {AABC159C-061A-46B6-A09B-16B24679CF7D}.Debug|Any CPU.Build.0 = Release|Any CPU + {AABC159C-061A-46B6-A09B-16B24679CF7D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AABC159C-061A-46B6-A09B-16B24679CF7D}.Debug|Any CPU.Build.0 = Debug|Any CPU {6FBCA29D-9EFD-4596-8BD0-F6E9C394228E}.Release|Any CPU.ActiveCfg = Release|Any CPU {6FBCA29D-9EFD-4596-8BD0-F6E9C394228E}.Release|Any CPU.Build.0 = Release|Any CPU - {6FBCA29D-9EFD-4596-8BD0-F6E9C394228E}.Debug|Any CPU.ActiveCfg = Release|Any CPU - {6FBCA29D-9EFD-4596-8BD0-F6E9C394228E}.Debug|Any CPU.Build.0 = Release|Any CPU + {6FBCA29D-9EFD-4596-8BD0-F6E9C394228E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6FBCA29D-9EFD-4596-8BD0-F6E9C394228E}.Debug|Any CPU.Build.0 = Debug|Any CPU {76AEC735-94F8-4904-9B60-4E53A142C812}.Release|Any CPU.ActiveCfg = Release|Any CPU {76AEC735-94F8-4904-9B60-4E53A142C812}.Release|Any CPU.Build.0 = Release|Any CPU - {76AEC735-94F8-4904-9B60-4E53A142C812}.Debug|Any CPU.ActiveCfg = Release|Any CPU - {76AEC735-94F8-4904-9B60-4E53A142C812}.Debug|Any CPU.Build.0 = Release|Any CPU + {76AEC735-94F8-4904-9B60-4E53A142C812}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {76AEC735-94F8-4904-9B60-4E53A142C812}.Debug|Any CPU.Build.0 = Debug|Any CPU {21EE8956-B00B-45B7-ACD9-53CD1648ADC6}.Release|Any CPU.ActiveCfg = Release|Any CPU {21EE8956-B00B-45B7-ACD9-53CD1648ADC6}.Release|Any CPU.Build.0 = Release|Any CPU {21EE8956-B00B-45B7-ACD9-53CD1648ADC6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU @@ -138,19 +179,75 @@ Global {AAE68EF8-EC92-42CA-A554-6733F28C250C}.Debug|Any CPU.Build.0 = Debug|Any CPU {7A4C3CA4-A821-4BBF-9D33-C3B506684E1A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {7A4C3CA4-A821-4BBF-9D33-C3B506684E1A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {7A4C3CA4-A821-4BBF-9D33-C3B506684E1A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {7A4C3CA4-A821-4BBF-9D33-C3B506684E1A}.Release|Any CPU.Build.0 = Release|Any CPU + {7A4C3CA4-A821-4BBF-9D33-C3B506684E1A}.Release|Any CPU.ActiveCfg = Debug|Any CPU + {7A4C3CA4-A821-4BBF-9D33-C3B506684E1A}.Release|Any CPU.Build.0 = Debug|Any CPU {E2B94853-6782-4711-AF6F-7B619FC8CC82}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {E2B94853-6782-4711-AF6F-7B619FC8CC82}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E2B94853-6782-4711-AF6F-7B619FC8CC82}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E2B94853-6782-4711-AF6F-7B619FC8CC82}.Release|Any CPU.Build.0 = Release|Any CPU + {E2B94853-6782-4711-AF6F-7B619FC8CC82}.Release|Any CPU.ActiveCfg = Debug|Any CPU + {E2B94853-6782-4711-AF6F-7B619FC8CC82}.Release|Any CPU.Build.0 = Debug|Any CPU + {303F2F11-39B3-488A-8A93-8C7FEBDED5A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {303F2F11-39B3-488A-8A93-8C7FEBDED5A5}.Debug|Any CPU.Build.0 = Debug|Any CPU {303F2F11-39B3-488A-8A93-8C7FEBDED5A5}.Release|Any CPU.ActiveCfg = Release|Any CPU {303F2F11-39B3-488A-8A93-8C7FEBDED5A5}.Release|Any CPU.Build.0 = Release|Any CPU - {303F2F11-39B3-488A-8A93-8C7FEBDED5A5}.Debug|Any CPU.ActiveCfg = Release|Any CPU - {303F2F11-39B3-488A-8A93-8C7FEBDED5A5}.Debug|Any CPU.Build.0 = Release|Any CPU {40A67635-FA4B-4D71-AB8B-13BEDDE17E77}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {40A67635-FA4B-4D71-AB8B-13BEDDE17E77}.Debug|Any CPU.Build.0 = Debug|Any CPU {40A67635-FA4B-4D71-AB8B-13BEDDE17E77}.Release|Any CPU.ActiveCfg = Release|Any CPU {40A67635-FA4B-4D71-AB8B-13BEDDE17E77}.Release|Any CPU.Build.0 = Release|Any CPU + {994FFED7-4AE4-4795-9612-9B3F65C334FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {994FFED7-4AE4-4795-9612-9B3F65C334FC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {994FFED7-4AE4-4795-9612-9B3F65C334FC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {994FFED7-4AE4-4795-9612-9B3F65C334FC}.Release|Any CPU.Build.0 = Release|Any CPU + {875C0BB6-CC18-49C5-8FC3-CEFD071A5F4F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {875C0BB6-CC18-49C5-8FC3-CEFD071A5F4F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {875C0BB6-CC18-49C5-8FC3-CEFD071A5F4F}.Release|Any CPU.ActiveCfg = Debug|Any CPU + {875C0BB6-CC18-49C5-8FC3-CEFD071A5F4F}.Release|Any CPU.Build.0 = Debug|Any CPU + {C2CD4423-7841-431D-AC65-2246983CF6F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C2CD4423-7841-431D-AC65-2246983CF6F0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C2CD4423-7841-431D-AC65-2246983CF6F0}.Release|Any CPU.ActiveCfg = Debug|Any CPU + {C2CD4423-7841-431D-AC65-2246983CF6F0}.Release|Any CPU.Build.0 = Debug|Any CPU + {D848ABC7-B027-4E95-A98A-C71022BFDF79}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D848ABC7-B027-4E95-A98A-C71022BFDF79}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D848ABC7-B027-4E95-A98A-C71022BFDF79}.Release|Any CPU.ActiveCfg = Debug|Any CPU + {D848ABC7-B027-4E95-A98A-C71022BFDF79}.Release|Any CPU.Build.0 = Debug|Any CPU + {4C8CEF9E-31D1-433B-8A2D-45312A1C5D81}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4C8CEF9E-31D1-433B-8A2D-45312A1C5D81}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4C8CEF9E-31D1-433B-8A2D-45312A1C5D81}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4C8CEF9E-31D1-433B-8A2D-45312A1C5D81}.Release|Any CPU.Build.0 = Release|Any CPU + {2A636AD6-8D81-4948-8B12-6AB842F50040}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2A636AD6-8D81-4948-8B12-6AB842F50040}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2A636AD6-8D81-4948-8B12-6AB842F50040}.Release|Any CPU.ActiveCfg = Debug|Any CPU + {2A636AD6-8D81-4948-8B12-6AB842F50040}.Release|Any CPU.Build.0 = Debug|Any CPU + {A2CF4A1C-73F5-4968-8335-D030D5F64A0B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A2CF4A1C-73F5-4968-8335-D030D5F64A0B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A2CF4A1C-73F5-4968-8335-D030D5F64A0B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A2CF4A1C-73F5-4968-8335-D030D5F64A0B}.Release|Any CPU.Build.0 = Release|Any CPU + {C025F298-B242-4166-BC62-C03794CCE228}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C025F298-B242-4166-BC62-C03794CCE228}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C025F298-B242-4166-BC62-C03794CCE228}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C025F298-B242-4166-BC62-C03794CCE228}.Release|Any CPU.Build.0 = Release|Any CPU + {2DDC124E-8E7D-45F9-B2AD-7516DC065D23}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2DDC124E-8E7D-45F9-B2AD-7516DC065D23}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2DDC124E-8E7D-45F9-B2AD-7516DC065D23}.Release|Any CPU.ActiveCfg = Debug|Any CPU + {2DDC124E-8E7D-45F9-B2AD-7516DC065D23}.Release|Any CPU.Build.0 = Debug|Any CPU + {4019AF7B-3137-4EA4-AE05-E5D7A6F9AD66}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4019AF7B-3137-4EA4-AE05-E5D7A6F9AD66}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4019AF7B-3137-4EA4-AE05-E5D7A6F9AD66}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4019AF7B-3137-4EA4-AE05-E5D7A6F9AD66}.Release|Any CPU.Build.0 = Release|Any CPU + {79C8B98C-A75D-41F9-9873-FE30E88CB7BD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {79C8B98C-A75D-41F9-9873-FE30E88CB7BD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {79C8B98C-A75D-41F9-9873-FE30E88CB7BD}.Release|Any CPU.ActiveCfg = Debug|Any CPU + {79C8B98C-A75D-41F9-9873-FE30E88CB7BD}.Release|Any CPU.Build.0 = Debug|Any CPU + {35F679FA-4F45-4870-B7C6-7B31A6CD014F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {35F679FA-4F45-4870-B7C6-7B31A6CD014F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {35F679FA-4F45-4870-B7C6-7B31A6CD014F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {35F679FA-4F45-4870-B7C6-7B31A6CD014F}.Release|Any CPU.Build.0 = Release|Any CPU + {4B54BDA0-D16F-428F-97D2-03654311CE22}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4B54BDA0-D16F-428F-97D2-03654311CE22}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4B54BDA0-D16F-428F-97D2-03654311CE22}.Release|Any CPU.ActiveCfg = Debug|Any CPU + {4B54BDA0-D16F-428F-97D2-03654311CE22}.Release|Any CPU.Build.0 = Debug|Any CPU + {B3EEEF25-A90E-404F-9874-93A2E6990468}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B3EEEF25-A90E-404F-9874-93A2E6990468}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B3EEEF25-A90E-404F-9874-93A2E6990468}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B3EEEF25-A90E-404F-9874-93A2E6990468}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/SourceKit.Sample/Class1.cs b/samples/SourceKit.Reflect.Samples/Class1.cs similarity index 94% rename from SourceKit.Sample/Class1.cs rename to samples/SourceKit.Reflect.Samples/Class1.cs index 51f4847..4bac816 100644 --- a/SourceKit.Sample/Class1.cs +++ b/samples/SourceKit.Reflect.Samples/Class1.cs @@ -1,9 +1,9 @@ using System; using System.Collections.Generic; +using System.Drawing; using System.Linq; -using SourceKit.Sample.Models; -namespace SourceKit.Sample; +namespace SourceKit.Reflect.Samples; public class Class { diff --git a/samples/SourceKit.Reflect.Samples/SourceKit.Reflect.Samples.csproj b/samples/SourceKit.Reflect.Samples/SourceKit.Reflect.Samples.csproj new file mode 100644 index 0000000..eac4d57 --- /dev/null +++ b/samples/SourceKit.Reflect.Samples/SourceKit.Reflect.Samples.csproj @@ -0,0 +1,7 @@ + + + + disable + + + diff --git a/samples/analyzers/SourceKit.Analyzers.Collections.Samples/.editorconfig b/samples/analyzers/SourceKit.Analyzers.Collections.Samples/.editorconfig new file mode 100644 index 0000000..aee0924 --- /dev/null +++ b/samples/analyzers/SourceKit.Analyzers.Collections.Samples/.editorconfig @@ -0,0 +1,4 @@ +[*.cs] + +dotnet_diagnostic.SK1500.severity = suggestion +dotnet_diagnostic.SK1501.severity = suggestion \ No newline at end of file diff --git a/SourceKit.Sample/Analyzers/Collections/Dictionary/CustomKeyTypeImplementsEquatable.cs b/samples/analyzers/SourceKit.Analyzers.Collections.Samples/Dictionary/CustomKeyTypeImplementsEquatable.cs similarity index 67% rename from SourceKit.Sample/Analyzers/Collections/Dictionary/CustomKeyTypeImplementsEquatable.cs rename to samples/analyzers/SourceKit.Analyzers.Collections.Samples/Dictionary/CustomKeyTypeImplementsEquatable.cs index 451d41f..7cab492 100644 --- a/SourceKit.Sample/Analyzers/Collections/Dictionary/CustomKeyTypeImplementsEquatable.cs +++ b/samples/analyzers/SourceKit.Analyzers.Collections.Samples/Dictionary/CustomKeyTypeImplementsEquatable.cs @@ -1,8 +1,8 @@ using System.Collections.Generic; -namespace SourceKit.Sample.Analyzers.Collections.Dictionary; +namespace SourceKit.Analyzers.Collections.Samples.Dictionary; public class CustomKeyTypeImplementsEquatable { - public Dictionary Custom { get; set; } + public Dictionary Custom { get; set; } = new(); } \ No newline at end of file diff --git a/SourceKit.Sample/Analyzers/Collections/Dictionary/CustomKeyTypeImplementsOtherEquatable.cs b/samples/analyzers/SourceKit.Analyzers.Collections.Samples/Dictionary/CustomKeyTypeImplementsOtherEquatable.cs similarity index 85% rename from SourceKit.Sample/Analyzers/Collections/Dictionary/CustomKeyTypeImplementsOtherEquatable.cs rename to samples/analyzers/SourceKit.Analyzers.Collections.Samples/Dictionary/CustomKeyTypeImplementsOtherEquatable.cs index cff9c58..c55be0f 100644 --- a/SourceKit.Sample/Analyzers/Collections/Dictionary/CustomKeyTypeImplementsOtherEquatable.cs +++ b/samples/analyzers/SourceKit.Analyzers.Collections.Samples/Dictionary/CustomKeyTypeImplementsOtherEquatable.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; -namespace SourceKit.Sample.Analyzers.Collections.Dictionary; +namespace SourceKit.Analyzers.Collections.Samples.Dictionary; public class CustomKeyTypeImplementsOtherEquatable { diff --git a/SourceKit.Sample/Analyzers/Collections/Dictionary/EmptyKeyType.cs b/samples/analyzers/SourceKit.Analyzers.Collections.Samples/Dictionary/EmptyKeyType.cs similarity index 68% rename from SourceKit.Sample/Analyzers/Collections/Dictionary/EmptyKeyType.cs rename to samples/analyzers/SourceKit.Analyzers.Collections.Samples/Dictionary/EmptyKeyType.cs index 1acbc1f..9291a47 100644 --- a/SourceKit.Sample/Analyzers/Collections/Dictionary/EmptyKeyType.cs +++ b/samples/analyzers/SourceKit.Analyzers.Collections.Samples/Dictionary/EmptyKeyType.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; -namespace SourceKit.Sample.Analyzers.Collections.Dictionary; +namespace SourceKit.Analyzers.Collections.Samples.Dictionary; public class EmptyKeyType { diff --git a/SourceKit.Sample/Analyzers/Collections/Dictionary/EnumKeyDictionary.cs b/samples/analyzers/SourceKit.Analyzers.Collections.Samples/Dictionary/EnumKeyDictionary.cs similarity index 82% rename from SourceKit.Sample/Analyzers/Collections/Dictionary/EnumKeyDictionary.cs rename to samples/analyzers/SourceKit.Analyzers.Collections.Samples/Dictionary/EnumKeyDictionary.cs index 00aa219..3f9f556 100644 --- a/SourceKit.Sample/Analyzers/Collections/Dictionary/EnumKeyDictionary.cs +++ b/samples/analyzers/SourceKit.Analyzers.Collections.Samples/Dictionary/EnumKeyDictionary.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace SourceKit.Sample.Analyzers.Collections.Dictionary; +namespace SourceKit.Analyzers.Collections.Samples.Dictionary; public class EnumKeyDictionary { diff --git a/SourceKit.Sample/Analyzers/Collections/Dictionary/EquatableType.cs b/samples/analyzers/SourceKit.Analyzers.Collections.Samples/Dictionary/EquatableType.cs similarity index 87% rename from SourceKit.Sample/Analyzers/Collections/Dictionary/EquatableType.cs rename to samples/analyzers/SourceKit.Analyzers.Collections.Samples/Dictionary/EquatableType.cs index 4bf2ba8..4c1548b 100644 --- a/SourceKit.Sample/Analyzers/Collections/Dictionary/EquatableType.cs +++ b/samples/analyzers/SourceKit.Analyzers.Collections.Samples/Dictionary/EquatableType.cs @@ -1,6 +1,6 @@ using System; -namespace SourceKit.Sample.Analyzers.Collections.Dictionary; +namespace SourceKit.Analyzers.Collections.Samples.Dictionary; public class EquatableType : IEquatable { diff --git a/SourceKit.Sample/Analyzers/Collections/Dictionary/InheritedCustomKeyTypeImplementsEquatable.cs b/samples/analyzers/SourceKit.Analyzers.Collections.Samples/Dictionary/InheritedCustomKeyTypeImplementsEquatable.cs similarity index 77% rename from SourceKit.Sample/Analyzers/Collections/Dictionary/InheritedCustomKeyTypeImplementsEquatable.cs rename to samples/analyzers/SourceKit.Analyzers.Collections.Samples/Dictionary/InheritedCustomKeyTypeImplementsEquatable.cs index 7b8a121..55b581b 100644 --- a/SourceKit.Sample/Analyzers/Collections/Dictionary/InheritedCustomKeyTypeImplementsEquatable.cs +++ b/samples/analyzers/SourceKit.Analyzers.Collections.Samples/Dictionary/InheritedCustomKeyTypeImplementsEquatable.cs @@ -1,8 +1,7 @@ using System; using System.Collections.Generic; -using SourceKit.Sample.Analyzers.Collections.Dictionary; -namespace SourceKit.Sample.Analyzers.Collections.Dictionary; +namespace SourceKit.Analyzers.Collections.Samples.Dictionary; public class InheritedCustomKeyTypeImplementsEquatable { diff --git a/samples/analyzers/SourceKit.Analyzers.Collections.Samples/Dictionary/KeyTypeDoesNotImplementEquatable.cs b/samples/analyzers/SourceKit.Analyzers.Collections.Samples/Dictionary/KeyTypeDoesNotImplementEquatable.cs new file mode 100644 index 0000000..07049cb --- /dev/null +++ b/samples/analyzers/SourceKit.Analyzers.Collections.Samples/Dictionary/KeyTypeDoesNotImplementEquatable.cs @@ -0,0 +1,8 @@ +using System.Collections.Generic; + +namespace SourceKit.Analyzers.Collections.Samples.Dictionary; + +public class KeyTypeDoesNotImplementEquatable +{ + public Dictionary Sample { get; set; } = new(); +} \ No newline at end of file diff --git a/samples/analyzers/SourceKit.Analyzers.Collections.Samples/Dictionary/KeyTypeImplementsEquatable.cs b/samples/analyzers/SourceKit.Analyzers.Collections.Samples/Dictionary/KeyTypeImplementsEquatable.cs new file mode 100644 index 0000000..b413d85 --- /dev/null +++ b/samples/analyzers/SourceKit.Analyzers.Collections.Samples/Dictionary/KeyTypeImplementsEquatable.cs @@ -0,0 +1,8 @@ +using System.Collections.Generic; + +namespace SourceKit.Analyzers.Collections.Samples.Dictionary; + +public class KeyTypeImplementsEquatable +{ + public Dictionary Sample { get; set; } = new(); +} \ No newline at end of file diff --git a/SourceKit.Sample/Analyzers/ListForEachNotAllowed/ListForEachStatementComplexExample.cs b/samples/analyzers/SourceKit.Analyzers.Collections.Samples/ListForEachNotAllowed/ListForEachStatementComplexExample.cs similarity index 90% rename from SourceKit.Sample/Analyzers/ListForEachNotAllowed/ListForEachStatementComplexExample.cs rename to samples/analyzers/SourceKit.Analyzers.Collections.Samples/ListForEachNotAllowed/ListForEachStatementComplexExample.cs index 119e4e9..ff23aec 100644 --- a/SourceKit.Sample/Analyzers/ListForEachNotAllowed/ListForEachStatementComplexExample.cs +++ b/samples/analyzers/SourceKit.Analyzers.Collections.Samples/ListForEachNotAllowed/ListForEachStatementComplexExample.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; -namespace SourceKit.Sample.Analyzers.ListForEachNotAllowed; +namespace SourceKit.Analyzers.Collections.Samples.ListForEachNotAllowed; public class ListForEachStatementComplexExample { diff --git a/SourceKit.Sample/Analyzers/ListForEachNotAllowed/ListForEachStatementWithLambdaBlockExample.cs b/samples/analyzers/SourceKit.Analyzers.Collections.Samples/ListForEachNotAllowed/ListForEachStatementWithLambdaBlockExample.cs similarity index 82% rename from SourceKit.Sample/Analyzers/ListForEachNotAllowed/ListForEachStatementWithLambdaBlockExample.cs rename to samples/analyzers/SourceKit.Analyzers.Collections.Samples/ListForEachNotAllowed/ListForEachStatementWithLambdaBlockExample.cs index a501915..c30c1a9 100644 --- a/SourceKit.Sample/Analyzers/ListForEachNotAllowed/ListForEachStatementWithLambdaBlockExample.cs +++ b/samples/analyzers/SourceKit.Analyzers.Collections.Samples/ListForEachNotAllowed/ListForEachStatementWithLambdaBlockExample.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; -namespace SourceKit.Sample.Analyzers.ListForEachNotAllowed; +namespace SourceKit.Analyzers.Collections.Samples.ListForEachNotAllowed; public class ListForEachStatementWithLambdaBlockExample { diff --git a/SourceKit.Sample/Analyzers/ListForEachNotAllowed/ListForEachStatementWithLambdaExpressionExample.cs b/samples/analyzers/SourceKit.Analyzers.Collections.Samples/ListForEachNotAllowed/ListForEachStatementWithLambdaExpressionExample.cs similarity index 81% rename from SourceKit.Sample/Analyzers/ListForEachNotAllowed/ListForEachStatementWithLambdaExpressionExample.cs rename to samples/analyzers/SourceKit.Analyzers.Collections.Samples/ListForEachNotAllowed/ListForEachStatementWithLambdaExpressionExample.cs index 1e6dbce..37ff1a5 100644 --- a/SourceKit.Sample/Analyzers/ListForEachNotAllowed/ListForEachStatementWithLambdaExpressionExample.cs +++ b/samples/analyzers/SourceKit.Analyzers.Collections.Samples/ListForEachNotAllowed/ListForEachStatementWithLambdaExpressionExample.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace SourceKit.Sample.Analyzers.ListForEachNotAllowed; +namespace SourceKit.Analyzers.Collections.Samples.ListForEachNotAllowed; public class ListForEachStatementWithLambdaExpressionExample { diff --git a/SourceKit.Sample/Analyzers/ListForEachNotAllowed/ListForEachStatementWithMemberAccessExpressionExample.cs b/samples/analyzers/SourceKit.Analyzers.Collections.Samples/ListForEachNotAllowed/ListForEachStatementWithMemberAccessExpressionExample.cs similarity index 77% rename from SourceKit.Sample/Analyzers/ListForEachNotAllowed/ListForEachStatementWithMemberAccessExpressionExample.cs rename to samples/analyzers/SourceKit.Analyzers.Collections.Samples/ListForEachNotAllowed/ListForEachStatementWithMemberAccessExpressionExample.cs index e1553ee..778441c 100644 --- a/SourceKit.Sample/Analyzers/ListForEachNotAllowed/ListForEachStatementWithMemberAccessExpressionExample.cs +++ b/samples/analyzers/SourceKit.Analyzers.Collections.Samples/ListForEachNotAllowed/ListForEachStatementWithMemberAccessExpressionExample.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; -namespace SourceKit.Sample.Analyzers.ListForEachNotAllowed; +namespace SourceKit.Analyzers.Collections.Samples.ListForEachNotAllowed; public class ListForEachStatementWithMemberAccessExpressionExample { diff --git a/SourceKit.Sample/Analyzers/ListForEachNotAllowed/ListForEachStatementWithMethodLinkExample.cs b/samples/analyzers/SourceKit.Analyzers.Collections.Samples/ListForEachNotAllowed/ListForEachStatementWithMethodLinkExample.cs similarity index 83% rename from SourceKit.Sample/Analyzers/ListForEachNotAllowed/ListForEachStatementWithMethodLinkExample.cs rename to samples/analyzers/SourceKit.Analyzers.Collections.Samples/ListForEachNotAllowed/ListForEachStatementWithMethodLinkExample.cs index 39d7869..250bc76 100644 --- a/SourceKit.Sample/Analyzers/ListForEachNotAllowed/ListForEachStatementWithMethodLinkExample.cs +++ b/samples/analyzers/SourceKit.Analyzers.Collections.Samples/ListForEachNotAllowed/ListForEachStatementWithMethodLinkExample.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace SourceKit.Sample.Analyzers.ListForEachNotAllowed; +namespace SourceKit.Analyzers.Collections.Samples.ListForEachNotAllowed; public class ListForEachStatementWithMethodLinkExample { diff --git a/SourceKit.Sample/Analyzers/ListForEachNotAllowed/NoListForEachStatementExample.cs b/samples/analyzers/SourceKit.Analyzers.Collections.Samples/ListForEachNotAllowed/NoListForEachStatementExample.cs similarity index 79% rename from SourceKit.Sample/Analyzers/ListForEachNotAllowed/NoListForEachStatementExample.cs rename to samples/analyzers/SourceKit.Analyzers.Collections.Samples/ListForEachNotAllowed/NoListForEachStatementExample.cs index 2911647..cfcbb5b 100644 --- a/SourceKit.Sample/Analyzers/ListForEachNotAllowed/NoListForEachStatementExample.cs +++ b/samples/analyzers/SourceKit.Analyzers.Collections.Samples/ListForEachNotAllowed/NoListForEachStatementExample.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; -namespace SourceKit.Sample.Analyzers.ListForEachNotAllowed; +namespace SourceKit.Analyzers.Collections.Samples.ListForEachNotAllowed; public class NoListForEachStatementExample { diff --git a/samples/analyzers/SourceKit.Analyzers.Collections.Samples/SourceKit.Analyzers.Collections.Samples.csproj b/samples/analyzers/SourceKit.Analyzers.Collections.Samples/SourceKit.Analyzers.Collections.Samples.csproj new file mode 100644 index 0000000..5feed50 --- /dev/null +++ b/samples/analyzers/SourceKit.Analyzers.Collections.Samples/SourceKit.Analyzers.Collections.Samples.csproj @@ -0,0 +1,11 @@ + + + + disable + + + + + + + diff --git a/samples/analyzers/SourceKit.Analyzers.Enumerable.Samples/.editorconfig b/samples/analyzers/SourceKit.Analyzers.Enumerable.Samples/.editorconfig new file mode 100644 index 0000000..007327b --- /dev/null +++ b/samples/analyzers/SourceKit.Analyzers.Enumerable.Samples/.editorconfig @@ -0,0 +1,6 @@ +[*.cs] + +dotnet_diagnostic.CA2021.severity = none + +dotnet_diagnostic.SK1300.severity = suggestion +dotnet_diagnostic.SK1301.severity = suggestion \ No newline at end of file diff --git a/SourceKit.Sample/Analyzers/CannotLinqChainAfterTerminalOperation/CodeFixerTestCases.cs b/samples/analyzers/SourceKit.Analyzers.Enumerable.Samples/DoNotEnumerateCollectionsInLinqChain/CodeFixerTestCases.cs similarity index 60% rename from SourceKit.Sample/Analyzers/CannotLinqChainAfterTerminalOperation/CodeFixerTestCases.cs rename to samples/analyzers/SourceKit.Analyzers.Enumerable.Samples/DoNotEnumerateCollectionsInLinqChain/CodeFixerTestCases.cs index 7696acd..6b4f764 100644 --- a/SourceKit.Sample/Analyzers/CannotLinqChainAfterTerminalOperation/CodeFixerTestCases.cs +++ b/samples/analyzers/SourceKit.Analyzers.Enumerable.Samples/DoNotEnumerateCollectionsInLinqChain/CodeFixerTestCases.cs @@ -5,14 +5,20 @@ class CodeFixerTestCases { private class Comparer : IEqualityComparer { - bool IEqualityComparer.Equals(T x, T y) + bool IEqualityComparer.Equals(T? x, T? y) { - return x.Equals(y); + return (x, y) switch + { + (null, null) => true, + (null, not null) => false, + (not null, null) => false, + var (l, r) => l.Equals(r), + }; } - int IEqualityComparer.GetHashCode(T obj) + int IEqualityComparer.GetHashCode(T? obj) { - return obj.GetHashCode(); + return obj?.GetHashCode() ?? 0; } } static void Test(string[] args) diff --git a/SourceKit.Sample/Analyzers/Enumerable/OfTypeSample.cs b/samples/analyzers/SourceKit.Analyzers.Enumerable.Samples/OfTypeMustUseDerivedType/OfTypeSample.cs similarity index 100% rename from SourceKit.Sample/Analyzers/Enumerable/OfTypeSample.cs rename to samples/analyzers/SourceKit.Analyzers.Enumerable.Samples/OfTypeMustUseDerivedType/OfTypeSample.cs diff --git a/samples/analyzers/SourceKit.Analyzers.Enumerable.Samples/SourceKit.Analyzers.Enumerable.Samples.csproj b/samples/analyzers/SourceKit.Analyzers.Enumerable.Samples/SourceKit.Analyzers.Enumerable.Samples.csproj new file mode 100644 index 0000000..492a8bf --- /dev/null +++ b/samples/analyzers/SourceKit.Analyzers.Enumerable.Samples/SourceKit.Analyzers.Enumerable.Samples.csproj @@ -0,0 +1,11 @@ + + + + disable + + + + + + + diff --git a/samples/analyzers/SourceKit.Analyzers.MustBePartial.Samples/.editorconfig b/samples/analyzers/SourceKit.Analyzers.MustBePartial.Samples/.editorconfig new file mode 100644 index 0000000..2dd0746 --- /dev/null +++ b/samples/analyzers/SourceKit.Analyzers.MustBePartial.Samples/.editorconfig @@ -0,0 +1,3 @@ +[*.cs] + +dotnet_diagnostic.SK1000.severity = suggestion \ No newline at end of file diff --git a/SourceKit.Sample/Analyzers/MustBePartial/IPartialBase.cs b/samples/analyzers/SourceKit.Analyzers.MustBePartial.Samples/IPartialBase.cs similarity index 68% rename from SourceKit.Sample/Analyzers/MustBePartial/IPartialBase.cs rename to samples/analyzers/SourceKit.Analyzers.MustBePartial.Samples/IPartialBase.cs index 377916e..e954b69 100644 --- a/SourceKit.Sample/Analyzers/MustBePartial/IPartialBase.cs +++ b/samples/analyzers/SourceKit.Analyzers.MustBePartial.Samples/IPartialBase.cs @@ -1,6 +1,6 @@ using SourceKit.Analyzers.MustBePartial.Annotations; -namespace SourceKit.Sample.Analyzers.MustBePartial; +namespace SourceKit.Analyzers.MustBePartial.Samples; [DerivativesMustBePartial] public interface IPartialBase { } \ No newline at end of file diff --git a/samples/analyzers/SourceKit.Analyzers.MustBePartial.Samples/NonPartialDerivative.cs b/samples/analyzers/SourceKit.Analyzers.MustBePartial.Samples/NonPartialDerivative.cs new file mode 100644 index 0000000..02755c5 --- /dev/null +++ b/samples/analyzers/SourceKit.Analyzers.MustBePartial.Samples/NonPartialDerivative.cs @@ -0,0 +1,3 @@ +namespace SourceKit.Analyzers.MustBePartial.Samples; + +public class NonPartialDerivative : IPartialBase { } \ No newline at end of file diff --git a/SourceKit.Sample/Analyzers/MustBePartial/PartialDerivative.cs b/samples/analyzers/SourceKit.Analyzers.MustBePartial.Samples/PartialDerivative.cs similarity index 54% rename from SourceKit.Sample/Analyzers/MustBePartial/PartialDerivative.cs rename to samples/analyzers/SourceKit.Analyzers.MustBePartial.Samples/PartialDerivative.cs index d907656..c92cf6f 100644 --- a/SourceKit.Sample/Analyzers/MustBePartial/PartialDerivative.cs +++ b/samples/analyzers/SourceKit.Analyzers.MustBePartial.Samples/PartialDerivative.cs @@ -1,4 +1,4 @@ -namespace SourceKit.Sample.Analyzers.MustBePartial; +namespace SourceKit.Analyzers.MustBePartial.Samples; public partial class PartialDerivative : IPartialBase { diff --git a/samples/analyzers/SourceKit.Analyzers.MustBePartial.Samples/SourceKit.Analyzers.MustBePartial.Samples.csproj b/samples/analyzers/SourceKit.Analyzers.MustBePartial.Samples/SourceKit.Analyzers.MustBePartial.Samples.csproj new file mode 100644 index 0000000..314d55f --- /dev/null +++ b/samples/analyzers/SourceKit.Analyzers.MustBePartial.Samples/SourceKit.Analyzers.MustBePartial.Samples.csproj @@ -0,0 +1,11 @@ + + + + disable + + + + + + + diff --git a/samples/analyzers/SourceKit.Analyzers.Nullable.Samples/.editorconfig b/samples/analyzers/SourceKit.Analyzers.Nullable.Samples/.editorconfig new file mode 100644 index 0000000..4607575 --- /dev/null +++ b/samples/analyzers/SourceKit.Analyzers.Nullable.Samples/.editorconfig @@ -0,0 +1,4 @@ +[*.cs] + +dotnet_diagnostic.SK1200.severity = suggestion +dotnet_diagnostic.SK1201.severity = suggestion \ No newline at end of file diff --git a/SourceKit.Sample/Analyzers/NullForgivingOperatorNotAllowed/JokeExample.cs b/samples/analyzers/SourceKit.Analyzers.Nullable.Samples/NullForgivingOperatorNotAllowed/JokeExample.cs similarity index 100% rename from SourceKit.Sample/Analyzers/NullForgivingOperatorNotAllowed/JokeExample.cs rename to samples/analyzers/SourceKit.Analyzers.Nullable.Samples/NullForgivingOperatorNotAllowed/JokeExample.cs diff --git a/SourceKit.Sample/Analyzers/Nullable/MultipleNestedNullableDisable.cs b/samples/analyzers/SourceKit.Analyzers.Nullable.Samples/NullableDisableNotAllowed/MultipleNestedNullableDisable.cs similarity index 86% rename from SourceKit.Sample/Analyzers/Nullable/MultipleNestedNullableDisable.cs rename to samples/analyzers/SourceKit.Analyzers.Nullable.Samples/NullableDisableNotAllowed/MultipleNestedNullableDisable.cs index 77900b4..8658ec7 100644 --- a/SourceKit.Sample/Analyzers/Nullable/MultipleNestedNullableDisable.cs +++ b/samples/analyzers/SourceKit.Analyzers.Nullable.Samples/NullableDisableNotAllowed/MultipleNestedNullableDisable.cs @@ -1,7 +1,7 @@ #nullable disable using System; -namespace SourceKit.Sample.Analyzers.Nullable +namespace SourceKit.Analyzers.Nullable.Samples.NullableDisableNotAllowed { public class MultipleNestedNullableDisable { diff --git a/samples/analyzers/SourceKit.Analyzers.Nullable.Samples/NullableDisableNotAllowed/NullableDisable.cs b/samples/analyzers/SourceKit.Analyzers.Nullable.Samples/NullableDisableNotAllowed/NullableDisable.cs new file mode 100644 index 0000000..8ae90a4 --- /dev/null +++ b/samples/analyzers/SourceKit.Analyzers.Nullable.Samples/NullableDisableNotAllowed/NullableDisable.cs @@ -0,0 +1,8 @@ +#nullable disable + +namespace SourceKit.Analyzers.Nullable.Samples.NullableDisableNotAllowed; + +public class NullableDisable +{ + +} \ No newline at end of file diff --git a/samples/analyzers/SourceKit.Analyzers.Nullable.Samples/NullableDisableNotAllowed/NullableEnable.cs b/samples/analyzers/SourceKit.Analyzers.Nullable.Samples/NullableDisableNotAllowed/NullableEnable.cs new file mode 100644 index 0000000..c2d9083 --- /dev/null +++ b/samples/analyzers/SourceKit.Analyzers.Nullable.Samples/NullableDisableNotAllowed/NullableEnable.cs @@ -0,0 +1,8 @@ +#nullable enable + +namespace SourceKit.Analyzers.Nullable.Samples.NullableDisableNotAllowed; + +public class NullableEnable +{ + +} \ No newline at end of file diff --git a/SourceKit.Sample/CodeFixProviders/PropagateNullCorrectly/JokeExampleWithFieldAndProperties.cs b/samples/analyzers/SourceKit.Analyzers.Nullable.Samples/PropagateNullCorrectly/JokeExampleWithFieldAndProperties.cs similarity index 92% rename from SourceKit.Sample/CodeFixProviders/PropagateNullCorrectly/JokeExampleWithFieldAndProperties.cs rename to samples/analyzers/SourceKit.Analyzers.Nullable.Samples/PropagateNullCorrectly/JokeExampleWithFieldAndProperties.cs index e919dc1..efd4a40 100644 --- a/SourceKit.Sample/CodeFixProviders/PropagateNullCorrectly/JokeExampleWithFieldAndProperties.cs +++ b/samples/analyzers/SourceKit.Analyzers.Nullable.Samples/PropagateNullCorrectly/JokeExampleWithFieldAndProperties.cs @@ -1,4 +1,4 @@ -namespace SourceKit.Sample.CodeFixProviders; +namespace SourceKit.Analyzers.Nullable.Samples.PropagateNullCorrectly; public class JokeExampleWithFieldAndProperties { @@ -18,7 +18,7 @@ public string SecondJoke } public string ThirdJoke => _jokeInstance.GetJoke(3)!; - + public string? GetJoke(int number) { switch (number) diff --git a/SourceKit.Sample/CodeFixProviders/PropagateNullCorrectly/JokeExampleWithVariableDeclarations.cs b/samples/analyzers/SourceKit.Analyzers.Nullable.Samples/PropagateNullCorrectly/JokeExampleWithVariableDeclarations.cs similarity index 95% rename from SourceKit.Sample/CodeFixProviders/PropagateNullCorrectly/JokeExampleWithVariableDeclarations.cs rename to samples/analyzers/SourceKit.Analyzers.Nullable.Samples/PropagateNullCorrectly/JokeExampleWithVariableDeclarations.cs index de78205..42167be 100644 --- a/SourceKit.Sample/CodeFixProviders/PropagateNullCorrectly/JokeExampleWithVariableDeclarations.cs +++ b/samples/analyzers/SourceKit.Analyzers.Nullable.Samples/PropagateNullCorrectly/JokeExampleWithVariableDeclarations.cs @@ -1,4 +1,4 @@ -namespace SourceKit.Sample.CodeFixProviders; +namespace SourceKit.Analyzers.Nullable.Samples.PropagateNullCorrectly; public class JokeExampleWithVariableDeclarations { diff --git a/samples/analyzers/SourceKit.Analyzers.Nullable.Samples/SourceKit.Analyzers.Nullable.Samples.csproj b/samples/analyzers/SourceKit.Analyzers.Nullable.Samples/SourceKit.Analyzers.Nullable.Samples.csproj new file mode 100644 index 0000000..fe9d7d5 --- /dev/null +++ b/samples/analyzers/SourceKit.Analyzers.Nullable.Samples/SourceKit.Analyzers.Nullable.Samples.csproj @@ -0,0 +1,11 @@ + + + + disable + + + + + + + diff --git a/samples/analyzers/SourceKit.Analyzers.Properties.Samples/.editorconfig b/samples/analyzers/SourceKit.Analyzers.Properties.Samples/.editorconfig new file mode 100644 index 0000000..e9a8e2b --- /dev/null +++ b/samples/analyzers/SourceKit.Analyzers.Properties.Samples/.editorconfig @@ -0,0 +1,6 @@ +[*.cs] + +dotnet_diagnostic.SK1400.severity = suggestion +dotnet_diagnostic.CS8618.severity = none +dotnet_diagnostic.CS0649.severity = none +dotnet_diagnostic.CS0169.severity = none \ No newline at end of file diff --git a/SourceKit.Sample/Analyzers/DeclarationCouldBeConvertedToProperty/ExpressionBodyMethodsField.cs b/samples/analyzers/SourceKit.Analyzers.Properties.Samples/DeclarationCouldBeConvertedToProperty/ExpressionBodyMethodsField.cs similarity index 66% rename from SourceKit.Sample/Analyzers/DeclarationCouldBeConvertedToProperty/ExpressionBodyMethodsField.cs rename to samples/analyzers/SourceKit.Analyzers.Properties.Samples/DeclarationCouldBeConvertedToProperty/ExpressionBodyMethodsField.cs index a350c09..77415aa 100644 --- a/SourceKit.Sample/Analyzers/DeclarationCouldBeConvertedToProperty/ExpressionBodyMethodsField.cs +++ b/samples/analyzers/SourceKit.Analyzers.Properties.Samples/DeclarationCouldBeConvertedToProperty/ExpressionBodyMethodsField.cs @@ -1,4 +1,4 @@ -namespace SourceKit.Sample.Analyzers.DeclarationCouldBeConvertedToProperty; +namespace SourceKit.Analyzers.Properties.Samples.DeclarationCouldBeConvertedToProperty; public class ExpressionBodyMethodsField { diff --git a/SourceKit.Sample/Analyzers/DeclarationCouldBeConvertedToProperty/ManyPublicFields.cs b/samples/analyzers/SourceKit.Analyzers.Properties.Samples/DeclarationCouldBeConvertedToProperty/ManyPublicFields.cs similarity index 55% rename from SourceKit.Sample/Analyzers/DeclarationCouldBeConvertedToProperty/ManyPublicFields.cs rename to samples/analyzers/SourceKit.Analyzers.Properties.Samples/DeclarationCouldBeConvertedToProperty/ManyPublicFields.cs index a10891d..36274ca 100644 --- a/SourceKit.Sample/Analyzers/DeclarationCouldBeConvertedToProperty/ManyPublicFields.cs +++ b/samples/analyzers/SourceKit.Analyzers.Properties.Samples/DeclarationCouldBeConvertedToProperty/ManyPublicFields.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace SourceKit.Sample.Analyzers.DeclarationCouldBeConvertedToProperty; +namespace SourceKit.Analyzers.Properties.Samples.DeclarationCouldBeConvertedToProperty; public class ManyPublicFields { diff --git a/SourceKit.Sample/Analyzers/DeclarationCouldBeConvertedToProperty/OneField.cs b/samples/analyzers/SourceKit.Analyzers.Properties.Samples/DeclarationCouldBeConvertedToProperty/OneField.cs similarity index 68% rename from SourceKit.Sample/Analyzers/DeclarationCouldBeConvertedToProperty/OneField.cs rename to samples/analyzers/SourceKit.Analyzers.Properties.Samples/DeclarationCouldBeConvertedToProperty/OneField.cs index 2d152bf..8a060eb 100644 --- a/SourceKit.Sample/Analyzers/DeclarationCouldBeConvertedToProperty/OneField.cs +++ b/samples/analyzers/SourceKit.Analyzers.Properties.Samples/DeclarationCouldBeConvertedToProperty/OneField.cs @@ -1,4 +1,4 @@ -namespace SourceKit.Sample.Analyzers.DeclarationCouldBeConvertedToProperty; +namespace SourceKit.Analyzers.Properties.Samples.DeclarationCouldBeConvertedToProperty; public class OneField { diff --git a/samples/analyzers/SourceKit.Analyzers.Properties.Samples/DeclarationCouldBeConvertedToProperty/OnePublicField.cs b/samples/analyzers/SourceKit.Analyzers.Properties.Samples/DeclarationCouldBeConvertedToProperty/OnePublicField.cs new file mode 100644 index 0000000..3f8b6df --- /dev/null +++ b/samples/analyzers/SourceKit.Analyzers.Properties.Samples/DeclarationCouldBeConvertedToProperty/OnePublicField.cs @@ -0,0 +1,6 @@ +namespace SourceKit.Analyzers.Properties.Samples.DeclarationCouldBeConvertedToProperty; + +public class OnePublicField +{ + public string field; +} \ No newline at end of file diff --git a/SourceKit.Sample/Analyzers/DeclarationCouldBeConvertedToProperty/PrivateFieldWithoutMethods.cs b/samples/analyzers/SourceKit.Analyzers.Properties.Samples/DeclarationCouldBeConvertedToProperty/PrivateFieldWithoutMethods.cs similarity index 59% rename from SourceKit.Sample/Analyzers/DeclarationCouldBeConvertedToProperty/PrivateFieldWithoutMethods.cs rename to samples/analyzers/SourceKit.Analyzers.Properties.Samples/DeclarationCouldBeConvertedToProperty/PrivateFieldWithoutMethods.cs index d18fc96..976d85f 100644 --- a/SourceKit.Sample/Analyzers/DeclarationCouldBeConvertedToProperty/PrivateFieldWithoutMethods.cs +++ b/samples/analyzers/SourceKit.Analyzers.Properties.Samples/DeclarationCouldBeConvertedToProperty/PrivateFieldWithoutMethods.cs @@ -1,4 +1,4 @@ -namespace SourceKit.Sample.Analyzers.DeclarationCouldBeConvertedToProperty; +namespace SourceKit.Analyzers.Properties.Samples.DeclarationCouldBeConvertedToProperty; public class PrivateFieldWithoutMethods { diff --git a/samples/analyzers/SourceKit.Analyzers.Properties.Samples/DeclarationCouldBeConvertedToProperty/PublicProperty.cs b/samples/analyzers/SourceKit.Analyzers.Properties.Samples/DeclarationCouldBeConvertedToProperty/PublicProperty.cs new file mode 100644 index 0000000..486cad5 --- /dev/null +++ b/samples/analyzers/SourceKit.Analyzers.Properties.Samples/DeclarationCouldBeConvertedToProperty/PublicProperty.cs @@ -0,0 +1,6 @@ +namespace SourceKit.Analyzers.Properties.Samples.DeclarationCouldBeConvertedToProperty; + +public class PublicProperty +{ + public string Field { get; set; } +} \ No newline at end of file diff --git a/samples/analyzers/SourceKit.Analyzers.Properties.Samples/DeclarationCouldBeConvertedToProperty/ReadonlyPublicField.cs b/samples/analyzers/SourceKit.Analyzers.Properties.Samples/DeclarationCouldBeConvertedToProperty/ReadonlyPublicField.cs new file mode 100644 index 0000000..acdb2aa --- /dev/null +++ b/samples/analyzers/SourceKit.Analyzers.Properties.Samples/DeclarationCouldBeConvertedToProperty/ReadonlyPublicField.cs @@ -0,0 +1,6 @@ +namespace SourceKit.Analyzers.Properties.Samples.DeclarationCouldBeConvertedToProperty; + +public class ReadonlyPublicField +{ + public readonly string field; +} \ No newline at end of file diff --git a/SourceKit.Sample/Analyzers/DeclarationCouldBeConvertedToProperty/UnderscoreNameField.cs b/samples/analyzers/SourceKit.Analyzers.Properties.Samples/DeclarationCouldBeConvertedToProperty/UnderscoreNameField.cs similarity index 60% rename from SourceKit.Sample/Analyzers/DeclarationCouldBeConvertedToProperty/UnderscoreNameField.cs rename to samples/analyzers/SourceKit.Analyzers.Properties.Samples/DeclarationCouldBeConvertedToProperty/UnderscoreNameField.cs index e50a737..19e7615 100644 --- a/SourceKit.Sample/Analyzers/DeclarationCouldBeConvertedToProperty/UnderscoreNameField.cs +++ b/samples/analyzers/SourceKit.Analyzers.Properties.Samples/DeclarationCouldBeConvertedToProperty/UnderscoreNameField.cs @@ -1,4 +1,4 @@ -namespace SourceKit.Sample.Analyzers.DeclarationCouldBeConvertedToProperty; +namespace SourceKit.Analyzers.Properties.Samples.DeclarationCouldBeConvertedToProperty; public class UnderscoreNameField { diff --git a/samples/analyzers/SourceKit.Analyzers.Properties.Samples/SourceKit.Analyzers.Properties.Samples.csproj b/samples/analyzers/SourceKit.Analyzers.Properties.Samples/SourceKit.Analyzers.Properties.Samples.csproj new file mode 100644 index 0000000..111b34f --- /dev/null +++ b/samples/analyzers/SourceKit.Analyzers.Properties.Samples/SourceKit.Analyzers.Properties.Samples.csproj @@ -0,0 +1,11 @@ + + + + disable + + + + + + + diff --git a/samples/generators/SourceKit.Generators.Builder.Samples/.editorconfig b/samples/generators/SourceKit.Generators.Builder.Samples/.editorconfig new file mode 100644 index 0000000..f6b912e --- /dev/null +++ b/samples/generators/SourceKit.Generators.Builder.Samples/.editorconfig @@ -0,0 +1,5 @@ +[*.cs] + + +dotnet_diagnostic.SK2100.severity = suggestion + diff --git a/SourceKit.Sample/Generators/ArrayQuery.cs b/samples/generators/SourceKit.Generators.Builder.Samples/ArrayQuery.cs similarity index 72% rename from SourceKit.Sample/Generators/ArrayQuery.cs rename to samples/generators/SourceKit.Generators.Builder.Samples/ArrayQuery.cs index ab701b0..9a866c5 100644 --- a/SourceKit.Sample/Generators/ArrayQuery.cs +++ b/samples/generators/SourceKit.Generators.Builder.Samples/ArrayQuery.cs @@ -1,7 +1,7 @@ using System; using SourceKit.Generators.Builder.Annotations; -namespace SourceKit.Sample.Generators; +namespace SourceKit.Generators.Builder.Samples; [GenerateBuilder] public partial record ArrayQuery(Guid[] Ids); \ No newline at end of file diff --git a/SourceKit.Sample/Generators/CustomModelQuery.cs b/samples/generators/SourceKit.Generators.Builder.Samples/CustomModelQuery.cs similarity index 55% rename from SourceKit.Sample/Generators/CustomModelQuery.cs rename to samples/generators/SourceKit.Generators.Builder.Samples/CustomModelQuery.cs index 7cc0e8a..a4c85cd 100644 --- a/SourceKit.Sample/Generators/CustomModelQuery.cs +++ b/samples/generators/SourceKit.Generators.Builder.Samples/CustomModelQuery.cs @@ -1,7 +1,7 @@ using SourceKit.Generators.Builder.Annotations; -using SourceKit.Sample.Models; +using SourceKit.Generators.Builder.Samples.Models; -namespace SourceKit.Sample.Generators; +namespace SourceKit.Generators.Builder.Samples; [GenerateBuilder] public partial record CustomModelQuery(Point[] Point); \ No newline at end of file diff --git a/samples/generators/SourceKit.Generators.Builder.Samples/Models/Point.cs b/samples/generators/SourceKit.Generators.Builder.Samples/Models/Point.cs new file mode 100644 index 0000000..d372ecc --- /dev/null +++ b/samples/generators/SourceKit.Generators.Builder.Samples/Models/Point.cs @@ -0,0 +1,3 @@ +namespace SourceKit.Generators.Builder.Samples.Models; + +public record struct Point(int X, int Y); \ No newline at end of file diff --git a/samples/generators/SourceKit.Generators.Builder.Samples/Program.cs b/samples/generators/SourceKit.Generators.Builder.Samples/Program.cs new file mode 100644 index 0000000..71e7a3a --- /dev/null +++ b/samples/generators/SourceKit.Generators.Builder.Samples/Program.cs @@ -0,0 +1,5 @@ +// See https://aka.ms/new-console-template for more information + +using System; + +Console.WriteLine("Hello, World!"); \ No newline at end of file diff --git a/samples/generators/SourceKit.Generators.Builder.Samples/RequiredValue/InitializedRequiredValueSample.cs b/samples/generators/SourceKit.Generators.Builder.Samples/RequiredValue/InitializedRequiredValueSample.cs new file mode 100644 index 0000000..c8326bd --- /dev/null +++ b/samples/generators/SourceKit.Generators.Builder.Samples/RequiredValue/InitializedRequiredValueSample.cs @@ -0,0 +1,18 @@ +using System; +using SourceKit.Generators.Builder.Annotations; + +namespace SourceKit.Sample.Generators; + +public class InitializedRequiredValueSample +{ + public void A() + { + var query = InitializedRequiredValueSampleQuery.Build(x => x.WithValue("aboba")); + } +} + +[GenerateBuilder] +public partial record InitializedRequiredValueSampleQuery( + Guid[] Ids, + [RequiredValue] string Value, + string NotRequiredValue = "aboba"); \ No newline at end of file diff --git a/samples/generators/SourceKit.Generators.Builder.Samples/RequiredValue/UninitializedRequiredValueSample.cs b/samples/generators/SourceKit.Generators.Builder.Samples/RequiredValue/UninitializedRequiredValueSample.cs new file mode 100644 index 0000000..b37330d --- /dev/null +++ b/samples/generators/SourceKit.Generators.Builder.Samples/RequiredValue/UninitializedRequiredValueSample.cs @@ -0,0 +1,18 @@ +using System; +using SourceKit.Generators.Builder.Annotations; + +namespace SourceKit.Sample.Generators; + +public class UninitializedRequiredValueSample +{ + public void A() + { + var query = UninitializedRequiredValueSampleQuery.Build(x => x.WithId(Guid.NewGuid())); + } +} + +[GenerateBuilder] +public partial record UninitializedRequiredValueSampleQuery( + Guid[] Ids, + [RequiredValue] string Value, + string NotRequiredValue = "aboba"); \ No newline at end of file diff --git a/samples/generators/SourceKit.Generators.Builder.Samples/RequiredValueFromParameterComponent.cs b/samples/generators/SourceKit.Generators.Builder.Samples/RequiredValueFromParameterComponent.cs new file mode 100644 index 0000000..f1e0d7e --- /dev/null +++ b/samples/generators/SourceKit.Generators.Builder.Samples/RequiredValueFromParameterComponent.cs @@ -0,0 +1,14 @@ +using SourceKit.Generators.Builder.Annotations; + +namespace SourceKit.Generators.Builder.Samples; + +public class RequiredValueFromParameterComponent +{ + public static Query Create(Query query) + { + return Query.Build(builder => builder.WithPageSize(query.PageSize)); + } +} + +[GenerateBuilder] +public partial record Query([RequiredValue] int PageSize); \ No newline at end of file diff --git a/SourceKit.Sample/Generators/SomeQuery.cs b/samples/generators/SourceKit.Generators.Builder.Samples/SomeQuery.cs similarity index 84% rename from SourceKit.Sample/Generators/SomeQuery.cs rename to samples/generators/SourceKit.Generators.Builder.Samples/SomeQuery.cs index ba89b10..eafc5e3 100644 --- a/SourceKit.Sample/Generators/SomeQuery.cs +++ b/samples/generators/SourceKit.Generators.Builder.Samples/SomeQuery.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using SourceKit.Generators.Builder.Annotations; -namespace SourceKit.Sample.Generators; +namespace SourceKit.Generators.Builder.Samples; [GenerateBuilder] public partial record SomeQuery(IReadOnlyCollection Ids, int Count, int? OrderById) diff --git a/samples/generators/SourceKit.Generators.Builder.Samples/SourceKit.Generators.Builder.Samples.csproj b/samples/generators/SourceKit.Generators.Builder.Samples/SourceKit.Generators.Builder.Samples.csproj new file mode 100644 index 0000000..dab2048 --- /dev/null +++ b/samples/generators/SourceKit.Generators.Builder.Samples/SourceKit.Generators.Builder.Samples.csproj @@ -0,0 +1,12 @@ + + + + Exe + disable + + + + + + + diff --git a/samples/SourceKit.Generators.Grpc.Samples/Program.cs b/samples/generators/SourceKit.Generators.Grpc.Samples/Program.cs similarity index 83% rename from samples/SourceKit.Generators.Grpc.Samples/Program.cs rename to samples/generators/SourceKit.Generators.Grpc.Samples/Program.cs index 03962a4..89b88cc 100644 --- a/samples/SourceKit.Generators.Grpc.Samples/Program.cs +++ b/samples/generators/SourceKit.Generators.Grpc.Samples/Program.cs @@ -1,4 +1,6 @@ -using Playground; +using System; +using System.Collections.Generic; +using Playground; Console.WriteLine("Hello, World!"); diff --git a/samples/SourceKit.Generators.Grpc.Samples/SourceKit.Generators.Grpc.Samples.csproj b/samples/generators/SourceKit.Generators.Grpc.Samples/SourceKit.Generators.Grpc.Samples.csproj similarity index 55% rename from samples/SourceKit.Generators.Grpc.Samples/SourceKit.Generators.Grpc.Samples.csproj rename to samples/generators/SourceKit.Generators.Grpc.Samples/SourceKit.Generators.Grpc.Samples.csproj index 87e6e5f..472af13 100644 --- a/samples/SourceKit.Generators.Grpc.Samples/SourceKit.Generators.Grpc.Samples.csproj +++ b/samples/generators/SourceKit.Generators.Grpc.Samples/SourceKit.Generators.Grpc.Samples.csproj @@ -2,19 +2,9 @@ Exe - net7.0 - enable - enable + disable - - - - - - - - @@ -22,6 +12,7 @@ + diff --git a/samples/SourceKit.Generators.Grpc.Samples/protos/model.proto b/samples/generators/SourceKit.Generators.Grpc.Samples/protos/model.proto similarity index 100% rename from samples/SourceKit.Generators.Grpc.Samples/protos/model.proto rename to samples/generators/SourceKit.Generators.Grpc.Samples/protos/model.proto diff --git a/src/SourceKit.Reflect/SourceKit.Reflect.csproj b/src/SourceKit.Reflect/SourceKit.Reflect.csproj index 8f5f0f1..1b529f1 100644 --- a/src/SourceKit.Reflect/SourceKit.Reflect.csproj +++ b/src/SourceKit.Reflect/SourceKit.Reflect.csproj @@ -10,6 +10,7 @@ true false + false diff --git a/src/SourceKit/Extensions/NamedTypeSymbolExtensions.cs b/src/SourceKit/Extensions/NamedTypeSymbolExtensions.cs index aca9a99..e821578 100644 --- a/src/SourceKit/Extensions/NamedTypeSymbolExtensions.cs +++ b/src/SourceKit/Extensions/NamedTypeSymbolExtensions.cs @@ -107,7 +107,7 @@ public static TypeDeclarationSyntax ToSyntax(this INamedTypeSymbol symbol) TypeKind.Interface => InterfaceDeclaration(symbol.Name), - _ => throw new ArgumentOutOfRangeException() + _ => throw new ArgumentOutOfRangeException(), }; } } \ No newline at end of file diff --git a/src/SourceKit/Extensions/SyntaxTokenListExtensions.cs b/src/SourceKit/Extensions/SyntaxTokenListExtensions.cs index baeadf8..cfa3caa 100644 --- a/src/SourceKit/Extensions/SyntaxTokenListExtensions.cs +++ b/src/SourceKit/Extensions/SyntaxTokenListExtensions.cs @@ -14,7 +14,7 @@ public static Accessibility ToAccessibility(this SyntaxTokenList syntaxTokenList [SyntaxKind.ProtectedKeyword] => Accessibility.Protected, [SyntaxKind.InternalKeyword] => Accessibility.Internal, [SyntaxKind.PublicKeyword] => Accessibility.Public, - _ => Accessibility.NotApplicable + _ => Accessibility.NotApplicable, }; } } \ No newline at end of file diff --git a/src/SourceKit/Extensions/TypeSymbolExtensions.cs b/src/SourceKit/Extensions/TypeSymbolExtensions.cs index 62356d8..8f993f7 100644 --- a/src/SourceKit/Extensions/TypeSymbolExtensions.cs +++ b/src/SourceKit/Extensions/TypeSymbolExtensions.cs @@ -14,9 +14,9 @@ public static IdentifierNameSyntax ToTypeArgumentSyntax(this ITypeSymbol symbol) public static bool IsAssignableTo(this ITypeSymbol source, ITypeSymbol destination) { - return Equals(source, destination) - || source is INamedTypeSymbol namedSource - && namedSource.GetBaseTypesAndInterfaces().Contains(destination, SymbolEqualityComparer.Default); + return source.Equals(destination, SymbolEqualityComparer.IncludeNullability) + || source is INamedTypeSymbol namedSource + && namedSource.GetBaseTypesAndInterfaces().Contains(destination, SymbolEqualityComparer.Default); } public static bool IsAssignableFrom(this ITypeSymbol destination, INamedTypeSymbol source) @@ -31,10 +31,10 @@ public static bool IsAssignableFrom(this ITypeSymbol destination, INamedTypeSymb var symbols = type.FindAssignableTypesConstructedFrom(baseType); return symbols - .FirstOrDefault(current => + .FirstOrDefault(current => current.ConstructedFrom.Equals(baseType, SymbolEqualityComparer.Default)); } - + public static IEnumerable FindAssignableTypesConstructedFrom( this ITypeSymbol type, INamedTypeSymbol baseType) @@ -45,7 +45,7 @@ public static IEnumerable FindAssignableTypesConstructedFrom( IEnumerable baseTypes = namedTypeSymbol.GetBaseTypesAndInterfaces(); return baseTypes - .Where(current => + .Where(current => current.ConstructedFrom.Equals(baseType, SymbolEqualityComparer.Default)); } diff --git a/src/SourceKit/SourceKit.csproj b/src/SourceKit/SourceKit.csproj index 4139043..ce2e2d9 100644 --- a/src/SourceKit/SourceKit.csproj +++ b/src/SourceKit/SourceKit.csproj @@ -2,14 +2,12 @@ netstandard2.0 - enable - enable - 11 true false + true @@ -37,18 +35,15 @@ - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - + + + + - + + \ No newline at end of file diff --git a/src/analyzers/SourceKit.Analyzers.Collections/AnalyzerReleases.Shipped.md b/src/analyzers/SourceKit.Analyzers.Collections/AnalyzerReleases.Shipped.md new file mode 100644 index 0000000..9c7869c --- /dev/null +++ b/src/analyzers/SourceKit.Analyzers.Collections/AnalyzerReleases.Shipped.md @@ -0,0 +1,8 @@ +## Release 1.0 + +### New Rules + +Rule ID | Category | Severity | Notes +--------|----------|----------|-------------------- + SK1500 | Design | Error | Type argument for Dictionary's TKey must implement IEquatable + SK1501 | Design | Warning | Using ForEach method is not allowed \ No newline at end of file diff --git a/src/analyzers/SourceKit.Analyzers.Collections/AnalyzerReleases.Unshipped.md b/src/analyzers/SourceKit.Analyzers.Collections/AnalyzerReleases.Unshipped.md new file mode 100644 index 0000000..321e94d --- /dev/null +++ b/src/analyzers/SourceKit.Analyzers.Collections/AnalyzerReleases.Unshipped.md @@ -0,0 +1,4 @@ +### New Rules + +Rule ID | Category | Severity | Notes +--------|----------|----------|-------------------- \ No newline at end of file diff --git a/src/analyzers/SourceKit.Analyzers.Collections/Properties/launchSettings.json b/src/analyzers/SourceKit.Analyzers.Collections/Properties/launchSettings.json new file mode 100644 index 0000000..f902dac --- /dev/null +++ b/src/analyzers/SourceKit.Analyzers.Collections/Properties/launchSettings.json @@ -0,0 +1,9 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "profiles": { + "Debug": { + "commandName": "DebugRoslynComponent", + "targetProject": "../../../samples/analyzers/SourceKit.Analyzers.Collections.Samples/SourceKit.Analyzers.Collections.Samples.csproj" + } + } +} \ No newline at end of file diff --git a/src/analyzers/SourceKit.Analyzers.Collections/SourceKit.Analyzers.Collections.csproj b/src/analyzers/SourceKit.Analyzers.Collections/SourceKit.Analyzers.Collections.csproj index 954eb42..c7cd118 100644 --- a/src/analyzers/SourceKit.Analyzers.Collections/SourceKit.Analyzers.Collections.csproj +++ b/src/analyzers/SourceKit.Analyzers.Collections/SourceKit.Analyzers.Collections.csproj @@ -2,14 +2,13 @@ netstandard2.0 - 11 - enable - enable + true true false + true @@ -33,7 +32,6 @@ - @@ -48,4 +46,9 @@ + + + + + diff --git a/src/analyzers/SourceKit.Analyzers.Enumerable/AnalyzerReleases.Shipped.md b/src/analyzers/SourceKit.Analyzers.Enumerable/AnalyzerReleases.Shipped.md new file mode 100644 index 0000000..29b537b --- /dev/null +++ b/src/analyzers/SourceKit.Analyzers.Enumerable/AnalyzerReleases.Shipped.md @@ -0,0 +1,8 @@ +## Release 1.0 + +### New Rules + +Rule ID | Category | Severity | Notes +--------|----------|----------|-------------------- + SK1300| Usage | Error | When using LINQ's OfType, the casted type must be derived from base type + SK1301 | Performance | Error | Do not chain LINQ methods after collection materialization \ No newline at end of file diff --git a/src/analyzers/SourceKit.Analyzers.Enumerable/AnalyzerReleases.Unshipped.md b/src/analyzers/SourceKit.Analyzers.Enumerable/AnalyzerReleases.Unshipped.md new file mode 100644 index 0000000..321e94d --- /dev/null +++ b/src/analyzers/SourceKit.Analyzers.Enumerable/AnalyzerReleases.Unshipped.md @@ -0,0 +1,4 @@ +### New Rules + +Rule ID | Category | Severity | Notes +--------|----------|----------|-------------------- \ No newline at end of file diff --git a/src/analyzers/SourceKit.Analyzers.Enumerable/Analyzers/DoNotEnumerateCollectionInLinqChain.cs b/src/analyzers/SourceKit.Analyzers.Enumerable/Analyzers/DoNotEnumerateCollectionInLinqChainAnalyzer.cs similarity index 89% rename from src/analyzers/SourceKit.Analyzers.Enumerable/Analyzers/DoNotEnumerateCollectionInLinqChain.cs rename to src/analyzers/SourceKit.Analyzers.Enumerable/Analyzers/DoNotEnumerateCollectionInLinqChainAnalyzer.cs index 44644d0..6be6f2d 100644 --- a/src/analyzers/SourceKit.Analyzers.Enumerable/Analyzers/DoNotEnumerateCollectionInLinqChain.cs +++ b/src/analyzers/SourceKit.Analyzers.Enumerable/Analyzers/DoNotEnumerateCollectionInLinqChainAnalyzer.cs @@ -8,14 +8,13 @@ namespace SourceKit.Analyzers.Enumerable.Analyzers; [DiagnosticAnalyzer(LanguageNames.CSharp)] -public class DoNotEnumerateCollectionInLinqChain : DiagnosticAnalyzer +public class DoNotEnumerateCollectionInLinqChainAnalyzer : DiagnosticAnalyzer { public const string DiagnosticId = "SK1301"; - public const string Title = nameof(DoNotEnumerateCollectionInLinqChain); + public const string Title = nameof(DoNotEnumerateCollectionInLinqChainAnalyzer); public const string Format = """Cannot chain LINQ methods after terminal operation {0}"""; - private static readonly HashSet TerminationMethods = new() { // ToHashSet is missing in standard 2.0 @@ -32,7 +31,7 @@ public class DoNotEnumerateCollectionInLinqChain : DiagnosticAnalyzer nameof(ImmutableSortedSet.ToImmutableSortedSet), }; - public static readonly DiagnosticDescriptor Descriptor = new( + public static readonly DiagnosticDescriptor Descriptor = new DiagnosticDescriptor( DiagnosticId, Title, Format, @@ -53,7 +52,7 @@ public override void Initialize(AnalysisContext context) private static void RegisterDiagnostic(SyntaxNodeAnalysisContext context) { SemanticModel semanticModel = context.SemanticModel; - + if (context.Node is not InvocationExpressionSyntax node || IsTerminationMethod(node, semanticModel) is false) return; @@ -61,12 +60,17 @@ private static void RegisterDiagnostic(SyntaxNodeAnalysisContext context) .OfType() .Any(expressionSyntax => IsLinqEnumerable(expressionSyntax, semanticModel)); - if (hasLinqAncestor is false) return; + if (hasLinqAncestor is false) + return; ExpressionSyntax terminalOperationExpression = node.Expression; SyntaxToken terminalOperationWithoutParamsToken = terminalOperationExpression.GetLastToken(); - - context.ReportDiagnostic(Diagnostic.Create(Descriptor, terminalOperationWithoutParamsToken.GetLocation(), terminalOperationWithoutParamsToken)); + + context.ReportDiagnostic( + Diagnostic.Create( + Descriptor, + terminalOperationWithoutParamsToken.GetLocation(), + terminalOperationWithoutParamsToken)); } private static bool IsLinqEnumerable(ExpressionSyntax syntax, SemanticModel model) @@ -74,13 +78,13 @@ private static bool IsLinqEnumerable(ExpressionSyntax syntax, SemanticModel mode IMethodSymbol? symbol = GetSymbol(syntax, model); return IsLinqEnumerable(symbol, model); } - + private static bool IsLinqEnumerable(ISymbol? symbol, SemanticModel model) { Type linqEnumerableType = typeof(System.Linq.Enumerable); INamedTypeSymbol linqSymbol = model.Compilation.GetTypeSymbol(linqEnumerableType); var comparer = SymbolEqualityComparer.Default; - + return comparer.Equals(symbol?.ContainingType, linqSymbol); } @@ -88,10 +92,10 @@ private static bool IsTerminationMethod(InvocationExpressionSyntax syntax, Seman { ExpressionSyntax expression = syntax.Expression; SyntaxToken method = expression.GetLastToken(); - + return TerminationMethods.Contains(method.ToString()) && IsLinqEnumerable(syntax, model); } - private static IMethodSymbol? GetSymbol(ExpressionSyntax syntax, SemanticModel model) + private static IMethodSymbol? GetSymbol(ExpressionSyntax syntax, SemanticModel model) => model.GetSymbolInfo(syntax).Symbol as IMethodSymbol; } \ No newline at end of file diff --git a/src/analyzers/SourceKit.Analyzers.Enumerable/CodeFixes/RemoveTerminalOperationCodeFixProvider.cs b/src/analyzers/SourceKit.Analyzers.Enumerable/CodeFixes/RemoveTerminalOperationCodeFixProvider.cs index fe69cdf..29489b5 100644 --- a/src/analyzers/SourceKit.Analyzers.Enumerable/CodeFixes/RemoveTerminalOperationCodeFixProvider.cs +++ b/src/analyzers/SourceKit.Analyzers.Enumerable/CodeFixes/RemoveTerminalOperationCodeFixProvider.cs @@ -14,7 +14,7 @@ public class RemoveTerminalOperationCodeFixProvider : CodeFixProvider public const string Title = "Remove {0}"; public override ImmutableArray FixableDiagnosticIds { get; } = - ImmutableArray.Create(DoNotEnumerateCollectionInLinqChain.DiagnosticId); + ImmutableArray.Create(DoNotEnumerateCollectionInLinqChainAnalyzer.DiagnosticId); public override FixAllProvider GetFixAllProvider() => WellKnownFixAllProviders.BatchFixer; diff --git a/src/analyzers/SourceKit.Analyzers.Enumerable/Properties/launchSettings.json b/src/analyzers/SourceKit.Analyzers.Enumerable/Properties/launchSettings.json new file mode 100644 index 0000000..b634e70 --- /dev/null +++ b/src/analyzers/SourceKit.Analyzers.Enumerable/Properties/launchSettings.json @@ -0,0 +1,9 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "profiles": { + "Debug": { + "commandName": "DebugRoslynComponent", + "targetProject": "../../../samples/analyzers/SourceKit.Analyzers.Enumerable.Samples/SourceKit.Analyzers.Enumerable.Samples.csproj" + } + } +} \ No newline at end of file diff --git a/src/analyzers/SourceKit.Analyzers.Enumerable/SourceKit.Analyzers.Enumerable.csproj b/src/analyzers/SourceKit.Analyzers.Enumerable/SourceKit.Analyzers.Enumerable.csproj index 589678a..911ef3d 100644 --- a/src/analyzers/SourceKit.Analyzers.Enumerable/SourceKit.Analyzers.Enumerable.csproj +++ b/src/analyzers/SourceKit.Analyzers.Enumerable/SourceKit.Analyzers.Enumerable.csproj @@ -2,14 +2,13 @@ netstandard2.0 - 11 - enable - enable + true true false + true @@ -33,7 +32,6 @@ - @@ -48,4 +46,9 @@ + + + + + diff --git a/src/analyzers/SourceKit.Analyzers.MemberAccessibility/AnalyzerReleases.Shipped.md b/src/analyzers/SourceKit.Analyzers.MemberAccessibility/AnalyzerReleases.Shipped.md new file mode 100644 index 0000000..7127b83 --- /dev/null +++ b/src/analyzers/SourceKit.Analyzers.MemberAccessibility/AnalyzerReleases.Shipped.md @@ -0,0 +1,6 @@ +## Release 1.0 + +### New Rules + +Rule ID | Category | Severity | Notes +--------|----------|----------|-------------------- \ No newline at end of file diff --git a/src/analyzers/SourceKit.Analyzers.MemberAccessibility/AnalyzerReleases.Unshipped.md b/src/analyzers/SourceKit.Analyzers.MemberAccessibility/AnalyzerReleases.Unshipped.md new file mode 100644 index 0000000..be321c3 --- /dev/null +++ b/src/analyzers/SourceKit.Analyzers.MemberAccessibility/AnalyzerReleases.Unshipped.md @@ -0,0 +1,6 @@ +### New Rules + +Rule ID | Category | Severity | Notes +--------|----------|----------|-------------------- +SK1100 | Design | Error | Do not use private properties +SK1101 | Design | Error | Do not use public fields \ No newline at end of file diff --git a/src/analyzers/SourceKit.Analyzers.MemberAccessibility/Properties/launchSettings.json b/src/analyzers/SourceKit.Analyzers.MemberAccessibility/Properties/launchSettings.json new file mode 100644 index 0000000..ed17f12 --- /dev/null +++ b/src/analyzers/SourceKit.Analyzers.MemberAccessibility/Properties/launchSettings.json @@ -0,0 +1,9 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "profiles": { + "Debug": { + "commandName": "DebugRoslynComponent", + "targetProject": "../../../samples/analyzers/SourceKit.Analyzers.MemberAccessibility.Samples/SourceKit.Analyzers.MemberAccessibility.Samples.csproj" + } + } +} \ No newline at end of file diff --git a/src/analyzers/SourceKit.Analyzers.MemberAccessibility/SourceKit.Analyzers.MemberAccessibility.csproj b/src/analyzers/SourceKit.Analyzers.MemberAccessibility/SourceKit.Analyzers.MemberAccessibility.csproj index d4b75cc..33c1cf8 100644 --- a/src/analyzers/SourceKit.Analyzers.MemberAccessibility/SourceKit.Analyzers.MemberAccessibility.csproj +++ b/src/analyzers/SourceKit.Analyzers.MemberAccessibility/SourceKit.Analyzers.MemberAccessibility.csproj @@ -2,14 +2,13 @@ netstandard2.0 - 11 - enable - enable + true true false + false @@ -33,7 +32,6 @@ - @@ -47,4 +45,9 @@ + + + + + diff --git a/src/analyzers/SourceKit.Analyzers.MustBePartial.Annotations/SourceKit.Analyzers.MustBePartial.Annotations.csproj b/src/analyzers/SourceKit.Analyzers.MustBePartial.Annotations/SourceKit.Analyzers.MustBePartial.Annotations.csproj index 190a9f9..8fa0d08 100644 --- a/src/analyzers/SourceKit.Analyzers.MustBePartial.Annotations/SourceKit.Analyzers.MustBePartial.Annotations.csproj +++ b/src/analyzers/SourceKit.Analyzers.MustBePartial.Annotations/SourceKit.Analyzers.MustBePartial.Annotations.csproj @@ -2,13 +2,11 @@ netstandard2.0 - enable - enable - 11 true + true diff --git a/src/analyzers/SourceKit.Analyzers.MustBePartial/AnalyzerReleases.Shipped.md b/src/analyzers/SourceKit.Analyzers.MustBePartial/AnalyzerReleases.Shipped.md new file mode 100644 index 0000000..5a7468f --- /dev/null +++ b/src/analyzers/SourceKit.Analyzers.MustBePartial/AnalyzerReleases.Shipped.md @@ -0,0 +1,7 @@ +## Release 1.0 + +### New Rules + +Rule ID | Category | Severity | Notes +--------|----------|----------|-------------------- +SK1000 | Usage | Error | Checkes if type is partial when it supposed to be \ No newline at end of file diff --git a/src/analyzers/SourceKit.Analyzers.MustBePartial/AnalyzerReleases.Unshipped.md b/src/analyzers/SourceKit.Analyzers.MustBePartial/AnalyzerReleases.Unshipped.md new file mode 100644 index 0000000..1ec540c --- /dev/null +++ b/src/analyzers/SourceKit.Analyzers.MustBePartial/AnalyzerReleases.Unshipped.md @@ -0,0 +1,4 @@ +### New Rules + +Rule ID | Category | Severity | Notes +--------|----------|----------|--------------------s \ No newline at end of file diff --git a/src/analyzers/SourceKit.Analyzers.MustBePartial/Properties/launchSettings.json b/src/analyzers/SourceKit.Analyzers.MustBePartial/Properties/launchSettings.json new file mode 100644 index 0000000..513c03f --- /dev/null +++ b/src/analyzers/SourceKit.Analyzers.MustBePartial/Properties/launchSettings.json @@ -0,0 +1,9 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "profiles": { + "Debug": { + "commandName": "DebugRoslynComponent", + "targetProject": "../../../samples/analyzers/SourceKit.Analyzers.MustBePartial.Samples/SourceKit.Analyzers.MustBePartial.Samples.csproj" + } + } +} \ No newline at end of file diff --git a/src/analyzers/SourceKit.Analyzers.MustBePartial/SourceKit.Analyzers.MustBePartial.csproj b/src/analyzers/SourceKit.Analyzers.MustBePartial/SourceKit.Analyzers.MustBePartial.csproj index 7a1c45c..adcb33b 100644 --- a/src/analyzers/SourceKit.Analyzers.MustBePartial/SourceKit.Analyzers.MustBePartial.csproj +++ b/src/analyzers/SourceKit.Analyzers.MustBePartial/SourceKit.Analyzers.MustBePartial.csproj @@ -2,14 +2,13 @@ netstandard2.0 - enable - enable - 11 + true true false + true @@ -50,4 +49,9 @@ + + + + + diff --git a/src/analyzers/SourceKit.Analyzers.Nullable/AnalyzerReleases.Shipped.md b/src/analyzers/SourceKit.Analyzers.Nullable/AnalyzerReleases.Shipped.md new file mode 100644 index 0000000..7a35c9b --- /dev/null +++ b/src/analyzers/SourceKit.Analyzers.Nullable/AnalyzerReleases.Shipped.md @@ -0,0 +1,8 @@ +## Release 1.0 + +### New Rules + +Rule ID | Category | Severity | Notes +--------|----------|----------|-------------------- +SK1200 | Usage | Error | Null forgiving operator is not allowed +SK1201 | Usage | Error | #nullable disable is not allowed \ No newline at end of file diff --git a/src/analyzers/SourceKit.Analyzers.Nullable/AnalyzerReleases.Unshipped.md b/src/analyzers/SourceKit.Analyzers.Nullable/AnalyzerReleases.Unshipped.md new file mode 100644 index 0000000..1ec540c --- /dev/null +++ b/src/analyzers/SourceKit.Analyzers.Nullable/AnalyzerReleases.Unshipped.md @@ -0,0 +1,4 @@ +### New Rules + +Rule ID | Category | Severity | Notes +--------|----------|----------|--------------------s \ No newline at end of file diff --git a/src/analyzers/SourceKit.Analyzers.Nullable/CodeFixes/PropagateNullableCorrectlyCodeFixProvider.cs b/src/analyzers/SourceKit.Analyzers.Nullable/CodeFixes/PropagateNullableCorrectlyCodeFixProvider.cs index b72918b..5927c8b 100644 --- a/src/analyzers/SourceKit.Analyzers.Nullable/CodeFixes/PropagateNullableCorrectlyCodeFixProvider.cs +++ b/src/analyzers/SourceKit.Analyzers.Nullable/CodeFixes/PropagateNullableCorrectlyCodeFixProvider.cs @@ -90,7 +90,7 @@ private static bool IsNodeProcessable(SyntaxNode node) SyntaxKind.InvocationExpression => true, SyntaxKind.SimpleMemberAccessExpression => true, SyntaxKind.PointerMemberAccessExpression => true, - _ => false + _ => false, }; } } \ No newline at end of file diff --git a/src/analyzers/SourceKit.Analyzers.Nullable/Properties/launchSettings.json b/src/analyzers/SourceKit.Analyzers.Nullable/Properties/launchSettings.json new file mode 100644 index 0000000..db9c157 --- /dev/null +++ b/src/analyzers/SourceKit.Analyzers.Nullable/Properties/launchSettings.json @@ -0,0 +1,9 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "profiles": { + "Debug": { + "commandName": "DebugRoslynComponent", + "targetProject": "../../../samples/analyzers/SourceKit.Analyzers.Nullable.Samples/SourceKit.Analyzers.Nullable.Samples.csproj" + } + } +} \ No newline at end of file diff --git a/src/analyzers/SourceKit.Analyzers.Nullable/SourceKit.Analyzers.Nullable.csproj b/src/analyzers/SourceKit.Analyzers.Nullable/SourceKit.Analyzers.Nullable.csproj index a76541f..92cc897 100644 --- a/src/analyzers/SourceKit.Analyzers.Nullable/SourceKit.Analyzers.Nullable.csproj +++ b/src/analyzers/SourceKit.Analyzers.Nullable/SourceKit.Analyzers.Nullable.csproj @@ -2,14 +2,13 @@ netstandard2.0 - 11 - enable - enable + true true false + true @@ -35,7 +34,6 @@ - @@ -50,4 +48,9 @@ + + + + + diff --git a/src/analyzers/SourceKit.Analyzers.Properties/AnalyzerReleases.Shipped.md b/src/analyzers/SourceKit.Analyzers.Properties/AnalyzerReleases.Shipped.md new file mode 100644 index 0000000..5ea1645 --- /dev/null +++ b/src/analyzers/SourceKit.Analyzers.Properties/AnalyzerReleases.Shipped.md @@ -0,0 +1,7 @@ +## Release 1.0 + +### New Rules + +Rule ID | Category | Severity | Notes +--------|----------|----------|-------------------- +SK1400 | Design | Warning | Use C# properties over fields + getter/setter \ No newline at end of file diff --git a/src/analyzers/SourceKit.Analyzers.Properties/AnalyzerReleases.Unshipped.md b/src/analyzers/SourceKit.Analyzers.Properties/AnalyzerReleases.Unshipped.md new file mode 100644 index 0000000..1ec540c --- /dev/null +++ b/src/analyzers/SourceKit.Analyzers.Properties/AnalyzerReleases.Unshipped.md @@ -0,0 +1,4 @@ +### New Rules + +Rule ID | Category | Severity | Notes +--------|----------|----------|--------------------s \ No newline at end of file diff --git a/src/analyzers/SourceKit.Analyzers.Properties/Analyzers/DeclarationCouldBeConvertedToPropertyAnalyzer.cs b/src/analyzers/SourceKit.Analyzers.Properties/Analyzers/DeclarationCouldBeConvertedToPropertyAnalyzer.cs index d0359ee..0800a98 100644 --- a/src/analyzers/SourceKit.Analyzers.Properties/Analyzers/DeclarationCouldBeConvertedToPropertyAnalyzer.cs +++ b/src/analyzers/SourceKit.Analyzers.Properties/Analyzers/DeclarationCouldBeConvertedToPropertyAnalyzer.cs @@ -13,7 +13,7 @@ public class DeclarationCouldBeConvertedToPropertyAnalyzer : DiagnosticAnalyzer public const string DiagnosticId = "SK1400"; public const string Title = nameof(DeclarationCouldBeConvertedToPropertyAnalyzer); - public const string Format = """Field '{0}' could be converted to property."""; + public const string Format = """Field '{0}' could be converted to property"""; public static readonly DiagnosticDescriptor Descriptor = new DiagnosticDescriptor( DiagnosticId, diff --git a/src/analyzers/SourceKit.Analyzers.Properties/Properties/launchSettings.json b/src/analyzers/SourceKit.Analyzers.Properties/Properties/launchSettings.json new file mode 100644 index 0000000..22d1afe --- /dev/null +++ b/src/analyzers/SourceKit.Analyzers.Properties/Properties/launchSettings.json @@ -0,0 +1,9 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "profiles": { + "Debug": { + "commandName": "DebugRoslynComponent", + "targetProject": "../../../samples/analyzers/SourceKit.Analyzers.Properties.Samples/SourceKit.Analyzers.Properties.Samples.csproj" + } + } +} \ No newline at end of file diff --git a/src/analyzers/SourceKit.Analyzers.Properties/SourceKit.Analyzers.Properties.csproj b/src/analyzers/SourceKit.Analyzers.Properties/SourceKit.Analyzers.Properties.csproj index ed1dba1..427bcb3 100644 --- a/src/analyzers/SourceKit.Analyzers.Properties/SourceKit.Analyzers.Properties.csproj +++ b/src/analyzers/SourceKit.Analyzers.Properties/SourceKit.Analyzers.Properties.csproj @@ -2,14 +2,13 @@ netstandard2.0 - 11 - enable - enable + true true false + true @@ -33,7 +32,6 @@ - @@ -48,4 +46,9 @@ + + + + + diff --git a/src/generators/SourceKit.Generators.Builder.Annotations/InitializesPropertyAttribute.cs b/src/generators/SourceKit.Generators.Builder.Annotations/InitializesPropertyAttribute.cs index 949c0f0..1860c38 100644 --- a/src/generators/SourceKit.Generators.Builder.Annotations/InitializesPropertyAttribute.cs +++ b/src/generators/SourceKit.Generators.Builder.Annotations/InitializesPropertyAttribute.cs @@ -1,4 +1,6 @@ namespace SourceKit.Generators.Builder.Annotations; +#pragma warning disable CS9113 // Parameter is unread. + [AttributeUsage(AttributeTargets.Method)] -public class InitializesPropertyAttribute(string PropertyName) : Attribute; \ No newline at end of file +public class InitializesPropertyAttribute(string propertyName) : Attribute; \ No newline at end of file diff --git a/src/generators/SourceKit.Generators.Builder.Annotations/SourceKit.Generators.Builder.Annotations.csproj b/src/generators/SourceKit.Generators.Builder.Annotations/SourceKit.Generators.Builder.Annotations.csproj index e2a0e20..ae8c320 100644 --- a/src/generators/SourceKit.Generators.Builder.Annotations/SourceKit.Generators.Builder.Annotations.csproj +++ b/src/generators/SourceKit.Generators.Builder.Annotations/SourceKit.Generators.Builder.Annotations.csproj @@ -2,12 +2,11 @@ netstandard2.0 - enable - enable true + true @@ -24,16 +23,20 @@ 1.1.$(PatchVersion) - Added GenerateBuilder attribute + + Added GenerateBuilder attribute + - - + + - + diff --git a/src/generators/SourceKit.Generators.Builder/AnalyzerReleases.Shipped.md b/src/generators/SourceKit.Generators.Builder/AnalyzerReleases.Shipped.md new file mode 100644 index 0000000..1211dd4 --- /dev/null +++ b/src/generators/SourceKit.Generators.Builder/AnalyzerReleases.Shipped.md @@ -0,0 +1,7 @@ +## Release 1.0 + +### New Rules + +Rule ID | Category | Severity | Notes +--------|----------|----------|-------------------- +SK2100 | Usage | Error | Properties annotated with [RequiredValue] must be initialized with builder \ No newline at end of file diff --git a/src/generators/SourceKit.Generators.Builder/AnalyzerReleases.Unshipped.md b/src/generators/SourceKit.Generators.Builder/AnalyzerReleases.Unshipped.md new file mode 100644 index 0000000..39cc69d --- /dev/null +++ b/src/generators/SourceKit.Generators.Builder/AnalyzerReleases.Unshipped.md @@ -0,0 +1,4 @@ +### New Rules + +Rule ID | Category | Severity | Notes +--------|----------|----------|-------------------- \ No newline at end of file diff --git a/src/generators/SourceKit.Generators.Builder/Builders/FileBuilders/TypeBuilder.cs b/src/generators/SourceKit.Generators.Builder/Builders/FileBuilders/TypeBuilder.cs index b4d1258..84cf599 100644 --- a/src/generators/SourceKit.Generators.Builder/Builders/FileBuilders/TypeBuilder.cs +++ b/src/generators/SourceKit.Generators.Builder/Builders/FileBuilders/TypeBuilder.cs @@ -47,7 +47,7 @@ public CompilationUnitSyntax Process( request = request with { - CompilationUnit = request.CompilationUnit.AddMembers(namespaceDeclaration) + CompilationUnit = request.CompilationUnit.AddMembers(namespaceDeclaration), }; return next(request, context); diff --git a/src/generators/SourceKit.Generators.Builder/Builders/FileBuilders/UsingBuilder.cs b/src/generators/SourceKit.Generators.Builder/Builders/FileBuilders/UsingBuilder.cs index 5c1991d..38ae1c9 100644 --- a/src/generators/SourceKit.Generators.Builder/Builders/FileBuilders/UsingBuilder.cs +++ b/src/generators/SourceKit.Generators.Builder/Builders/FileBuilders/UsingBuilder.cs @@ -13,8 +13,8 @@ public class UsingBuilder : ILink { private static readonly IEqualityComparer Comparer = EqualityComparerFactory.Create( - (a, b) => a.Name.ToString().Equals(b.Name.ToString()), - x => x.Name.ToString().GetHashCode()); + (a, b) => string.Equals(a.Name?.ToString(), b.Name?.ToString()), + x => x.Name?.ToString().GetHashCode() ?? 0); private readonly IChain _commentChain; @@ -28,7 +28,7 @@ public CompilationUnitSyntax Process( SynchronousContext context, LinkDelegate next) { - var unit = next(request, context); + CompilationUnitSyntax unit = next(request, context); IEnumerable propertyUsingDirectives = request.Properties .Select(SelectType) @@ -42,10 +42,11 @@ public CompilationUnitSyntax Process( .Append(UsingDirective(IdentifierName(Constants.AnnotationsNamespace))) .Concat(propertyUsingDirectives) .Distinct(Comparer) - .OrderBy(x => x.Name.ToString()) + .Where(x => x.Name is not null) + .OrderBy(x => x.Name?.ToString()) .ToArray(); - var firstDirective = usingDirectives[0]; + UsingDirectiveSyntax firstDirective = usingDirectives[0]; var commentBuildingCommand = new UsingBuildingCommand(firstDirective, request.Symbol); usingDirectives[0] = _commentChain.Process(commentBuildingCommand); diff --git a/src/generators/SourceKit.Generators.Builder/Properties/launchSettings.json b/src/generators/SourceKit.Generators.Builder/Properties/launchSettings.json new file mode 100644 index 0000000..40ea28f --- /dev/null +++ b/src/generators/SourceKit.Generators.Builder/Properties/launchSettings.json @@ -0,0 +1,9 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "profiles": { + "Debug": { + "commandName": "DebugRoslynComponent", + "targetProject": "../../../samples/generators/SourceKit.Generators.Builder.Samples/SourceKit.Generators.Builder.Samples.csproj" + } + } +} \ No newline at end of file diff --git a/src/generators/SourceKit.Generators.Builder/SourceKit.Generators.Builder.csproj b/src/generators/SourceKit.Generators.Builder/SourceKit.Generators.Builder.csproj index 250ac63..b850741 100644 --- a/src/generators/SourceKit.Generators.Builder/SourceKit.Generators.Builder.csproj +++ b/src/generators/SourceKit.Generators.Builder/SourceKit.Generators.Builder.csproj @@ -2,14 +2,13 @@ netstandard2.0 - enable - enable - 11 + true true false + true @@ -27,7 +26,7 @@ 1.2.$(PatchVersion) - Added default values support + Added default values support @@ -37,9 +36,15 @@ - - - + + all + + + all + + + all + @@ -65,12 +70,7 @@ - - all - - runtime; build; native; contentfiles; analyzers; buildtransitive - - + diff --git a/src/generators/SourceKit.Generators.Grpc/Builders/FileBuilders/UsingBuilder.cs b/src/generators/SourceKit.Generators.Grpc/Builders/FileBuilders/UsingBuilder.cs index 7dfc98b..4732024 100644 --- a/src/generators/SourceKit.Generators.Grpc/Builders/FileBuilders/UsingBuilder.cs +++ b/src/generators/SourceKit.Generators.Grpc/Builders/FileBuilders/UsingBuilder.cs @@ -13,8 +13,8 @@ public class UsingBuilder : ILink { private static readonly IEqualityComparer Comparer = EqualityComparerFactory.Create( - (a, b) => a.Name.ToString().Equals(b.Name.ToString()), - x => x.Name.ToString().GetHashCode()); + (a, b) => string.Equals(a.Name?.ToString(), b.Name?.ToString()), + x => x.Name?.ToString().GetHashCode() ?? 0); private readonly IChain _usingChain; @@ -28,7 +28,7 @@ public CompilationUnitSyntax Process( SynchronousContext context, LinkDelegate next) { - var unit = next(request, context); + CompilationUnitSyntax unit = next(request, context); #pragma warning disable RS1024 IEnumerable propertyUsingDirectives = ExtractNamespaces(request.Message.Properties) @@ -43,10 +43,11 @@ public CompilationUnitSyntax Process( .Append(UsingDirective(IdentifierName("System.Collections.Generic"))) .Concat(propertyUsingDirectives) .Distinct(Comparer) - .OrderBy(x => x.Name.ToString()) + .Where(x => x.Name is not null) + .OrderBy(x => x.Name?.ToString()) .ToArray(); - var firstDirective = usingDirectives[0]; + UsingDirectiveSyntax firstDirective = usingDirectives[0]; var usingBuildingCommand = new UsingBuildingCommand(firstDirective); usingDirectives[0] = _usingChain.Process(usingBuildingCommand); @@ -56,7 +57,7 @@ public CompilationUnitSyntax Process( private static IEnumerable ExtractNamespaces(IEnumerable properties) { - foreach (var property in properties) + foreach (ProtoProperty? property in properties) { if (property is RepeatableProtoProperty repeatableProperty) { diff --git a/src/generators/SourceKit.Generators.Grpc/Properties/launchSettings.json b/src/generators/SourceKit.Generators.Grpc/Properties/launchSettings.json new file mode 100644 index 0000000..2bae683 --- /dev/null +++ b/src/generators/SourceKit.Generators.Grpc/Properties/launchSettings.json @@ -0,0 +1,9 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "profiles": { + "Debug": { + "commandName": "DebugRoslynComponent", + "targetProject": "../../../samples/generators/SourceKit.Generators.Grpc.Samples/SourceKit.Generators.Grpc.Samples.csproj" + } + } +} \ No newline at end of file diff --git a/src/generators/SourceKit.Generators.Grpc/SourceKit.Generators.Grpc.csproj b/src/generators/SourceKit.Generators.Grpc/SourceKit.Generators.Grpc.csproj index fa74d2c..573ca3b 100644 --- a/src/generators/SourceKit.Generators.Grpc/SourceKit.Generators.Grpc.csproj +++ b/src/generators/SourceKit.Generators.Grpc/SourceKit.Generators.Grpc.csproj @@ -2,14 +2,13 @@ netstandard2.0 - enable - enable - 11 + true true false + true @@ -65,12 +64,7 @@ - - all - - runtime; build; native; contentfiles; analyzers; buildtransitive - - + diff --git a/tests/SourceKit.Analyzers.Collections.Tests/CollectionsTests.cs b/tests/SourceKit.Analyzers.Collections.Tests/CollectionsTests.cs new file mode 100644 index 0000000..16c8eec --- /dev/null +++ b/tests/SourceKit.Analyzers.Collections.Tests/CollectionsTests.cs @@ -0,0 +1,110 @@ +using Microsoft.CodeAnalysis.Testing; +using SourceKit.Analyzers.Collections.Analyzers; +using SourceKit.Tests.Common; +using SourceKit.Tests.Common.TestBases; +using Xunit; + +namespace SourceKit.Analyzers.Collections.Tests; + +public class CollectionsTests : AnalyzerTestBase +{ + [Fact] + public async Task DictionaryKeyType_ShouldReportDiagnostic_WhenTypeIsNotImplementEquatable() + { + SourceFile sourceFile = await SourceFile.LoadAsync( + "SourceKit.Analyzers.Collections.Samples/Dictionary/KeyTypeDoesNotImplementEquatable.cs"); + + DiagnosticResult diagnostic = AnalyzerVerifier + .Diagnostic(DictionaryKeyTypeMustImplementEquatableAnalyzer.Descriptor) + .WithLocation(sourceFile.Name, 7, 12) + .WithArguments("KeyTypeDoesNotImplementEquatable"); + + await AnalyzerTest + .WithSource(sourceFile) + .WithExpectedDiagnostic(diagnostic) + .Build() + .RunAsync(); + } + + [Fact] + public async Task DictionaryCustomKeyType_ShouldReportDiagnostic_WhenTypeImplementsOtherEquatable() + { + SourceFile sourceFile = await SourceFile.LoadAsync( + "SourceKit.Analyzers.Collections.Samples/Dictionary/CustomKeyTypeImplementsOtherEquatable.cs"); + + DiagnosticResult diagnostic = AnalyzerVerifier + .Diagnostic(DictionaryKeyTypeMustImplementEquatableAnalyzer.Descriptor) + .WithLocation(sourceFile.Name, 18, 23) + .WithArguments("CustomKeyTypeImplementsOtherEquatable"); + + await AnalyzerTest + .WithSource(sourceFile) + .WithExpectedDiagnostic(diagnostic) + .Build() + .RunAsync(); + } + + [Fact] + public async Task DictionaryKeyType_ShouldNotReportDiagnostic_WhenTypeImplementsEquatable() + { + SourceFile sourceFile = await SourceFile.LoadAsync( + "SourceKit.Analyzers.Collections.Samples/Dictionary/KeyTypeImplementsEquatable.cs"); + + await AnalyzerTest + .WithSource(sourceFile) + .Build() + .RunAsync(); + } + + [Fact] + public async Task DictionaryCustomKeyType_ShouldNotReportDiagnostic_WhenTypeImplementsEquatable() + { + SourceFile customKeySourceFile = await SourceFile.LoadAsync( + "SourceKit.Analyzers.Collections.Samples/Dictionary/CustomKeyTypeImplementsEquatable.cs"); + + SourceFile equatableSourceFile = await SourceFile.LoadAsync( + "SourceKit.Analyzers.Collections.Samples/Dictionary/EquatableType.cs"); + + await AnalyzerTest + .WithSource(customKeySourceFile) + .WithSource(equatableSourceFile) + .Build() + .RunAsync(); + } + + [Fact] + public async Task DictionaryKeyType_ShouldNotReportDiagnostic_WhenTypeIsEmpty() + { + SourceFile sourceFile = await SourceFile.LoadAsync( + "SourceKit.Analyzers.Collections.Samples/Dictionary/EmptyKeyType.cs"); + + await AnalyzerTest + .WithSource(sourceFile) + .Build() + .RunAsync(); + } + + [Fact] + public async Task DictionaryInheritedCustomKeyType_ShouldNotReportDiagnostic_WhenTypeImplementsEquatable() + { + SourceFile sourceFile = await SourceFile.LoadAsync( + "SourceKit.Analyzers.Collections.Samples/Dictionary/InheritedCustomKeyTypeImplementsEquatable.cs"); + + await AnalyzerTest + .WithSource(sourceFile) + .Build() + .RunAsync(); + } + + [Fact] + public async Task DictionaryInheritedCustomKeyType_ShouldNotReportDiagnostic_WhenKeyTypeIsEnum() + { + SourceFile sourceFile = await SourceFile.LoadAsync( + "SourceKit.Analyzers.Collections.Samples/Dictionary/EnumKeyDictionary.cs"); + + await AnalyzerTest + .WithSource(sourceFile) + .Build() + .RunAsync(); + } +} \ No newline at end of file diff --git a/tests/SourceKit.Analyzers.Collections.Tests/ConvertListForEachIntoForEachLoop.cs b/tests/SourceKit.Analyzers.Collections.Tests/ConvertListForEachIntoForEachLoop.cs new file mode 100644 index 0000000..54cf431 --- /dev/null +++ b/tests/SourceKit.Analyzers.Collections.Tests/ConvertListForEachIntoForEachLoop.cs @@ -0,0 +1,186 @@ +using Microsoft.CodeAnalysis.Testing; +using SourceKit.Analyzers.Collections.Analyzers; +using SourceKit.Analyzers.Collections.CodeFixes; +using SourceKit.Tests.Common; +using SourceKit.Tests.Common.TestBases; +using Xunit; + +namespace SourceKit.Analyzers.Collections.Tests; + +public class ConvertListForEachIntoForEachLoop : CodeFixTestBase< + ListForEachNotAllowedAnalyzer, + ConvertListForEachIntoForEachLoopCodeFixProvider> +{ + [Fact] + public async Task ShouldConvertListForEachWithLambdaBlockIntoForEachLoop_WhenDiagnosticReported() + { + SourceFile sourceFile = await SourceFile.LoadAsync( + "SourceKit.Analyzers.Collections.Samples/ListForEachNotAllowed/ListForEachStatementWithLambdaBlockExample.cs"); + + var fixedFile = new SourceFile( + Name: "ListForEachStatementWithLambdaBlockExample.cs", + Content: """ + using System; + using System.Collections.Generic; + + namespace SourceKit.Analyzers.Collections.Samples.ListForEachNotAllowed; + + public class ListForEachStatementWithLambdaBlockExample + { + public void DoSomething() + { + var a = new List { 1, 2, 3 }; + + foreach (var element in a) + { + Console.WriteLine(element); + Console.WriteLine(element / 2); + } + } + } + """); + + DiagnosticResult diagnostic = AnalyzerVerifier + .Diagnostic(ListForEachNotAllowedAnalyzer.Descriptor) + .WithLocation(sourceFile.Name, 12, 9) + .WithMessage(string.Format(ListForEachNotAllowedAnalyzer.Format)); + + await CodeFixTest + .WithSource(sourceFile) + .WithFixedSource(fixedFile) + .WithExpectedDiagnostic(diagnostic) + .Build() + .RunAsync(); + } + + [Fact] + public async Task ShouldConvertListForEachWithLambdaExpressionIntoForEachLoop_WhenDiagnosticReported() + { + SourceFile sourceFile = await SourceFile.LoadAsync( + "SourceKit.Analyzers.Collections.Samples/ListForEachNotAllowed/ListForEachStatementWithLambdaExpressionExample.cs"); + + var fixedFile = new SourceFile( + Name: "ListForEachStatementWithLambdaExpressionExample.cs", + Content: """ + using System.Collections.Generic; + + namespace SourceKit.Analyzers.Collections.Samples.ListForEachNotAllowed; + + public class ListForEachStatementWithLambdaExpressionExample + { + public List DoSomething() + { + var a = new List { 10, 20, 30 }; + var result = new List(); + + foreach (var element in a) + { + result.Add(element / 2); + } + + return result; + } + } + """); + + DiagnosticResult diagnostic = AnalyzerVerifier + .Diagnostic(ListForEachNotAllowedAnalyzer.Descriptor) + .WithLocation(sourceFile.Name, 12, 9) + .WithMessage(string.Format(ListForEachNotAllowedAnalyzer.Format)); + + await CodeFixTest + .WithSource(sourceFile) + .WithFixedSource(fixedFile) + .WithExpectedDiagnostic(diagnostic) + .Build() + .RunAsync(); + } + + [Fact] + public async Task ShouldConvertListForEachWithMemberAccessExpressionIntoForEachLoop_WhenDiagnosticReported() + { + SourceFile sourceFile = await SourceFile.LoadAsync( + "SourceKit.Analyzers.Collections.Samples/ListForEachNotAllowed/ListForEachStatementWithMemberAccessExpressionExample.cs"); + + var fixedFile = new SourceFile( + Name: "ListForEachStatementWithMemberAccessExpressionExample.cs", + Content: """ + using System; + using System.Collections.Generic; + + namespace SourceKit.Analyzers.Collections.Samples.ListForEachNotAllowed; + + public class ListForEachStatementWithMemberAccessExpressionExample + { + public void DoSomething() + { + var a = new List { 1, 2, 3 }; + + foreach (var element in a) + { + Console.WriteLine(element); + } + } + } + """); + + DiagnosticResult diagnostic = AnalyzerVerifier + .Diagnostic(ListForEachNotAllowedAnalyzer.Descriptor) + .WithLocation(sourceFile.Name, 12, 9) + .WithMessage(string.Format(ListForEachNotAllowedAnalyzer.Format)); + + await CodeFixTest + .WithSource(sourceFile) + .WithFixedSource(fixedFile) + .WithExpectedDiagnostic(diagnostic) + .Build() + .RunAsync(); + } + + [Fact] + public async Task ShouldConvertListForEachWithMethodLinkIntoForEachLoop_WhenDiagnosticReported() + { + SourceFile sourceFile = await SourceFile.LoadAsync( + "SourceKit.Analyzers.Collections.Samples/ListForEachNotAllowed/ListForEachStatementWithMethodLinkExample.cs"); + + var fixedFile = new SourceFile( + Name: "ListForEachStatementWithMethodLinkExample.cs", + Content: """ + using System.Collections.Generic; + + namespace SourceKit.Analyzers.Collections.Samples.ListForEachNotAllowed; + + public class ListForEachStatementWithMethodLinkExample + { + private readonly List _list = new(); + + public void DoSomething() + { + var a = new List { 13, 21, 32 }; + + foreach (var element in a) + { + AddToPrivateList(element); + } + } + + private void AddToPrivateList(int element) + { + _list.Add(element * 10); + } + } + """); + + DiagnosticResult diagnostic = AnalyzerVerifier + .Diagnostic(ListForEachNotAllowedAnalyzer.Descriptor) + .WithLocation(sourceFile.Name, 13, 9) + .WithMessage(string.Format(ListForEachNotAllowedAnalyzer.Format)); + + await CodeFixTest + .WithSource(sourceFile) + .WithFixedSource(fixedFile) + .WithExpectedDiagnostic(diagnostic) + .Build() + .RunAsync(); + } +} \ No newline at end of file diff --git a/tests/SourceKit.Analyzers.Collections.Tests/ListForEachNotAllowedTests.cs b/tests/SourceKit.Analyzers.Collections.Tests/ListForEachNotAllowedTests.cs new file mode 100644 index 0000000..f853d73 --- /dev/null +++ b/tests/SourceKit.Analyzers.Collections.Tests/ListForEachNotAllowedTests.cs @@ -0,0 +1,130 @@ +using Microsoft.CodeAnalysis.Testing; +using SourceKit.Analyzers.Collections.Analyzers; +using SourceKit.Tests.Common; +using SourceKit.Tests.Common.TestBases; +using Xunit; + +namespace SourceKit.Analyzers.Collections.Tests; + +public class ListForEachNotAllowedTests : AnalyzerTestBase +{ + [Fact] + public async Task ShouldReportNoDiagnostic_WhenNoListForEachExpressionsPresent() + { + SourceFile sourceFile = await SourceFile.LoadAsync( + "SourceKit.Analyzers.Collections.Samples/ListForEachNotAllowed/NoListForEachStatementExample.cs"); + + await AnalyzerTest + .WithSource(sourceFile) + .Build() + .RunAsync(); + } + + [Fact] + public async Task ShouldReportDiagnostic_WhenClassMethodContainsListForEachStatementWithLambdaBlock() + { + SourceFile sourceFile = await SourceFile.LoadAsync( + "SourceKit.Analyzers.Collections.Samples/ListForEachNotAllowed/ListForEachStatementWithLambdaBlockExample.cs"); + + DiagnosticResult diagnostic = AnalyzerVerifier + .Diagnostic(ListForEachNotAllowedAnalyzer.Descriptor) + .WithLocation(sourceFile.Name, 12, 9) + .WithMessage(string.Format(ListForEachNotAllowedAnalyzer.Format)); + + await AnalyzerTest + .WithSource(sourceFile) + .WithExpectedDiagnostic(diagnostic) + .Build() + .RunAsync(); + } + + [Fact] + public async Task ShouldReportDiagnostic_WhenClassMethodContainsListForEachStatementWithLambdaExpression() + { + SourceFile sourceFile = await SourceFile.LoadAsync( + "SourceKit.Analyzers.Collections.Samples/ListForEachNotAllowed/ListForEachStatementWithLambdaExpressionExample.cs"); + + DiagnosticResult diagnostic = AnalyzerVerifier + .Diagnostic(ListForEachNotAllowedAnalyzer.Descriptor) + .WithLocation(sourceFile.Name, 12, 9) + .WithMessage(string.Format(ListForEachNotAllowedAnalyzer.Format)); + + await AnalyzerTest + .WithSource(sourceFile) + .WithExpectedDiagnostic(diagnostic) + .Build() + .RunAsync(); + } + + [Fact] + public async Task ShouldReportDiagnostic_WhenClassMethodContainsListForEachStatementWithMemberAccessExpression() + { + SourceFile sourceFile = await SourceFile.LoadAsync( + "SourceKit.Analyzers.Collections.Samples/ListForEachNotAllowed/ListForEachStatementWithMemberAccessExpressionExample.cs"); + + DiagnosticResult diagnostic = AnalyzerVerifier + .Diagnostic(ListForEachNotAllowedAnalyzer.Descriptor) + .WithLocation(sourceFile.Name, 12, 9) + .WithMessage(string.Format(ListForEachNotAllowedAnalyzer.Format)); + + await AnalyzerTest + .WithSource(sourceFile) + .WithExpectedDiagnostic(diagnostic) + .Build() + .RunAsync(); + } + + [Fact] + public async Task ShouldReportDiagnostic_WhenClassMethodContainsListForEachStatementWithMethodLink() + { + SourceFile sourceFile = await SourceFile.LoadAsync( + "SourceKit.Analyzers.Collections.Samples/ListForEachNotAllowed/ListForEachStatementWithMethodLinkExample.cs"); + + DiagnosticResult diagnostic = AnalyzerVerifier + .Diagnostic(ListForEachNotAllowedAnalyzer.Descriptor) + .WithLocation(sourceFile.Name, 13, 9) + .WithMessage(string.Format(ListForEachNotAllowedAnalyzer.Format)); + + await AnalyzerTest + .WithSource(sourceFile) + .WithExpectedDiagnostic(diagnostic) + .Build() + .RunAsync(); + } + + [Fact] + public async Task ShouldReportDiagnostic_WhenClassMethodContainsSeveralListForEachExpressions() + { + SourceFile sourceFile = await SourceFile.LoadAsync( + "SourceKit.Analyzers.Collections.Samples/ListForEachNotAllowed/ListForEachStatementComplexExample.cs"); + + DiagnosticResult lambdaWithExpressionDiagnostic = AnalyzerVerifier + .Diagnostic(ListForEachNotAllowedAnalyzer.Descriptor) + .WithLocation(sourceFile.Name, 15, 9) + .WithMessage(string.Format(ListForEachNotAllowedAnalyzer.Format)); + + DiagnosticResult lambdaWithBlockDiagnostic = AnalyzerVerifier + .Diagnostic(ListForEachNotAllowedAnalyzer.Descriptor) + .WithLocation(sourceFile.Name, 16, 9) + .WithMessage(string.Format(ListForEachNotAllowedAnalyzer.Format)); + + DiagnosticResult memberAccessExpressionDiagnostic = AnalyzerVerifier + .Diagnostic(ListForEachNotAllowedAnalyzer.Descriptor) + .WithLocation(sourceFile.Name, 21, 9) + .WithMessage(string.Format(ListForEachNotAllowedAnalyzer.Format)); + + DiagnosticResult identifierNameDiagnostic = AnalyzerVerifier + .Diagnostic(ListForEachNotAllowedAnalyzer.Descriptor) + .WithLocation(sourceFile.Name, 22, 9) + .WithMessage(string.Format(ListForEachNotAllowedAnalyzer.Format)); + + await AnalyzerTest + .WithSource(sourceFile) + .WithExpectedDiagnostic(lambdaWithExpressionDiagnostic) + .WithExpectedDiagnostic(lambdaWithBlockDiagnostic) + .WithExpectedDiagnostic(memberAccessExpressionDiagnostic) + .WithExpectedDiagnostic(identifierNameDiagnostic) + .Build() + .RunAsync(); + } +} \ No newline at end of file diff --git a/tests/SourceKit.Analyzers.Collections.Tests/SourceKit.Analyzers.Collections.Tests.csproj b/tests/SourceKit.Analyzers.Collections.Tests/SourceKit.Analyzers.Collections.Tests.csproj new file mode 100644 index 0000000..23e7da5 --- /dev/null +++ b/tests/SourceKit.Analyzers.Collections.Tests/SourceKit.Analyzers.Collections.Tests.csproj @@ -0,0 +1,30 @@ + + + + false + true + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/SourceKit.Analyzers.Enumerable.Tests/DoNotEnumerateCollectionInLinqChainAnalyzerTests.cs b/tests/SourceKit.Analyzers.Enumerable.Tests/DoNotEnumerateCollectionInLinqChainAnalyzerTests.cs new file mode 100644 index 0000000..133efce --- /dev/null +++ b/tests/SourceKit.Analyzers.Enumerable.Tests/DoNotEnumerateCollectionInLinqChainAnalyzerTests.cs @@ -0,0 +1,152 @@ +using Microsoft.CodeAnalysis.Testing; +using SourceKit.Analyzers.Enumerable.Analyzers; +using SourceKit.Tests.Common; +using SourceKit.Tests.Common.TestBases; +using Xunit; + +namespace SourceKit.Analyzers.Enumerable.Tests; + +public class DoNotEnumerateCollectionInLinqChainAnalyzerTests : AnalyzerTestBase< + DoNotEnumerateCollectionInLinqChainAnalyzer> +{ + [Fact] + public async Task ShouldNotReportDiagnostics_WhenNoLinqMethodsUsedAfterTerminalMethods() + { + var sourceFile = new SourceFile( + Name: "Program.cs", + Content: """ + using System; + using System.Collections.Generic; + using System.Linq; + + class Program + { + static void Main(string[] args) + { + var list = GetItems().Select(x => new List{x}).Select(x => x.First()).ToList(); + } + static IEnumerable GetItems() + { + return Enumerable.Range(1, 10); + } + } + """); + + await AnalyzerTest + .WithSource(sourceFile) + .Build() + .RunAsync(); + } + + [Fact] + public async Task ShouldReportDiagnostic_WhenLinqMethodUsedAfterToList() + { + var sourceFile = new SourceFile( + Name: "Program.cs", + Content: """ + using System; + using System.Collections.Generic; + using System.Linq; + class Program + { + static void Main(string[] args) + { + var list = GetItems().ToList().Where(x => x > 5); + } + static IEnumerable GetItems() + { + return Enumerable.Range(1, 10); + } + } + """); + + DiagnosticResult diagnostic = AnalyzerVerifier + .Diagnostic(DoNotEnumerateCollectionInLinqChainAnalyzer.Descriptor) + .WithLocation(sourceFile.Name, 8, 31) + .WithArguments("ToList"); + + await AnalyzerTest + .WithSource(sourceFile) + .WithExpectedDiagnostic(diagnostic) + .Build() + .RunAsync(); + } + + [Fact] + public async Task ShouldReportDiagnostic_WhenLinqMethodUsedAfterToLookup() + { + var sourceFile = new SourceFile( + Name: "Program.cs", + Content: + """ + using System.Collections.Generic; + using System.Linq; + class Program + { + private class Comparer : IEqualityComparer + { + bool IEqualityComparer.Equals(T x, T y) + { + return x.Equals(y); + } + int IEqualityComparer.GetHashCode(T obj) + { + return obj.GetHashCode(); + } + } + static void Main(string[] args) + { + var list = GetItems().ToLookup(x => x, new Comparer()).Where(x => x.Key > 4); + } + static IEnumerable GetItems() + { + return Enumerable.Range(1, 10); + } + } + """); + + DiagnosticResult diagnostic = AnalyzerVerifier + .Diagnostic(DoNotEnumerateCollectionInLinqChainAnalyzer.Descriptor) + .WithLocation(sourceFile.Name, 18, 31).WithArguments("ToLookup"); + + await AnalyzerTest + .WithSource(sourceFile) + .WithExpectedDiagnostic(diagnostic) + .Build() + .RunAsync(); + } + + [Fact] + public async Task ShouldReportDiagnostic_WhenLinqMethodUsedAfterToArray() + { + var sourceFile = new SourceFile( + Name: "Program.cs", + Content: + """ + using System; + using System.Collections.Generic; + using System.Linq; + class Program + { + static void Main(string[] args) + { + var list = GetItems().ToArray().Where(x => x > 5); + } + static IEnumerable GetItems() + { + return Enumerable.Range(1, 10); + } + } + """); + + DiagnosticResult diagnostic = AnalyzerVerifier + .Diagnostic(DoNotEnumerateCollectionInLinqChainAnalyzer.Descriptor) + .WithLocation(sourceFile.Name, 8, 31).WithArguments("ToArray"); + + await AnalyzerTest + .WithSource(sourceFile) + .WithExpectedDiagnostic(diagnostic) + .Build() + .RunAsync(); + } +} \ No newline at end of file diff --git a/tests/SourceKit.Analyzers.Enumerable.Tests/OfTypeMustUseDerivedTypeTests.cs b/tests/SourceKit.Analyzers.Enumerable.Tests/OfTypeMustUseDerivedTypeTests.cs new file mode 100644 index 0000000..1a7a120 --- /dev/null +++ b/tests/SourceKit.Analyzers.Enumerable.Tests/OfTypeMustUseDerivedTypeTests.cs @@ -0,0 +1,28 @@ +using Microsoft.CodeAnalysis.Testing; +using SourceKit.Analyzers.Enumerable.Analyzers; +using SourceKit.Tests.Common; +using SourceKit.Tests.Common.TestBases; +using Xunit; + +namespace SourceKit.Analyzers.Enumerable.Tests; + +public class OfTypeMustUseDerivedTypeTests : AnalyzerTestBase +{ + [Fact] + public async Task ShouldReportDiagnostic_WhenUsedWithNotDerivedType() + { + SourceFile sourceFile = await SourceFile.LoadAsync( + "SourceKit.Analyzers.Enumerable.Samples/OfTypeMustUseDerivedType/OfTypeSample.cs"); + + DiagnosticResult diagnostic = AnalyzerVerifier + .Diagnostic(OfTypeMustUseDerivedTypeAnalyzer.Descriptor) + .WithLocation(sourceFile.Name, 10, 16) + .WithArguments(nameof(Int32), nameof(String)); + + await AnalyzerTest + .WithSource(sourceFile) + .WithExpectedDiagnostic(diagnostic) + .Build() + .RunAsync(); + } +} \ No newline at end of file diff --git a/tests/SourceKit.Analyzers.Enumerable.Tests/RemoveTerminalOperationCodeFixProviderTests.cs b/tests/SourceKit.Analyzers.Enumerable.Tests/RemoveTerminalOperationCodeFixProviderTests.cs new file mode 100644 index 0000000..deb9397 --- /dev/null +++ b/tests/SourceKit.Analyzers.Enumerable.Tests/RemoveTerminalOperationCodeFixProviderTests.cs @@ -0,0 +1,88 @@ +using Microsoft.CodeAnalysis.Testing; +using SourceKit.Analyzers.Enumerable.Analyzers; +using SourceKit.Analyzers.Enumerable.CodeFixes; +using SourceKit.Tests.Common; +using SourceKit.Tests.Common.TestBases; +using Xunit; + +namespace SourceKit.Analyzers.Enumerable.Tests; + +public class RemoveTerminalOperationCodeFixProviderTests : CodeFixTestBase< + DoNotEnumerateCollectionInLinqChainAnalyzer, + RemoveTerminalOperationCodeFixProvider> +{ + [Fact] + public async Task ShouldRemoveTerminalOperation_WhenLinqUsedAfterTerminationMethods() + { + var sourceFile = new SourceFile( + Name: "Program.cs", + Content: """ + using System.Collections.Generic; + using System.Linq; + class Program + { + private class Comparer : IEqualityComparer + { + bool IEqualityComparer.Equals(T x, T y) + { + return x.Equals(y); + } + int IEqualityComparer.GetHashCode(T obj) + { + return obj.GetHashCode(); + } + } + static void Main(string[] args) + { + var list = GetItems().ToLookup(x => x, new Comparer()).First(); + } + static IEnumerable GetItems() + { + return Enumerable.Range(1, 10); + } + } + """); + + var fixedSource = new SourceFile( + Name: "Program.cs", + Content: """ + using System.Collections.Generic; + using System.Linq; + class Program + { + private class Comparer : IEqualityComparer + { + bool IEqualityComparer.Equals(T x, T y) + { + return x.Equals(y); + } + int IEqualityComparer.GetHashCode(T obj) + { + return obj.GetHashCode(); + } + } + static void Main(string[] args) + { + var list = GetItems().First(); + } + static IEnumerable GetItems() + { + return Enumerable.Range(1, 10); + } + } + """); + + DiagnosticResult diagnostic = AnalyzerVerifier + .Diagnostic(DoNotEnumerateCollectionInLinqChainAnalyzer.Descriptor) + .WithLocation(sourceFile.Name, 18, 31) + .WithArguments("ToLookup"); + + await CodeFixTest + .WithSource(sourceFile) + .WithFixedSource(fixedSource) + .WithExpectedDiagnostic(diagnostic) + .WithDisabledDiagnostic("CS1061") + .Build() + .RunAsync(); + } +} \ No newline at end of file diff --git a/tests/SourceKit.Analyzers.Enumerable.Tests/SourceKit.Analyzers.Enumerable.Tests.csproj b/tests/SourceKit.Analyzers.Enumerable.Tests/SourceKit.Analyzers.Enumerable.Tests.csproj new file mode 100644 index 0000000..c537231 --- /dev/null +++ b/tests/SourceKit.Analyzers.Enumerable.Tests/SourceKit.Analyzers.Enumerable.Tests.csproj @@ -0,0 +1,30 @@ + + + + false + true + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/SourceKit.Analyzers.MustBePartial.Tests/MakeTypePartialCodeFixTests.cs b/tests/SourceKit.Analyzers.MustBePartial.Tests/MakeTypePartialCodeFixTests.cs new file mode 100644 index 0000000..a76228e --- /dev/null +++ b/tests/SourceKit.Analyzers.MustBePartial.Tests/MakeTypePartialCodeFixTests.cs @@ -0,0 +1,40 @@ +using Microsoft.CodeAnalysis.Testing; +using SourceKit.Analyzers.MustBePartial.Analyzers; +using SourceKit.Analyzers.MustBePartial.Annotations; +using SourceKit.Analyzers.MustBePartial.CodeFixes; +using SourceKit.Tests.Common; +using SourceKit.Tests.Common.TestBases; +using Xunit; + +namespace SourceKit.Analyzers.MustBePartial.Tests; + +public class MakeTypePartialCodeFixTests : CodeFixTestBase +{ + [Fact] + public async Task ShouldMakeTypePartial_WhenDiagnosticReported() + { + SourceFile interfaceSource = await SourceFile.LoadAsync( + "SourceKit.Analyzers.MustBePartial.Samples/IPartialBase.cs"); + + SourceFile sourceFile = await SourceFile.LoadAsync( + "SourceKit.Analyzers.MustBePartial.Samples/NonPartialDerivative.cs"); + + string fixedContent = sourceFile.Content.Replace("public class", "public partial class"); + + SourceFile fixedSource = sourceFile with { Content = fixedContent }; + + DiagnosticResult diagnostic = AnalyzerVerifier.Diagnostic(TypeMustBePartialAnalyzer.Descriptor) + .WithLocation(sourceFile.Name, 3, 14) + .WithArguments("NonPartialDerivative"); + + await CodeFixTest + .WithSource(sourceFile) + .WithSource(interfaceSource) + .WithFixedSource(fixedSource) + .WithFixedSource(interfaceSource) + .WithExpectedDiagnostic(diagnostic) + .WithAdditionalReference(typeof(DerivativesMustBePartialAttribute).Assembly) + .Build() + .RunAsync(); + } +} \ No newline at end of file diff --git a/tests/SourceKit.Analyzers.MustBePartial.Tests/SourceKit.Analyzers.MustBePartial.Tests.csproj b/tests/SourceKit.Analyzers.MustBePartial.Tests/SourceKit.Analyzers.MustBePartial.Tests.csproj new file mode 100644 index 0000000..980629f --- /dev/null +++ b/tests/SourceKit.Analyzers.MustBePartial.Tests/SourceKit.Analyzers.MustBePartial.Tests.csproj @@ -0,0 +1,30 @@ + + + + false + true + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/SourceKit.Analyzers.MustBePartial.Tests/TypesMustBePartialAnalyzerTests.cs b/tests/SourceKit.Analyzers.MustBePartial.Tests/TypesMustBePartialAnalyzerTests.cs new file mode 100644 index 0000000..3637d9a --- /dev/null +++ b/tests/SourceKit.Analyzers.MustBePartial.Tests/TypesMustBePartialAnalyzerTests.cs @@ -0,0 +1,47 @@ +using Microsoft.CodeAnalysis.CSharp.Testing; +using Microsoft.CodeAnalysis.Testing; +using Microsoft.CodeAnalysis.Testing.Verifiers; +using SourceKit.Analyzers.MustBePartial.Analyzers; +using SourceKit.Analyzers.MustBePartial.Annotations; +using SourceKit.Tests.Common; +using SourceKit.Tests.Common.TestBases; +using Xunit; + +namespace SourceKit.Analyzers.MustBePartial.Tests; + +public class TypesMustBePartialAnalyzerTests : AnalyzerTestBase +{ + [Fact] + public async Task ShouldReportDiagnostic_WhenTypeIsNotPartial() + { + SourceFile sourceFile = await SourceFile.LoadAsync( + "SourceKit.Analyzers.MustBePartial.Samples/NonPartialDerivative.cs"); + + SourceFile interfaceSource = await SourceFile.LoadAsync( + "SourceKit.Analyzers.MustBePartial.Samples/IPartialBase.cs"); + + DiagnosticResult diagnostic = AnalyzerVerifier + .Diagnostic(TypeMustBePartialAnalyzer.Descriptor) + .WithLocation(sourceFile.Name, 3, 14) + .WithArguments("NonPartialDerivative"); + + await AnalyzerTest + .WithSource(sourceFile) + .WithSource(interfaceSource) + .WithAdditionalReference(typeof(DerivativesMustBePartialAttribute).Assembly) + .WithExpectedDiagnostic(diagnostic) + .Build() + .RunAsync(); + } + + [Fact] + public async Task ShouldReportNoDiagnostic_WhenTypeIsPartial() + { + await AnalyzerTest + .WithSource(await SourceFile.LoadAsync("SourceKit.Analyzers.MustBePartial.Samples/PartialDerivative.cs")) + .WithSource(await SourceFile.LoadAsync("SourceKit.Analyzers.MustBePartial.Samples/IPartialBase.cs")) + .WithAdditionalReference(typeof(DerivativesMustBePartialAttribute).Assembly) + .Build() + .RunAsync(); + } +} \ No newline at end of file diff --git a/tests/SourceKit.Analyzers.Nullable.Tests/NullForgivingOperatorNotAllowedTests.cs b/tests/SourceKit.Analyzers.Nullable.Tests/NullForgivingOperatorNotAllowedTests.cs new file mode 100644 index 0000000..5c14cb9 --- /dev/null +++ b/tests/SourceKit.Analyzers.Nullable.Tests/NullForgivingOperatorNotAllowedTests.cs @@ -0,0 +1,57 @@ +using SourceKit.Analyzers.Nullable.Analyzers; +using SourceKit.Tests.Common; +using SourceKit.Tests.Common.TestBases; +using Xunit; + +namespace SourceKit.Analyzers.Nullable.Tests; + +public class NullForgivingOperatorNotAllowedTests : AnalyzerTestBase +{ + [Fact] + public async Task ShouldReportDiagnostic_AllVariationsOfNullSuppression() + { + SourceFile sourceFile = await SourceFile.LoadAsync( + "SourceKit.Analyzers.Nullable.Samples/NullForgivingOperatorNotAllowed/JokeExample.cs"); + + await AnalyzerTest + .WithSource(sourceFile) + .WithExpectedDiagnostic( + AnalyzerVerifier + .Diagnostic(NullForgivingOperatorNotAllowedAnalyzer.Descriptor) + .WithSpan(sourceFile.Name, 34, 36, 34, 65)) + .WithExpectedDiagnostic( + AnalyzerVerifier + .Diagnostic(NullForgivingOperatorNotAllowedAnalyzer.Descriptor) + .WithSpan(sourceFile.Name, 36, 35, 36, 68)) + .WithExpectedDiagnostic( + AnalyzerVerifier + .Diagnostic(NullForgivingOperatorNotAllowedAnalyzer.Descriptor) + .WithSpan(sourceFile.Name, 38, 47, 38, 97)) + .WithExpectedDiagnostic( + AnalyzerVerifier + .Diagnostic(NullForgivingOperatorNotAllowedAnalyzer.Descriptor) + .WithSpan(sourceFile.Name, 39, 45, 39, 95)) + .WithExpectedDiagnostic( + AnalyzerVerifier + .Diagnostic(NullForgivingOperatorNotAllowedAnalyzer.Descriptor) + .WithSpan(sourceFile.Name, 40, 46, 40, 75)) + .WithExpectedDiagnostic( + AnalyzerVerifier + .Diagnostic(NullForgivingOperatorNotAllowedAnalyzer.Descriptor) + .WithSpan(sourceFile.Name, 42, 55, 42, 105)) + .WithExpectedDiagnostic( + AnalyzerVerifier + .Diagnostic(NullForgivingOperatorNotAllowedAnalyzer.Descriptor) + .WithSpan(sourceFile.Name, 43, 52, 43, 85)) + .WithExpectedDiagnostic( + AnalyzerVerifier + .Diagnostic(NullForgivingOperatorNotAllowedAnalyzer.Descriptor) + .WithSpan(sourceFile.Name, 46, 13, 46, 63)) + .WithExpectedDiagnostic( + AnalyzerVerifier + .Diagnostic(NullForgivingOperatorNotAllowedAnalyzer.Descriptor) + .WithSpan(sourceFile.Name, 48, 13, 48, 67)) + .Build() + .RunAsync(); + } +} \ No newline at end of file diff --git a/tests/SourceKit.Analyzers.Nullable.Tests/NullableDisableNotAllowedTests.cs b/tests/SourceKit.Analyzers.Nullable.Tests/NullableDisableNotAllowedTests.cs new file mode 100644 index 0000000..c13fbe9 --- /dev/null +++ b/tests/SourceKit.Analyzers.Nullable.Tests/NullableDisableNotAllowedTests.cs @@ -0,0 +1,61 @@ +using Microsoft.CodeAnalysis.Testing; +using SourceKit.Analyzers.Nullable.Analyzers; +using SourceKit.Tests.Common; +using SourceKit.Tests.Common.TestBases; +using Xunit; + +namespace SourceKit.Analyzers.Nullable.Tests; + +public class NullableDisableNotAllowedTests : AnalyzerTestBase +{ + [Fact] + public async Task ShouldReportDiagnostic_WhenNullableDisableIsUsed() + { + SourceFile sourceFile = await SourceFile.LoadAsync( + "SourceKit.Analyzers.Nullable.Samples/NullableDisableNotAllowed/NullableDisable.cs"); + + DiagnosticResult diagnostic = AnalyzerVerifier + .Diagnostic(NullableDisableNotAllowedAnalyzer.Descriptor) + .WithLocation(sourceFile.Name, 1, 1); + + await AnalyzerTest + .WithSource(sourceFile) + .WithExpectedDiagnostic(diagnostic) + .Build() + .RunAsync(); + } + + [Fact] + public async Task ShouldReportNoDiagnostic_WhenNullableEnableIsUsed() + { + SourceFile sourceFile = await SourceFile.LoadAsync( + "SourceKit.Analyzers.Nullable.Samples/NullableDisableNotAllowed/NullableEnable.cs"); + + await AnalyzerTest + .WithSource(sourceFile) + .Build() + .RunAsync(); + } + + [Fact] + public async Task NullableDisableNotAllowed_ShouldReport2Diagnostics_WhenNullableDisableIsUsedTwice() + { + SourceFile sourceFile = await SourceFile.LoadAsync( + "SourceKit.Analyzers.Nullable.Samples/NullableDisableNotAllowed/MultipleNestedNullableDisable.cs"); + + DiagnosticResult diagnostic1 = AnalyzerVerifier + .Diagnostic(NullableDisableNotAllowedAnalyzer.Descriptor) + .WithLocation(sourceFile.Name, 1, 1); + + DiagnosticResult diagnostic2 = AnalyzerVerifier + .Diagnostic(NullableDisableNotAllowedAnalyzer.Descriptor) + .WithLocation(sourceFile.Name, 18, 21); + + await AnalyzerTest + .WithSource(sourceFile) + .WithExpectedDiagnostic(diagnostic1) + .WithExpectedDiagnostic(diagnostic2) + .Build() + .RunAsync(); + } +} \ No newline at end of file diff --git a/tests/SourceKit.Analyzers.Nullable.Tests/PropagateNullableCorrectlyCodeFixTests.cs b/tests/SourceKit.Analyzers.Nullable.Tests/PropagateNullableCorrectlyCodeFixTests.cs new file mode 100644 index 0000000..377f23e --- /dev/null +++ b/tests/SourceKit.Analyzers.Nullable.Tests/PropagateNullableCorrectlyCodeFixTests.cs @@ -0,0 +1,202 @@ +using SourceKit.Analyzers.Nullable.Analyzers; +using SourceKit.Analyzers.Nullable.CodeFixes; +using SourceKit.Tests.Common; +using SourceKit.Tests.Common.TestBases; +using Xunit; + +namespace SourceKit.Analyzers.Nullable.Tests; + +public class PropagateNullableCorrectlyCodeFixTests : CodeFixTestBase< + NullForgivingOperatorNotAllowedAnalyzer, + PropagateNullableCorrectlyCodeFixProvider> +{ + [Fact] + public async Task ShouldParseAllSequencesAndChangeTypeOfVariables() + { + SourceFile sourceFile = await SourceFile.LoadAsync( + "SourceKit.Analyzers.Nullable.Samples/PropagateNullCorrectly/JokeExampleWithVariableDeclarations.cs"); + + SourceFile fixedSource = sourceFile with + { + Content = """ + namespace SourceKit.Analyzers.Nullable.Samples.PropagateNullCorrectly; + + public class JokeExampleWithVariableDeclarations + { + public string? GetJoke(int number) + { + switch (number) + { + case 1: + return "Lol"; + case 2: + return "Kek"; + case 3: + return "Trololo"; + default: + return null; + } + } + + public static JokeExampleWithVariableDeclarations? GetJokeClass(int number) + { + if (number == 0) + { + return new JokeExampleWithVariableDeclarations(); + } + else + { + return null; + } + } + + public static string GetUpperJoke(int instanceNumber, int jokeNumber) + { + JokeExampleWithVariableDeclarations? jokeInstance = GetJokeClass(instanceNumber); + + string? jokeFromInstance = jokeInstance.GetJoke(jokeNumber); + + var jokeFromSequenceNothingNullable = GetJokeClass(instanceNumber)?.GetJoke(jokeNumber); + var jokeFromSequenceFirstNullable = GetJokeClass(instanceNumber)?.GetJoke(jokeNumber); + var jokeFromSequenceSecondNullable = GetJokeClass(instanceNumber)?.GetJoke(jokeNumber); + + string? upperJokeFromSequenceNothingNullable = GetJokeClass(instanceNumber)?.GetJoke(jokeNumber)?.ToUpper(); + string? upperJokeFromSequenceFromInstance = jokeInstance.GetJoke(jokeNumber)?.ToUpper(); + + var upperJokeFirstCringeCompilation = + GetJokeClass(instanceNumber)?.GetJoke(jokeNumber)?.ToUpper().ToUpper().ToUpper(); + var upperJokeSecondCringeCompilation = + jokeInstance.GetJoke(jokeNumber)?.ToUpper().ToUpper()?.ToUpper(); + + return upperJokeFirstCringeCompilation; + } + } + """, + }; + + await CodeFixTest + .WithSource(sourceFile) + .WithFixedSource(fixedSource) + .WithExpectedDiagnostic( + AnalyzerVerifier + .Diagnostic(NullForgivingOperatorNotAllowedAnalyzer.Descriptor) + .WithSpan(sourceFile.Name, 34, 60, 34, 89)) + .WithExpectedDiagnostic( + AnalyzerVerifier + .Diagnostic(NullForgivingOperatorNotAllowedAnalyzer.Descriptor) + .WithSpan(sourceFile.Name, 36, 35, 36, 68)) + .WithExpectedDiagnostic( + AnalyzerVerifier + .Diagnostic(NullForgivingOperatorNotAllowedAnalyzer.Descriptor) + .WithSpan(sourceFile.Name, 38, 47, 38, 97)) + .WithExpectedDiagnostic( + AnalyzerVerifier + .Diagnostic(NullForgivingOperatorNotAllowedAnalyzer.Descriptor) + .WithSpan(sourceFile.Name, 39, 45, 39, 95)) + .WithExpectedDiagnostic( + AnalyzerVerifier + .Diagnostic(NullForgivingOperatorNotAllowedAnalyzer.Descriptor) + .WithSpan(sourceFile.Name, 40, 46, 40, 75)) + .WithExpectedDiagnostic( + AnalyzerVerifier + .Diagnostic(NullForgivingOperatorNotAllowedAnalyzer.Descriptor) + .WithSpan(sourceFile.Name, 42, 55, 42, 105)) + .WithExpectedDiagnostic( + AnalyzerVerifier + .Diagnostic(NullForgivingOperatorNotAllowedAnalyzer.Descriptor) + .WithSpan(sourceFile.Name, 43, 52, 43, 85)) + .WithExpectedDiagnostic( + AnalyzerVerifier + .Diagnostic(NullForgivingOperatorNotAllowedAnalyzer.Descriptor) + .WithSpan(sourceFile.Name, 46, 13, 46, 63)) + .WithExpectedDiagnostic( + AnalyzerVerifier + .Diagnostic(NullForgivingOperatorNotAllowedAnalyzer.Descriptor) + .WithSpan(sourceFile.Name, 48, 13, 48, 67)) + .Build() + .RunAsync(); + } + + [Fact] + public async Task PropagateNullableCorrectlyCodeFix_ShouldChangeTypeOfFieldAndProperties() + { + SourceFile sourceFile = await SourceFile.LoadAsync( + "SourceKit.Analyzers.Nullable.Samples/PropagateNullCorrectly/JokeExampleWithFieldAndProperties.cs"); + + SourceFile fixedSource = sourceFile with + { + Content = """ + namespace SourceKit.Analyzers.Nullable.Samples.PropagateNullCorrectly; + + public class JokeExampleWithFieldAndProperties + { + private JokeExampleWithFieldAndProperties? _jokeInstance = GetJokeClass(0); + + public string? FirstJoke + { + get => _jokeInstance.GetJoke(1); + } + + public string? SecondJoke + { + get + { + return _jokeInstance.GetJoke(2); + } + } + + public string? ThirdJoke => _jokeInstance.GetJoke(3); + + public string? GetJoke(int number) + { + switch (number) + { + case 1: + return "Lol"; + case 2: + return "Kek"; + case 3: + return "Trololo"; + default: + return null; + } + } + + public static JokeExampleWithFieldAndProperties? GetJokeClass(int number) + { + if (number == 0) + { + return new JokeExampleWithFieldAndProperties(); + } + else + { + return null; + } + } + } + """, + }; + + await CodeFixTest + .WithSource(sourceFile) + .WithFixedSource(fixedSource) + .WithExpectedDiagnostic( + AnalyzerVerifier + .Diagnostic(NullForgivingOperatorNotAllowedAnalyzer.Descriptor) + .WithSpan(sourceFile.Name, 5, 63, 5, 79)) + .WithExpectedDiagnostic( + AnalyzerVerifier + .Diagnostic(NullForgivingOperatorNotAllowedAnalyzer.Descriptor) + .WithSpan(sourceFile.Name, 9, 16, 9, 41)) + .WithExpectedDiagnostic( + AnalyzerVerifier + .Diagnostic(NullForgivingOperatorNotAllowedAnalyzer.Descriptor) + .WithSpan(sourceFile.Name, 16, 20, 16, 45)) + .WithExpectedDiagnostic( + AnalyzerVerifier + .Diagnostic(NullForgivingOperatorNotAllowedAnalyzer.Descriptor) + .WithSpan(sourceFile.Name, 20, 32, 20, 57)) + .Build() + .RunAsync(); + } +} \ No newline at end of file diff --git a/tests/SourceKit.Analyzers.Nullable.Tests/SourceKit.Analyzers.Nullable.Tests.csproj b/tests/SourceKit.Analyzers.Nullable.Tests/SourceKit.Analyzers.Nullable.Tests.csproj new file mode 100644 index 0000000..370832a --- /dev/null +++ b/tests/SourceKit.Analyzers.Nullable.Tests/SourceKit.Analyzers.Nullable.Tests.csproj @@ -0,0 +1,30 @@ + + + + false + true + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/SourceKit.Analyzers.Properties.Tests/ConvertDeclarationIntoPropertyCodeFixTests.cs b/tests/SourceKit.Analyzers.Properties.Tests/ConvertDeclarationIntoPropertyCodeFixTests.cs new file mode 100644 index 0000000..3f7c363 --- /dev/null +++ b/tests/SourceKit.Analyzers.Properties.Tests/ConvertDeclarationIntoPropertyCodeFixTests.cs @@ -0,0 +1,253 @@ +using Microsoft.CodeAnalysis.Testing; +using SourceKit.Analyzers.Properties.Analyzers; +using SourceKit.Analyzers.Properties.CodeFixes; +using SourceKit.Tests.Common; +using SourceKit.Tests.Common.TestBases; +using Xunit; + +namespace SourceKit.Analyzers.Properties.Tests; + +public class ConvertDeclarationIntoPropertyCodeFixTests : CodeFixTestBase< + DeclarationCouldBeConvertedToPropertyAnalyzer, + ConvertDeclarationIntoPropertyCodeFixProvider> +{ + [Fact] + public async Task ShouldGenerateProperty_WhenSingleFieldPubliclyDeclared() + { + SourceFile sourceFile = await SourceFile.LoadAsync( + "SourceKit.Analyzers.Properties.Samples/DeclarationCouldBeConvertedToProperty/OnePublicField.cs"); + + var fixedFile = new SourceFile( + Name: "OnePublicField.cs", + Content: """ + namespace SourceKit.Analyzers.Properties.Samples.DeclarationCouldBeConvertedToProperty; + + public class OnePublicField + { + public string Field { get; set; } + } + """); + + DiagnosticResult diagnostic = AnalyzerVerifier + .Diagnostic(DeclarationCouldBeConvertedToPropertyAnalyzer.Descriptor) + .WithLocation(sourceFile.Name, 5, 19) + .WithLocation(sourceFile.Name, 5, 19) + .WithMessage(string.Format(DeclarationCouldBeConvertedToPropertyAnalyzer.Format, "field")); + + await CodeFixTest + .WithSource(sourceFile) + .WithExpectedDiagnostic(diagnostic) + .WithFixedSource(fixedFile) + .Build() + .RunAsync(); + } + + [Fact] + public async Task ShouldGenerateProperties_WhenMultipleFieldsPubliclyDeclared() + { + SourceFile sourceFile = await SourceFile.LoadAsync( + "SourceKit.Analyzers.Properties.Samples/DeclarationCouldBeConvertedToProperty/ManyPublicFields.cs"); + + var fixedFile = new SourceFile( + Name: "ManyPublicFields.cs", + Content: """ + using System.Collections.Generic; + + namespace SourceKit.Analyzers.Properties.Samples.DeclarationCouldBeConvertedToProperty; + + public class ManyPublicFields + { + public List First { get; set; } + public List Second { get; set; } + } + """); + + DiagnosticResult diagnostic1 = AnalyzerVerifier + .Diagnostic(DeclarationCouldBeConvertedToPropertyAnalyzer.Descriptor) + .WithLocation(sourceFile.Name, 7, 25) + .WithLocation(sourceFile.Name, 7, 25) + .WithMessage(string.Format(DeclarationCouldBeConvertedToPropertyAnalyzer.Format, "first")); + + DiagnosticResult diagnostic2 = AnalyzerVerifier + .Diagnostic(DeclarationCouldBeConvertedToPropertyAnalyzer.Descriptor) + .WithLocation(sourceFile.Name, 7, 32) + .WithLocation(sourceFile.Name, 7, 32) + .WithMessage(string.Format(DeclarationCouldBeConvertedToPropertyAnalyzer.Format, "second")); + + await CodeFixTest + .WithSource(sourceFile) + .WithExpectedDiagnostic(diagnostic1) + .WithExpectedDiagnostic(diagnostic2) + .WithFixedSource(fixedFile) + .WithIterationNumber(2) + .Build() + .RunAsync(); + } + + [Fact] + public async Task ShouldGenerateProperty_WhenPrivateFieldWithGetterAndSetterDeclared() + { + SourceFile sourceFile = await SourceFile.LoadAsync( + "SourceKit.Analyzers.Properties.Samples/DeclarationCouldBeConvertedToProperty/OneField.cs"); + + var fixedFile = new SourceFile( + Name: "OneField.cs", + Content: """ + namespace SourceKit.Analyzers.Properties.Samples.DeclarationCouldBeConvertedToProperty; + + public class OneField + { + public string Field { get; set; } = "10"; + } + """); + + DiagnosticResult diagnostic1 = AnalyzerVerifier + .Diagnostic(DeclarationCouldBeConvertedToPropertyAnalyzer.Descriptor) + .WithLocation(sourceFile.Name, 5, 20) + .WithLocation(sourceFile.Name, 5, 20) + .WithLocation(sourceFile.Name, 3, 1) + .WithMessage(string.Format(DeclarationCouldBeConvertedToPropertyAnalyzer.Format, "field")); + + DiagnosticResult diagnostic2 = AnalyzerVerifier + .Diagnostic(DeclarationCouldBeConvertedToPropertyAnalyzer.Descriptor) + .WithLocation(sourceFile.Name, 7, 19) + .WithLocation(sourceFile.Name, 5, 20) + .WithLocation(sourceFile.Name, 3, 1) + .WithMessage(string.Format(DeclarationCouldBeConvertedToPropertyAnalyzer.Format, "field")); + + DiagnosticResult diagnostic3 = AnalyzerVerifier + .Diagnostic(DeclarationCouldBeConvertedToPropertyAnalyzer.Descriptor) + .WithLocation(sourceFile.Name, 12, 17) + .WithLocation(sourceFile.Name, 5, 20) + .WithLocation(sourceFile.Name, 3, 1) + .WithMessage(string.Format(DeclarationCouldBeConvertedToPropertyAnalyzer.Format, "field")); + + await CodeFixTest + .WithSource(sourceFile) + .WithExpectedDiagnostic(diagnostic1) + .WithExpectedDiagnostic(diagnostic2) + .WithExpectedDiagnostic(diagnostic3) + .WithFixedSource(fixedFile) + .Build() + .RunAsync(); + } + + [Fact] + public async Task ShouldGenerateCorrectPropertyName_WhenFieldHasUnderscorePrefix() + { + SourceFile sourceFile = await SourceFile.LoadAsync( + "SourceKit.Analyzers.Properties.Samples/DeclarationCouldBeConvertedToProperty/UnderscoreNameField.cs"); + + var fixedFile = new SourceFile( + Name: "UnderscoreNameField.cs", + Content: """ + namespace SourceKit.Analyzers.Properties.Samples.DeclarationCouldBeConvertedToProperty; + + public class UnderscoreNameField + { + public string Field { get; } + } + """); + + DiagnosticResult diagnostic1 = AnalyzerVerifier + .Diagnostic(DeclarationCouldBeConvertedToPropertyAnalyzer.Descriptor) + .WithLocation(sourceFile.Name, 5, 29) + .WithLocation(sourceFile.Name, 5, 29) + .WithLocation(sourceFile.Name, 3, 1) + .WithMessage(string.Format(DeclarationCouldBeConvertedToPropertyAnalyzer.Format, "_field")); + + DiagnosticResult diagnostic2 = AnalyzerVerifier + .Diagnostic(DeclarationCouldBeConvertedToPropertyAnalyzer.Descriptor) + .WithLocation(sourceFile.Name, 7, 19) + .WithLocation(sourceFile.Name, 5, 29) + .WithLocation(sourceFile.Name, 3, 1) + .WithMessage(string.Format(DeclarationCouldBeConvertedToPropertyAnalyzer.Format, "_field")); + + await CodeFixTest + .WithSource(sourceFile) + .WithExpectedDiagnostic(diagnostic1) + .WithExpectedDiagnostic(diagnostic2) + .WithFixedSource(fixedFile) + .Build() + .RunAsync(); + } + + [Fact] + public async Task ShouldGenerateCorrectProperty_WhenGetterAndSetterMethodsAreExpressionBodied() + { + SourceFile sourceFile = await SourceFile.LoadAsync( + "SourceKit.Analyzers.Properties.Samples/DeclarationCouldBeConvertedToProperty/ExpressionBodyMethodsField.cs"); + + var fixedFile = new SourceFile( + Name: "ExpressionBodyMethodsField.cs", + Content: """ + namespace SourceKit.Analyzers.Properties.Samples.DeclarationCouldBeConvertedToProperty; + + public class ExpressionBodyMethodsField + { + public string Field { get; protected internal set; } + } + """); + + DiagnosticResult diagnostic1 = AnalyzerVerifier + .Diagnostic(DeclarationCouldBeConvertedToPropertyAnalyzer.Descriptor) + .WithLocation(sourceFile.Name, 5, 20) + .WithLocation(sourceFile.Name, 5, 20) + .WithLocation(sourceFile.Name, 3, 1) + .WithMessage(string.Format(DeclarationCouldBeConvertedToPropertyAnalyzer.Format, "field")); + + DiagnosticResult diagnostic2 = AnalyzerVerifier + .Diagnostic(DeclarationCouldBeConvertedToPropertyAnalyzer.Descriptor) + .WithLocation(sourceFile.Name, 7, 19) + .WithLocation(sourceFile.Name, 5, 20) + .WithLocation(sourceFile.Name, 3, 1) + .WithMessage(string.Format(DeclarationCouldBeConvertedToPropertyAnalyzer.Format, "field")); + + DiagnosticResult diagnostic3 = AnalyzerVerifier + .Diagnostic(DeclarationCouldBeConvertedToPropertyAnalyzer.Descriptor) + .WithLocation(sourceFile.Name, 9, 29) + .WithLocation(sourceFile.Name, 5, 20) + .WithLocation(sourceFile.Name, 3, 1) + .WithMessage(string.Format(DeclarationCouldBeConvertedToPropertyAnalyzer.Format, "field")); + + await CodeFixTest + .WithSource(sourceFile) + .WithExpectedDiagnostic(diagnostic1) + .WithExpectedDiagnostic(diagnostic2) + .WithExpectedDiagnostic(diagnostic3) + .WithFixedSource(fixedFile) + .Build() + .RunAsync(); + } + + [Fact] + public async Task ShouldGenerateGetOnlyProperty_WhenPublicFieldIsReadonly() + { + SourceFile sourceFile = await SourceFile.LoadAsync( + "SourceKit.Analyzers.Properties.Samples/DeclarationCouldBeConvertedToProperty/ReadonlyPublicField.cs"); + + var fixedFile = new SourceFile( + Name: "ReadonlyPublicField.cs", + Content: """ + namespace SourceKit.Analyzers.Properties.Samples.DeclarationCouldBeConvertedToProperty; + + public class ReadonlyPublicField + { + public string Field { get; } + } + """); + + DiagnosticResult diagnostic = AnalyzerVerifier + .Diagnostic(DeclarationCouldBeConvertedToPropertyAnalyzer.Descriptor) + .WithLocation(sourceFile.Name, 5, 28) + .WithLocation(sourceFile.Name, 5, 28) + .WithMessage(string.Format(DeclarationCouldBeConvertedToPropertyAnalyzer.Format, "field")); + + await CodeFixTest + .WithSource(sourceFile) + .WithExpectedDiagnostic(diagnostic) + .WithFixedSource(fixedFile) + .Build() + .RunAsync(); + } +} \ No newline at end of file diff --git a/tests/SourceKit.Analyzers.Properties.Tests/DeclarationCouldBeConvertedToPropertyTests.cs b/tests/SourceKit.Analyzers.Properties.Tests/DeclarationCouldBeConvertedToPropertyTests.cs new file mode 100644 index 0000000..72e5fa2 --- /dev/null +++ b/tests/SourceKit.Analyzers.Properties.Tests/DeclarationCouldBeConvertedToPropertyTests.cs @@ -0,0 +1,199 @@ +using Microsoft.CodeAnalysis.Testing; +using SourceKit.Analyzers.Properties.Analyzers; +using SourceKit.Tests.Common; +using SourceKit.Tests.Common.TestBases; +using Xunit; + +namespace SourceKit.Analyzers.Properties.Tests; + +public class DeclarationCouldBeConvertedToPropertyTests : AnalyzerTestBase< + DeclarationCouldBeConvertedToPropertyAnalyzer> +{ + [Fact] + public async Task ShouldReportNoDiagnostic_WhenPublicPropertyDeclared() + { + SourceFile sourceFile = await SourceFile.LoadAsync( + "SourceKit.Analyzers.Properties.Samples/DeclarationCouldBeConvertedToProperty/PublicProperty.cs"); + + await AnalyzerTest + .WithSource(sourceFile) + .Build() + .RunAsync(); + } + + [Fact] + public async Task ShouldReportNoDiagnostic_WhenPrivateFieldWithNoGetterAndSetterDeclared() + { + SourceFile sourceFile = await SourceFile.LoadAsync( + "SourceKit.Analyzers.Properties.Samples/DeclarationCouldBeConvertedToProperty/PrivateFieldWithoutMethods.cs"); + + await AnalyzerTest + .WithSource(sourceFile) + .Build() + .RunAsync(); + } + + [Fact] + public async Task ShouldReportDiagnostic_WhenPublicFieldDeclared() + { + SourceFile sourceFile = await SourceFile.LoadAsync( + "SourceKit.Analyzers.Properties.Samples/DeclarationCouldBeConvertedToProperty/OnePublicField.cs"); + + DiagnosticResult diagnostic = AnalyzerVerifier + .Diagnostic(DeclarationCouldBeConvertedToPropertyAnalyzer.Descriptor) + .WithLocation(sourceFile.Name, 5, 19) + .WithLocation(sourceFile.Name, 5, 19) + .WithMessage(string.Format(DeclarationCouldBeConvertedToPropertyAnalyzer.Format, "field")); + + await AnalyzerTest + .WithSource(sourceFile) + .WithExpectedDiagnostic(diagnostic) + .Build() + .RunAsync(); + } + + [Fact] + public async Task ShouldReportDiagnotics_WhenMultiplePublicFieldDeclared() + { + SourceFile sourceFile = await SourceFile.LoadAsync( + "SourceKit.Analyzers.Properties.Samples/DeclarationCouldBeConvertedToProperty/ManyPublicFields.cs"); + + DiagnosticResult diagnostic1 = AnalyzerVerifier + .Diagnostic(DeclarationCouldBeConvertedToPropertyAnalyzer.Descriptor) + .WithLocation(sourceFile.Name, 7, 25) + .WithLocation(sourceFile.Name, 7, 25) + .WithMessage(string.Format(DeclarationCouldBeConvertedToPropertyAnalyzer.Format, "first")); + + DiagnosticResult diagnostic2 = AnalyzerVerifier + .Diagnostic(DeclarationCouldBeConvertedToPropertyAnalyzer.Descriptor) + .WithLocation(sourceFile.Name, 7, 32) + .WithLocation(sourceFile.Name, 7, 32) + .WithMessage(string.Format(DeclarationCouldBeConvertedToPropertyAnalyzer.Format, "second")); + + await AnalyzerTest + .WithSource(sourceFile) + .WithExpectedDiagnostic(diagnostic1) + .WithExpectedDiagnostic(diagnostic2) + .Build() + .RunAsync(); + } + + [Fact] + public async Task ShouldReportDiagnostic_WhenPrivateFieldWithGetterAndSetterDeclared() + { + SourceFile sourceFile = await SourceFile.LoadAsync( + "SourceKit.Analyzers.Properties.Samples/DeclarationCouldBeConvertedToProperty/OneField.cs"); + + DiagnosticResult diagnostic1 = AnalyzerVerifier + .Diagnostic(DeclarationCouldBeConvertedToPropertyAnalyzer.Descriptor) + .WithLocation(sourceFile.Name, 5, 20) + .WithLocation(sourceFile.Name, 5, 20) + .WithLocation(sourceFile.Name, 3, 1) + .WithMessage(string.Format(DeclarationCouldBeConvertedToPropertyAnalyzer.Format, "field")); + + DiagnosticResult diagnostic2 = AnalyzerVerifier + .Diagnostic(DeclarationCouldBeConvertedToPropertyAnalyzer.Descriptor) + .WithLocation(sourceFile.Name, 7, 19) + .WithLocation(sourceFile.Name, 5, 20) + .WithLocation(sourceFile.Name, 3, 1) + .WithMessage(string.Format(DeclarationCouldBeConvertedToPropertyAnalyzer.Format, "field")); + + DiagnosticResult diagnostic3 = AnalyzerVerifier + .Diagnostic(DeclarationCouldBeConvertedToPropertyAnalyzer.Descriptor) + .WithLocation(sourceFile.Name, 12, 17) + .WithLocation(sourceFile.Name, 5, 20) + .WithLocation(sourceFile.Name, 3, 1) + .WithMessage(string.Format(DeclarationCouldBeConvertedToPropertyAnalyzer.Format, "field")); + + await AnalyzerTest + .WithSource(sourceFile) + .WithExpectedDiagnostic(diagnostic1) + .WithExpectedDiagnostic(diagnostic2) + .WithExpectedDiagnostic(diagnostic3) + .Build() + .RunAsync(); + } + + [Fact] + public async Task ShouldReportDiagnostic_WhenFieldHasUnderscorePrefix() + { + SourceFile sourceFile = await SourceFile.LoadAsync( + "SourceKit.Analyzers.Properties.Samples/DeclarationCouldBeConvertedToProperty/UnderscoreNameField.cs"); + + DiagnosticResult diagnostic1 = AnalyzerVerifier + .Diagnostic(DeclarationCouldBeConvertedToPropertyAnalyzer.Descriptor) + .WithLocation(sourceFile.Name, 5, 29) + .WithLocation(sourceFile.Name, 5, 29) + .WithLocation(sourceFile.Name, 3, 1) + .WithMessage(string.Format(DeclarationCouldBeConvertedToPropertyAnalyzer.Format, "_field")); + + DiagnosticResult diagnostic2 = AnalyzerVerifier + .Diagnostic(DeclarationCouldBeConvertedToPropertyAnalyzer.Descriptor) + .WithLocation(sourceFile.Name, 7, 19) + .WithLocation(sourceFile.Name, 5, 29) + .WithLocation(sourceFile.Name, 3, 1) + .WithMessage(string.Format(DeclarationCouldBeConvertedToPropertyAnalyzer.Format, "_field")); + + await AnalyzerTest + .WithSource(sourceFile) + .WithExpectedDiagnostic(diagnostic1) + .WithExpectedDiagnostic(diagnostic2) + .Build() + .RunAsync(); + } + + [Fact] + public async Task ShouldReportDiagnostic_WhenGetterAndSetterMethodsHasExpressionBody() + { + SourceFile sourceFile = await SourceFile.LoadAsync( + "SourceKit.Analyzers.Properties.Samples/DeclarationCouldBeConvertedToProperty/ExpressionBodyMethodsField.cs"); + + DiagnosticResult diagnostic1 = AnalyzerVerifier + .Diagnostic(DeclarationCouldBeConvertedToPropertyAnalyzer.Descriptor) + .WithLocation(sourceFile.Name, 5, 20) + .WithLocation(sourceFile.Name, 5, 20) + .WithLocation(sourceFile.Name, 3, 1) + .WithMessage(string.Format(DeclarationCouldBeConvertedToPropertyAnalyzer.Format, "field")); + + DiagnosticResult diagnostic2 = AnalyzerVerifier + .Diagnostic(DeclarationCouldBeConvertedToPropertyAnalyzer.Descriptor) + .WithLocation(sourceFile.Name, 7, 19) + .WithLocation(sourceFile.Name, 5, 20) + .WithLocation(sourceFile.Name, 3, 1) + .WithMessage(string.Format(DeclarationCouldBeConvertedToPropertyAnalyzer.Format, "field")); + + DiagnosticResult diagnostic3 = AnalyzerVerifier + .Diagnostic(DeclarationCouldBeConvertedToPropertyAnalyzer.Descriptor) + .WithLocation(sourceFile.Name, 9, 29) + .WithLocation(sourceFile.Name, 5, 20) + .WithLocation(sourceFile.Name, 3, 1) + .WithMessage(string.Format(DeclarationCouldBeConvertedToPropertyAnalyzer.Format, "field")); + + await AnalyzerTest + .WithSource(sourceFile) + .WithExpectedDiagnostic(diagnostic1) + .WithExpectedDiagnostic(diagnostic2) + .WithExpectedDiagnostic(diagnostic3) + .Build() + .RunAsync(); + } + + [Fact] + public async Task ShouldReportDiagnostic_WhenPublicReadonlyFieldDeclared() + { + SourceFile sourceFile = await SourceFile.LoadAsync( + "SourceKit.Analyzers.Properties.Samples/DeclarationCouldBeConvertedToProperty/ReadonlyPublicField.cs"); + + DiagnosticResult diagnostic = AnalyzerVerifier + .Diagnostic(DeclarationCouldBeConvertedToPropertyAnalyzer.Descriptor) + .WithLocation(sourceFile.Name, 5, 28) + .WithLocation(sourceFile.Name, 5, 28) + .WithMessage(string.Format(DeclarationCouldBeConvertedToPropertyAnalyzer.Format, "field")); + + await AnalyzerTest + .WithSource(sourceFile) + .WithExpectedDiagnostic(diagnostic) + .Build() + .RunAsync(); + } +} \ No newline at end of file diff --git a/tests/SourceKit.Analyzers.Properties.Tests/SourceKit.Analyzers.Properties.Tests.csproj b/tests/SourceKit.Analyzers.Properties.Tests/SourceKit.Analyzers.Properties.Tests.csproj new file mode 100644 index 0000000..63d98c1 --- /dev/null +++ b/tests/SourceKit.Analyzers.Properties.Tests/SourceKit.Analyzers.Properties.Tests.csproj @@ -0,0 +1,30 @@ + + + + false + true + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/SourceKit.Generators.Builder.Tests/BuilderSourceGeneratorTests.cs b/tests/SourceKit.Generators.Builder.Tests/BuilderSourceGeneratorTests.cs new file mode 100644 index 0000000..69e4180 --- /dev/null +++ b/tests/SourceKit.Generators.Builder.Tests/BuilderSourceGeneratorTests.cs @@ -0,0 +1,232 @@ +using SourceKit.Generators.Builder.Annotations; +using SourceKit.Generators.Builder.Generators; +using SourceKit.Tests.Common; +using SourceKit.Tests.Common.TestBases; +using Xunit; + +namespace SourceKit.Generators.Builder.Tests; + +public class BuilderSourceGeneratorTests : GeneratorTestBase +{ + [Fact] + public async Task ShouldGenerateCorrectBuilderType() + { + SourceFile sourceFile = await SourceFile.LoadAsync("SourceKit.Generators.Builder.Samples/SomeQuery.cs"); + + var generatedSource = new SourceFile( + Name: """ + SourceKit.Generators.Builder/SourceKit.Generators.Builder.Generators.BuilderSourceGenerator/SomeQuery.SourceKit.Generation.Builder.g.cs + """, + Content: """ + // + // This code was generated by a SourceKit.Generators.Builder code generator. + // https://github.com/itmo-is-dev/SourceKit + // + #pragma warning disable CS1591 + using SourceKit.Generators.Builder.Annotations; + using System; + using System.Collections.Generic; + using System.Linq; + + namespace SourceKit.Generators.Builder.Samples + { + public partial record SomeQuery + { + public static SomeQuery Build(Func action) + { + return action(new Builder()).Build(); + } + + public sealed class Builder + { + private readonly List _ids; + private Int32 _count; + private Nullable _orderById; + public Builder() + { + _ids = new List(); + _count = default; + _orderById = default; + } + + [InitializesPropertyAttribute(nameof(Ids))] + public Builder WithId(Guid element) + { + _ids.Add(element); + return this; + } + + [InitializesPropertyAttribute(nameof(Ids))] + public Builder WithIds(IEnumerable elements) + { + _ids.AddRange(elements); + return this; + } + + [InitializesPropertyAttribute(nameof(Count))] + public Builder WithCount(Int32 value) + { + _count = value; + return this; + } + + [InitializesPropertyAttribute(nameof(OrderById))] + public Builder WithOrderById(Nullable value) + { + _orderById = value; + return this; + } + + public SomeQuery Build() + { + return new SomeQuery(_ids.Distinct().ToArray(), _count, _orderById); + } + } + } + } + """); + + await GeneratorTest + .WithSource(sourceFile) + .WithGeneratedSource(generatedSource) + .WithAdditionalReference(typeof(GenerateBuilderAttribute).Assembly) + .Build() + .RunAsync(); + } + + [Fact] + public async Task ShouldGenerateCorrectBuilderType_WhenPropertyIsArray() + { + SourceFile sourceFile = await SourceFile.LoadAsync("SourceKit.Generators.Builder.Samples/ArrayQuery.cs"); + + var generatedSource = new SourceFile( + Name: """ + SourceKit.Generators.Builder/SourceKit.Generators.Builder.Generators.BuilderSourceGenerator/ArrayQuery.SourceKit.Generation.Builder.g.cs + """, + Content: """ + // + // This code was generated by a SourceKit.Generators.Builder code generator. + // https://github.com/itmo-is-dev/SourceKit + // + #pragma warning disable CS1591 + using SourceKit.Generators.Builder.Annotations; + using System; + using System.Collections.Generic; + using System.Linq; + + namespace SourceKit.Generators.Builder.Samples + { + public partial record ArrayQuery + { + public static ArrayQuery Build(Func action) + { + return action(new Builder()).Build(); + } + + public sealed class Builder + { + private readonly List _ids; + public Builder() + { + _ids = new List(); + } + + [InitializesPropertyAttribute(nameof(Ids))] + public Builder WithId(Guid element) + { + _ids.Add(element); + return this; + } + + [InitializesPropertyAttribute(nameof(Ids))] + public Builder WithIds(IEnumerable elements) + { + _ids.AddRange(elements); + return this; + } + + public ArrayQuery Build() + { + return new ArrayQuery(_ids.Distinct().ToArray()); + } + } + } + } + """); + + await GeneratorTest + .WithSource(sourceFile) + .WithGeneratedSource(generatedSource) + .WithAdditionalReference(typeof(GenerateBuilderAttribute).Assembly) + .Build() + .RunAsync(); + } + + [Fact] + public async Task ShouldGenerateCorrectBuilderType_WhenPropertyHasCustomType() + { + SourceFile sourceFile = await SourceFile.LoadAsync("SourceKit.Generators.Builder.Samples/ArrayQuery.cs"); + + var generatedSource = new SourceFile( + Name: """ + SourceKit.Generators.Builder/SourceKit.Generators.Builder.Generators.BuilderSourceGenerator/ArrayQuery.SourceKit.Generation.Builder.g.cs + """, + Content: """ + // + // This code was generated by a SourceKit.Generators.Builder code generator. + // https://github.com/itmo-is-dev/SourceKit + // + #pragma warning disable CS1591 + using SourceKit.Generators.Builder.Annotations; + using System; + using System.Collections.Generic; + using System.Linq; + + namespace SourceKit.Generators.Builder.Samples + { + public partial record ArrayQuery + { + public static ArrayQuery Build(Func action) + { + return action(new Builder()).Build(); + } + + public sealed class Builder + { + private readonly List _ids; + public Builder() + { + _ids = new List(); + } + + [InitializesPropertyAttribute(nameof(Ids))] + public Builder WithId(Guid element) + { + _ids.Add(element); + return this; + } + + [InitializesPropertyAttribute(nameof(Ids))] + public Builder WithIds(IEnumerable elements) + { + _ids.AddRange(elements); + return this; + } + + public ArrayQuery Build() + { + return new ArrayQuery(_ids.Distinct().ToArray()); + } + } + } + } + """); + + await GeneratorTest + .WithSource(sourceFile) + .WithGeneratedSource(generatedSource) + .WithAdditionalReference(typeof(GenerateBuilderAttribute).Assembly) + .Build() + .RunAsync(); + } +} \ No newline at end of file diff --git a/tests/SourceKit.Generators.Builder.Tests/RequiredValueAnalyzerTests.cs b/tests/SourceKit.Generators.Builder.Tests/RequiredValueAnalyzerTests.cs new file mode 100644 index 0000000..5ceef30 --- /dev/null +++ b/tests/SourceKit.Generators.Builder.Tests/RequiredValueAnalyzerTests.cs @@ -0,0 +1,46 @@ +using Microsoft.CodeAnalysis.Testing; +using SourceKit.Generators.Builder.Analyzers; +using SourceKit.Generators.Builder.Annotations; +using SourceKit.Generators.Builder.Generators; +using SourceKit.Tests.Common; +using SourceKit.Tests.Common.TestBases; +using Xunit; + +namespace SourceKit.Generators.Builder.Tests; + +public class RequiredValueAnalyzerTests : AnalyzerTestBase +{ + [Fact] + public async Task ShouldProduceError_WhenRequiredValueNotDefined() + { + SourceFile usageFile = await SourceFile.LoadAsync( + "SourceKit.Generators.Builder.Samples/RequiredValue/UninitializedRequiredValueSample.cs"); + + DiagnosticResult diagnostic = AnalyzerVerifier + .Diagnostic(RequiredValueAnalyzer.Descriptor) + .WithLocation(usageFile.Name, 10, 21) + .WithArguments("Value"); + + await AnalyzerTest + .WithSource(usageFile) + .WithAdditionalReference(typeof(GenerateBuilderAttribute).Assembly) + .WithExpectedDiagnostic(diagnostic) + .WithSourceGenerator(new BuilderSourceGenerator()) + .Build() + .RunAsync(); + } + + [Fact] + public async Task ShouldProduceNoError_WhenRequiredValueDefined() + { + SourceFile usageFile = await SourceFile.LoadAsync( + "SourceKit.Generators.Builder.Samples/RequiredValue/InitializedRequiredValueSample.cs"); + + await AnalyzerTest + .WithSource(usageFile) + .WithAdditionalReference(typeof(GenerateBuilderAttribute).Assembly) + .WithSourceGenerator(new BuilderSourceGenerator()) + .Build() + .RunAsync(); + } +} \ No newline at end of file diff --git a/tests/SourceKit.Generators.Builder.Tests/SourceKit.Generators.Builder.Tests.csproj b/tests/SourceKit.Generators.Builder.Tests/SourceKit.Generators.Builder.Tests.csproj new file mode 100644 index 0000000..69f23ee --- /dev/null +++ b/tests/SourceKit.Generators.Builder.Tests/SourceKit.Generators.Builder.Tests.csproj @@ -0,0 +1,30 @@ + + + + false + true + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/SourceKit.Generators.Grpc.Tests/ProtoMessageConstructorGeneratorTests.cs b/tests/SourceKit.Generators.Grpc.Tests/ProtoMessageConstructorGeneratorTests.cs new file mode 100644 index 0000000..46fd128 --- /dev/null +++ b/tests/SourceKit.Generators.Grpc.Tests/ProtoMessageConstructorGeneratorTests.cs @@ -0,0 +1,704 @@ +using System.Text; +using Google.Protobuf; +using SourceKit.Generators.Grpc.Generators; +using SourceKit.Tests.Common; +using SourceKit.Tests.Common.TestBases; +using Xunit; + +namespace SourceKit.Generators.Grpc.Tests; + +public class ProtoMessageConstructorGeneratorTests : GeneratorTestBase +{ + [Fact] + public async Task ProtoMessageConstructorGenerator_ShouldGenerateCorrectConstructor() + { + var protoSource = new SourceFile( + Name: "Model.cs", + Content: """ + // + // Generated by the protocol buffer compiler. DO NOT EDIT! + // source: model.proto + // + #pragma warning disable 1591, 0612, 3021, 8981 + #region Designer generated code + + using pb = global::Google.Protobuf; + using pbc = global::Google.Protobuf.Collections; + using pbr = global::Google.Protobuf.Reflection; + using scg = global::System.Collections.Generic; + namespace Playground { + + /// Holder for reflection information generated from model.proto + public static partial class ModelReflection { + + #region Descriptor + /// File descriptor for model.proto + public static pbr::FileDescriptor Descriptor { + get { return descriptor; } + } + private static pbr::FileDescriptor descriptor; + + static ModelReflection() { + byte[] descriptorData = global::System.Convert.FromBase64String( + string.Concat( + "Cgttb2RlbC5wcm90bxoeZ29vZ2xlL3Byb3RvYnVmL3dyYXBwZXJzLnByb3Rv", + "IqMDCgpQcm90b01vZGVsEjAKCnBhZ2VfdG9rZW4YASABKAsyHC5nb29nbGUu", + "cHJvdG9idWYuU3RyaW5nVmFsdWUSDgoGdmFsdWVzGAIgAygJEhEKCXBhZ2Vf", + "c2l6ZRgDIAEoBRISCgppbnRfdmFsdWVzGAQgAygFEhkKD2ludF9vbmVvZl92", + "YWx1ZRgFIAEoBUgAEhwKEnN0cmluZ19vbmVvZl92YWx1ZRgGIAEoCUgAEh0K", + "FW5vdF9udWxsX3N0cmluZ192YWx1ZRgHIAEoCRIzCg5udWxsX2ludF92YWx1", + "ZRgIIAEoCzIbLmdvb2dsZS5wcm90b2J1Zi5JbnQzMlZhbHVlEjcKEW51bGxf", + "c3RyaW5nX3ZhbHVlGAkgASgLMhwuZ29vZ2xlLnByb3RvYnVmLlN0cmluZ1Zh", + "bHVlEiwKCW1hcF92YWx1ZRgKIAMoCzIZLlByb3RvTW9kZWwuTWFwVmFsdWVF", + "bnRyeRovCg1NYXBWYWx1ZUVudHJ5EgsKA2tleRgBIAEoBRINCgV2YWx1ZRgC", + "IAEoCToCOAFCBwoFdmFsdWVCDaoCClBsYXlncm91bmRiBnByb3RvMw==")); + descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, + new pbr::FileDescriptor[] { global::Google.Protobuf.WellKnownTypes.WrappersReflection.Descriptor, }, + new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] { + new pbr::GeneratedClrTypeInfo(typeof(global::Playground.ProtoModel), global::Playground.ProtoModel.Parser, new[]{ "PageToken", "Values", "PageSize", "IntValues", "IntOneofValue", "StringOneofValue", "NotNullStringValue", "NullIntValue", "NullStringValue", "MapValue" }, new[]{ "Value" }, null, null, new pbr::GeneratedClrTypeInfo[] { null, }) + })); + } + #endregion + + } + #region Messages + public sealed partial class ProtoModel : pb::IMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new ProtoModel()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public static pbr::MessageDescriptor Descriptor { + get { return global::Playground.ModelReflection.Descriptor.MessageTypes[0]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public ProtoModel() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public ProtoModel(ProtoModel other) : this() { + PageToken = other.PageToken; + values_ = other.values_.Clone(); + pageSize_ = other.pageSize_; + intValues_ = other.intValues_.Clone(); + notNullStringValue_ = other.notNullStringValue_; + NullIntValue = other.NullIntValue; + NullStringValue = other.NullStringValue; + mapValue_ = other.mapValue_.Clone(); + switch (other.ValueCase) { + case ValueOneofCase.IntOneofValue: + IntOneofValue = other.IntOneofValue; + break; + case ValueOneofCase.StringOneofValue: + StringOneofValue = other.StringOneofValue; + break; + } + + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public ProtoModel Clone() { + return new ProtoModel(this); + } + + /// Field number for the "page_token" field. + public const int PageTokenFieldNumber = 1; + private static readonly pb::FieldCodec _single_pageToken_codec = pb::FieldCodec.ForClassWrapper(10); + private string pageToken_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public string PageToken { + get { return pageToken_; } + set { + pageToken_ = value; + } + } + + + /// Field number for the "values" field. + public const int ValuesFieldNumber = 2; + private static readonly pb::FieldCodec _repeated_values_codec + = pb::FieldCodec.ForString(18); + private readonly pbc::RepeatedField values_ = new pbc::RepeatedField(); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public pbc::RepeatedField Values { + get { return values_; } + } + + /// Field number for the "page_size" field. + public const int PageSizeFieldNumber = 3; + private int pageSize_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public int PageSize { + get { return pageSize_; } + set { + pageSize_ = value; + } + } + + /// Field number for the "int_values" field. + public const int IntValuesFieldNumber = 4; + private static readonly pb::FieldCodec _repeated_intValues_codec + = pb::FieldCodec.ForInt32(34); + private readonly pbc::RepeatedField intValues_ = new pbc::RepeatedField(); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public pbc::RepeatedField IntValues { + get { return intValues_; } + } + + /// Field number for the "int_oneof_value" field. + public const int IntOneofValueFieldNumber = 5; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public int IntOneofValue { + get { return HasIntOneofValue ? (int) value_ : 0; } + set { + value_ = value; + valueCase_ = ValueOneofCase.IntOneofValue; + } + } + /// Gets whether the "int_oneof_value" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool HasIntOneofValue { + get { return valueCase_ == ValueOneofCase.IntOneofValue; } + } + /// Clears the value of the oneof if it's currently set to "int_oneof_value" + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void ClearIntOneofValue() { + if (HasIntOneofValue) { + ClearValue(); + } + } + + /// Field number for the "string_oneof_value" field. + public const int StringOneofValueFieldNumber = 6; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public string StringOneofValue { + get { return HasStringOneofValue ? (string) value_ : ""; } + set { + value_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + valueCase_ = ValueOneofCase.StringOneofValue; + } + } + /// Gets whether the "string_oneof_value" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool HasStringOneofValue { + get { return valueCase_ == ValueOneofCase.StringOneofValue; } + } + /// Clears the value of the oneof if it's currently set to "string_oneof_value" + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void ClearStringOneofValue() { + if (HasStringOneofValue) { + ClearValue(); + } + } + + /// Field number for the "not_null_string_value" field. + public const int NotNullStringValueFieldNumber = 7; + private string notNullStringValue_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public string NotNullStringValue { + get { return notNullStringValue_; } + set { + notNullStringValue_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "null_int_value" field. + public const int NullIntValueFieldNumber = 8; + private static readonly pb::FieldCodec _single_nullIntValue_codec = pb::FieldCodec.ForStructWrapper(66); + private int? nullIntValue_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public int? NullIntValue { + get { return nullIntValue_; } + set { + nullIntValue_ = value; + } + } + + + /// Field number for the "null_string_value" field. + public const int NullStringValueFieldNumber = 9; + private static readonly pb::FieldCodec _single_nullStringValue_codec = pb::FieldCodec.ForClassWrapper(74); + private string nullStringValue_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public string NullStringValue { + get { return nullStringValue_; } + set { + nullStringValue_ = value; + } + } + + + /// Field number for the "map_value" field. + public const int MapValueFieldNumber = 10; + private static readonly pbc::MapField.Codec _map_mapValue_codec + = new pbc::MapField.Codec(pb::FieldCodec.ForInt32(8, 0), pb::FieldCodec.ForString(18, ""), 82); + private readonly pbc::MapField mapValue_ = new pbc::MapField(); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public pbc::MapField MapValue { + get { return mapValue_; } + } + + private object value_; + /// Enum of possible cases for the "value" oneof. + public enum ValueOneofCase { + None = 0, + IntOneofValue = 5, + StringOneofValue = 6, + } + private ValueOneofCase valueCase_ = ValueOneofCase.None; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public ValueOneofCase ValueCase { + get { return valueCase_; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void ClearValue() { + valueCase_ = ValueOneofCase.None; + value_ = null; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public override bool Equals(object other) { + return Equals(other as ProtoModel); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool Equals(ProtoModel other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (PageToken != other.PageToken) return false; + if(!values_.Equals(other.values_)) return false; + if (PageSize != other.PageSize) return false; + if(!intValues_.Equals(other.intValues_)) return false; + if (IntOneofValue != other.IntOneofValue) return false; + if (StringOneofValue != other.StringOneofValue) return false; + if (NotNullStringValue != other.NotNullStringValue) return false; + if (NullIntValue != other.NullIntValue) return false; + if (NullStringValue != other.NullStringValue) return false; + if (!MapValue.Equals(other.MapValue)) return false; + if (ValueCase != other.ValueCase) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public override int GetHashCode() { + int hash = 1; + if (pageToken_ != null) hash ^= PageToken.GetHashCode(); + hash ^= values_.GetHashCode(); + if (PageSize != 0) hash ^= PageSize.GetHashCode(); + hash ^= intValues_.GetHashCode(); + if (HasIntOneofValue) hash ^= IntOneofValue.GetHashCode(); + if (HasStringOneofValue) hash ^= StringOneofValue.GetHashCode(); + if (NotNullStringValue.Length != 0) hash ^= NotNullStringValue.GetHashCode(); + if (nullIntValue_ != null) hash ^= NullIntValue.GetHashCode(); + if (nullStringValue_ != null) hash ^= NullStringValue.GetHashCode(); + hash ^= MapValue.GetHashCode(); + hash ^= (int) valueCase_; + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + if (pageToken_ != null) { + _single_pageToken_codec.WriteTagAndValue(output, PageToken); + } + values_.WriteTo(output, _repeated_values_codec); + if (PageSize != 0) { + output.WriteRawTag(24); + output.WriteInt32(PageSize); + } + intValues_.WriteTo(output, _repeated_intValues_codec); + if (HasIntOneofValue) { + output.WriteRawTag(40); + output.WriteInt32(IntOneofValue); + } + if (HasStringOneofValue) { + output.WriteRawTag(50); + output.WriteString(StringOneofValue); + } + if (NotNullStringValue.Length != 0) { + output.WriteRawTag(58); + output.WriteString(NotNullStringValue); + } + if (nullIntValue_ != null) { + _single_nullIntValue_codec.WriteTagAndValue(output, NullIntValue); + } + if (nullStringValue_ != null) { + _single_nullStringValue_codec.WriteTagAndValue(output, NullStringValue); + } + mapValue_.WriteTo(output, _map_mapValue_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + if (pageToken_ != null) { + _single_pageToken_codec.WriteTagAndValue(ref output, PageToken); + } + values_.WriteTo(ref output, _repeated_values_codec); + if (PageSize != 0) { + output.WriteRawTag(24); + output.WriteInt32(PageSize); + } + intValues_.WriteTo(ref output, _repeated_intValues_codec); + if (HasIntOneofValue) { + output.WriteRawTag(40); + output.WriteInt32(IntOneofValue); + } + if (HasStringOneofValue) { + output.WriteRawTag(50); + output.WriteString(StringOneofValue); + } + if (NotNullStringValue.Length != 0) { + output.WriteRawTag(58); + output.WriteString(NotNullStringValue); + } + if (nullIntValue_ != null) { + _single_nullIntValue_codec.WriteTagAndValue(ref output, NullIntValue); + } + if (nullStringValue_ != null) { + _single_nullStringValue_codec.WriteTagAndValue(ref output, NullStringValue); + } + mapValue_.WriteTo(ref output, _map_mapValue_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public int CalculateSize() { + int size = 0; + if (pageToken_ != null) { + size += _single_pageToken_codec.CalculateSizeWithTag(PageToken); + } + size += values_.CalculateSize(_repeated_values_codec); + if (PageSize != 0) { + size += 1 + pb::CodedOutputStream.ComputeInt32Size(PageSize); + } + size += intValues_.CalculateSize(_repeated_intValues_codec); + if (HasIntOneofValue) { + size += 1 + pb::CodedOutputStream.ComputeInt32Size(IntOneofValue); + } + if (HasStringOneofValue) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(StringOneofValue); + } + if (NotNullStringValue.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(NotNullStringValue); + } + if (nullIntValue_ != null) { + size += _single_nullIntValue_codec.CalculateSizeWithTag(NullIntValue); + } + if (nullStringValue_ != null) { + size += _single_nullStringValue_codec.CalculateSizeWithTag(NullStringValue); + } + size += mapValue_.CalculateSize(_map_mapValue_codec); + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void MergeFrom(ProtoModel other) { + if (other == null) { + return; + } + if (other.pageToken_ != null) { + if (pageToken_ == null || other.PageToken != "") { + PageToken = other.PageToken; + } + } + values_.Add(other.values_); + if (other.PageSize != 0) { + PageSize = other.PageSize; + } + intValues_.Add(other.intValues_); + if (other.NotNullStringValue.Length != 0) { + NotNullStringValue = other.NotNullStringValue; + } + if (other.nullIntValue_ != null) { + if (nullIntValue_ == null || other.NullIntValue != 0) { + NullIntValue = other.NullIntValue; + } + } + if (other.nullStringValue_ != null) { + if (nullStringValue_ == null || other.NullStringValue != "") { + NullStringValue = other.NullStringValue; + } + } + mapValue_.MergeFrom(other.mapValue_); + switch (other.ValueCase) { + case ValueOneofCase.IntOneofValue: + IntOneofValue = other.IntOneofValue; + break; + case ValueOneofCase.StringOneofValue: + StringOneofValue = other.StringOneofValue; + break; + } + + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 10: { + string value = _single_pageToken_codec.Read(input); + if (pageToken_ == null || value != "") { + PageToken = value; + } + break; + } + case 18: { + values_.AddEntriesFrom(input, _repeated_values_codec); + break; + } + case 24: { + PageSize = input.ReadInt32(); + break; + } + case 34: + case 32: { + intValues_.AddEntriesFrom(input, _repeated_intValues_codec); + break; + } + case 40: { + IntOneofValue = input.ReadInt32(); + break; + } + case 50: { + StringOneofValue = input.ReadString(); + break; + } + case 58: { + NotNullStringValue = input.ReadString(); + break; + } + case 66: { + int? value = _single_nullIntValue_codec.Read(input); + if (nullIntValue_ == null || value != 0) { + NullIntValue = value; + } + break; + } + case 74: { + string value = _single_nullStringValue_codec.Read(input); + if (nullStringValue_ == null || value != "") { + NullStringValue = value; + } + break; + } + case 82: { + mapValue_.AddEntriesFrom(input, _map_mapValue_codec); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + string value = _single_pageToken_codec.Read(ref input); + if (pageToken_ == null || value != "") { + PageToken = value; + } + break; + } + case 18: { + values_.AddEntriesFrom(ref input, _repeated_values_codec); + break; + } + case 24: { + PageSize = input.ReadInt32(); + break; + } + case 34: + case 32: { + intValues_.AddEntriesFrom(ref input, _repeated_intValues_codec); + break; + } + case 40: { + IntOneofValue = input.ReadInt32(); + break; + } + case 50: { + StringOneofValue = input.ReadString(); + break; + } + case 58: { + NotNullStringValue = input.ReadString(); + break; + } + case 66: { + int? value = _single_nullIntValue_codec.Read(ref input); + if (nullIntValue_ == null || value != 0) { + NullIntValue = value; + } + break; + } + case 74: { + string value = _single_nullStringValue_codec.Read(ref input); + if (nullStringValue_ == null || value != "") { + NullStringValue = value; + } + break; + } + case 82: { + mapValue_.AddEntriesFrom(ref input, _map_mapValue_codec); + break; + } + } + } + } + #endif + + } + + #endregion + + } + + #endregion Designer generated code + """, + Encoding: Encoding.UTF8); + + var generatedSource = new SourceFile( + Name: """ + SourceKit.Generators.Grpc/SourceKit.Generators.Grpc.Generators.ProtoMessageConstructorGenerator/ProtoModel.SourceKit.Generators.Grpc.g.cs + """, + Content: """ + // + // This code was generated by a SourceKit.Generators.Grpc code generator. + // https://github.com/itmo-is-dev/SourceKit + // + #pragma warning disable CS1591 + using System; + using System.Collections.Generic; + using System.Linq; + + #nullable enable + namespace Playground + { + public partial class ProtoModel + { + public ProtoModel(String? pageToken, IEnumerable values, Int32 pageSize, IEnumerable intValues, Int32? intOneofValue, String? stringOneofValue, String notNullStringValue, Nullable nullIntValue, String? nullStringValue, IEnumerable> mapValue) + { + PageToken = pageToken; + Values.Add(values); + PageSize = pageSize; + IntValues.Add(intValues); + if (intOneofValue is not null) + { + IntOneofValue = intOneofValue.Value; + } + + if (stringOneofValue is not null) + { + StringOneofValue = stringOneofValue; + } + + NotNullStringValue = notNullStringValue; + NullIntValue = nullIntValue; + NullStringValue = nullStringValue; + foreach (KeyValuePair item in mapValue) + { + MapValue.Add(item.Key, item.Value); + } + } + } + } + """, + Encoding: Encoding.UTF8); + + await GeneratorTest + .WithSource(protoSource) + .WithGeneratedSource(generatedSource) + .WithAdditionalReference(typeof(IMessage).Assembly) + .Build() + .RunAsync(); + } +} \ No newline at end of file diff --git a/tests/SourceKit.Generators.Grpc.Tests/SourceKit.Generators.Grpc.Tests.csproj b/tests/SourceKit.Generators.Grpc.Tests/SourceKit.Generators.Grpc.Tests.csproj new file mode 100644 index 0000000..7672d02 --- /dev/null +++ b/tests/SourceKit.Generators.Grpc.Tests/SourceKit.Generators.Grpc.Tests.csproj @@ -0,0 +1,34 @@ + + + + false + true + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/SourceKit.Reflect.Tests/InstanceReflectorTests.cs b/tests/SourceKit.Reflect.Tests/InstanceReflectorTests.cs index a53cd3b..8d0d970 100644 --- a/tests/SourceKit.Reflect.Tests/InstanceReflectorTests.cs +++ b/tests/SourceKit.Reflect.Tests/InstanceReflectorTests.cs @@ -1,8 +1,8 @@ +using System.Drawing; using FluentAssertions; using Microsoft.CodeAnalysis.CSharp.Syntax; using SourceKit.Extensions; using SourceKit.Reflect.Reflectors; -using SourceKit.Sample.Models; using SourceKit.Tests.Common; using Xunit; diff --git a/tests/SourceKit.Reflect.Tests/MethodReflectorTests.cs b/tests/SourceKit.Reflect.Tests/MethodReflectorTests.cs index 2963f46..9d7caa6 100644 --- a/tests/SourceKit.Reflect.Tests/MethodReflectorTests.cs +++ b/tests/SourceKit.Reflect.Tests/MethodReflectorTests.cs @@ -2,7 +2,7 @@ using Microsoft.CodeAnalysis.CSharp.Syntax; using SourceKit.Reflect.Extensions; using SourceKit.Reflect.Reflectors; -using SourceKit.Sample; +using SourceKit.Reflect.Samples; using SourceKit.Tests.Common; using Xunit; diff --git a/tests/SourceKit.Reflect.Tests/SourceKit.Reflect.Tests.csproj b/tests/SourceKit.Reflect.Tests/SourceKit.Reflect.Tests.csproj index 7374b7f..06e77de 100644 --- a/tests/SourceKit.Reflect.Tests/SourceKit.Reflect.Tests.csproj +++ b/tests/SourceKit.Reflect.Tests/SourceKit.Reflect.Tests.csproj @@ -1,7 +1,7 @@ - net7.0 + net8.0 enable enable @@ -26,7 +26,7 @@ - + diff --git a/tests/SourceKit.Tests.Common/CompilationBuilder.cs b/tests/SourceKit.Tests.Common/CompilationBuilder.cs index d867179..613eaf6 100644 --- a/tests/SourceKit.Tests.Common/CompilationBuilder.cs +++ b/tests/SourceKit.Tests.Common/CompilationBuilder.cs @@ -1,65 +1,6 @@ -using System.Reflection; -using System.Text; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp; - namespace SourceKit.Tests.Common; -public static class CompilationBuilder +public class CompilationBuilder { - public static Task CompileSampleProjectAsync() - { - var workspace = new AdhocWorkspace(); - var _ = typeof(Microsoft.CodeAnalysis.CSharp.Formatting.CSharpFormattingOptions); - - var solution = workspace.CurrentSolution; - var projectId = ProjectId.CreateNewId(); - - solution = solution.AddProject(projectId, "SourceKit.Sample", "SourceKit.Sample", LanguageNames.CSharp); - - IEnumerable sourceFiles = Directory.EnumerateFiles( - "SourceKit.Sample", - "*.*", - SearchOption.AllDirectories) - .Select(Path.GetFullPath); - - foreach (var sourceFile in sourceFiles) - { - var fileName = Path.GetFileName(sourceFile); - var source = new FileTextLoader(sourceFile, Encoding.Default); - - solution = solution.AddDocument(DocumentId.CreateNewId(projectId), fileName, source); - } - - Type[] referencedTypes = - { - typeof(object), - typeof(Console), - typeof(IEnumerable<>), - typeof(Enumerable), - }; - - var project = solution.GetProject(projectId)!; - project = project.WithCompilationOptions(new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)); - project = project.AddMetadataReferences(GetAllReferencesNeededForTypes(referencedTypes)); - - workspace.TryApplyChanges(project.Solution); - - return workspace.CurrentSolution.Projects.Single().GetCompilationAsync()!; - } - - private static IEnumerable GetAllReferencesNeededForTypes(IReadOnlyCollection types) - { - IEnumerable files = types.SelectMany(GetAllAssemblyFilesNeededForType); - return files.Select(x => (MetadataReference)MetadataReference.CreateFromFile(x)); - } - - private static string[] GetAllAssemblyFilesNeededForType(Type type) - { - return type.Assembly.GetReferencedAssemblies() - .Select(x => Assembly.Load(x.FullName)) - .Append(type.Assembly) - .Select(x => x.Location) - .ToArray(); - } + } \ No newline at end of file diff --git a/tests/SourceKit.Tests.Common/SourceFile.cs b/tests/SourceKit.Tests.Common/SourceFile.cs new file mode 100644 index 0000000..40695a7 --- /dev/null +++ b/tests/SourceKit.Tests.Common/SourceFile.cs @@ -0,0 +1,20 @@ +using System.Text; +using Microsoft.CodeAnalysis.Text; + +namespace SourceKit.Tests.Common; + +public readonly record struct SourceFile(string Name, string Content, Encoding? Encoding = null) +{ + public string FilePath { get; init; } = Name; + + public static async Task LoadAsync(string path) + { + string name = Path.GetFileName(path); + string content = await File.ReadAllTextAsync(path); + + return new SourceFile(name, content, null) { FilePath = path }; + } + + public static implicit operator (string, SourceText)(SourceFile sourceFile) + => (sourceFile.Name, SourceText.From(sourceFile.Content, sourceFile.Encoding ?? Encoding.UTF8)); +} \ No newline at end of file diff --git a/tests/SourceKit.Tests.Common/SourceKit.Tests.Common.csproj b/tests/SourceKit.Tests.Common/SourceKit.Tests.Common.csproj index d58e4f4..d65afe6 100644 --- a/tests/SourceKit.Tests.Common/SourceKit.Tests.Common.csproj +++ b/tests/SourceKit.Tests.Common/SourceKit.Tests.Common.csproj @@ -1,7 +1,6 @@ - net7.0 enable enable @@ -9,8 +8,11 @@ - + + + + diff --git a/tests/SourceKit.Tests.Common/TestBases/AnalyzerTestBase.cs b/tests/SourceKit.Tests.Common/TestBases/AnalyzerTestBase.cs new file mode 100644 index 0000000..7157477 --- /dev/null +++ b/tests/SourceKit.Tests.Common/TestBases/AnalyzerTestBase.cs @@ -0,0 +1,143 @@ +using System.Collections.Immutable; +using System.Reflection; +using System.Runtime; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Testing; +using Microsoft.CodeAnalysis.CSharp.Testing.XUnit; +using Microsoft.CodeAnalysis.Diagnostics; +using Microsoft.CodeAnalysis.Testing; +using Microsoft.CodeAnalysis.Testing.Verifiers; +using Microsoft.CodeAnalysis.Text; + +namespace SourceKit.Tests.Common.TestBases; + +public abstract class AnalyzerTestBase + where TAnalyzer : DiagnosticAnalyzer, new() +{ + protected Verifier AnalyzerVerifier { get; } = new(); + + protected AnalyzerTestBuilder AnalyzerTest => new(); + + protected sealed class Verifier + { + public DiagnosticResult Diagnostic(DiagnosticDescriptor descriptor) + { + return AnalyzerVerifier.Diagnostic(descriptor); + } + } + + protected sealed class AnalyzerTestBuilder + { + private readonly List _sources = []; + private readonly List _additionalReferences = []; + private readonly List _expectedDiagnostics = []; + private readonly List _sourceGenerators = []; + private readonly ReferenceAssemblies _referenceAssemblies = ReferenceAssemblies.Net.Net60; + + public AnalyzerTestBuilder WithSource(SourceFile file) + { + _sources.Add(file); + return this; + } + + public AnalyzerTestBuilder WithAdditionalReference(Assembly assembly) + { + _additionalReferences.Add(assembly); + return this; + } + + public AnalyzerTestBuilder WithExpectedDiagnostic(DiagnosticResult diagnostic) + { + _expectedDiagnostics.Add(diagnostic); + return this; + } + + public AnalyzerTestBuilder WithSourceGenerator(ISourceGenerator generator) + { + _sourceGenerators.Add(generator); + return this; + } + + public CSharpAnalyzerTest Build() + { + var test = new CSharpAnalyzerTest + { + ReferenceAssemblies = _referenceAssemblies, + }; + + foreach (SourceFile source in _sources) + test.TestState.Sources.Add(source); + + foreach (Assembly assembly in _additionalReferences) + test.TestState.AdditionalReferences.Add(assembly); + + foreach (DiagnosticResult diagnostic in _expectedDiagnostics) + test.ExpectedDiagnostics.Add(diagnostic); + + AddGeneratedSources(test); + + return test; + } + + private void AddGeneratedSources(CSharpAnalyzerTest test) + { + if (_sourceGenerators is []) + return; + + var workspace = new AdhocWorkspace(); + _ = typeof(Microsoft.CodeAnalysis.CSharp.Formatting.CSharpFormattingOptions); + + Solution solution = workspace.CurrentSolution; + var projectId = ProjectId.CreateNewId(); + + solution = solution.AddProject( + projectId, + "project", + "project", + LanguageNames.CSharp); + + solution = _sources.Aggregate( + solution, + (current, source) => current.AddDocument( + DocumentId.CreateNewId(projectId), + name: source.Name, + text: source.Content)); + + IEnumerable metadataReferences = test.TestState.AdditionalReferences + .Concat(_referenceAssemblies.ResolveAsync(test.Language, default).GetAwaiter().GetResult()) + .DistinctBy(x => x.Display); + + Project project = solution.GetProject(projectId)!; + project = project.WithCompilationOptions(new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)); + project = project.WithMetadataReferences(metadataReferences); + + if (workspace.TryApplyChanges(project.Solution) is false) + throw new InvalidOperationException("Failed to apply changes to workspace"); + + Compilation? compilation = workspace.CurrentSolution.Projects + .Single() + .GetCompilationAsync() + .GetAwaiter() + .GetResult(); + + if (compilation is null) + throw new InvalidOperationException("Failed to get compilation"); + + GeneratorDriver driver = CSharpGeneratorDriver.Create(_sourceGenerators); + + driver = driver.RunGeneratorsAndUpdateCompilation( + compilation, + out _, + out _); + + GeneratorDriverRunResult result = driver.GetRunResult(); + + IEnumerable<(string HintName, SourceText SourceText)> generatedSources = result.Results + .SelectMany(x => x.GeneratedSources) + .Select(x => (x.HintName, x.SourceText)); + + test.TestState.Sources.AddRange(generatedSources); + } + } +} \ No newline at end of file diff --git a/tests/SourceKit.Tests.Common/TestBases/CodeFixTestBase.cs b/tests/SourceKit.Tests.Common/TestBases/CodeFixTestBase.cs new file mode 100644 index 0000000..79bda12 --- /dev/null +++ b/tests/SourceKit.Tests.Common/TestBases/CodeFixTestBase.cs @@ -0,0 +1,90 @@ +using System.Reflection; +using Microsoft.CodeAnalysis.CodeFixes; +using Microsoft.CodeAnalysis.CSharp.Testing; +using Microsoft.CodeAnalysis.Diagnostics; +using Microsoft.CodeAnalysis.Testing; +using Microsoft.CodeAnalysis.Testing.Verifiers; + +namespace SourceKit.Tests.Common.TestBases; + +public abstract class CodeFixTestBase : AnalyzerTestBase + where TAnalyzer : DiagnosticAnalyzer, new() + where TCodeFixProvider : CodeFixProvider, new() +{ + protected CodeFixTestBuilder CodeFixTest => new(); + + protected sealed class CodeFixTestBuilder + { + private readonly List _sources = []; + private readonly List _additionalReferences = []; + private readonly List _fixedSources = []; + private readonly List _expectedDiagnostics = []; + private readonly List _disabledDiagnostics = []; + private int? _codeFixIterationNumber; + + public CodeFixTestBuilder WithSource(SourceFile file) + { + _sources.Add(file); + return this; + } + + public CodeFixTestBuilder WithAdditionalReference(Assembly assembly) + { + _additionalReferences.Add(assembly); + return this; + } + + public CodeFixTestBuilder WithFixedSource(SourceFile file) + { + _fixedSources.Add(file); + return this; + } + + public CodeFixTestBuilder WithExpectedDiagnostic(DiagnosticResult diagnostic) + { + _expectedDiagnostics.Add(diagnostic); + return this; + } + + public CodeFixTestBuilder WithDisabledDiagnostic(string diagnostic) + { + _disabledDiagnostics.Add(diagnostic); + return this; + } + + public CodeFixTestBuilder WithIterationNumber(int value) + { + _codeFixIterationNumber = value; + return this; + } + + public CSharpCodeFixTest Build() + { + var test = new CSharpCodeFixTest(); + + foreach (SourceFile source in _sources) + test.TestState.Sources.Add(source); + + foreach (Assembly assembly in _additionalReferences) + { + test.TestState.AdditionalReferences.Add(assembly); + test.FixedState.AdditionalReferences.Add(assembly); + } + + foreach (SourceFile source in _fixedSources) + test.FixedState.Sources.Add(source); + + foreach (DiagnosticResult diagnostic in _expectedDiagnostics) + test.ExpectedDiagnostics.Add(diagnostic); + + foreach (string diagnostic in _disabledDiagnostics) + test.DisabledDiagnostics.Add(diagnostic); + + test.NumberOfFixAllIterations = _codeFixIterationNumber; + test.NumberOfFixAllInProjectIterations = _codeFixIterationNumber; + test.NumberOfFixAllInDocumentIterations = _codeFixIterationNumber; + + return test; + } + } +} \ No newline at end of file diff --git a/tests/SourceKit.Tests.Common/TestBases/GeneratorTestBase.cs b/tests/SourceKit.Tests.Common/TestBases/GeneratorTestBase.cs new file mode 100644 index 0000000..c375fd1 --- /dev/null +++ b/tests/SourceKit.Tests.Common/TestBases/GeneratorTestBase.cs @@ -0,0 +1,64 @@ +using System.Reflection; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp.Testing; +using Microsoft.CodeAnalysis.Testing; +using Microsoft.CodeAnalysis.Testing.Verifiers; + +namespace SourceKit.Tests.Common.TestBases; + +public abstract class GeneratorTestBase + where TGenerator : ISourceGenerator, new() +{ + protected GeneratorTestBuilder GeneratorTest => new(); + + protected sealed class GeneratorTestBuilder + { + private readonly List _sources = []; + private readonly List _generatedSources = []; + private readonly List _additionalReferences = []; + private ReferenceAssemblies _referenceAssemblies = ReferenceAssemblies.Net.Net60; + + public GeneratorTestBuilder WithSource(SourceFile file) + { + _sources.Add(file); + return this; + } + + public GeneratorTestBuilder WithGeneratedSource(SourceFile file) + { + _generatedSources.Add(file); + return this; + } + + public GeneratorTestBuilder WithAdditionalReference(Assembly assembly) + { + _additionalReferences.Add(assembly); + return this; + } + + public GeneratorTestBuilder WithReferenceAssemblies(ReferenceAssemblies assemblies) + { + _referenceAssemblies = assemblies; + return this; + } + + public CSharpSourceGeneratorTest Build() + { + var test = new CSharpSourceGeneratorTest + { + ReferenceAssemblies = _referenceAssemblies, + }; + + foreach (SourceFile source in _sources) + test.TestState.Sources.Add(source); + + foreach (SourceFile source in _generatedSources) + test.TestState.GeneratedSources.Add(source); + + foreach (Assembly assembly in _additionalReferences) + test.TestState.AdditionalReferences.Add(assembly); + + return test; + } + } +} \ No newline at end of file diff --git a/tests/SourceKit.Tests/Analyzers/CollectionsTests.cs b/tests/SourceKit.Tests/Analyzers/CollectionsTests.cs deleted file mode 100644 index e70fcf9..0000000 --- a/tests/SourceKit.Tests/Analyzers/CollectionsTests.cs +++ /dev/null @@ -1,158 +0,0 @@ -using Microsoft.CodeAnalysis.CSharp.Testing; -using Microsoft.CodeAnalysis.Testing.Verifiers; -using SourceKit.Analyzers.Collections.Analyzers; -using SourceKit.Tests.Tools; -using AnalyzerVerifier = Microsoft.CodeAnalysis.CSharp.Testing.XUnit.AnalyzerVerifier< - SourceKit.Analyzers.MustBePartial.Analyzers.TypeMustBePartialAnalyzer>; -using Xunit; - -namespace SourceKit.Tests.Analyzers; - -public class CollectionsTests -{ - [Fact] - public async Task DictionaryKeyType_ShouldReportDiagnostic_WhenTypeIsNotImplementEquatable() - { - var sourceFile = await SourceFile.LoadAsync( - "SourceKit.Sample/Analyzers/Collections/Dictionary/KeyTypeDoesNotImplementEquatable.cs"); - - var diagnostic = AnalyzerVerifier.Diagnostic(DictionaryKeyTypeMustImplementEquatableAnalyzer.Descriptor) - .WithLocation(sourceFile.Name, 7, 12) - .WithArguments("KeyTypeDoesNotImplementEquatable"); - - var test = new CSharpAnalyzerTest - { - TestState = - { - Sources = - { - sourceFile, - }, - }, - ExpectedDiagnostics = { diagnostic }, - }; - - await test.RunAsync(); - } - - [Fact] - public async Task DictionaryCustomKeyType_ShouldReportDiagnostic_WhenTypeImplementsOtherEquatable() - { - var sourceFile = await SourceFile.LoadAsync( - "SourceKit.Sample/Analyzers/Collections/Dictionary/CustomKeyTypeImplementsOtherEquatable.cs"); - - var diagnostic = AnalyzerVerifier.Diagnostic(DictionaryKeyTypeMustImplementEquatableAnalyzer.Descriptor) - .WithLocation(sourceFile.Name, 18, 23) - .WithArguments("CustomKeyTypeImplementsOtherEquatable"); - - var test = new CSharpAnalyzerTest - { - TestState = - { - Sources = - { - sourceFile, - }, - }, - ExpectedDiagnostics = { diagnostic }, - }; - - await test.RunAsync(); - } - - [Fact] - public async Task DictionaryKeyType_ShouldNotReportDiagnostic_WhenTypeImplementsEquatable() - { - var test = new CSharpAnalyzerTest - { - TestState = - { - Sources = - { - await SourceFile.LoadAsync( - "SourceKit.Sample/Analyzers/Collections/Dictionary/KeyTypeImplementsEquatable.cs"), - }, - }, - }; - - await test.RunAsync(); - } - - [Fact] - public async Task DictionaryCustomKeyType_ShouldNotReportDiagnostic_WhenTypeImplementsEquatable() - { - var sourceFile = await SourceFile.LoadAsync( - "SourceKit.Sample/Analyzers/Collections/Dictionary/CustomKeyTypeImplementsEquatable.cs"); - - var test = new CSharpAnalyzerTest - { - TestState = - { - Sources = - { - sourceFile, - await SourceFile.LoadAsync("SourceKit.Sample/Analyzers/Collections/Dictionary/EquatableType.cs"), - }, - }, - }; - - await test.RunAsync(); - } - - [Fact] - public async Task DictionaryKeyType_ShouldNotReportDiagnostic_WhenTypeIsEmpty() - { - var test = new CSharpAnalyzerTest - { - TestState = - { - Sources = - { - await SourceFile.LoadAsync("SourceKit.Sample/Analyzers/Collections/Dictionary/EmptyKeyType.cs"), - }, - }, - }; - - await test.RunAsync(); - } - - [Fact] - public async Task DictionaryInheritedCustomKeyType_ShouldNotReportDiagnostic_WhenTypeImplementsEquatable() - { - var sourceFile = await SourceFile.LoadAsync( - "SourceKit.Sample/Analyzers/Collections/Dictionary/InheritedCustomKeyTypeImplementsEquatable.cs"); - - var test = new CSharpAnalyzerTest - { - TestState = - { - Sources = - { - sourceFile, - }, - }, - }; - - await test.RunAsync(); - } - - [Fact] - public async Task DictionaryInheritedCustomKeyType_ShouldNotReportDiagnostic_WhenKeyTypeIsEnum() - { - var sourceFile = await SourceFile.LoadAsync( - "SourceKit.Sample/Analyzers/Collections/Dictionary/EnumKeyDictionary.cs"); - - var test = new CSharpAnalyzerTest - { - TestState = - { - Sources = - { - sourceFile, - }, - }, - }; - - await test.RunAsync(); - } -} \ No newline at end of file diff --git a/tests/SourceKit.Tests/Analyzers/DeclarationCouldBeConvertedToPropertyTests.cs b/tests/SourceKit.Tests/Analyzers/DeclarationCouldBeConvertedToPropertyTests.cs deleted file mode 100644 index 212ef04..0000000 --- a/tests/SourceKit.Tests/Analyzers/DeclarationCouldBeConvertedToPropertyTests.cs +++ /dev/null @@ -1,256 +0,0 @@ -using Microsoft.CodeAnalysis.CSharp.Testing; -using Microsoft.CodeAnalysis.Testing.Verifiers; -using SourceKit.Analyzers.Properties.Analyzers; -using SourceKit.Tests.Tools; -using AnalyzerVerifier = Microsoft.CodeAnalysis.CSharp.Testing.XUnit.AnalyzerVerifier< - SourceKit.Analyzers.Properties.Analyzers.DeclarationCouldBeConvertedToPropertyAnalyzer>; -using Xunit; - -namespace SourceKit.Tests.Analyzers; - -public class DeclarationCouldBeConvertedToPropertyTests -{ - [Fact] - public async Task PublicDeclarationCouldNotBeConvertedToProperty_ShouldNotReportDiagnostic() - { - var sourceFile = await SourceFile.LoadAsync(PublicPropertyFilePath); - - var test = new CSharpAnalyzerTest - { - TestState = - { - Sources = - { - sourceFile, - }, - }, - }; - - await test.RunAsync(); - } - - [Fact] - public async Task DeclarationCouldNotBeConvertedToProperty_ShouldNotReportDiagnostic() - { - var sourceFile = await SourceFile.LoadAsync(PrivateFieldWithoutMethodsFilePath); - - var test = new CSharpAnalyzerTest - { - TestState = - { - Sources = - { - sourceFile, - }, - }, - }; - - await test.RunAsync(); - } - - [Fact] - public async Task DeclarationCouldBeConvertedToProperty_ShouldReportDiagnostic_WhenPublicField() - { - var sourceFile = await SourceFile.LoadAsync(OnePublicFieldFilePath); - - var diagnostic = AnalyzerVerifier.Diagnostic(DeclarationCouldBeConvertedToPropertyAnalyzer.Descriptor) - .WithLocation(sourceFile.Name, 5, 19) - .WithLocation(sourceFile.Name, 5, 19) - .WithMessage(string.Format(DeclarationCouldBeConvertedToPropertyAnalyzer.Format, "field")); - - var test = new CSharpAnalyzerTest - { - TestState = - { - Sources = - { - sourceFile, - }, - }, - ExpectedDiagnostics = { diagnostic }, - }; - - await test.RunAsync(); - } - - [Fact] - public async Task DeclarationsCouldBeConvertedToProperties_ShouldReportAllDiagnostics_WhenEveryPublicField() - { - var sourceFile = await SourceFile.LoadAsync(ManyPublicFieldsFilePath); - - var diagnostic1 = AnalyzerVerifier.Diagnostic(DeclarationCouldBeConvertedToPropertyAnalyzer.Descriptor) - .WithLocation(sourceFile.Name, 7, 25) - .WithLocation(sourceFile.Name, 7, 25) - .WithMessage(string.Format(DeclarationCouldBeConvertedToPropertyAnalyzer.Format, "first")); - var diagnostic2 = AnalyzerVerifier.Diagnostic(DeclarationCouldBeConvertedToPropertyAnalyzer.Descriptor) - .WithLocation(sourceFile.Name, 7, 32) - .WithLocation(sourceFile.Name, 7, 32) - .WithMessage(string.Format(DeclarationCouldBeConvertedToPropertyAnalyzer.Format, "second")); - - var test = new CSharpAnalyzerTest - { - TestState = - { - Sources = - { - sourceFile, - }, - }, - ExpectedDiagnostics = { diagnostic1, diagnostic2 }, - }; - - await test.RunAsync(); - } - - [Fact] - public async Task DeclarationCouldBeConvertedToProperty_ShouldReportDiagnostic_WhenField() - { - var sourceFile = await SourceFile.LoadAsync(OneFieldFilePath); - - var diagnostic1 = AnalyzerVerifier.Diagnostic(DeclarationCouldBeConvertedToPropertyAnalyzer.Descriptor) - .WithLocation(sourceFile.Name, 5, 20) - .WithLocation(sourceFile.Name, 5, 20) - .WithLocation(sourceFile.Name, 3, 1) - .WithMessage(string.Format(DeclarationCouldBeConvertedToPropertyAnalyzer.Format, "field")); - var diagnostic2 = AnalyzerVerifier.Diagnostic(DeclarationCouldBeConvertedToPropertyAnalyzer.Descriptor) - .WithLocation(sourceFile.Name, 7, 19) - .WithLocation(sourceFile.Name, 5, 20) - .WithLocation(sourceFile.Name, 3, 1) - .WithMessage(string.Format(DeclarationCouldBeConvertedToPropertyAnalyzer.Format, "field")); - var diagnostic3 = AnalyzerVerifier.Diagnostic(DeclarationCouldBeConvertedToPropertyAnalyzer.Descriptor) - .WithLocation(sourceFile.Name, 12, 17) - .WithLocation(sourceFile.Name, 5, 20) - .WithLocation(sourceFile.Name, 3, 1) - .WithMessage(string.Format(DeclarationCouldBeConvertedToPropertyAnalyzer.Format, "field")); - - var test = new CSharpAnalyzerTest - { - TestState = - { - Sources = - { - sourceFile, - }, - }, - ExpectedDiagnostics = { diagnostic1, diagnostic2, diagnostic3 }, - }; - - await test.RunAsync(); - } - - [Fact] - public async Task DeclarationCouldBeConvertedToProperties_ShouldReportDiagnostics_WhenUnderscoreNameField() - { - var sourceFile = await SourceFile.LoadAsync(UnderscoreNameFieldFilePath); - - var diagnostic1 = AnalyzerVerifier.Diagnostic(DeclarationCouldBeConvertedToPropertyAnalyzer.Descriptor) - .WithLocation(sourceFile.Name, 5, 29) - .WithLocation(sourceFile.Name, 5, 29) - .WithLocation(sourceFile.Name, 3, 1) - .WithMessage(string.Format(DeclarationCouldBeConvertedToPropertyAnalyzer.Format, "_field")); - var diagnostic2 = AnalyzerVerifier.Diagnostic(DeclarationCouldBeConvertedToPropertyAnalyzer.Descriptor) - .WithLocation(sourceFile.Name, 7, 19) - .WithLocation(sourceFile.Name, 5, 29) - .WithLocation(sourceFile.Name, 3, 1) - .WithMessage(string.Format(DeclarationCouldBeConvertedToPropertyAnalyzer.Format, "_field")); - - var test = new CSharpAnalyzerTest - { - TestState = - { - Sources = - { - sourceFile, - }, - }, - ExpectedDiagnostics = { diagnostic1, diagnostic2 }, - }; - - await test.RunAsync(); - } - - [Fact] - public async Task DeclarationCouldBeConvertedToProperties_ShouldReportDiagnostics_WhenMethodsWithExpressionBody() - { - var sourceFile = await SourceFile.LoadAsync(ExpressionBodyMethodsFieldFilePath); - - var diagnostic1 = AnalyzerVerifier.Diagnostic(DeclarationCouldBeConvertedToPropertyAnalyzer.Descriptor) - .WithLocation(sourceFile.Name, 5, 20) - .WithLocation(sourceFile.Name, 5, 20) - .WithLocation(sourceFile.Name, 3, 1) - .WithMessage(string.Format(DeclarationCouldBeConvertedToPropertyAnalyzer.Format, "field")); - var diagnostic2 = AnalyzerVerifier.Diagnostic(DeclarationCouldBeConvertedToPropertyAnalyzer.Descriptor) - .WithLocation(sourceFile.Name, 7, 19) - .WithLocation(sourceFile.Name, 5, 20) - .WithLocation(sourceFile.Name, 3, 1) - .WithMessage(string.Format(DeclarationCouldBeConvertedToPropertyAnalyzer.Format, "field")); - var diagnostic3 = AnalyzerVerifier.Diagnostic(DeclarationCouldBeConvertedToPropertyAnalyzer.Descriptor) - .WithLocation(sourceFile.Name, 9, 29) - .WithLocation(sourceFile.Name, 5, 20) - .WithLocation(sourceFile.Name, 3, 1) - .WithMessage(string.Format(DeclarationCouldBeConvertedToPropertyAnalyzer.Format, "field")); - - var test = new CSharpAnalyzerTest - { - TestState = - { - Sources = - { - sourceFile, - }, - }, - ExpectedDiagnostics = { diagnostic1, diagnostic2, diagnostic3 }, - }; - - await test.RunAsync(); - } - - [Fact] - public async Task PublicReadonlyDeclarationCouldBeConvertedToProperties_ShouldReportDiagnostics_WhenField() - { - var sourceFile = await SourceFile.LoadAsync(ReadonlyPublicFieldsFilePath); - - var diagnostic = AnalyzerVerifier.Diagnostic(DeclarationCouldBeConvertedToPropertyAnalyzer.Descriptor) - .WithLocation(sourceFile.Name, 5, 28) - .WithLocation(sourceFile.Name, 5, 28) - .WithMessage(string.Format(DeclarationCouldBeConvertedToPropertyAnalyzer.Format, "field")); - - var test = new CSharpAnalyzerTest - { - TestState = - { - Sources = - { - sourceFile, - }, - }, - ExpectedDiagnostics = { diagnostic }, - }; - - await test.RunAsync(); - } - - private const string PublicPropertyFilePath = - "SourceKit.Sample/Analyzers/DeclarationCouldBeConvertedToProperty/PublicProperty.cs"; - - private const string PrivateFieldWithoutMethodsFilePath = - "SourceKit.Sample/Analyzers/DeclarationCouldBeConvertedToProperty/PrivateFieldWithoutMethods.cs"; - - private const string OnePublicFieldFilePath = - "SourceKit.Sample/Analyzers/DeclarationCouldBeConvertedToProperty/OnePublicField.cs"; - - private const string ManyPublicFieldsFilePath = - "SourceKit.Sample/Analyzers/DeclarationCouldBeConvertedToProperty/ManyPublicFields.cs"; - - private const string OneFieldFilePath = - "SourceKit.Sample/Analyzers/DeclarationCouldBeConvertedToProperty/OneField.cs"; - - private const string UnderscoreNameFieldFilePath = - "SourceKit.Sample/Analyzers/DeclarationCouldBeConvertedToProperty/UnderscoreNameField.cs"; - - private const string ExpressionBodyMethodsFieldFilePath = - "SourceKit.Sample/Analyzers/DeclarationCouldBeConvertedToProperty/ExpressionBodyMethodsField.cs"; - - private const string ReadonlyPublicFieldsFilePath = - "SourceKit.Sample/Analyzers/DeclarationCouldBeConvertedToProperty/ReadonlyPublicField.cs"; -} \ No newline at end of file diff --git a/tests/SourceKit.Tests/Analyzers/DoNotEnumerateCollectionInLinqChainTests.cs b/tests/SourceKit.Tests/Analyzers/DoNotEnumerateCollectionInLinqChainTests.cs deleted file mode 100644 index a186db5..0000000 --- a/tests/SourceKit.Tests/Analyzers/DoNotEnumerateCollectionInLinqChainTests.cs +++ /dev/null @@ -1,227 +0,0 @@ -using Microsoft.CodeAnalysis.Testing; -using SourceKit.Analyzers.Enumerable.Analyzers; -using Xunit; -using CSharpAnalyzerTest = Microsoft.CodeAnalysis.CSharp.Testing.CSharpAnalyzerTest< - SourceKit.Analyzers.Enumerable.Analyzers.DoNotEnumerateCollectionInLinqChain, - Microsoft.CodeAnalysis.Testing.Verifiers.XUnitVerifier>; -using AnalyzerVerifier = Microsoft.CodeAnalysis.CSharp.Testing.XUnit.AnalyzerVerifier< - SourceKit.Analyzers.Enumerable.Analyzers.DoNotEnumerateCollectionInLinqChain>; -using CodeFixTest = Microsoft.CodeAnalysis.CSharp.Testing.CSharpCodeFixTest< - SourceKit.Analyzers.Enumerable.Analyzers.DoNotEnumerateCollectionInLinqChain, - SourceKit.Analyzers.Enumerable.CodeFixes.RemoveTerminalOperationCodeFixProvider, - Microsoft.CodeAnalysis.Testing.Verifiers.XUnitVerifier>; - -namespace SourceKit.Tests.Analyzers; - -public class DoNotEnumerateCollectionInLinqChainTests -{ - [Fact] - public async Task NoIssues_WhenNoLinqMethodsUsedAfterConversionMethods() - { - const string testCode = - """ - using System; - using System.Collections.Generic; - using System.Linq; - class Program - { - static void Main(string[] args) - { - var list = GetItems().Select(x => new List{x}).Select(x => x.First()).ToList(); - } - static IEnumerable GetItems() - { - return Enumerable.Range(1, 10); - } - } - """; - var test = new CSharpAnalyzerTest - { - TestCode = testCode, - }; - await test.RunAsync(); - } - - [Fact] - public async Task AnalyzerReportsIssue_WhenLinqMethodUsedAfterToList() - { - const string testCode = - """ - using System; - using System.Collections.Generic; - using System.Linq; - class Program - { - static void Main(string[] args) - { - var list = GetItems().ToList().Where(x => x > 5); - } - static IEnumerable GetItems() - { - return Enumerable.Range(1, 10); - } - } - """; - - DiagnosticResult expectedDiagnostic = AnalyzerVerifier.Diagnostic(DoNotEnumerateCollectionInLinqChain.Descriptor) - .WithLocation(8, 31).WithArguments("ToList"); - - var test = new CSharpAnalyzerTest - { - TestCode = testCode, - ExpectedDiagnostics = { expectedDiagnostic } - }; - - await test.RunAsync(); - } - - [Fact] - public async Task AnalyzerReportsIssue_WhenLinqMethodUsedAfterToLookup() - { - const string testCode = - """ - using System.Collections.Generic; - using System.Linq; - class Program - { - private class Comparer : IEqualityComparer - { - bool IEqualityComparer.Equals(T x, T y) - { - return x.Equals(y); - } - int IEqualityComparer.GetHashCode(T obj) - { - return obj.GetHashCode(); - } - } - static void Main(string[] args) - { - var list = GetItems().ToLookup(x => x, new Comparer()).Where(x => x.Key > 4); - } - static IEnumerable GetItems() - { - return Enumerable.Range(1, 10); - } - } - """; - - DiagnosticResult expectedDiagnostic = AnalyzerVerifier.Diagnostic(DoNotEnumerateCollectionInLinqChain.Descriptor) - .WithLocation(18, 31).WithArguments("ToLookup"); - - var test = new CSharpAnalyzerTest - { - TestCode = testCode, - ExpectedDiagnostics = { expectedDiagnostic } - }; - - await test.RunAsync(); - } - - [Fact] - public async Task AnalyzerReportsIssue_WhenLinqMethodUsedAfterToArray() - { - const string testCode = - """ - using System; - using System.Collections.Generic; - using System.Linq; - class Program - { - static void Main(string[] args) - { - var list = GetItems().ToArray().Where(x => x > 5); - } - static IEnumerable GetItems() - { - return Enumerable.Range(1, 10); - } - } - """; - - DiagnosticResult expectedDiagnostic = AnalyzerVerifier.Diagnostic(DoNotEnumerateCollectionInLinqChain.Descriptor) - .WithLocation(8, 31).WithArguments("ToArray"); - - var test = new CSharpAnalyzerTest - { - TestCode = testCode, - ExpectedDiagnostics = { expectedDiagnostic } - }; - - await test.RunAsync(); - } - - [Fact] - public async Task CodeFixerFix_WhenLinqUsedAfterTerminationMethods() - { - const string fix = """ - using System.Collections.Generic; - using System.Linq; - class Program - { - private class Comparer : IEqualityComparer - { - bool IEqualityComparer.Equals(T x, T y) - { - return x.Equals(y); - } - int IEqualityComparer.GetHashCode(T obj) - { - return obj.GetHashCode(); - } - } - static void Main(string[] args) - { - var list = GetItems().First(); - } - static IEnumerable GetItems() - { - return Enumerable.Range(1, 10); - } - } - """; - const string testCode = """ - using System.Collections.Generic; - using System.Linq; - class Program - { - private class Comparer : IEqualityComparer - { - bool IEqualityComparer.Equals(T x, T y) - { - return x.Equals(y); - } - int IEqualityComparer.GetHashCode(T obj) - { - return obj.GetHashCode(); - } - } - static void Main(string[] args) - { - var list = GetItems().ToLookup(x => x, new Comparer()).First(); - } - static IEnumerable GetItems() - { - return Enumerable.Range(1, 10); - } - } - """; - - var test = new CodeFixTest - { - TestCode = testCode, - FixedCode = fix, - ExpectedDiagnostics = - { - AnalyzerVerifier.Diagnostic(DoNotEnumerateCollectionInLinqChain.Descriptor) - .WithLocation(18, 31).WithArguments("ToLookup"), - }, - DisabledDiagnostics = - { - "CS1061", - } - }; - - await test.RunAsync(); - } -} \ No newline at end of file diff --git a/tests/SourceKit.Tests/Analyzers/Enumerable/OfTypeMustUseDerivedTypeTests.cs b/tests/SourceKit.Tests/Analyzers/Enumerable/OfTypeMustUseDerivedTypeTests.cs deleted file mode 100644 index eed7698..0000000 --- a/tests/SourceKit.Tests/Analyzers/Enumerable/OfTypeMustUseDerivedTypeTests.cs +++ /dev/null @@ -1,36 +0,0 @@ -using Microsoft.CodeAnalysis.CSharp.Testing; -using Microsoft.CodeAnalysis.Testing.Verifiers; -using SourceKit.Analyzers.Enumerable.Analyzers; -using SourceKit.Tests.Tools; -using Xunit; -using AnalyzerVerifier = Microsoft.CodeAnalysis.CSharp.Testing.XUnit.AnalyzerVerifier< - SourceKit.Analyzers.Enumerable.Analyzers.OfTypeMustUseDerivedTypeAnalyzer>; - -namespace SourceKit.Tests.Analyzers.Enumerable; - -public class OfTypeMustUseDerivedTypeTests -{ - [Fact] - public async Task OfTypeMustUseDerivedType_ShouldReportDiagnostic_WhenUsedWithNotDerivedType() - { - var sourceFile = await SourceFile.LoadAsync("SourceKit.Sample/Analyzers/Enumerable/OfTypeSample.cs"); - - var diagnostic = AnalyzerVerifier.Diagnostic(OfTypeMustUseDerivedTypeAnalyzer.Descriptor) - .WithLocation(sourceFile.Name, 10, 16) - .WithArguments(nameof(Int32), nameof(String)); - - var test = new CSharpAnalyzerTest - { - TestState = - { - Sources = - { - sourceFile, - }, - }, - ExpectedDiagnostics = { diagnostic }, - }; - - await test.RunAsync(); - } -} \ No newline at end of file diff --git a/tests/SourceKit.Tests/Analyzers/ListForEachNotAllowedTests.cs b/tests/SourceKit.Tests/Analyzers/ListForEachNotAllowedTests.cs deleted file mode 100644 index 879c6ac..0000000 --- a/tests/SourceKit.Tests/Analyzers/ListForEachNotAllowedTests.cs +++ /dev/null @@ -1,198 +0,0 @@ -using Microsoft.CodeAnalysis.CSharp.Testing; -using Microsoft.CodeAnalysis.Testing.Verifiers; -using SourceKit.Analyzers.Collections.Analyzers; -using SourceKit.Tests.Tools; -using Xunit; - -namespace SourceKit.Tests.Analyzers; - -using AnalyzerVerifier = Microsoft.CodeAnalysis.CSharp.Testing.XUnit.AnalyzerVerifier; - -public class ListForEachNotAllowedTests -{ - [Fact] - public async Task ListForEachNotAllowed_NoListForEachExpressions_ShouldReportNoDiagnostic() - { - var test = new CSharpAnalyzerTest - { - TestState = - { - Sources = - { - await SourceFile.LoadAsync(NoListForEachStatementPath) - } - } - }; - - await test.RunAsync(); - } - - [Fact] - public async Task - ListForEachNotAllowed_ClassMethodContainsListForEachStatementWithLambdaBlock_ShouldReportDiagnostic() - { - var sourceFile = await SourceFile.LoadAsync(ListForEachStatementWithLambdaBlockPath); - - var diagnostic = AnalyzerVerifier.Diagnostic(ListForEachNotAllowedAnalyzer.Descriptor) - .WithLocation(sourceFile.Name, 12, 9) - .WithMessage(string.Format(ListForEachNotAllowedAnalyzer.Format)); - - var test = new CSharpAnalyzerTest - { - TestState = - { - Sources = - { - sourceFile - } - }, - ExpectedDiagnostics = - { - diagnostic - } - }; - - await test.RunAsync(); - } - - [Fact] - public async Task - ListForEachNotAllowed_ClassMethodContainsListForEachStatementWithLambdaExpression_ShouldReportDiagnostic() - { - var sourceFile = await SourceFile.LoadAsync(ListForEachStatementWithLambdaExpressionPath); - - var diagnostic = AnalyzerVerifier.Diagnostic(ListForEachNotAllowedAnalyzer.Descriptor) - .WithLocation(sourceFile.Name, 12, 9) - .WithMessage(string.Format(ListForEachNotAllowedAnalyzer.Format)); - - var test = new CSharpAnalyzerTest - { - TestState = - { - Sources = - { - sourceFile - } - }, - ExpectedDiagnostics = - { - diagnostic - } - }; - - await test.RunAsync(); - } - - [Fact] - public async Task - ListForEachNotAllowed_ClassMethodContainsListForEachStatementWithMemberAccessExpression_ShouldReportDiagnostic() - { - var sourceFile = await SourceFile.LoadAsync(ListForEachStatementWithMemberAccessExpressionPath); - - var diagnostic = AnalyzerVerifier.Diagnostic(ListForEachNotAllowedAnalyzer.Descriptor) - .WithLocation(sourceFile.Name, 12, 9) - .WithMessage(string.Format(ListForEachNotAllowedAnalyzer.Format)); - - var test = new CSharpAnalyzerTest - { - TestState = - { - Sources = - { - sourceFile - } - }, - ExpectedDiagnostics = - { - diagnostic - } - }; - - await test.RunAsync(); - } - - [Fact] - public async Task - ListForEachNotAllowed_ClassMethodContainsListForEachStatementWithMethodLink_ShouldReportDiagnostic() - { - var sourceFile = await SourceFile.LoadAsync(ListForEachStatementWithMethodLinkPath); - - var diagnostic = AnalyzerVerifier.Diagnostic(ListForEachNotAllowedAnalyzer.Descriptor) - .WithLocation(sourceFile.Name, 13, 9) - .WithMessage(string.Format(ListForEachNotAllowedAnalyzer.Format)); - - var test = new CSharpAnalyzerTest - { - TestState = - { - Sources = - { - sourceFile - } - }, - ExpectedDiagnostics = - { - diagnostic - } - }; - - await test.RunAsync(); - } - - [Fact] - public async Task ListForEachNotAllowed_ClassMethodContainsSeveralListForEachExpressions_ShouldReportDiagnostic() - { - var sourceFile = await SourceFile.LoadAsync(SeveralListForEachStatementsPath); - - var lambdaWithExpressionDiagnostic = AnalyzerVerifier.Diagnostic(ListForEachNotAllowedAnalyzer.Descriptor) - .WithLocation(sourceFile.Name, 15, 9) - .WithMessage(string.Format(ListForEachNotAllowedAnalyzer.Format)); - var lambdaWithBlockDiagnostic = AnalyzerVerifier.Diagnostic(ListForEachNotAllowedAnalyzer.Descriptor) - .WithLocation(sourceFile.Name, 16, 9) - .WithMessage(string.Format(ListForEachNotAllowedAnalyzer.Format)); - var memberAccessExpressionDiagnostic = AnalyzerVerifier.Diagnostic(ListForEachNotAllowedAnalyzer.Descriptor) - .WithLocation(sourceFile.Name, 21, 9) - .WithMessage(string.Format(ListForEachNotAllowedAnalyzer.Format)); - var identifierNameDiagnostic = AnalyzerVerifier.Diagnostic(ListForEachNotAllowedAnalyzer.Descriptor) - .WithLocation(sourceFile.Name, 22, 9) - .WithMessage(string.Format(ListForEachNotAllowedAnalyzer.Format)); - - var test = new CSharpAnalyzerTest - { - TestState = - { - Sources = - { - sourceFile - } - }, - ExpectedDiagnostics = - { - lambdaWithExpressionDiagnostic, - lambdaWithBlockDiagnostic, - memberAccessExpressionDiagnostic, - identifierNameDiagnostic - } - }; - - await test.RunAsync(); - } - - private const string NoListForEachStatementPath = - "SourceKit.Sample/Analyzers/ListForEachNotAllowed/NoListForEachStatementExample.cs"; - - private const string ListForEachStatementWithLambdaBlockPath = - "SourceKit.Sample/Analyzers/ListForEachNotAllowed/ListForEachStatementWithLambdaBlockExample.cs"; - - private const string ListForEachStatementWithLambdaExpressionPath = - "SourceKit.Sample/Analyzers/ListForEachNotAllowed/ListForEachStatementWithLambdaExpressionExample.cs"; - - private const string ListForEachStatementWithMemberAccessExpressionPath = - "SourceKit.Sample/Analyzers/ListForEachNotAllowed/ListForEachStatementWithMemberAccessExpressionExample.cs"; - - private const string ListForEachStatementWithMethodLinkPath = - "SourceKit.Sample/Analyzers/ListForEachNotAllowed/ListForEachStatementWithMethodLinkExample.cs"; - - private const string SeveralListForEachStatementsPath = - "SourceKit.Sample/Analyzers/ListForEachNotAllowed/ListForEachStatementComplexExample.cs"; -} \ No newline at end of file diff --git a/tests/SourceKit.Tests/Analyzers/MustBePartialTests.cs b/tests/SourceKit.Tests/Analyzers/MustBePartialTests.cs deleted file mode 100644 index 804bb5b..0000000 --- a/tests/SourceKit.Tests/Analyzers/MustBePartialTests.cs +++ /dev/null @@ -1,92 +0,0 @@ -using Microsoft.CodeAnalysis.CSharp.Testing; -using Microsoft.CodeAnalysis.Testing.Verifiers; -using SourceKit.Analyzers.MustBePartial.Analyzers; -using SourceKit.Analyzers.MustBePartial.Annotations; -using SourceKit.Tests.Tools; -using Xunit; -using AnalyzerVerifier = Microsoft.CodeAnalysis.CSharp.Testing.XUnit.AnalyzerVerifier< - SourceKit.Analyzers.MustBePartial.Analyzers.TypeMustBePartialAnalyzer>; -using CodeFixTest = Microsoft.CodeAnalysis.CSharp.Testing.CSharpCodeFixTest< - SourceKit.Analyzers.MustBePartial.Analyzers.TypeMustBePartialAnalyzer, - SourceKit.Analyzers.MustBePartial.CodeFixes.MakeTypePartialCodeFixProvider, - Microsoft.CodeAnalysis.Testing.Verifiers.XUnitVerifier>; - -namespace SourceKit.Tests.Analyzers; - -public class MustBePartialTests -{ - [Fact] - public async Task DerivativesMustBePartial_ShouldReportDiagnostic_WhenTypeIsNotPartial() - { - var sourceFile = await SourceFile.LoadAsync("SourceKit.Sample/Analyzers/MustBePartial/NonPartialDerivative.cs"); - - var diagnostic = AnalyzerVerifier.Diagnostic(TypeMustBePartialAnalyzer.Descriptor) - .WithLocation(sourceFile.Name, 3, 14) - .WithArguments("NonPartialDerivative"); - - var test = new CSharpAnalyzerTest - { - TestState = - { - Sources = - { - sourceFile, - await SourceFile.LoadAsync("SourceKit.Sample/Analyzers/MustBePartial/IPartialBase.cs"), - }, - AdditionalReferences = { typeof(DerivativesMustBePartialAttribute).Assembly }, - }, - ExpectedDiagnostics = { diagnostic }, - }; - - await test.RunAsync(); - } - - [Fact] - public async Task DerivativesMustBePartial_ShouldReportNoDiagnostic_WhenTypeIsPartial() - { - var test = new CSharpAnalyzerTest - { - TestState = - { - Sources = - { - await SourceFile.LoadAsync("SourceKit.Sample/Analyzers/MustBePartial/PartialDerivative.cs"), - await SourceFile.LoadAsync("SourceKit.Sample/Analyzers/MustBePartial/IPartialBase.cs"), - }, - AdditionalReferences = { typeof(DerivativesMustBePartialAttribute).Assembly }, - }, - }; - - await test.RunAsync(); - } - - [Fact] - public async Task MakeTypePartial_ShouldMakeTypePartial_WhenDiagnosticReported() - { - var interfaceSource = await SourceFile.LoadAsync("SourceKit.Sample/Analyzers/MustBePartial/IPartialBase.cs"); - var sourceFile = await SourceFile.LoadAsync("SourceKit.Sample/Analyzers/MustBePartial/NonPartialDerivative.cs"); - var fixedContent = sourceFile.Content.Replace("public class", "public partial class"); - - var fixedSource = sourceFile with { Content = fixedContent }; - - var diagnostic = AnalyzerVerifier.Diagnostic(TypeMustBePartialAnalyzer.Descriptor) - .WithLocation(sourceFile.Name, 3, 14) - .WithArguments("NonPartialDerivative"); - - var test = new CodeFixTest - { - TestState = - { - Sources = { sourceFile, interfaceSource, }, - AdditionalReferences = { typeof(DerivativesMustBePartialAttribute).Assembly }, - }, - FixedState = - { - Sources = { fixedSource, interfaceSource }, - }, - ExpectedDiagnostics = { diagnostic }, - }; - - await test.RunAsync(); - } -} \ No newline at end of file diff --git a/tests/SourceKit.Tests/Analyzers/NullForgivingOperatorNotAllowedTests.cs b/tests/SourceKit.Tests/Analyzers/NullForgivingOperatorNotAllowedTests.cs deleted file mode 100644 index 116b878..0000000 --- a/tests/SourceKit.Tests/Analyzers/NullForgivingOperatorNotAllowedTests.cs +++ /dev/null @@ -1,57 +0,0 @@ -using Microsoft.CodeAnalysis.CSharp.Testing; -using Microsoft.CodeAnalysis.Testing.Verifiers; -using SourceKit.Analyzers.Nullable.Analyzers; -using SourceKit.Tests.Tools; -using Xunit; -using AnalyzerVerifier = Microsoft.CodeAnalysis.CSharp.Testing.XUnit.AnalyzerVerifier< - SourceKit.Analyzers.Nullable.Analyzers.NullForgivingOperatorNotAllowedAnalyzer>; -using CodeFixTest = Microsoft.CodeAnalysis.CSharp.Testing.CSharpCodeFixTest< - SourceKit.Analyzers.Nullable.Analyzers.NullForgivingOperatorNotAllowedAnalyzer, - SourceKit.Analyzers.Nullable.CodeFixes.PropagateNullableCorrectlyCodeFixProvider, - Microsoft.CodeAnalysis.Testing.Verifiers.XUnitVerifier>; - -namespace SourceKit.Tests.Analyzers; - -public class NullForgivingOperatorNotAllowedTests -{ - [Fact] - public async Task NullForgivingOperatorNotAllowed_ShouldReportDiagnostic_AllVariationsOfNullSuppression() - { - var sourceFile = - await SourceFile.LoadAsync("SourceKit.Sample/Analyzers/NullForgivingOperatorNotAllowed/JokeExample.cs"); - - var test = new CSharpAnalyzerTest - { - TestState = - { - Sources = - { - sourceFile - } - }, - ExpectedDiagnostics = - { - AnalyzerVerifier.Diagnostic(NullForgivingOperatorNotAllowedAnalyzer.Descriptor) - .WithSpan(sourceFile.Name, 34, 36, 34, 65), - AnalyzerVerifier.Diagnostic(NullForgivingOperatorNotAllowedAnalyzer.Descriptor) - .WithSpan(sourceFile.Name, 36, 35, 36, 68), - AnalyzerVerifier.Diagnostic(NullForgivingOperatorNotAllowedAnalyzer.Descriptor) - .WithSpan(sourceFile.Name, 38, 47, 38, 97), - AnalyzerVerifier.Diagnostic(NullForgivingOperatorNotAllowedAnalyzer.Descriptor) - .WithSpan(sourceFile.Name, 39, 45, 39, 95), - AnalyzerVerifier.Diagnostic(NullForgivingOperatorNotAllowedAnalyzer.Descriptor) - .WithSpan(sourceFile.Name, 40, 46, 40, 75), - AnalyzerVerifier.Diagnostic(NullForgivingOperatorNotAllowedAnalyzer.Descriptor) - .WithSpan(sourceFile.Name, 42, 55, 42, 105), - AnalyzerVerifier.Diagnostic(NullForgivingOperatorNotAllowedAnalyzer.Descriptor) - .WithSpan(sourceFile.Name, 43, 52, 43, 85), - AnalyzerVerifier.Diagnostic(NullForgivingOperatorNotAllowedAnalyzer.Descriptor) - .WithSpan(sourceFile.Name, 46, 13, 46, 63), - AnalyzerVerifier.Diagnostic(NullForgivingOperatorNotAllowedAnalyzer.Descriptor) - .WithSpan(sourceFile.Name, 48, 13, 48, 67), - } - }; - - await test.RunAsync(); - } -} \ No newline at end of file diff --git a/tests/SourceKit.Tests/Analyzers/NullableDisableNotAllowedTests.cs b/tests/SourceKit.Tests/Analyzers/NullableDisableNotAllowedTests.cs deleted file mode 100644 index fabeab5..0000000 --- a/tests/SourceKit.Tests/Analyzers/NullableDisableNotAllowedTests.cs +++ /dev/null @@ -1,80 +0,0 @@ -using Microsoft.CodeAnalysis.CSharp.Testing; -using Microsoft.CodeAnalysis.Testing.Verifiers; -using SourceKit.Analyzers.Nullable.Analyzers; -using SourceKit.Tests.Tools; -using Xunit; -using AnalyzerVerifier = Microsoft.CodeAnalysis.CSharp.Testing.XUnit.AnalyzerVerifier< - SourceKit.Analyzers.Nullable.Analyzers.NullableDisableNotAllowedAnalyzer>; -namespace SourceKit.Tests.Analyzers; - -public class NullableDisableNotAllowedTests -{ - - [Fact] - public async Task NullableDisableNotAllowed_ShouldReportDiagnostic_WhenNullableDisableIsUsed() - { - var sourceFile = await SourceFile.LoadAsync("SourceKit.Sample/Analyzers/Nullable/NullableDisable.cs"); - - var diagnostic = AnalyzerVerifier.Diagnostic(NullableDisableNotAllowedAnalyzer.Descriptor) - .WithLocation(sourceFile.Name, 1, 1); - - var test = new CSharpAnalyzerTest - { - TestState = - { - Sources = - { - sourceFile, - }, - }, - ExpectedDiagnostics = { diagnostic }, - }; - - await test.RunAsync(); - } - - [Fact] - public async Task OtherNullableKeywordsAllowed_ShouldReportNoDiagnostic_WhenNullableEnableIsUsed() - { - var sourceFile = await SourceFile.LoadAsync("SourceKit.Sample/Analyzers/Nullable/NullableEnable.cs"); - - var test = new CSharpAnalyzerTest - { - TestState = - { - Sources = - { - sourceFile, - }, - }, - ExpectedDiagnostics = { }, - }; - - await test.RunAsync(); - } - [Fact] - public async Task NullableDisableNotAllowed_ShouldReport2Diagnostics_WhenNullableDisableIsUsedTwice() - { - var sourceFile = await SourceFile.LoadAsync("SourceKit.Sample/Analyzers/Nullable/MultipleNestedNullableDisable.cs"); - - var diagnostic1 = AnalyzerVerifier.Diagnostic(NullableDisableNotAllowedAnalyzer.Descriptor) - .WithLocation(sourceFile.Name, 1, 1); - var diagnostic2 = AnalyzerVerifier.Diagnostic(NullableDisableNotAllowedAnalyzer.Descriptor) - .WithLocation(sourceFile.Name, 18, 21); - - var test = new CSharpAnalyzerTest - { - TestState = - { - Sources = - { - sourceFile, - }, - - }, - ExpectedDiagnostics = { diagnostic1, diagnostic2 }, - }; - - await test.RunAsync(); - } -} \ No newline at end of file diff --git a/tests/SourceKit.Tests/CodeFixProviders/ConvertDeclarationIntoPropertyTests.cs b/tests/SourceKit.Tests/CodeFixProviders/ConvertDeclarationIntoPropertyTests.cs deleted file mode 100644 index f16ad4c..0000000 --- a/tests/SourceKit.Tests/CodeFixProviders/ConvertDeclarationIntoPropertyTests.cs +++ /dev/null @@ -1,298 +0,0 @@ -using SourceKit.Analyzers.Properties.Analyzers; -using SourceKit.Tests.Tools; -using AnalyzerVerifier = Microsoft.CodeAnalysis.CSharp.Testing.XUnit.AnalyzerVerifier< - SourceKit.Analyzers.Properties.Analyzers.DeclarationCouldBeConvertedToPropertyAnalyzer>; -using CodeFixTest = Microsoft.CodeAnalysis.CSharp.Testing.CSharpCodeFixTest< - SourceKit.Analyzers.Properties.Analyzers.DeclarationCouldBeConvertedToPropertyAnalyzer, - SourceKit.Analyzers.Properties.CodeFixes.ConvertDeclarationIntoPropertyCodeFixProvider, - Microsoft.CodeAnalysis.Testing.Verifiers.XUnitVerifier>; -using Xunit; - -namespace SourceKit.Tests.CodeFixProviders; - -public class ConvertDeclarationIntoPropertyTests -{ - [Fact] - public async Task ConvertPublicDeclarationIntoProperty_ShouldGenerateCorrectProperty() - { - var sourceFile = await SourceFile.LoadAsync(OnePublicFieldFilePath); - var fixedFile = new SourceFile(FixedOnePublicFieldFileName, OnePublicFieldFile); - - var diagnostic = AnalyzerVerifier.Diagnostic(DeclarationCouldBeConvertedToPropertyAnalyzer.Descriptor) - .WithLocation(sourceFile.Name, 5, 19) - .WithLocation(sourceFile.Name, 5, 19) - .WithMessage(string.Format(DeclarationCouldBeConvertedToPropertyAnalyzer.Format, "field")); - - var test = new CodeFixTest - { - TestState = - { - Sources = { sourceFile }, - ExpectedDiagnostics = { diagnostic }, - }, - FixedState = - { - Sources = { fixedFile } - } - }; - - await test.RunAsync(); - } - - [Fact] - public async Task ConvertPublicDeclarationsIntoProperties_ShouldGenerateCorrectProperties() - { - var sourceFile = await SourceFile.LoadAsync(ManyPublicFieldsFilePath); - var fixedFile = new SourceFile(FixedManyPublicFieldsFileName, FixedManyPublicFieldsFile); - - var diagnostic1 = AnalyzerVerifier.Diagnostic(DeclarationCouldBeConvertedToPropertyAnalyzer.Descriptor) - .WithLocation(sourceFile.Name, 7, 25) - .WithLocation(sourceFile.Name, 7, 25) - .WithMessage(string.Format(DeclarationCouldBeConvertedToPropertyAnalyzer.Format, "first")); - var diagnostic2 = AnalyzerVerifier.Diagnostic(DeclarationCouldBeConvertedToPropertyAnalyzer.Descriptor) - .WithLocation(sourceFile.Name, 7, 32) - .WithLocation(sourceFile.Name, 7, 32) - .WithMessage(string.Format(DeclarationCouldBeConvertedToPropertyAnalyzer.Format, "second")); - - var test = new CodeFixTest - { - TestState = - { - Sources = { sourceFile }, - ExpectedDiagnostics = { diagnostic1, diagnostic2 }, - }, - FixedState = - { - Sources = { fixedFile }, - }, - NumberOfFixAllInDocumentIterations = 2, - NumberOfFixAllInProjectIterations = 2, - NumberOfFixAllIterations = 2 - }; - - await test.RunAsync(); - } - - [Fact] - public async Task ConvertDeclarationIntoProperty_ShouldGenerateCorrectProperty() - { - var sourceFile = await SourceFile.LoadAsync(OneFieldFilepath); - var fixedFile = new SourceFile(FixedOneFieldFileName, FixedOneFieldFile); - - var diagnostic1 = AnalyzerVerifier.Diagnostic(DeclarationCouldBeConvertedToPropertyAnalyzer.Descriptor) - .WithLocation(sourceFile.Name, 5, 20) - .WithLocation(sourceFile.Name, 5, 20) - .WithLocation(sourceFile.Name, 3, 1) - .WithMessage(string.Format(DeclarationCouldBeConvertedToPropertyAnalyzer.Format, "field")); - var diagnostic2 = AnalyzerVerifier.Diagnostic(DeclarationCouldBeConvertedToPropertyAnalyzer.Descriptor) - .WithLocation(sourceFile.Name, 7, 19) - .WithLocation(sourceFile.Name, 5, 20) - .WithLocation(sourceFile.Name, 3, 1) - .WithMessage(string.Format(DeclarationCouldBeConvertedToPropertyAnalyzer.Format, "field")); - var diagnostic3 = AnalyzerVerifier.Diagnostic(DeclarationCouldBeConvertedToPropertyAnalyzer.Descriptor) - .WithLocation(sourceFile.Name, 12, 17) - .WithLocation(sourceFile.Name, 5, 20) - .WithLocation(sourceFile.Name, 3, 1) - .WithMessage(string.Format(DeclarationCouldBeConvertedToPropertyAnalyzer.Format, "field")); - - var test = new CodeFixTest - { - TestState = - { - Sources = { sourceFile }, - ExpectedDiagnostics = { diagnostic1, diagnostic2, diagnostic3 }, - }, - FixedState = - { - Sources = { fixedFile } - } - }; - - await test.RunAsync(); - } - - [Fact] - public async Task ConvertDeclarationWithUnderscoreIntoProperty_ShouldGenerateCorrectProperty() - { - var sourceFile = await SourceFile.LoadAsync(UnderscoreNameFieldFilePath); - var fixedFile = new SourceFile(FixedUnderscoreNameFieldFileName, FixedUnderscoreNameFieldFile); - - var diagnostic1 = AnalyzerVerifier.Diagnostic(DeclarationCouldBeConvertedToPropertyAnalyzer.Descriptor) - .WithLocation(sourceFile.Name, 5, 29) - .WithLocation(sourceFile.Name, 5, 29) - .WithLocation(sourceFile.Name, 3, 1) - .WithMessage(string.Format(DeclarationCouldBeConvertedToPropertyAnalyzer.Format, "_field")); - var diagnostic2 = AnalyzerVerifier.Diagnostic(DeclarationCouldBeConvertedToPropertyAnalyzer.Descriptor) - .WithLocation(sourceFile.Name, 7, 19) - .WithLocation(sourceFile.Name, 5, 29) - .WithLocation(sourceFile.Name, 3, 1) - .WithMessage(string.Format(DeclarationCouldBeConvertedToPropertyAnalyzer.Format, "_field")); - - var test = new CodeFixTest - { - TestState = - { - Sources = { sourceFile }, - ExpectedDiagnostics = { diagnostic1, diagnostic2 }, - }, - FixedState = - { - Sources = { fixedFile } - } - }; - - await test.RunAsync(); - } - - [Fact] - public async Task ConvertDeclarationWithExpressionBodyIntoProperty_ShouldGenerateCorrectProperty() - { - var sourceFile = await SourceFile.LoadAsync(ExpressionBodyMethodsFieldFilePath); - var fixedFile = new SourceFile(FixedExpressionBodyMethodsFieldFileName, FixedExpressionBodyMethodsFieldFile); - - var diagnostic1 = AnalyzerVerifier.Diagnostic(DeclarationCouldBeConvertedToPropertyAnalyzer.Descriptor) - .WithLocation(sourceFile.Name, 5, 20) - .WithLocation(sourceFile.Name, 5, 20) - .WithLocation(sourceFile.Name, 3, 1) - .WithMessage(string.Format(DeclarationCouldBeConvertedToPropertyAnalyzer.Format, "field")); - var diagnostic2 = AnalyzerVerifier.Diagnostic(DeclarationCouldBeConvertedToPropertyAnalyzer.Descriptor) - .WithLocation(sourceFile.Name, 7, 19) - .WithLocation(sourceFile.Name, 5, 20) - .WithLocation(sourceFile.Name, 3, 1) - .WithMessage(string.Format(DeclarationCouldBeConvertedToPropertyAnalyzer.Format, "field")); - var diagnostic3 = AnalyzerVerifier.Diagnostic(DeclarationCouldBeConvertedToPropertyAnalyzer.Descriptor) - .WithLocation(sourceFile.Name, 9, 29) - .WithLocation(sourceFile.Name, 5, 20) - .WithLocation(sourceFile.Name, 3, 1) - .WithMessage(string.Format(DeclarationCouldBeConvertedToPropertyAnalyzer.Format, "field")); - - var test = new CodeFixTest - { - TestState = - { - Sources = { sourceFile }, - ExpectedDiagnostics = { diagnostic1, diagnostic2, diagnostic3 }, - }, - FixedState = - { - Sources = { fixedFile } - } - }; - - await test.RunAsync(); - } - - [Fact] - public async Task ConvertDeclarationWithReadonlyIntoProperty_ShouldGenerateCorrectProperty() - { - var sourceFile = await SourceFile.LoadAsync(ReadonlyPublicFieldFilePath); - var fixedFile = new SourceFile(ReadonlyPublicFieldFileName, ReadonlyPublicFieldFile); - - var diagnostic = AnalyzerVerifier.Diagnostic(DeclarationCouldBeConvertedToPropertyAnalyzer.Descriptor) - .WithLocation(sourceFile.Name, 5, 28) - .WithLocation(sourceFile.Name, 5, 28) - .WithMessage(string.Format(DeclarationCouldBeConvertedToPropertyAnalyzer.Format, "field")); - - var test = new CodeFixTest - { - TestState = - { - Sources = { sourceFile }, - ExpectedDiagnostics = { diagnostic }, - }, - FixedState = - { - Sources = { fixedFile } - } - }; - - await test.RunAsync(); - } - - private const string OnePublicFieldFilePath = - "SourceKit.Sample/Analyzers/DeclarationCouldBeConvertedToProperty/OnePublicField.cs"; - - private const string FixedOnePublicFieldFileName = "OnePublicField.cs"; - - private const string OnePublicFieldFile = """ -namespace SourceKit.Sample.Analyzers.DeclarationCouldBeConvertedToProperty; - -public class OnePublicField -{ - public string Field { get; set; } -} -"""; - - private const string ManyPublicFieldsFilePath = - "SourceKit.Sample/Analyzers/DeclarationCouldBeConvertedToProperty/ManyPublicFields.cs"; - - private const string FixedManyPublicFieldsFileName = "ManyPublicFields.cs"; - - private const string FixedManyPublicFieldsFile = """ -using System.Collections.Generic; - -namespace SourceKit.Sample.Analyzers.DeclarationCouldBeConvertedToProperty; - -public class ManyPublicFields -{ - public List First { get; set; } - public List Second { get; set; } -} -"""; - - private const string OneFieldFilepath = - "SourceKit.Sample/Analyzers/DeclarationCouldBeConvertedToProperty/OneField.cs"; - - private const string FixedOneFieldFileName = "OneField.cs"; - - private const string FixedOneFieldFile = """ -namespace SourceKit.Sample.Analyzers.DeclarationCouldBeConvertedToProperty; - -public class OneField -{ - public string Field { get; set; } = "10"; -} -"""; - - private const string UnderscoreNameFieldFilePath = - "SourceKit.Sample/Analyzers/DeclarationCouldBeConvertedToProperty/UnderscoreNameField.cs"; - - private const string FixedUnderscoreNameFieldFileName = "UnderscoreNameField.cs"; - - private const string FixedUnderscoreNameFieldFile = """ -namespace SourceKit.Sample.Analyzers.DeclarationCouldBeConvertedToProperty; - -public class UnderscoreNameField -{ - public string Field { get; } -} -"""; - - private const string ExpressionBodyMethodsFieldFilePath = - "SourceKit.Sample/Analyzers/DeclarationCouldBeConvertedToProperty/ExpressionBodyMethodsField.cs"; - - private const string FixedExpressionBodyMethodsFieldFileName = "ExpressionBodyMethodsField.cs"; - - private const string FixedExpressionBodyMethodsFieldFile = """ -namespace SourceKit.Sample.Analyzers.DeclarationCouldBeConvertedToProperty; - -public class ExpressionBodyMethodsField -{ - public string Field { get; protected internal set; } -} -"""; - - private const string ReadonlyPublicFieldFilePath = - "SourceKit.Sample/Analyzers/DeclarationCouldBeConvertedToProperty/ReadonlyPublicField.cs"; - - private const string ReadonlyPublicFieldFileName = "ReadonlyPublicField.cs"; - - private const string ReadonlyPublicFieldFile = """ -namespace SourceKit.Sample.Analyzers.DeclarationCouldBeConvertedToProperty; - -public class ReadonlyPublicField -{ - public string Field { get; } -} -"""; -} \ No newline at end of file diff --git a/tests/SourceKit.Tests/CodeFixProviders/ConvertListForEachIntoForEachLoop.cs b/tests/SourceKit.Tests/CodeFixProviders/ConvertListForEachIntoForEachLoop.cs deleted file mode 100644 index ba28b48..0000000 --- a/tests/SourceKit.Tests/CodeFixProviders/ConvertListForEachIntoForEachLoop.cs +++ /dev/null @@ -1,251 +0,0 @@ -using SourceKit.Analyzers.Collections.Analyzers; -using SourceKit.Analyzers.Collections.CodeFixes; -using SourceKit.Tests.Tools; -using Xunit; - -namespace SourceKit.Tests.CodeFixProviders; - -using AnalyzerVerifier = Microsoft.CodeAnalysis.CSharp.Testing.XUnit.AnalyzerVerifier; -using CodeFixTest = - Microsoft.CodeAnalysis.CSharp.Testing.CSharpCodeFixTest; - -public class ConvertListForEachIntoForEachLoop -{ - [Fact] - public async Task - ConvertListForEachIntoForEachLoop_WhenDiagnosticReported_ShouldConvertListForEachWithLambdaBlockIntoForEachLoop() - { - var sourceFile = await SourceFile.LoadAsync(ListForEachStatementWithLambdaBlockPath); - var fixedFile = new SourceFile(FixedListForEachStatementWithLambdaBlockExampleFilename, - FixedListForEachStatementWithLambdaBlockExample); - - var diagnostic = AnalyzerVerifier.Diagnostic(ListForEachNotAllowedAnalyzer.Descriptor) - .WithLocation(sourceFile.Name, 12, 9) - .WithMessage(string.Format(ListForEachNotAllowedAnalyzer.Format)); - - var test = new CodeFixTest - { - TestState = - { - Sources = { sourceFile } - }, - FixedState = - { - Sources = { fixedFile } - }, - ExpectedDiagnostics = - { - diagnostic - } - }; - - await test.RunAsync(); - } - - [Fact] - public async Task - ConvertListForEachIntoForEachLoop_WhenDiagnosticReported_ShouldConvertListForEachWithLambdaExpressionIntoForEachLoop() - { - var sourceFile = await SourceFile.LoadAsync(ListForEachStatementWithLambdaExpressionPath); - var fixedFile = new SourceFile(FixedListForEachStatementWithLambdaExpressionExampleFilename, - FixedListForEachStatementWithLambdaExpressionExample); - - var diagnostic = AnalyzerVerifier.Diagnostic(ListForEachNotAllowedAnalyzer.Descriptor) - .WithLocation(sourceFile.Name, 12, 9) - .WithMessage(string.Format(ListForEachNotAllowedAnalyzer.Format)); - - var test = new CodeFixTest - { - TestState = - { - Sources = { sourceFile } - }, - FixedState = - { - Sources = { fixedFile } - }, - ExpectedDiagnostics = - { - diagnostic - } - }; - - await test.RunAsync(); - } - - [Fact] - public async Task - ConvertListForEachIntoForEachLoop_WhenDiagnosticReported_ShouldConvertListForEachWithMemberAccessExpressionIntoForEachLoop() - { - var sourceFile = await SourceFile.LoadAsync(ListForEachStatementWithMemberAccessExpressionPath); - var fixedFile = new SourceFile(FixedListForEachStatementWithMemberAccessExpressionFilename, - FixedListForEachStatementWithMemberAccessExpressionExample); - - var diagnostic = AnalyzerVerifier.Diagnostic(ListForEachNotAllowedAnalyzer.Descriptor) - .WithLocation(sourceFile.Name, 12, 9) - .WithMessage(string.Format(ListForEachNotAllowedAnalyzer.Format)); - - var test = new CodeFixTest - { - TestState = - { - Sources = { sourceFile } - }, - FixedState = - { - Sources = { fixedFile } - }, - ExpectedDiagnostics = - { - diagnostic - } - }; - - await test.RunAsync(); - } - - [Fact] - public async Task - ConvertListForEachIntoForEachLoop_WhenDiagnosticReported_ShouldConvertListForEachWithMethodLinkIntoForEachLoop() - { - var sourceFile = await SourceFile.LoadAsync(ListForEachStatementWithMethodLinkPath); - var fixedFile = new SourceFile(FixedListForEachStatementWithMethodLinkFilename, - FixedListForEachStatementWithMethodLinkExample); - - var diagnostic = AnalyzerVerifier.Diagnostic(ListForEachNotAllowedAnalyzer.Descriptor) - .WithLocation(sourceFile.Name, 13, 9) - .WithMessage(string.Format(ListForEachNotAllowedAnalyzer.Format)); - - var test = new CodeFixTest - { - TestState = - { - Sources = { sourceFile } - }, - FixedState = - { - Sources = { fixedFile } - }, - ExpectedDiagnostics = - { - diagnostic - } - }; - - await test.RunAsync(); - } - - private const string ListForEachStatementWithLambdaBlockPath = - "SourceKit.Sample/Analyzers/ListForEachNotAllowed/ListForEachStatementWithLambdaBlockExample.cs"; - - private const string ListForEachStatementWithLambdaExpressionPath = - "SourceKit.Sample/Analyzers/ListForEachNotAllowed/ListForEachStatementWithLambdaExpressionExample.cs"; - - private const string ListForEachStatementWithMemberAccessExpressionPath = - "SourceKit.Sample/Analyzers/ListForEachNotAllowed/ListForEachStatementWithMemberAccessExpressionExample.cs"; - - private const string ListForEachStatementWithMethodLinkPath = - "SourceKit.Sample/Analyzers/ListForEachNotAllowed/ListForEachStatementWithMethodLinkExample.cs"; - - private const string FixedListForEachStatementWithLambdaBlockExampleFilename = - "ListForEachStatementWithLambdaBlockExample.cs"; - - private const string FixedListForEachStatementWithLambdaExpressionExampleFilename = - "ListForEachStatementWithLambdaExpressionExample.cs"; - - private const string FixedListForEachStatementWithMemberAccessExpressionFilename = - "ListForEachStatementWithMemberAccessExpressionExample.cs"; - - private const string FixedListForEachStatementWithMethodLinkFilename = - "ListForEachStatementWithMethodLinkExample.cs"; - - private const string FixedListForEachStatementWithLambdaBlockExample = """ -using System; -using System.Collections.Generic; - -namespace SourceKit.Sample.Analyzers.ListForEachNotAllowed; - -public class ListForEachStatementWithLambdaBlockExample -{ - public void DoSomething() - { - var a = new List { 1, 2, 3 }; - - foreach (var element in a) - { - Console.WriteLine(element); - Console.WriteLine(element / 2); - } - } -} -"""; - - private const string FixedListForEachStatementWithLambdaExpressionExample = """ -using System.Collections.Generic; - -namespace SourceKit.Sample.Analyzers.ListForEachNotAllowed; - -public class ListForEachStatementWithLambdaExpressionExample -{ - public List DoSomething() - { - var a = new List { 10, 20, 30 }; - var result = new List(); - - foreach (var element in a) - { - result.Add(element / 2); - } - - return result; - } -} -"""; - - private const string FixedListForEachStatementWithMemberAccessExpressionExample = """ -using System; -using System.Collections.Generic; - -namespace SourceKit.Sample.Analyzers.ListForEachNotAllowed; - -public class ListForEachStatementWithMemberAccessExpressionExample -{ - public void DoSomething() - { - var a = new List { 1, 2, 3 }; - - foreach (var element in a) - { - Console.WriteLine(element); - } - } -} -"""; - - private const string FixedListForEachStatementWithMethodLinkExample = """ -using System.Collections.Generic; - -namespace SourceKit.Sample.Analyzers.ListForEachNotAllowed; - -public class ListForEachStatementWithMethodLinkExample -{ - private readonly List _list = new(); - - public void DoSomething() - { - var a = new List { 13, 21, 32 }; - - foreach (var element in a) - { - AddToPrivateList(element); - } - } - - private void AddToPrivateList(int element) - { - _list.Add(element * 10); - } -} -"""; -} \ No newline at end of file diff --git a/tests/SourceKit.Tests/CodeFixProviders/PropagateNullableCorrectlyCodeFixTests.cs b/tests/SourceKit.Tests/CodeFixProviders/PropagateNullableCorrectlyCodeFixTests.cs deleted file mode 100644 index ab34905..0000000 --- a/tests/SourceKit.Tests/CodeFixProviders/PropagateNullableCorrectlyCodeFixTests.cs +++ /dev/null @@ -1,214 +0,0 @@ -using Microsoft.CodeAnalysis.CSharp.Testing; -using Microsoft.CodeAnalysis.Testing.Verifiers; -using SourceKit.Analyzers.Nullable.Analyzers; -using SourceKit.Analyzers.Nullable.CodeFixes; -using SourceKit.Tests.Tools; -using Xunit; -using AnalyzerVerifier = Microsoft.CodeAnalysis.CSharp.Testing.XUnit.AnalyzerVerifier< - SourceKit.Analyzers.Nullable.Analyzers.NullForgivingOperatorNotAllowedAnalyzer>; -using CodeFixTest = Microsoft.CodeAnalysis.CSharp.Testing.CSharpCodeFixTest< - SourceKit.Analyzers.Nullable.Analyzers.NullForgivingOperatorNotAllowedAnalyzer, - SourceKit.Analyzers.Nullable.CodeFixes.PropagateNullableCorrectlyCodeFixProvider, - Microsoft.CodeAnalysis.Testing.Verifiers.XUnitVerifier>; - -namespace SourceKit.Tests.CodeFixProviders; - -public class PropagateNullableCorrectlyCodeFixTests -{ - [Fact] - public async Task PropagateNullableCorrectlyCodeFix_ShouldParseAllSequencesAndChangeTypeOfVariables() - { - var sourceFile = await SourceFile.LoadAsync( - "SourceKit.Sample/CodeFixProviders/PropagateNullCorrectly/JokeExampleWithVariableDeclarations.cs"); - - var test = new CSharpCodeFixTest< - NullForgivingOperatorNotAllowedAnalyzer, - PropagateNullableCorrectlyCodeFixProvider, - XUnitVerifier> - { - TestState = - { - Sources = - { - sourceFile, - }, - ExpectedDiagnostics = - { - AnalyzerVerifier.Diagnostic(NullForgivingOperatorNotAllowedAnalyzer.Descriptor) - .WithSpan(sourceFile.Name, 34, 60, 34, 89), - AnalyzerVerifier.Diagnostic(NullForgivingOperatorNotAllowedAnalyzer.Descriptor) - .WithSpan(sourceFile.Name, 36, 35, 36, 68), - AnalyzerVerifier.Diagnostic(NullForgivingOperatorNotAllowedAnalyzer.Descriptor) - .WithSpan(sourceFile.Name, 38, 47, 38, 97), - AnalyzerVerifier.Diagnostic(NullForgivingOperatorNotAllowedAnalyzer.Descriptor) - .WithSpan(sourceFile.Name, 39, 45, 39, 95), - AnalyzerVerifier.Diagnostic(NullForgivingOperatorNotAllowedAnalyzer.Descriptor) - .WithSpan(sourceFile.Name, 40, 46, 40, 75), - AnalyzerVerifier.Diagnostic(NullForgivingOperatorNotAllowedAnalyzer.Descriptor) - .WithSpan(sourceFile.Name, 42, 55, 42, 105), - AnalyzerVerifier.Diagnostic(NullForgivingOperatorNotAllowedAnalyzer.Descriptor) - .WithSpan(sourceFile.Name, 43, 52, 43, 85), - AnalyzerVerifier.Diagnostic(NullForgivingOperatorNotAllowedAnalyzer.Descriptor) - .WithSpan(sourceFile.Name, 46, 13, 46, 63), - AnalyzerVerifier.Diagnostic(NullForgivingOperatorNotAllowedAnalyzer.Descriptor) - .WithSpan(sourceFile.Name, 48, 13, 48, 67), - } - }, - FixedState = - { - Sources = - { - new SourceFile(sourceFile.Name, JokeExampleWithVariableDeclarations) - } - } - }; - - await test.RunAsync(); - } - - [Fact] - public async Task PropagateNullableCorrectlyCodeFix_ShouldChangeTypeOfFieldAndProperties() - { - var sourceFile = await SourceFile.LoadAsync( - "SourceKit.Sample/CodeFixProviders/PropagateNullCorrectly/JokeExampleWithFieldAndProperties.cs"); - - var test = - new CSharpCodeFixTest() - { - TestState = - { - Sources = - { - sourceFile, - }, - ExpectedDiagnostics = - { - AnalyzerVerifier.Diagnostic(NullForgivingOperatorNotAllowedAnalyzer.Descriptor) - .WithSpan(sourceFile.Name, 5, 63, 5, 79), - AnalyzerVerifier.Diagnostic(NullForgivingOperatorNotAllowedAnalyzer.Descriptor) - .WithSpan(sourceFile.Name, 9, 16, 9, 41), - AnalyzerVerifier.Diagnostic(NullForgivingOperatorNotAllowedAnalyzer.Descriptor) - .WithSpan(sourceFile.Name, 16, 20, 16, 45), - AnalyzerVerifier.Diagnostic(NullForgivingOperatorNotAllowedAnalyzer.Descriptor) - .WithSpan(sourceFile.Name, 20, 32, 20, 57), - } - }, - FixedState = - { - Sources = - { - new SourceFile(sourceFile.Name, JokeExampleWithFieldAndProperties) - } - } - }; - - await test.RunAsync(); - } - - const string JokeExampleWithVariableDeclarations = """ -namespace SourceKit.Sample.CodeFixProviders; - -public class JokeExampleWithVariableDeclarations -{ - public string? GetJoke(int number) - { - switch (number) - { - case 1: - return "Lol"; - case 2: - return "Kek"; - case 3: - return "Trololo"; - default: - return null; - } - } - - public static JokeExampleWithVariableDeclarations? GetJokeClass(int number) - { - if (number == 0) - { - return new JokeExampleWithVariableDeclarations(); - } - else - { - return null; - } - } - - public static string GetUpperJoke(int instanceNumber, int jokeNumber) - { - JokeExampleWithVariableDeclarations? jokeInstance = GetJokeClass(instanceNumber); - - string? jokeFromInstance = jokeInstance.GetJoke(jokeNumber); - - var jokeFromSequenceNothingNullable = GetJokeClass(instanceNumber)?.GetJoke(jokeNumber); - var jokeFromSequenceFirstNullable = GetJokeClass(instanceNumber)?.GetJoke(jokeNumber); - var jokeFromSequenceSecondNullable = GetJokeClass(instanceNumber)?.GetJoke(jokeNumber); - - string? upperJokeFromSequenceNothingNullable = GetJokeClass(instanceNumber)?.GetJoke(jokeNumber)?.ToUpper(); - string? upperJokeFromSequenceFromInstance = jokeInstance.GetJoke(jokeNumber)?.ToUpper(); - - var upperJokeFirstCringeCompilation = - GetJokeClass(instanceNumber)?.GetJoke(jokeNumber)?.ToUpper().ToUpper().ToUpper(); - var upperJokeSecondCringeCompilation = - jokeInstance.GetJoke(jokeNumber)?.ToUpper().ToUpper()?.ToUpper(); - - return upperJokeFirstCringeCompilation; - } -} -"""; - - const string JokeExampleWithFieldAndProperties = """ -namespace SourceKit.Sample.CodeFixProviders; - -public class JokeExampleWithFieldAndProperties -{ - private JokeExampleWithFieldAndProperties? _jokeInstance = GetJokeClass(0); - - public string? FirstJoke - { - get => _jokeInstance.GetJoke(1); - } - - public string? SecondJoke - { - get - { - return _jokeInstance.GetJoke(2); - } - } - - public string? ThirdJoke => _jokeInstance.GetJoke(3); - - public string? GetJoke(int number) - { - switch (number) - { - case 1: - return "Lol"; - case 2: - return "Kek"; - case 3: - return "Trololo"; - default: - return null; - } - } - - public static JokeExampleWithFieldAndProperties? GetJokeClass(int number) - { - if (number == 0) - { - return new JokeExampleWithFieldAndProperties(); - } - else - { - return null; - } - } -} -"""; -} \ No newline at end of file diff --git a/tests/SourceKit.Tests/Generators/BuilderTests.cs b/tests/SourceKit.Tests/Generators/BuilderTests.cs deleted file mode 100644 index 4e92f2c..0000000 --- a/tests/SourceKit.Tests/Generators/BuilderTests.cs +++ /dev/null @@ -1,212 +0,0 @@ -using Microsoft.CodeAnalysis.CSharp.Testing; -using Microsoft.CodeAnalysis.Testing; -using Microsoft.CodeAnalysis.Testing.Verifiers; -using SourceKit.Generators.Builder.Annotations; -using SourceKit.Generators.Builder.Generators; -using SourceKit.Tests.Tools; -using Xunit; -using Verifier = Microsoft.CodeAnalysis.CSharp.Testing.CSharpSourceGeneratorVerifier< - SourceKit.Generators.Builder.Generators.BuilderSourceGenerator, - Microsoft.CodeAnalysis.Testing.Verifiers.XUnitVerifier>; - -namespace SourceKit.Tests.Generators; - -public class BuilderTests -{ - [Fact] - public async Task BuilderSourceGenerator_ShouldGenerateCorrectBuilderType() - { - var test = new CSharpSourceGeneratorTest - { - TestState = - { - Sources = - { - await SourceFile.LoadAsync("SourceKit.Sample/Generators/SomeQuery.cs"), - }, - GeneratedSources = - { - new SourceFile(GeneratedBuilderName, GeneratedBuilder), - }, - AdditionalReferences = { typeof(GenerateBuilderAttribute).Assembly }, - ReferenceAssemblies = ReferenceAssemblies.Net.Net60, - }, - }; - - await test.RunAsync(); - } - - [Fact] - public async Task BuilderSourceGenerator_ShouldGenerateCorrectBuilderType_WhenPropertyIsArray() - { - var test = new CSharpSourceGeneratorTest - { - TestState = - { - Sources = - { - await SourceFile.LoadAsync("SourceKit.Sample/Generators/ArrayQuery.cs"), - }, - GeneratedSources = - { - new SourceFile(GeneratedArrayBuilderName, GeneratedArrayBuilder), - }, - AdditionalReferences = { typeof(GenerateBuilderAttribute).Assembly }, - ReferenceAssemblies = ReferenceAssemblies.Net.Net60, - }, - }; - - await test.RunAsync(); - } - - [Fact] - public async Task BuilderSourceGenerator_ShouldGenerateCorrectBuilderType_WhenPropertyHasCustomType() - { - var test = new CSharpSourceGeneratorTest - { - TestState = - { - Sources = - { - await SourceFile.LoadAsync("SourceKit.Sample/Generators/ArrayQuery.cs"), - }, - GeneratedSources = - { - new SourceFile(GeneratedArrayBuilderName, GeneratedArrayBuilder), - }, - AdditionalReferences = { typeof(GenerateBuilderAttribute).Assembly }, - ReferenceAssemblies = ReferenceAssemblies.Net.Net60, - }, - }; - - await test.RunAsync(); - } - - private const string GeneratedBuilderName = """ -SourceKit.Generators.Builder/SourceKit.Generators.Builder.Generators.BuilderSourceGenerator/SomeQuery.SourceKit.Generation.Builder.g.cs -"""; - - private const string GeneratedBuilder = """ -// -// This code was generated by a SourceKit.Generators.Builder code generator. -// https://github.com/itmo-is-dev/SourceKit -// -#pragma warning disable CS1591 -using SourceKit.Generators.Builder.Annotations; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace SourceKit.Sample.Generators -{ - public partial record SomeQuery - { - public static SomeQuery Build(Func action) - { - return action(new Builder()).Build(); - } - - public sealed class Builder - { - private readonly List _ids; - private Int32 _count; - private Nullable _orderById; - public Builder() - { - _ids = new List(); - _count = default; - _orderById = default; - } - - [InitializesPropertyAttribute(nameof(Ids))] - public Builder WithId(Guid element) - { - _ids.Add(element); - return this; - } - - [InitializesPropertyAttribute(nameof(Ids))] - public Builder WithIds(IEnumerable elements) - { - _ids.AddRange(elements); - return this; - } - - [InitializesPropertyAttribute(nameof(Count))] - public Builder WithCount(Int32 value) - { - _count = value; - return this; - } - - [InitializesPropertyAttribute(nameof(OrderById))] - public Builder WithOrderById(Nullable value) - { - _orderById = value; - return this; - } - - public SomeQuery Build() - { - return new SomeQuery(_ids.Distinct().ToArray(), _count, _orderById); - } - } - } -} -"""; - - private const string GeneratedArrayBuilderName = """ -SourceKit.Generators.Builder/SourceKit.Generators.Builder.Generators.BuilderSourceGenerator/ArrayQuery.SourceKit.Generation.Builder.g.cs -"""; - - private const string GeneratedArrayBuilder = """ -// -// This code was generated by a SourceKit.Generators.Builder code generator. -// https://github.com/itmo-is-dev/SourceKit -// -#pragma warning disable CS1591 -using SourceKit.Generators.Builder.Annotations; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace SourceKit.Sample.Generators -{ - public partial record ArrayQuery - { - public static ArrayQuery Build(Func action) - { - return action(new Builder()).Build(); - } - - public sealed class Builder - { - private readonly List _ids; - public Builder() - { - _ids = new List(); - } - - [InitializesPropertyAttribute(nameof(Ids))] - public Builder WithId(Guid element) - { - _ids.Add(element); - return this; - } - - [InitializesPropertyAttribute(nameof(Ids))] - public Builder WithIds(IEnumerable elements) - { - _ids.AddRange(elements); - return this; - } - - public ArrayQuery Build() - { - return new ArrayQuery(_ids.Distinct().ToArray()); - } - } - } -} -"""; -} \ No newline at end of file diff --git a/tests/SourceKit.Tests/Generators/GrpcConstructorTests.cs b/tests/SourceKit.Tests/Generators/GrpcConstructorTests.cs deleted file mode 100644 index 30a24af..0000000 --- a/tests/SourceKit.Tests/Generators/GrpcConstructorTests.cs +++ /dev/null @@ -1,718 +0,0 @@ -using System.Text; -using Google.Protobuf; -using Microsoft.CodeAnalysis.CSharp.Testing; -using Microsoft.CodeAnalysis.Testing; -using Microsoft.CodeAnalysis.Testing.Verifiers; -using SourceKit.Generators.Builder.Annotations; -using SourceKit.Generators.Grpc.Generators; -using SourceKit.Tests.Tools; -using Xunit; - -namespace SourceKit.Tests.Generators; - -public class GrpcConstructorTests -{ - [Fact] - public async Task ProtoMessageConstructorGenerator_ShouldGenerateCorrectConstructor() - { - var test = new CSharpSourceGeneratorTest - { - TestState = - { - Sources = - { - new SourceFile("Model.cs", FileContent, Encoding.UTF8), - }, - GeneratedSources = - { - new SourceFile( - "SourceKit.Generators.Grpc/SourceKit.Generators.Grpc.Generators.ProtoMessageConstructorGenerator/ProtoModel.SourceKit.Generators.Grpc.g.cs", - ConstructorContent, - Encoding.UTF8), - }, - AdditionalReferences = - { - typeof(GenerateBuilderAttribute).Assembly, - typeof(IMessage).Assembly, - }, - ReferenceAssemblies = ReferenceAssemblies.Net.Net60, - }, - }; - - await test.RunAsync(); - } - - private const string FileContent = """ -// -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: model.proto -// -#pragma warning disable 1591, 0612, 3021, 8981 -#region Designer generated code - -using pb = global::Google.Protobuf; -using pbc = global::Google.Protobuf.Collections; -using pbr = global::Google.Protobuf.Reflection; -using scg = global::System.Collections.Generic; -namespace Playground { - - /// Holder for reflection information generated from model.proto - public static partial class ModelReflection { - - #region Descriptor - /// File descriptor for model.proto - public static pbr::FileDescriptor Descriptor { - get { return descriptor; } - } - private static pbr::FileDescriptor descriptor; - - static ModelReflection() { - byte[] descriptorData = global::System.Convert.FromBase64String( - string.Concat( - "Cgttb2RlbC5wcm90bxoeZ29vZ2xlL3Byb3RvYnVmL3dyYXBwZXJzLnByb3Rv", - "IqMDCgpQcm90b01vZGVsEjAKCnBhZ2VfdG9rZW4YASABKAsyHC5nb29nbGUu", - "cHJvdG9idWYuU3RyaW5nVmFsdWUSDgoGdmFsdWVzGAIgAygJEhEKCXBhZ2Vf", - "c2l6ZRgDIAEoBRISCgppbnRfdmFsdWVzGAQgAygFEhkKD2ludF9vbmVvZl92", - "YWx1ZRgFIAEoBUgAEhwKEnN0cmluZ19vbmVvZl92YWx1ZRgGIAEoCUgAEh0K", - "FW5vdF9udWxsX3N0cmluZ192YWx1ZRgHIAEoCRIzCg5udWxsX2ludF92YWx1", - "ZRgIIAEoCzIbLmdvb2dsZS5wcm90b2J1Zi5JbnQzMlZhbHVlEjcKEW51bGxf", - "c3RyaW5nX3ZhbHVlGAkgASgLMhwuZ29vZ2xlLnByb3RvYnVmLlN0cmluZ1Zh", - "bHVlEiwKCW1hcF92YWx1ZRgKIAMoCzIZLlByb3RvTW9kZWwuTWFwVmFsdWVF", - "bnRyeRovCg1NYXBWYWx1ZUVudHJ5EgsKA2tleRgBIAEoBRINCgV2YWx1ZRgC", - "IAEoCToCOAFCBwoFdmFsdWVCDaoCClBsYXlncm91bmRiBnByb3RvMw==")); - descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, - new pbr::FileDescriptor[] { global::Google.Protobuf.WellKnownTypes.WrappersReflection.Descriptor, }, - new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] { - new pbr::GeneratedClrTypeInfo(typeof(global::Playground.ProtoModel), global::Playground.ProtoModel.Parser, new[]{ "PageToken", "Values", "PageSize", "IntValues", "IntOneofValue", "StringOneofValue", "NotNullStringValue", "NullIntValue", "NullStringValue", "MapValue" }, new[]{ "Value" }, null, null, new pbr::GeneratedClrTypeInfo[] { null, }) - })); - } - #endregion - - } - #region Messages - public sealed partial class ProtoModel : pb::IMessage - #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE - , pb::IBufferMessage - #endif - { - private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new ProtoModel()); - private pb::UnknownFieldSet _unknownFields; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public static pb::MessageParser Parser { get { return _parser; } } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public static pbr::MessageDescriptor Descriptor { - get { return global::Playground.ModelReflection.Descriptor.MessageTypes[0]; } - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - pbr::MessageDescriptor pb::IMessage.Descriptor { - get { return Descriptor; } - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public ProtoModel() { - OnConstruction(); - } - - partial void OnConstruction(); - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public ProtoModel(ProtoModel other) : this() { - PageToken = other.PageToken; - values_ = other.values_.Clone(); - pageSize_ = other.pageSize_; - intValues_ = other.intValues_.Clone(); - notNullStringValue_ = other.notNullStringValue_; - NullIntValue = other.NullIntValue; - NullStringValue = other.NullStringValue; - mapValue_ = other.mapValue_.Clone(); - switch (other.ValueCase) { - case ValueOneofCase.IntOneofValue: - IntOneofValue = other.IntOneofValue; - break; - case ValueOneofCase.StringOneofValue: - StringOneofValue = other.StringOneofValue; - break; - } - - _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public ProtoModel Clone() { - return new ProtoModel(this); - } - - /// Field number for the "page_token" field. - public const int PageTokenFieldNumber = 1; - private static readonly pb::FieldCodec _single_pageToken_codec = pb::FieldCodec.ForClassWrapper(10); - private string pageToken_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public string PageToken { - get { return pageToken_; } - set { - pageToken_ = value; - } - } - - - /// Field number for the "values" field. - public const int ValuesFieldNumber = 2; - private static readonly pb::FieldCodec _repeated_values_codec - = pb::FieldCodec.ForString(18); - private readonly pbc::RepeatedField values_ = new pbc::RepeatedField(); - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public pbc::RepeatedField Values { - get { return values_; } - } - - /// Field number for the "page_size" field. - public const int PageSizeFieldNumber = 3; - private int pageSize_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public int PageSize { - get { return pageSize_; } - set { - pageSize_ = value; - } - } - - /// Field number for the "int_values" field. - public const int IntValuesFieldNumber = 4; - private static readonly pb::FieldCodec _repeated_intValues_codec - = pb::FieldCodec.ForInt32(34); - private readonly pbc::RepeatedField intValues_ = new pbc::RepeatedField(); - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public pbc::RepeatedField IntValues { - get { return intValues_; } - } - - /// Field number for the "int_oneof_value" field. - public const int IntOneofValueFieldNumber = 5; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public int IntOneofValue { - get { return HasIntOneofValue ? (int) value_ : 0; } - set { - value_ = value; - valueCase_ = ValueOneofCase.IntOneofValue; - } - } - /// Gets whether the "int_oneof_value" field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public bool HasIntOneofValue { - get { return valueCase_ == ValueOneofCase.IntOneofValue; } - } - /// Clears the value of the oneof if it's currently set to "int_oneof_value" - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public void ClearIntOneofValue() { - if (HasIntOneofValue) { - ClearValue(); - } - } - - /// Field number for the "string_oneof_value" field. - public const int StringOneofValueFieldNumber = 6; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public string StringOneofValue { - get { return HasStringOneofValue ? (string) value_ : ""; } - set { - value_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); - valueCase_ = ValueOneofCase.StringOneofValue; - } - } - /// Gets whether the "string_oneof_value" field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public bool HasStringOneofValue { - get { return valueCase_ == ValueOneofCase.StringOneofValue; } - } - /// Clears the value of the oneof if it's currently set to "string_oneof_value" - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public void ClearStringOneofValue() { - if (HasStringOneofValue) { - ClearValue(); - } - } - - /// Field number for the "not_null_string_value" field. - public const int NotNullStringValueFieldNumber = 7; - private string notNullStringValue_ = ""; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public string NotNullStringValue { - get { return notNullStringValue_; } - set { - notNullStringValue_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); - } - } - - /// Field number for the "null_int_value" field. - public const int NullIntValueFieldNumber = 8; - private static readonly pb::FieldCodec _single_nullIntValue_codec = pb::FieldCodec.ForStructWrapper(66); - private int? nullIntValue_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public int? NullIntValue { - get { return nullIntValue_; } - set { - nullIntValue_ = value; - } - } - - - /// Field number for the "null_string_value" field. - public const int NullStringValueFieldNumber = 9; - private static readonly pb::FieldCodec _single_nullStringValue_codec = pb::FieldCodec.ForClassWrapper(74); - private string nullStringValue_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public string NullStringValue { - get { return nullStringValue_; } - set { - nullStringValue_ = value; - } - } - - - /// Field number for the "map_value" field. - public const int MapValueFieldNumber = 10; - private static readonly pbc::MapField.Codec _map_mapValue_codec - = new pbc::MapField.Codec(pb::FieldCodec.ForInt32(8, 0), pb::FieldCodec.ForString(18, ""), 82); - private readonly pbc::MapField mapValue_ = new pbc::MapField(); - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public pbc::MapField MapValue { - get { return mapValue_; } - } - - private object value_; - /// Enum of possible cases for the "value" oneof. - public enum ValueOneofCase { - None = 0, - IntOneofValue = 5, - StringOneofValue = 6, - } - private ValueOneofCase valueCase_ = ValueOneofCase.None; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public ValueOneofCase ValueCase { - get { return valueCase_; } - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public void ClearValue() { - valueCase_ = ValueOneofCase.None; - value_ = null; - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public override bool Equals(object other) { - return Equals(other as ProtoModel); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public bool Equals(ProtoModel other) { - if (ReferenceEquals(other, null)) { - return false; - } - if (ReferenceEquals(other, this)) { - return true; - } - if (PageToken != other.PageToken) return false; - if(!values_.Equals(other.values_)) return false; - if (PageSize != other.PageSize) return false; - if(!intValues_.Equals(other.intValues_)) return false; - if (IntOneofValue != other.IntOneofValue) return false; - if (StringOneofValue != other.StringOneofValue) return false; - if (NotNullStringValue != other.NotNullStringValue) return false; - if (NullIntValue != other.NullIntValue) return false; - if (NullStringValue != other.NullStringValue) return false; - if (!MapValue.Equals(other.MapValue)) return false; - if (ValueCase != other.ValueCase) return false; - return Equals(_unknownFields, other._unknownFields); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public override int GetHashCode() { - int hash = 1; - if (pageToken_ != null) hash ^= PageToken.GetHashCode(); - hash ^= values_.GetHashCode(); - if (PageSize != 0) hash ^= PageSize.GetHashCode(); - hash ^= intValues_.GetHashCode(); - if (HasIntOneofValue) hash ^= IntOneofValue.GetHashCode(); - if (HasStringOneofValue) hash ^= StringOneofValue.GetHashCode(); - if (NotNullStringValue.Length != 0) hash ^= NotNullStringValue.GetHashCode(); - if (nullIntValue_ != null) hash ^= NullIntValue.GetHashCode(); - if (nullStringValue_ != null) hash ^= NullStringValue.GetHashCode(); - hash ^= MapValue.GetHashCode(); - hash ^= (int) valueCase_; - if (_unknownFields != null) { - hash ^= _unknownFields.GetHashCode(); - } - return hash; - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public override string ToString() { - return pb::JsonFormatter.ToDiagnosticString(this); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public void WriteTo(pb::CodedOutputStream output) { - #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE - output.WriteRawMessage(this); - #else - if (pageToken_ != null) { - _single_pageToken_codec.WriteTagAndValue(output, PageToken); - } - values_.WriteTo(output, _repeated_values_codec); - if (PageSize != 0) { - output.WriteRawTag(24); - output.WriteInt32(PageSize); - } - intValues_.WriteTo(output, _repeated_intValues_codec); - if (HasIntOneofValue) { - output.WriteRawTag(40); - output.WriteInt32(IntOneofValue); - } - if (HasStringOneofValue) { - output.WriteRawTag(50); - output.WriteString(StringOneofValue); - } - if (NotNullStringValue.Length != 0) { - output.WriteRawTag(58); - output.WriteString(NotNullStringValue); - } - if (nullIntValue_ != null) { - _single_nullIntValue_codec.WriteTagAndValue(output, NullIntValue); - } - if (nullStringValue_ != null) { - _single_nullStringValue_codec.WriteTagAndValue(output, NullStringValue); - } - mapValue_.WriteTo(output, _map_mapValue_codec); - if (_unknownFields != null) { - _unknownFields.WriteTo(output); - } - #endif - } - - #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { - if (pageToken_ != null) { - _single_pageToken_codec.WriteTagAndValue(ref output, PageToken); - } - values_.WriteTo(ref output, _repeated_values_codec); - if (PageSize != 0) { - output.WriteRawTag(24); - output.WriteInt32(PageSize); - } - intValues_.WriteTo(ref output, _repeated_intValues_codec); - if (HasIntOneofValue) { - output.WriteRawTag(40); - output.WriteInt32(IntOneofValue); - } - if (HasStringOneofValue) { - output.WriteRawTag(50); - output.WriteString(StringOneofValue); - } - if (NotNullStringValue.Length != 0) { - output.WriteRawTag(58); - output.WriteString(NotNullStringValue); - } - if (nullIntValue_ != null) { - _single_nullIntValue_codec.WriteTagAndValue(ref output, NullIntValue); - } - if (nullStringValue_ != null) { - _single_nullStringValue_codec.WriteTagAndValue(ref output, NullStringValue); - } - mapValue_.WriteTo(ref output, _map_mapValue_codec); - if (_unknownFields != null) { - _unknownFields.WriteTo(ref output); - } - } - #endif - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public int CalculateSize() { - int size = 0; - if (pageToken_ != null) { - size += _single_pageToken_codec.CalculateSizeWithTag(PageToken); - } - size += values_.CalculateSize(_repeated_values_codec); - if (PageSize != 0) { - size += 1 + pb::CodedOutputStream.ComputeInt32Size(PageSize); - } - size += intValues_.CalculateSize(_repeated_intValues_codec); - if (HasIntOneofValue) { - size += 1 + pb::CodedOutputStream.ComputeInt32Size(IntOneofValue); - } - if (HasStringOneofValue) { - size += 1 + pb::CodedOutputStream.ComputeStringSize(StringOneofValue); - } - if (NotNullStringValue.Length != 0) { - size += 1 + pb::CodedOutputStream.ComputeStringSize(NotNullStringValue); - } - if (nullIntValue_ != null) { - size += _single_nullIntValue_codec.CalculateSizeWithTag(NullIntValue); - } - if (nullStringValue_ != null) { - size += _single_nullStringValue_codec.CalculateSizeWithTag(NullStringValue); - } - size += mapValue_.CalculateSize(_map_mapValue_codec); - if (_unknownFields != null) { - size += _unknownFields.CalculateSize(); - } - return size; - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public void MergeFrom(ProtoModel other) { - if (other == null) { - return; - } - if (other.pageToken_ != null) { - if (pageToken_ == null || other.PageToken != "") { - PageToken = other.PageToken; - } - } - values_.Add(other.values_); - if (other.PageSize != 0) { - PageSize = other.PageSize; - } - intValues_.Add(other.intValues_); - if (other.NotNullStringValue.Length != 0) { - NotNullStringValue = other.NotNullStringValue; - } - if (other.nullIntValue_ != null) { - if (nullIntValue_ == null || other.NullIntValue != 0) { - NullIntValue = other.NullIntValue; - } - } - if (other.nullStringValue_ != null) { - if (nullStringValue_ == null || other.NullStringValue != "") { - NullStringValue = other.NullStringValue; - } - } - mapValue_.MergeFrom(other.mapValue_); - switch (other.ValueCase) { - case ValueOneofCase.IntOneofValue: - IntOneofValue = other.IntOneofValue; - break; - case ValueOneofCase.StringOneofValue: - StringOneofValue = other.StringOneofValue; - break; - } - - _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public void MergeFrom(pb::CodedInputStream input) { - #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE - input.ReadRawMessage(this); - #else - uint tag; - while ((tag = input.ReadTag()) != 0) { - switch(tag) { - default: - _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); - break; - case 10: { - string value = _single_pageToken_codec.Read(input); - if (pageToken_ == null || value != "") { - PageToken = value; - } - break; - } - case 18: { - values_.AddEntriesFrom(input, _repeated_values_codec); - break; - } - case 24: { - PageSize = input.ReadInt32(); - break; - } - case 34: - case 32: { - intValues_.AddEntriesFrom(input, _repeated_intValues_codec); - break; - } - case 40: { - IntOneofValue = input.ReadInt32(); - break; - } - case 50: { - StringOneofValue = input.ReadString(); - break; - } - case 58: { - NotNullStringValue = input.ReadString(); - break; - } - case 66: { - int? value = _single_nullIntValue_codec.Read(input); - if (nullIntValue_ == null || value != 0) { - NullIntValue = value; - } - break; - } - case 74: { - string value = _single_nullStringValue_codec.Read(input); - if (nullStringValue_ == null || value != "") { - NullStringValue = value; - } - break; - } - case 82: { - mapValue_.AddEntriesFrom(input, _map_mapValue_codec); - break; - } - } - } - #endif - } - - #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { - uint tag; - while ((tag = input.ReadTag()) != 0) { - switch(tag) { - default: - _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); - break; - case 10: { - string value = _single_pageToken_codec.Read(ref input); - if (pageToken_ == null || value != "") { - PageToken = value; - } - break; - } - case 18: { - values_.AddEntriesFrom(ref input, _repeated_values_codec); - break; - } - case 24: { - PageSize = input.ReadInt32(); - break; - } - case 34: - case 32: { - intValues_.AddEntriesFrom(ref input, _repeated_intValues_codec); - break; - } - case 40: { - IntOneofValue = input.ReadInt32(); - break; - } - case 50: { - StringOneofValue = input.ReadString(); - break; - } - case 58: { - NotNullStringValue = input.ReadString(); - break; - } - case 66: { - int? value = _single_nullIntValue_codec.Read(ref input); - if (nullIntValue_ == null || value != 0) { - NullIntValue = value; - } - break; - } - case 74: { - string value = _single_nullStringValue_codec.Read(ref input); - if (nullStringValue_ == null || value != "") { - NullStringValue = value; - } - break; - } - case 82: { - mapValue_.AddEntriesFrom(ref input, _map_mapValue_codec); - break; - } - } - } - } - #endif - - } - - #endregion - -} - -#endregion Designer generated code -"""; - - private const string ConstructorContent = """ -// -// This code was generated by a SourceKit.Generators.Grpc code generator. -// https://github.com/itmo-is-dev/SourceKit -// -#pragma warning disable CS1591 -using System; -using System.Collections.Generic; -using System.Linq; - -#nullable enable -namespace Playground -{ - public partial class ProtoModel - { - public ProtoModel(String? pageToken, IEnumerable values, Int32 pageSize, IEnumerable intValues, Int32? intOneofValue, String? stringOneofValue, String notNullStringValue, Nullable nullIntValue, String? nullStringValue, IEnumerable> mapValue) - { - PageToken = pageToken; - Values.Add(values); - PageSize = pageSize; - IntValues.Add(intValues); - if (intOneofValue is not null) - { - IntOneofValue = intOneofValue.Value; - } - - if (stringOneofValue is not null) - { - StringOneofValue = stringOneofValue; - } - - NotNullStringValue = notNullStringValue; - NullIntValue = nullIntValue; - NullStringValue = nullStringValue; - foreach (KeyValuePair item in mapValue) - { - MapValue.Add(item.Key, item.Value); - } - } - } -} -"""; -} \ No newline at end of file diff --git a/tests/SourceKit.Tests/Generators/RequiredValueAnalyzerTests.cs b/tests/SourceKit.Tests/Generators/RequiredValueAnalyzerTests.cs deleted file mode 100644 index 44b8a6d..0000000 --- a/tests/SourceKit.Tests/Generators/RequiredValueAnalyzerTests.cs +++ /dev/null @@ -1,61 +0,0 @@ -using Microsoft.CodeAnalysis.CSharp.Testing; -using Microsoft.CodeAnalysis.Testing; -using Microsoft.CodeAnalysis.Testing.Verifiers; -using SourceKit.Generators.Builder.Analyzers; -using SourceKit.Generators.Builder.Annotations; -using SourceKit.Tests.Tools; -using Xunit; -using AnalyzerVerifier = Microsoft.CodeAnalysis.CSharp.Testing.XUnit.AnalyzerVerifier< - SourceKit.Generators.Builder.Analyzers.RequiredValueAnalyzer>; - -namespace SourceKit.Tests.Generators; - -public class RequiredValueAnalyzerTests -{ - [Fact] - public async Task RequiredValue_ShouldProduceError_WhenRequiredValueNotDefined() - { - var usageFile = await SourceFile.LoadAsync("SourceKit.Sample/Generators/ArrayQueryUsage.cs"); - - var diagnostic = AnalyzerVerifier.Diagnostic(RequiredValueAnalyzer.Descriptor) - .WithLocation(usageFile.Name, 12, 21) - .WithArguments("Value"); - - var test = new CSharpAnalyzerTest - { - TestState = - { - Sources = { usageFile }, - AdditionalReferences = - { - typeof(GenerateBuilderAttribute).Assembly, - }, - ReferenceAssemblies = ReferenceAssemblies.Net.Net60, - }, - ExpectedDiagnostics = { diagnostic }, - }; - - await test.RunAsync(); - } - - [Fact] - public async Task RequiredValue_ShouldProduceNoError_WhenRequiredValueDefined() - { - var usageFile = await SourceFile.LoadAsync("SourceKit.Sample/Generators/ValidArrayQueryUsage.cs"); - - var test = new CSharpAnalyzerTest - { - TestState = - { - Sources = { usageFile }, - AdditionalReferences = - { - typeof(GenerateBuilderAttribute).Assembly, - }, - ReferenceAssemblies = ReferenceAssemblies.Net.Net60, - }, - }; - - await test.RunAsync(); - } -} \ No newline at end of file diff --git a/tests/SourceKit.Tests/SourceKit.Tests.csproj b/tests/SourceKit.Tests/SourceKit.Tests.csproj deleted file mode 100644 index 38c55ed..0000000 --- a/tests/SourceKit.Tests/SourceKit.Tests.csproj +++ /dev/null @@ -1,51 +0,0 @@ - - - - net7.0 - enable - enable - false - - - - - - - - - - - - - - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - - - - - - - - - - - - - - - - - - - - diff --git a/tests/SourceKit.Tests/Startup.cs b/tests/SourceKit.Tests/Startup.cs deleted file mode 100644 index 04f06a5..0000000 --- a/tests/SourceKit.Tests/Startup.cs +++ /dev/null @@ -1,11 +0,0 @@ -using Microsoft.Extensions.DependencyInjection; - -namespace SourceKit.Tests; - -public class Startup -{ - public void ConfigureServices(IServiceCollection services) - { - // services.UseDemystifyExceptionFilter(); - } -} \ No newline at end of file diff --git a/tests/SourceKit.Tests/Tools/SourceFile.cs b/tests/SourceKit.Tests/Tools/SourceFile.cs deleted file mode 100644 index 882e8fa..0000000 --- a/tests/SourceKit.Tests/Tools/SourceFile.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Text; -using Microsoft.CodeAnalysis.Text; - -namespace SourceKit.Tests.Tools; - -public record struct SourceFile(string Name, string Content, Encoding? Encoding = null) -{ - public static async Task LoadAsync(string path) - { - var name = Path.GetFileName(path); - var content = await File.ReadAllTextAsync(path); - - return new SourceFile(name, content, null); - } - - public static implicit operator (string, SourceText)(SourceFile sourceFile) - => (sourceFile.Name, SourceText.From(sourceFile.Content, sourceFile.Encoding ?? Encoding.UTF8)); -} \ No newline at end of file From ad28c1062990ec666587ca212786a07f80c757d8 Mon Sep 17 00:00:00 2001 From: ronimizy Date: Wed, 1 May 2024 22:03:25 +0300 Subject: [PATCH 2/7] fix: build workflow --- .github/workflows/dotnet-build.yml | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/.github/workflows/dotnet-build.yml b/.github/workflows/dotnet-build.yml index 01fc391..73b7264 100644 --- a/.github/workflows/dotnet-build.yml +++ b/.github/workflows/dotnet-build.yml @@ -42,9 +42,24 @@ jobs: restore-keys: | ${{ runner.os }}-nuget- - - name: Restore - if: steps.cache-tests.output.cache-hit != 'true' - run: dotnet restore + - name: move nuget config + if: steps.cache-tests.outputs.cache-hit != 'true' + run: | + mkdir .tmp-nuget-config + mv NuGet.config .tmp-nuget-config + + - name: build sources + if: steps.cache-tests.outputs.cache-hit != 'true' + run: | + for csproj in $(find src | grep csproj$) + do + dotnet build -c Release "$csproj" + done + + - name: move nuget config back + run: | + mv .tmp-nuget-config/NuGet.config . + rm -rf .tmp-nuget-config - name: Build if: steps.cache-tests.outputs.cache-hit != 'true' From 2336cc3c45c794e239286339c48e96c0bfff9d45 Mon Sep 17 00:00:00 2001 From: ronimizy Date: Wed, 1 May 2024 22:17:49 +0300 Subject: [PATCH 3/7] fix: build workflow --- .github/workflows/dotnet-build.yml | 46 ++++++++++++++++-------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/.github/workflows/dotnet-build.yml b/.github/workflows/dotnet-build.yml index 73b7264..d314c1e 100644 --- a/.github/workflows/dotnet-build.yml +++ b/.github/workflows/dotnet-build.yml @@ -42,29 +42,31 @@ jobs: restore-keys: | ${{ runner.os }}-nuget- - - name: move nuget config - if: steps.cache-tests.outputs.cache-hit != 'true' - run: | - mkdir .tmp-nuget-config - mv NuGet.config .tmp-nuget-config - - - name: build sources - if: steps.cache-tests.outputs.cache-hit != 'true' +# - name: move nuget config +# if: steps.cache-tests.outputs.cache-hit != 'true' +# run: | +# mkdir .tmp-nuget-config +# mv NuGet.config .tmp-nuget-config +# +# - name: build sources +# if: steps.cache-tests.outputs.cache-hit != 'true' +# run: | +# for csproj in $(find src | grep csproj$) +# do +# dotnet build -c Release "$csproj" +# done +# +# - name: move nuget config back +# run: | +# mv .tmp-nuget-config/NuGet.config . +# rm -rf .tmp-nuget-config + + - name: Remove .Reflect tests + if: steps.cache-tests.outpust.cache-hit != 'true' run: | - for csproj in $(find src | grep csproj$) - do - dotnet build -c Release "$csproj" - done - - - name: move nuget config back - run: | - mv .tmp-nuget-config/NuGet.config . - rm -rf .tmp-nuget-config - - - name: Build - if: steps.cache-tests.outputs.cache-hit != 'true' - run: dotnet build -c Debug + dotnet sln SourceKit.sln remove tests/SourceKit.Reflect.Tests/SourceKit.Reflect.Tests.csproj + rm -rf tests/SourceKit.Reflect.Tests - name: Test if: steps.cache-tests.outputs.cache-hit != 'true' - run: dotnet test -c Debug --no-restore --no-build \ No newline at end of file + run: dotnet test -c Debug \ No newline at end of file From 3b1e1402cbde40349d1e26b9ca53b1184fe3b981 Mon Sep 17 00:00:00 2001 From: ronimizy Date: Wed, 1 May 2024 22:28:50 +0300 Subject: [PATCH 4/7] hack: added packages check --- .github/workflows/dotnet-build.yml | 48 +++++++++++++++++++----------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/.github/workflows/dotnet-build.yml b/.github/workflows/dotnet-build.yml index d314c1e..114409c 100644 --- a/.github/workflows/dotnet-build.yml +++ b/.github/workflows/dotnet-build.yml @@ -42,24 +42,36 @@ jobs: restore-keys: | ${{ runner.os }}-nuget- -# - name: move nuget config -# if: steps.cache-tests.outputs.cache-hit != 'true' -# run: | -# mkdir .tmp-nuget-config -# mv NuGet.config .tmp-nuget-config -# -# - name: build sources -# if: steps.cache-tests.outputs.cache-hit != 'true' -# run: | -# for csproj in $(find src | grep csproj$) -# do -# dotnet build -c Release "$csproj" -# done -# -# - name: move nuget config back -# run: | -# mv .tmp-nuget-config/NuGet.config . -# rm -rf .tmp-nuget-config + - name: move nuget config + if: steps.cache-tests.outputs.cache-hit != 'true' + run: | + mkdir .tmp-nuget-config + mv NuGet.config .tmp-nuget-config + + - name: build sources + if: steps.cache-tests.outputs.cache-hit != 'true' + run: | + for csproj in $(find src | grep csproj$) + do + dotnet build -c Release "$csproj" + done + + - name: move nuget config back + if: steps.cache-tests.outputs.cache-hit != 'true' + run: | + mv .tmp-nuget-config/NuGet.config . + rm -rf .tmp-nuget-config + + - name: validate packages + if: steps.cache-tests.outputs.cache-hit != 'true' + run: | + if [ ! -d bin/packages ] + then + echo packages dir not created + exit 1 + fi + + ls bin/packages - name: Remove .Reflect tests if: steps.cache-tests.outpust.cache-hit != 'true' From def742f1d3ae55963382351ace3386e4b117abd3 Mon Sep 17 00:00:00 2001 From: ronimizy Date: Wed, 1 May 2024 22:32:15 +0300 Subject: [PATCH 5/7] hack: ls the fs --- .github/workflows/dotnet-build.yml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/dotnet-build.yml b/.github/workflows/dotnet-build.yml index 114409c..7c2ca65 100644 --- a/.github/workflows/dotnet-build.yml +++ b/.github/workflows/dotnet-build.yml @@ -65,13 +65,7 @@ jobs: - name: validate packages if: steps.cache-tests.outputs.cache-hit != 'true' run: | - if [ ! -d bin/packages ] - then - echo packages dir not created - exit 1 - fi - - ls bin/packages + ls - name: Remove .Reflect tests if: steps.cache-tests.outpust.cache-hit != 'true' From 427b3ffab39153e3ab1146c7ae1b9099384ebbf5 Mon Sep 17 00:00:00 2001 From: ronimizy Date: Wed, 1 May 2024 22:59:26 +0300 Subject: [PATCH 6/7] fix: manually setting SolutionDir --- .github/workflows/dotnet-build.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/dotnet-build.yml b/.github/workflows/dotnet-build.yml index 7c2ca65..91ac657 100644 --- a/.github/workflows/dotnet-build.yml +++ b/.github/workflows/dotnet-build.yml @@ -53,7 +53,7 @@ jobs: run: | for csproj in $(find src | grep csproj$) do - dotnet build -c Release "$csproj" + dotnet build -c Release "$csproj" /p:SolutionDir=$(pwd) done - name: move nuget config back @@ -62,11 +62,6 @@ jobs: mv .tmp-nuget-config/NuGet.config . rm -rf .tmp-nuget-config - - name: validate packages - if: steps.cache-tests.outputs.cache-hit != 'true' - run: | - ls - - name: Remove .Reflect tests if: steps.cache-tests.outpust.cache-hit != 'true' run: | From 0f00586f3d1ddbbda7a9966e3b5112b969842e21 Mon Sep 17 00:00:00 2001 From: ronimizy Date: Wed, 1 May 2024 23:07:37 +0300 Subject: [PATCH 7/7] fix: publish workflow --- .github/workflows/publish.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 74d4040..0c04481 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -52,6 +52,14 @@ jobs: run: | dotnet sln SourceKit.sln remove tests/SourceKit.Reflect.Tests/SourceKit.Reflect.Tests.csproj rm -rf tests/SourceKit.Reflect.Tests + + for proj in $(find samples | grep csproj$) + do + proj_dir=$(dirname "$proj") + + dotnet sln SourceKit.sln remove "$proj" + rm -rf "$proj_dir" + done - name: restore if: ${{ steps.cache-packages.outputs.cache-hit != 'true' }}