├── .editorconfig ├── .gitattributes ├── .github ├── dependabot.yml └── workflows │ └── ci.yml ├── .gitignore ├── Gu.Analyzers.Benchmarks ├── .editorconfig ├── AssemblyAttributes.cs ├── BenchmarkTests.cs ├── Benchmarks │ ├── AllBenchmarks.cs │ ├── AllBenchmarks.md │ ├── ArgumentAnalyzerBenchmarks.cs │ ├── ArgumentListAnalyzerBenchmarks.cs │ ├── ArgumentListAnalyzerBenchmarks.md │ ├── AssertAnalyzerBenchmarks.cs │ ├── BinaryExpressionAnalyzerBenchmarks.cs │ ├── ClassDeclarationAnalyzerBenchmarks.cs │ ├── CodeGen │ │ ├── Code.cs │ │ └── CodeGen.cs │ ├── ConstructorAnalyzerBenchmarks.cs │ ├── ConstructorAnalyzerBenchmarks.md │ ├── DocsAnalyzerBenchmarks.cs │ ├── ExceptionAnalyzerBenchmarks.cs │ ├── GU0006UseNameofBenchmarks.cs │ ├── GU0006UseNameofBenchmarks.md │ ├── GU0007PreferInjectingBenchmarks.cs │ ├── GU0007PreferInjectingBenchmarks.md │ ├── GU0008AvoidRelayPropertiesBenchmarks.md │ ├── GU0009UseNamedParametersForBooleansBenchmarks.cs │ ├── GU0009UseNamedParametersForBooleansBenchmarks.md │ ├── GU0011DoNotIgnoreReturnValueBenchmarks.cs │ ├── GU0011DontIgnoreReturnValueBenchmarks.md │ ├── GU0020SortPropertiesBenchmarks.cs │ ├── GU0020SortPropertiesBenchmarks.md │ ├── GU0021CalculatedPropertyAllocatesBenchmarks.md │ ├── GU0022UseGetOnlyBenchmarks.cs │ ├── GU0022UseGetOnlyBenchmarks.md │ ├── GU0023StaticMemberOrderAnalyzerBenchmarks.cs │ ├── GU0050IgnoreEventsWhenSerializingBenchmarks.cs │ ├── GU0050IgnoreEventsWhenSerializingBenchmarks.md │ ├── GU0051XmlSerializerNotCachedBenchmarks.cs │ ├── GU0051XmlSerializerNotCachedBenchmarks.md │ ├── GU0052ExceptionShouldBeSerializableBenchmarks.cs │ ├── GU0060EnumMemberValueConflictsWithAnotherBenchmarks.cs │ ├── GU0060EnumMemberValueConflictsWithAnotherBenchmarks.md │ ├── GU0061EnumMemberValueOutOfRangeBenchmarks.cs │ ├── GU0070DefaultConstructedValueTypeWithNoUsefulDefaultBenchmarks.cs │ ├── GU0070DefaultConstructedValueTypeWithNoUsefulDefaultBenchmarks.md │ ├── GU0071ForeachImplicitCastBenchmarks.cs │ ├── GU0071ForeachImplicitCastBenchmarks.md │ ├── GU0072AllTypesShouldBeInternalBenchmarks.cs │ ├── GU0073MemberShouldBeInternalBenchmarks.cs │ ├── IdentifierNameAnalyzerBenchmarks.cs │ ├── MethodGroupAnalyzerBenchmarks.cs │ ├── ObjectCreationAnalyzerBenchmarks.cs │ ├── ObjectCreationAnalyzerBenchmarks.md │ ├── ParameterAnalyzerBenchmarks.cs │ ├── ParameterAnalyzerBenchmarks.md │ ├── PropertyDeclarationAnalyzerBenchmarks.cs │ ├── SimpleAssignmentAnalyzerBenchmarks.cs │ ├── SimpleAssignmentAnalyzerBenchmarks.md │ ├── StringLiteralExpressionAnalyzerBenchmarks.cs │ ├── TestMethodAnalyzerBenchmarks.cs │ ├── VariableDeclaratorAnalyzerBenchmarks.cs │ └── WhenAnalyzerBenchmarks.cs ├── Gu.Analyzers.Benchmarks.csproj ├── Gu.Analyzers.Benchmarks.csproj.DotSettings └── Program.cs ├── Gu.Analyzers.Test ├── .editorconfig ├── AnalyzerExt.cs ├── AssemblyAttributes.cs ├── CodeFixes │ ├── GenerateUselessDocsFixTests │ │ ├── CodeFixWhenEmptyParameterDocsSA1614.cs │ │ ├── CodeFixWhenMissingParameterDocsSA1611.SpecialType.cs │ │ ├── CodeFixWhenMissingParameterDocsSA1611.cs │ │ ├── CodeFixWhenMissingTypeParameterDocsSA1618.cs │ │ └── StandardDocsForOperator.cs │ ├── MakeStaticFixTests.CA1052.cs │ ├── MakeStaticFixTests.CS0708.cs │ ├── NullCheckParameterFixTests.cs │ └── NullableFixTests.cs ├── DocumentationTests.cs ├── GU0001NameArgumentsTests │ ├── CodeFix.cs │ ├── NoFix.cs │ └── Valid.cs ├── GU0002NamedArgumentPositionMatchesTests │ ├── CodeFix.cs │ ├── NoFix.cs │ └── Valid.cs ├── GU0003CtorParameterNamesShouldMatchTests │ ├── CodeFix.cs │ └── Valid.cs ├── GU0004AssignAllReadOnlyMembersTests │ ├── Diagnostics.cs │ └── Valid.cs ├── GU0005ExceptionArgumentsPositionsTests │ ├── CodeFix.cs │ └── Valid.cs ├── GU0006UseNameofTests │ ├── CodeFix.cs │ └── Valid.cs ├── GU0007PreferInjectingTests │ ├── CodeFix.ServiceLocator.cs │ ├── CodeFix.Simple.cs │ ├── CodeFix.Singleton.cs │ ├── CodeFix.cs │ ├── Valid.Ignore.cs │ ├── Valid.Recursion.cs │ └── Valid.cs ├── GU0008AvoidRelayPropertiesTests │ ├── Diagnostics.cs │ └── Valid.cs ├── GU0009UseNamedParametersForBooleansTests │ ├── Diagnostics.cs │ └── Valid.cs ├── GU0010DoNotAssignSameValueTests │ ├── Diagnostics.cs │ └── Valid.cs ├── GU0011DoNotIgnoreReturnValueTests │ ├── Diagnostics.cs │ ├── Valid.Ignore.cs │ └── Valid.cs ├── GU0012NullCheckParameterTests │ ├── CodeFix.Parameter.cs │ ├── Codefix.SimpleAssignment.cs │ ├── FixAll.cs │ └── Valid.cs ├── GU0013CheckNameInThrowTests │ ├── CodeFix.cs │ └── Valid.cs ├── GU0014PreferParameterTests │ ├── CodeFix.cs │ └── Valid.cs ├── GU0015DoNotAssignMoreThanOnceTests │ ├── Diagnostics.cs │ └── Valid.cs ├── GU0016PreferLambdaTests │ ├── CodeFix.cs │ └── Valid.cs ├── GU0017DonNotUseDiscardedTests │ ├── Diagnostics.cs │ └── Valid.cs ├── GU0018NameMockTests │ ├── CodeFix.cs │ └── Valid.cs ├── GU0019LinqOrDefaultStructs │ ├── Diagnostics.cs │ └── Valid.cs ├── GU0020SortPropertiesTests │ ├── CodeFix.cs │ ├── FixAll.cs │ └── Valid.cs ├── GU0021CalculatedPropertyAllocatesTests │ ├── CodeFix.cs │ └── Valid.cs ├── GU0022UseGetOnlyTests │ ├── CodeFix.cs │ └── Valid.cs ├── GU0023StaticMemberOrderTests │ ├── Diagnostics.cs │ └── Valid.cs ├── GU0024SealTypeWithDefaultMemberTests │ ├── CodeFix.cs │ └── Valid.cs ├── GU0025SealTypeWithOverridenEqualityTests │ ├── CodeFix.cs │ └── Valid.cs ├── GU0026RangeAllocation │ ├── CodeFix.cs │ └── Valid.cs ├── GU0050IgnoreEventsWhenSerializingTests │ ├── CodeFix.cs │ └── Valid.cs ├── GU0051XmlSerializerNotCachedTests │ ├── Diagnostics.cs │ └── Valid.cs ├── GU0052ExceptionShouldBeSerializableTests │ ├── Diagnostics.cs │ └── Valid.cs ├── GU0060EnumMemberValueConflictsWithAnotherTests │ ├── Diagnostics.cs │ └── Valid.cs ├── GU0061EnumMemberValueOutOfRangeTests │ ├── Diagnostics.cs │ └── Valid.cs ├── GU0070DefaultConstructedValueTypeWithNoUsefulDefaultTests │ ├── Diagnostics.cs │ └── Valid.cs ├── GU0071ForeachImplicitCastTests │ ├── Diagnostics.cs │ └── Valid.cs ├── GU0072AllTypesShouldBeInternalTests │ ├── CodeFix.cs │ └── Valid.cs ├── GU0073MemberShouldBeInternalTests │ ├── CodeFix.cs │ └── Valid.cs ├── GU0074PreferPatternTests │ └── CodeFix.cs ├── GU0075PreferReturnNullable │ └── CodeFix.cs ├── GU0076MergePatternTests │ ├── CodeFix.And.cs │ └── CodeFix.When.cs ├── GU0077PreferIsNullTests │ └── CodeFix.cs ├── GU0080TestAttributeCountMismatchTests │ ├── CodeFix.cs │ └── Valid.cs ├── GU0081TestCasesAttributeMismatchTests │ ├── Diagnostics.cs │ └── Valid.cs ├── GU0082IdenticalTestCaseTests │ ├── Diagnostics.cs │ └── Valid.cs ├── GU0083TestCaseAttributeMismatchMethodTests │ ├── CodeFix.cs │ ├── NoFix.cs │ └── Valid.cs ├── GU0084AssertExceptionMessageTests │ └── CodeFix.cs ├── GU0090DoNotThrowNotImplementedExceptionTests │ ├── Diagnostics.cs │ └── Valid.cs ├── GU0100WrongDocsTests │ ├── CodeFix.cs │ └── Valid.cs ├── Gu.Analyzers.Test.csproj ├── Gu.Analyzers.Test.csproj.DotSettings ├── HandlesRecursion.cs ├── ModuleInitializer.cs ├── Refactorings │ ├── ParameterRefactoringTests.cs │ └── SplitStringRefactoringTests.cs ├── ReproBox.cs └── ValidAll.cs ├── Gu.Analyzers.Vsix ├── Gu.Analyzers.Vsix.csproj ├── Properties │ └── launchSettings.json ├── Readme.txt └── source.extension.vsixmanifest ├── Gu.Analyzers.sln ├── Gu.Analyzers.sln.DotSettings ├── Gu.Analyzers.snk ├── Gu.Analyzers ├── .editorconfig ├── AnalyzerCategory.cs ├── Analyzers │ ├── ArgumentAnalyzer.cs │ ├── ArgumentListAnalyzer.cs │ ├── AssertAnalyzer.cs │ ├── BinaryExpressionAnalyzer.cs │ ├── ClassDeclarationAnalyzer.cs │ ├── ConstructorAnalyzer.cs │ ├── DocsAnalyzer.cs │ ├── ExceptionAnalyzer.cs │ ├── IdentifierNameAnalyzer.cs │ ├── InvocationAnalyzer.cs │ ├── MethodGroupAnalyzer.cs │ ├── ObjectCreationAnalyzer.cs │ ├── ParameterAnalyzer.cs │ ├── PropertyDeclarationAnalyzer.cs │ ├── RangeAnalyzer.cs │ ├── SimpleAssignmentAnalyzer.cs │ ├── StringLiteralExpressionAnalyzer.cs │ ├── TestMethodAnalyzer.cs │ ├── VariableDeclaratorAnalyzer.cs │ └── WhenAnalyzer.cs ├── AssemblyAttributes.cs ├── CodeFixes │ ├── AssertFix.cs │ ├── DocsFix.cs │ ├── InjectFix.cs │ ├── IsNullFix.cs │ ├── MakeInternalFix.cs │ ├── MakeSealedFix.cs │ ├── MakeStaticFix.cs │ ├── MoveArgumentFix.cs │ ├── NameArgumentsFix.cs │ ├── NonSerializedFix.cs │ ├── NullCheckParameterFix.cs │ ├── NullableFix.cs │ ├── PatternFix.cs │ ├── RenameConstructorParameterFix.cs │ ├── RenameFix.cs │ ├── ReturnNullableFix.cs │ ├── SortPropertiesFix.cs │ ├── TestMethodParametersFix.cs │ ├── ThrowForCorrectParameterFix.cs │ ├── UseGetOnlyFix.cs │ ├── UseLambdaFix.cs │ ├── UseNameofFix.cs │ ├── UseParameterFix.cs │ └── UseSpanFix.cs ├── Descriptors.cs ├── GU0007PreferInjecting.cs ├── GU0011DoNotIgnoreReturnValue.cs ├── GU0020SortProperties.cs ├── GU0022UseGetOnly.cs ├── GU0023StaticMemberOrderAnalyzer.cs ├── GU0050IgnoreEventsWhenSerializing.cs ├── GU0051XmlSerializerNotCached.cs ├── GU0052ExceptionShouldBeSerializable.cs ├── GU0060EnumMemberValueConflictsWithAnother.cs ├── GU0061EnumMemberValueOutOfRange.cs ├── GU0070DefaultConstructedValueTypeWithNoUsefulDefault.cs ├── GU0071ForeachImplicitCast.cs ├── GU0072AllTypesShouldBeInternal.cs ├── GU0073MemberShouldBeInternal.cs ├── Gu.Analyzers.csproj ├── Gu.Analyzers.csproj.DotSettings ├── Helpers │ ├── Inject.cs │ ├── KnownSymbols │ │ ├── DependencyObjectType.cs │ │ ├── DependencyPropertyType.cs │ │ ├── EnumerableType.cs │ │ ├── IEnumerableType.cs │ │ ├── KnownSymbols.cs │ │ ├── NUnitAssertType.cs │ │ ├── StringBuilderType.cs │ │ ├── StringType.cs │ │ ├── TaskType.cs │ │ ├── XmlSerializerType.cs │ │ └── XunitAssertType.cs │ ├── Pattern.cs │ ├── StandardDocs.cs │ ├── StringExt.cs │ ├── SyntaxtTreeHelpers │ │ ├── ArgumentSyntaxExt.cs │ │ └── BasePropertyDeclarationSyntaxExt.cs │ ├── Temp.cs │ └── Walkers │ │ └── ObjectCreationWalker.cs ├── InternalsVisibleTo.cs ├── Refactoring │ ├── ParameterRefactoring.cs │ └── SplitStringRefactoring.cs └── tools │ ├── install.ps1 │ └── uninstall.ps1 ├── LICENSE ├── README.md ├── RELEASE_NOTES.md ├── ValidCode ├── .editorconfig ├── AssemblyAttributes.cs ├── Bar.cs ├── CompositeDisposableExt.cs ├── Disposable.cs ├── EmptyClass.cs ├── Exceptions.cs ├── Foo.cs ├── Foo1.cs ├── FooAsync.cs ├── FooBase.cs ├── FooCached.cs ├── FooImpl.cs ├── FooList.cs ├── FooOut.cs ├── Inheritance │ ├── Bar.cs │ └── Foo.cs ├── LazyFoo.cs ├── Recursion.cs ├── ReturnValue │ ├── C.cs │ ├── C1.cs │ └── Ext.cs ├── StringBuilderCases.cs ├── Tests.cs ├── UsingReactive.cs ├── ValidCode.csproj └── WithCustomDelegate.cs ├── appveyor.yml ├── azure-pipelines.yml └── documentation ├── GU0001.md ├── GU0002.md ├── GU0003.md ├── GU0004.md ├── GU0005.md ├── GU0006.md ├── GU0007.md ├── GU0008.md ├── GU0009.md ├── GU0010.md ├── GU0011.md ├── GU0012.md ├── GU0013.md ├── GU0014.md ├── GU0015.md ├── GU0016.md ├── GU0017.md ├── GU0018a.md ├── GU0018b.md ├── GU0019.md ├── GU0020.md ├── GU0021.md ├── GU0022.md ├── GU0023.md ├── GU0024.md ├── GU0025.md ├── GU0026.md ├── GU0050.md ├── GU0051.md ├── GU0052.md ├── GU0060.md ├── GU0061.md ├── GU0070.md ├── GU0071.md ├── GU0072.md ├── GU0073.md ├── GU0074.md ├── GU0075.md ├── GU0076.md ├── GU0077.md ├── GU0080.md ├── GU0081.md ├── GU0082.md ├── GU0083.md ├── GU0084.md ├── GU0090.md └── GU0100.md /.gitattributes: -------------------------------------------------------------------------------- 1 | # Source code files 2 | *.cs text 3 | *.vsixmanifest text 4 | *.config text 5 | *.resx text 6 | *.vstemplate text 7 | *.nuspec text 8 | *.md text 9 | *.txt text 10 | *.ps1 text 11 | LICENSE text 12 | 13 | # Projects and solutions 14 | *.sln text 15 | *.csproj text 16 | 17 | # Certainly binary files 18 | *.png binary 19 | *.ico binary 20 | *.snk binary 21 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: nuget 4 | directory: "/" 5 | schedule: 6 | interval: daily 7 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: ci 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | runs-on: windows-latest 8 | 9 | steps: 10 | - uses: actions/checkout@v3 11 | - name: setup 12 | uses: actions/setup-dotnet@v3 13 | with: 14 | dotnet-version: 7.0.x 15 | - name: restore 16 | run: dotnet restore 17 | - name: build 18 | run: dotnet build --configuration Release --no-restore 19 | - name: test 20 | run: dotnet test --no-restore --verbosity normal 21 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/.editorconfig: -------------------------------------------------------------------------------- 1 | [*.cs] 2 | 3 | # Default severity for analyzer diagnostics with category 'StyleCop.CSharp.DocumentationRules' 4 | dotnet_analyzer_diagnostic.category-StyleCop.CSharp.DocumentationRules.severity = none 5 | 6 | # SA0001: XML comment analysis is disabled due to project configuration 7 | dotnet_diagnostic.SA0001.severity = none 8 | 9 | # CA1822: Member 'ConstructorAnalyzer' does not access instance data and can be marked as static 10 | dotnet_diagnostic.CA1822.severity = none 11 | 12 | # CA1062: In externally visible method 'void CodeGen.AnalyzersBenchmark(DiagnosticAnalyzer analyzer)', validate parameter 'analyzer' is non-null before using it. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument. 13 | dotnet_diagnostic.CA1062.severity = none 14 | 15 | # CA1724: The type name Code conflicts in whole or in part with the namespace name 'BenchmarkDotNet.Code'. Change either name to eliminate the conflict. 16 | dotnet_diagnostic.CA1724.severity = none 17 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/AssemblyAttributes.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | [assembly: CLSCompliant(false)] 4 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/BenchmarkTests.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable RedundantNameQualifier 2 | namespace Gu.Analyzers.Benchmarks 3 | { 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using Microsoft.CodeAnalysis.Diagnostics; 8 | using NUnit.Framework; 9 | 10 | internal static class BenchmarkTests 11 | { 12 | private static IReadOnlyList AllAnalyzers { get; } = 13 | typeof(KnownSymbols) 14 | .Assembly 15 | .GetTypes() 16 | .Where(t => typeof(DiagnosticAnalyzer).IsAssignableFrom(t) && !t.IsAbstract) 17 | .Select(t => (DiagnosticAnalyzer)Activator.CreateInstance(t)!) 18 | .ToArray(); 19 | 20 | private static IReadOnlyList AllBenchmarks { get; } = AllAnalyzers 21 | .Select(x => Gu.Roslyn.Asserts.Benchmark.Create(Code.AnalyzersProject, x)) 22 | .ToArray(); 23 | 24 | [OneTimeSetUp] 25 | public static void OneTimeSetUp() 26 | { 27 | foreach (var benchmark in AllBenchmarks) 28 | { 29 | benchmark.Run(); 30 | } 31 | } 32 | 33 | [TestCaseSource(nameof(AllBenchmarks))] 34 | public static void Run(Gu.Roslyn.Asserts.Benchmark benchmark) 35 | { 36 | benchmark.Run(); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/ArgumentAnalyzerBenchmarks.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable RedundantNameQualifier 2 | // ReSharper disable InconsistentNaming 3 | namespace Gu.Analyzers.Benchmarks 4 | { 5 | [BenchmarkDotNet.Attributes.MemoryDiagnoser] 6 | public class ArgumentAnalyzerBenchmarks 7 | { 8 | private static readonly Gu.Roslyn.Asserts.Benchmark Benchmark = Gu.Roslyn.Asserts.Benchmark.Create(Code.AnalyzersProject, new Gu.Analyzers.ArgumentAnalyzer()); 9 | 10 | [BenchmarkDotNet.Attributes.Benchmark] 11 | public void RunOnGuAnalyzersProject() 12 | { 13 | Benchmark.Run(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/ArgumentListAnalyzerBenchmarks.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable RedundantNameQualifier 2 | // ReSharper disable InconsistentNaming 3 | namespace Gu.Analyzers.Benchmarks 4 | { 5 | [BenchmarkDotNet.Attributes.MemoryDiagnoser] 6 | public class ArgumentListAnalyzerBenchmarks 7 | { 8 | private static readonly Gu.Roslyn.Asserts.Benchmark Benchmark = Gu.Roslyn.Asserts.Benchmark.Create(Code.AnalyzersProject, new Gu.Analyzers.ArgumentListAnalyzer()); 9 | 10 | [BenchmarkDotNet.Attributes.Benchmark] 11 | public void RunOnGuAnalyzersProject() 12 | { 13 | Benchmark.Run(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/ArgumentListAnalyzerBenchmarks.md: -------------------------------------------------------------------------------- 1 | ``` ini 2 | 3 | BenchmarkDotNet=v0.10.13, OS=Windows 7 SP1 (6.1.7601.0) 4 | Intel Xeon CPU E5-2637 v4 3.50GHz, 2 CPU, 16 logical cores and 8 physical cores 5 | Frequency=3410117 Hz, Resolution=293.2451 ns, Timer=TSC 6 | [Host] : .NET Framework 4.7 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.2558.0 7 | DefaultJob : .NET Framework 4.7 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.2558.0 8 | 9 | 10 | ``` 11 | | Method | Mean | Error | StdDev | Allocated | 12 | |------------------------ |---------:|----------:|----------:|----------:| 13 | | RunOnGuAnalyzersProject | 2.389 ms | 0.0477 ms | 0.1264 ms | 17.63 KB | 14 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/AssertAnalyzerBenchmarks.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable RedundantNameQualifier 2 | // ReSharper disable InconsistentNaming 3 | namespace Gu.Analyzers.Benchmarks 4 | { 5 | [BenchmarkDotNet.Attributes.MemoryDiagnoser] 6 | public class AssertAnalyzerBenchmarks 7 | { 8 | private static readonly Gu.Roslyn.Asserts.Benchmark Benchmark = Gu.Roslyn.Asserts.Benchmark.Create(Code.AnalyzersProject, new Gu.Analyzers.AssertAnalyzer()); 9 | 10 | [BenchmarkDotNet.Attributes.Benchmark] 11 | public void RunOnGuAnalyzersProject() 12 | { 13 | Benchmark.Run(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/BinaryExpressionAnalyzerBenchmarks.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable RedundantNameQualifier 2 | // ReSharper disable InconsistentNaming 3 | namespace Gu.Analyzers.Benchmarks 4 | { 5 | [BenchmarkDotNet.Attributes.MemoryDiagnoser] 6 | public class BinaryExpressionAnalyzerBenchmarks 7 | { 8 | private static readonly Gu.Roslyn.Asserts.Benchmark Benchmark = Gu.Roslyn.Asserts.Benchmark.Create(Code.AnalyzersProject, new Gu.Analyzers.BinaryExpressionAnalyzer()); 9 | 10 | [BenchmarkDotNet.Attributes.Benchmark] 11 | public void RunOnGuAnalyzersProject() 12 | { 13 | Benchmark.Run(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/ClassDeclarationAnalyzerBenchmarks.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable RedundantNameQualifier 2 | // ReSharper disable InconsistentNaming 3 | namespace Gu.Analyzers.Benchmarks 4 | { 5 | [BenchmarkDotNet.Attributes.MemoryDiagnoser] 6 | public class ClassDeclarationAnalyzerBenchmarks 7 | { 8 | private static readonly Gu.Roslyn.Asserts.Benchmark Benchmark = Gu.Roslyn.Asserts.Benchmark.Create(Code.AnalyzersProject, new Gu.Analyzers.ClassDeclarationAnalyzer()); 9 | 10 | [BenchmarkDotNet.Attributes.Benchmark] 11 | public void RunOnGuAnalyzersProject() 12 | { 13 | Benchmark.Run(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/CodeGen/Code.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers.Benchmarks 2 | { 3 | using Gu.Roslyn.Asserts; 4 | using Microsoft.CodeAnalysis; 5 | 6 | public static class Code 7 | { 8 | public static Solution AnalyzersProject { get; } = CodeFactory.CreateSolution( 9 | ProjectFile.Find("Gu.Analyzers.csproj")); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/ConstructorAnalyzerBenchmarks.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable RedundantNameQualifier 2 | // ReSharper disable InconsistentNaming 3 | namespace Gu.Analyzers.Benchmarks 4 | { 5 | [BenchmarkDotNet.Attributes.MemoryDiagnoser] 6 | public class ConstructorAnalyzerBenchmarks 7 | { 8 | private static readonly Gu.Roslyn.Asserts.Benchmark Benchmark = Gu.Roslyn.Asserts.Benchmark.Create(Code.AnalyzersProject, new Gu.Analyzers.ConstructorAnalyzer()); 9 | 10 | [BenchmarkDotNet.Attributes.Benchmark] 11 | public void RunOnGuAnalyzersProject() 12 | { 13 | Benchmark.Run(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/ConstructorAnalyzerBenchmarks.md: -------------------------------------------------------------------------------- 1 | ``` ini 2 | 3 | BenchmarkDotNet=v0.10.13, OS=Windows 7 SP1 (6.1.7601.0) 4 | Intel Xeon CPU E5-2637 v4 3.50GHz, 2 CPU, 16 logical cores and 8 physical cores 5 | Frequency=3410117 Hz, Resolution=293.2451 ns, Timer=TSC 6 | [Host] : .NET Framework 4.7 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.2558.0 7 | DefaultJob : .NET Framework 4.7 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.2558.0 8 | 9 | 10 | ``` 11 | | Method | Mean | Error | StdDev | Gen 0 | Allocated | 12 | |------------------------ |---------:|----------:|----------:|--------:|----------:| 13 | | RunOnGuAnalyzersProject | 5.497 ms | 0.1426 ms | 0.4161 ms | 39.0625 | 288.87 KB | 14 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/DocsAnalyzerBenchmarks.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable RedundantNameQualifier 2 | // ReSharper disable InconsistentNaming 3 | namespace Gu.Analyzers.Benchmarks 4 | { 5 | [BenchmarkDotNet.Attributes.MemoryDiagnoser] 6 | public class DocsAnalyzerBenchmarks 7 | { 8 | private static readonly Gu.Roslyn.Asserts.Benchmark Benchmark = Gu.Roslyn.Asserts.Benchmark.Create(Code.AnalyzersProject, new Gu.Analyzers.DocsAnalyzer()); 9 | 10 | [BenchmarkDotNet.Attributes.Benchmark] 11 | public void RunOnGuAnalyzersProject() 12 | { 13 | Benchmark.Run(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/ExceptionAnalyzerBenchmarks.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable RedundantNameQualifier 2 | // ReSharper disable InconsistentNaming 3 | namespace Gu.Analyzers.Benchmarks 4 | { 5 | [BenchmarkDotNet.Attributes.MemoryDiagnoser] 6 | public class ExceptionAnalyzerBenchmarks 7 | { 8 | private static readonly Gu.Roslyn.Asserts.Benchmark Benchmark = Gu.Roslyn.Asserts.Benchmark.Create(Code.AnalyzersProject, new Gu.Analyzers.ExceptionAnalyzer()); 9 | 10 | [BenchmarkDotNet.Attributes.Benchmark] 11 | public void RunOnGuAnalyzersProject() 12 | { 13 | Benchmark.Run(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/GU0006UseNameofBenchmarks.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable RedundantNameQualifier 2 | // ReSharper disable InconsistentNaming 3 | namespace Gu.Analyzers.Benchmarks 4 | { 5 | [BenchmarkDotNet.Attributes.MemoryDiagnoser] 6 | public class GU0006UseNameofBenchmarks 7 | { 8 | private static readonly Gu.Roslyn.Asserts.Benchmark Benchmark = Gu.Roslyn.Asserts.Benchmark.Create(Code.AnalyzersProject, new Gu.Analyzers.StringLiteralExpressionAnalyzer()); 9 | 10 | [BenchmarkDotNet.Attributes.Benchmark] 11 | public void RunOnGuAnalyzersProject() 12 | { 13 | Benchmark.Run(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/GU0006UseNameofBenchmarks.md: -------------------------------------------------------------------------------- 1 | ``` ini 2 | 3 | BenchmarkDotNet=v0.10.13, OS=Windows 7 SP1 (6.1.7601.0) 4 | Intel Xeon CPU E5-2637 v4 3.50GHz, 2 CPU, 16 logical cores and 8 physical cores 5 | Frequency=3410117 Hz, Resolution=293.2451 ns, Timer=TSC 6 | [Host] : .NET Framework 4.7 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.2558.0 7 | DefaultJob : .NET Framework 4.7 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.2558.0 8 | 9 | 10 | ``` 11 | | Method | Mean | Error | StdDev | Gen 0 | Allocated | 12 | |------------------------ |---------:|----------:|----------:|--------:|----------:| 13 | | RunOnGuAnalyzersProject | 3.236 ms | 0.0633 ms | 0.1689 ms | 46.8750 | 311.59 KB | 14 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/GU0007PreferInjectingBenchmarks.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable RedundantNameQualifier 2 | // ReSharper disable InconsistentNaming 3 | namespace Gu.Analyzers.Benchmarks 4 | { 5 | [BenchmarkDotNet.Attributes.MemoryDiagnoser] 6 | public class GU0007PreferInjectingBenchmarks 7 | { 8 | private static readonly Gu.Roslyn.Asserts.Benchmark Benchmark = Gu.Roslyn.Asserts.Benchmark.Create(Code.AnalyzersProject, new Gu.Analyzers.GU0007PreferInjecting()); 9 | 10 | [BenchmarkDotNet.Attributes.Benchmark] 11 | public void RunOnGuAnalyzersProject() 12 | { 13 | Benchmark.Run(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/GU0007PreferInjectingBenchmarks.md: -------------------------------------------------------------------------------- 1 | ``` ini 2 | 3 | BenchmarkDotNet=v0.10.13, OS=Windows 7 SP1 (6.1.7601.0) 4 | Intel Xeon CPU E5-2637 v4 3.50GHz, 2 CPU, 16 logical cores and 8 physical cores 5 | Frequency=3410117 Hz, Resolution=293.2451 ns, Timer=TSC 6 | [Host] : .NET Framework 4.7 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.2558.0 7 | DefaultJob : .NET Framework 4.7 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.2558.0 8 | 9 | 10 | ``` 11 | | Method | Mean | Error | StdDev | Allocated | 12 | |------------------------ |---------:|----------:|----------:|----------:| 13 | | RunOnGuAnalyzersProject | 5.132 ms | 0.1020 ms | 0.2282 ms | 20.51 KB | 14 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/GU0008AvoidRelayPropertiesBenchmarks.md: -------------------------------------------------------------------------------- 1 | ``` ini 2 | 3 | BenchmarkDotNet=v0.10.13, OS=Windows 7 SP1 (6.1.7601.0) 4 | Intel Xeon CPU E5-2637 v4 3.50GHz, 2 CPU, 16 logical cores and 8 physical cores 5 | Frequency=3410117 Hz, Resolution=293.2451 ns, Timer=TSC 6 | [Host] : .NET Framework 4.7 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.2558.0 7 | DefaultJob : .NET Framework 4.7 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.2558.0 8 | 9 | 10 | ``` 11 | | Method | Mean | Error | StdDev | Allocated | 12 | |------------------------ |---------:|---------:|---------:|----------:| 13 | | RunOnGuAnalyzersProject | 733.0 us | 14.49 us | 36.35 us | 7.04 KB | 14 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/GU0009UseNamedParametersForBooleansBenchmarks.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable RedundantNameQualifier 2 | // ReSharper disable InconsistentNaming 3 | namespace Gu.Analyzers.Benchmarks 4 | { 5 | [BenchmarkDotNet.Attributes.MemoryDiagnoser] 6 | public class GU0009UseNamedParametersForBooleansBenchmarks 7 | { 8 | private static readonly Gu.Roslyn.Asserts.Benchmark Benchmark = Gu.Roslyn.Asserts.Benchmark.Create(Code.AnalyzersProject, new Gu.Analyzers.ArgumentAnalyzer()); 9 | 10 | [BenchmarkDotNet.Attributes.Benchmark] 11 | public void RunOnGuAnalyzersProject() 12 | { 13 | Benchmark.Run(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/GU0009UseNamedParametersForBooleansBenchmarks.md: -------------------------------------------------------------------------------- 1 | ``` ini 2 | 3 | BenchmarkDotNet=v0.10.13, OS=Windows 7 SP1 (6.1.7601.0) 4 | Intel Xeon CPU E5-2637 v4 3.50GHz, 2 CPU, 16 logical cores and 8 physical cores 5 | Frequency=3410117 Hz, Resolution=293.2451 ns, Timer=TSC 6 | [Host] : .NET Framework 4.7 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.2558.0 7 | DefaultJob : .NET Framework 4.7 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.2558.0 8 | 9 | 10 | ``` 11 | | Method | Mean | Error | StdDev | Allocated | 12 | |------------------------ |---------:|----------:|----------:|----------:| 13 | | RunOnGuAnalyzersProject | 2.566 ms | 0.0538 ms | 0.0661 ms | 544 B | 14 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/GU0011DoNotIgnoreReturnValueBenchmarks.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable RedundantNameQualifier 2 | // ReSharper disable InconsistentNaming 3 | namespace Gu.Analyzers.Benchmarks 4 | { 5 | [BenchmarkDotNet.Attributes.MemoryDiagnoser] 6 | public class GU0011DoNotIgnoreReturnValueBenchmarks 7 | { 8 | private static readonly Gu.Roslyn.Asserts.Benchmark Benchmark = Gu.Roslyn.Asserts.Benchmark.Create(Code.AnalyzersProject, new Gu.Analyzers.GU0011DoNotIgnoreReturnValue()); 9 | 10 | [BenchmarkDotNet.Attributes.Benchmark] 11 | public void RunOnGuAnalyzersProject() 12 | { 13 | Benchmark.Run(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/GU0011DontIgnoreReturnValueBenchmarks.md: -------------------------------------------------------------------------------- 1 | ``` ini 2 | 3 | BenchmarkDotNet=v0.10.13, OS=Windows 7 SP1 (6.1.7601.0) 4 | Intel Xeon CPU E5-2637 v4 3.50GHz, 2 CPU, 16 logical cores and 8 physical cores 5 | Frequency=3410117 Hz, Resolution=293.2451 ns, Timer=TSC 6 | [Host] : .NET Framework 4.7 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.2558.0 7 | DefaultJob : .NET Framework 4.7 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.2558.0 8 | 9 | 10 | ``` 11 | | Method | Mean | Error | StdDev | Gen 0 | Allocated | 12 | |------------------------ |---------:|----------:|----------:|-------:|----------:| 13 | | RunOnGuAnalyzersProject | 2.317 ms | 0.0528 ms | 0.1531 ms | 3.9063 | 46.21 KB | 14 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/GU0020SortPropertiesBenchmarks.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable RedundantNameQualifier 2 | // ReSharper disable InconsistentNaming 3 | namespace Gu.Analyzers.Benchmarks 4 | { 5 | [BenchmarkDotNet.Attributes.MemoryDiagnoser] 6 | public class GU0020SortPropertiesBenchmarks 7 | { 8 | private static readonly Gu.Roslyn.Asserts.Benchmark Benchmark = Gu.Roslyn.Asserts.Benchmark.Create(Code.AnalyzersProject, new Gu.Analyzers.GU0020SortProperties()); 9 | 10 | [BenchmarkDotNet.Attributes.Benchmark] 11 | public void RunOnGuAnalyzersProject() 12 | { 13 | Benchmark.Run(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/GU0020SortPropertiesBenchmarks.md: -------------------------------------------------------------------------------- 1 | ``` ini 2 | 3 | BenchmarkDotNet=v0.10.13, OS=Windows 7 SP1 (6.1.7601.0) 4 | Intel Xeon CPU E5-2637 v4 3.50GHz, 2 CPU, 16 logical cores and 8 physical cores 5 | Frequency=3410117 Hz, Resolution=293.2451 ns, Timer=TSC 6 | [Host] : .NET Framework 4.7 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.2558.0 7 | DefaultJob : .NET Framework 4.7 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.2558.0 8 | 9 | 10 | ``` 11 | | Method | Mean | Error | StdDev | Gen 0 | Allocated | 12 | |------------------------ |---------:|---------:|---------:|-------:|----------:| 13 | | RunOnGuAnalyzersProject | 82.53 us | 1.643 us | 3.320 us | 0.8545 | 5.81 KB | 14 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/GU0021CalculatedPropertyAllocatesBenchmarks.md: -------------------------------------------------------------------------------- 1 | ``` ini 2 | 3 | BenchmarkDotNet=v0.10.13, OS=Windows 7 SP1 (6.1.7601.0) 4 | Intel Xeon CPU E5-2637 v4 3.50GHz, 2 CPU, 16 logical cores and 8 physical cores 5 | Frequency=3410117 Hz, Resolution=293.2451 ns, Timer=TSC 6 | [Host] : .NET Framework 4.7 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.2558.0 7 | DefaultJob : .NET Framework 4.7 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.2558.0 8 | 9 | 10 | ``` 11 | | Method | Mean | Error | StdDev | Allocated | 12 | |------------------------ |---------:|---------:|---------:|----------:| 13 | | RunOnGuAnalyzersProject | 74.80 us | 1.486 us | 4.141 us | 441 B | 14 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/GU0022UseGetOnlyBenchmarks.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable RedundantNameQualifier 2 | // ReSharper disable InconsistentNaming 3 | namespace Gu.Analyzers.Benchmarks 4 | { 5 | [BenchmarkDotNet.Attributes.MemoryDiagnoser] 6 | public class GU0022UseGetOnlyBenchmarks 7 | { 8 | private static readonly Gu.Roslyn.Asserts.Benchmark Benchmark = Gu.Roslyn.Asserts.Benchmark.Create(Code.AnalyzersProject, new Gu.Analyzers.GU0022UseGetOnly()); 9 | 10 | [BenchmarkDotNet.Attributes.Benchmark] 11 | public void RunOnGuAnalyzersProject() 12 | { 13 | Benchmark.Run(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/GU0022UseGetOnlyBenchmarks.md: -------------------------------------------------------------------------------- 1 | ``` ini 2 | 3 | BenchmarkDotNet=v0.10.13, OS=Windows 7 SP1 (6.1.7601.0) 4 | Intel Xeon CPU E5-2637 v4 3.50GHz, 2 CPU, 16 logical cores and 8 physical cores 5 | Frequency=3410117 Hz, Resolution=293.2451 ns, Timer=TSC 6 | [Host] : .NET Framework 4.7 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.2558.0 7 | DefaultJob : .NET Framework 4.7 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.2558.0 8 | 9 | 10 | ``` 11 | | Method | Mean | Error | StdDev | Gen 0 | Allocated | 12 | |------------------------ |---------:|----------:|----------:|--------:|----------:| 13 | | RunOnGuAnalyzersProject | 2.561 ms | 0.0596 ms | 0.1747 ms | 11.7188 | 89.81 KB | 14 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/GU0023StaticMemberOrderAnalyzerBenchmarks.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable RedundantNameQualifier 2 | // ReSharper disable InconsistentNaming 3 | namespace Gu.Analyzers.Benchmarks 4 | { 5 | [BenchmarkDotNet.Attributes.MemoryDiagnoser] 6 | public class GU0023StaticMemberOrderAnalyzerBenchmarks 7 | { 8 | private static readonly Gu.Roslyn.Asserts.Benchmark Benchmark = Gu.Roslyn.Asserts.Benchmark.Create(Code.AnalyzersProject, new Gu.Analyzers.GU0023StaticMemberOrderAnalyzer()); 9 | 10 | [BenchmarkDotNet.Attributes.Benchmark] 11 | public void RunOnGuAnalyzersProject() 12 | { 13 | Benchmark.Run(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/GU0050IgnoreEventsWhenSerializingBenchmarks.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable RedundantNameQualifier 2 | // ReSharper disable InconsistentNaming 3 | namespace Gu.Analyzers.Benchmarks 4 | { 5 | [BenchmarkDotNet.Attributes.MemoryDiagnoser] 6 | public class GU0050IgnoreEventsWhenSerializingBenchmarks 7 | { 8 | private static readonly Gu.Roslyn.Asserts.Benchmark Benchmark = Gu.Roslyn.Asserts.Benchmark.Create(Code.AnalyzersProject, new Gu.Analyzers.GU0050IgnoreEventsWhenSerializing()); 9 | 10 | [BenchmarkDotNet.Attributes.Benchmark] 11 | public void RunOnGuAnalyzersProject() 12 | { 13 | Benchmark.Run(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/GU0050IgnoreEventsWhenSerializingBenchmarks.md: -------------------------------------------------------------------------------- 1 | ``` ini 2 | 3 | BenchmarkDotNet=v0.10.13, OS=Windows 7 SP1 (6.1.7601.0) 4 | Intel Xeon CPU E5-2637 v4 3.50GHz, 2 CPU, 16 logical cores and 8 physical cores 5 | Frequency=3410117 Hz, Resolution=293.2451 ns, Timer=TSC 6 | [Host] : .NET Framework 4.7 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.2558.0 7 | DefaultJob : .NET Framework 4.7 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.2558.0 8 | 9 | 10 | ``` 11 | | Method | Mean | Error | StdDev | Gen 0 | Allocated | 12 | |------------------------ |---------:|---------:|---------:|-------:|----------:| 13 | | RunOnGuAnalyzersProject | 340.9 us | 6.754 us | 17.67 us | 2.9297 | 20.25 KB | 14 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/GU0051XmlSerializerNotCachedBenchmarks.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable RedundantNameQualifier 2 | // ReSharper disable InconsistentNaming 3 | namespace Gu.Analyzers.Benchmarks 4 | { 5 | [BenchmarkDotNet.Attributes.MemoryDiagnoser] 6 | public class GU0051XmlSerializerNotCachedBenchmarks 7 | { 8 | private static readonly Gu.Roslyn.Asserts.Benchmark Benchmark = Gu.Roslyn.Asserts.Benchmark.Create(Code.AnalyzersProject, new Gu.Analyzers.GU0051XmlSerializerNotCached()); 9 | 10 | [BenchmarkDotNet.Attributes.Benchmark] 11 | public void RunOnGuAnalyzersProject() 12 | { 13 | Benchmark.Run(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/GU0051XmlSerializerNotCachedBenchmarks.md: -------------------------------------------------------------------------------- 1 | ``` ini 2 | 3 | BenchmarkDotNet=v0.10.13, OS=Windows 7 SP1 (6.1.7601.0) 4 | Intel Xeon CPU E5-2637 v4 3.50GHz, 2 CPU, 16 logical cores and 8 physical cores 5 | Frequency=3410117 Hz, Resolution=293.2451 ns, Timer=TSC 6 | [Host] : .NET Framework 4.7 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.2558.0 7 | DefaultJob : .NET Framework 4.7 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.2558.0 8 | 9 | 10 | ``` 11 | | Method | Mean | Error | StdDev | Gen 0 | Gen 1 | Allocated | 12 | |------------------------ |---------:|---------:|---------:|-------:|-------:|----------:| 13 | | RunOnGuAnalyzersProject | 368.0 us | 6.846 us | 12.86 us | 3.9063 | 0.4883 | 27.19 KB | 14 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/GU0052ExceptionShouldBeSerializableBenchmarks.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable RedundantNameQualifier 2 | // ReSharper disable InconsistentNaming 3 | namespace Gu.Analyzers.Benchmarks 4 | { 5 | [BenchmarkDotNet.Attributes.MemoryDiagnoser] 6 | public class GU0052ExceptionShouldBeSerializableBenchmarks 7 | { 8 | private static readonly Gu.Roslyn.Asserts.Benchmark Benchmark = Gu.Roslyn.Asserts.Benchmark.Create(Code.AnalyzersProject, new Gu.Analyzers.GU0052ExceptionShouldBeSerializable()); 9 | 10 | [BenchmarkDotNet.Attributes.Benchmark] 11 | public void RunOnGuAnalyzersProject() 12 | { 13 | Benchmark.Run(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/GU0060EnumMemberValueConflictsWithAnotherBenchmarks.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable RedundantNameQualifier 2 | // ReSharper disable InconsistentNaming 3 | namespace Gu.Analyzers.Benchmarks 4 | { 5 | [BenchmarkDotNet.Attributes.MemoryDiagnoser] 6 | public class GU0060EnumMemberValueConflictsWithAnotherBenchmarks 7 | { 8 | private static readonly Gu.Roslyn.Asserts.Benchmark Benchmark = Gu.Roslyn.Asserts.Benchmark.Create(Code.AnalyzersProject, new Gu.Analyzers.GU0060EnumMemberValueConflictsWithAnother()); 9 | 10 | [BenchmarkDotNet.Attributes.Benchmark] 11 | public void RunOnGuAnalyzersProject() 12 | { 13 | Benchmark.Run(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/GU0060EnumMemberValueConflictsWithAnotherBenchmarks.md: -------------------------------------------------------------------------------- 1 | ``` ini 2 | 3 | BenchmarkDotNet=v0.10.13, OS=Windows 7 SP1 (6.1.7601.0) 4 | Intel Xeon CPU E5-2637 v4 3.50GHz, 2 CPU, 16 logical cores and 8 physical cores 5 | Frequency=3410117 Hz, Resolution=293.2451 ns, Timer=TSC 6 | [Host] : .NET Framework 4.7 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.2558.0 7 | DefaultJob : .NET Framework 4.7 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.2558.0 8 | 9 | 10 | ``` 11 | | Method | Mean | Error | StdDev | Gen 0 | Gen 1 | Allocated | 12 | |------------------------ |---------:|----------:|---------:|-------:|-------:|----------:| 13 | | RunOnGuAnalyzersProject | 21.65 us | 0.5908 us | 1.742 us | 0.1831 | 0.0305 | 1.32 KB | 14 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/GU0061EnumMemberValueOutOfRangeBenchmarks.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable RedundantNameQualifier 2 | // ReSharper disable InconsistentNaming 3 | namespace Gu.Analyzers.Benchmarks 4 | { 5 | [BenchmarkDotNet.Attributes.MemoryDiagnoser] 6 | public class GU0061EnumMemberValueOutOfRangeBenchmarks 7 | { 8 | private static readonly Gu.Roslyn.Asserts.Benchmark Benchmark = Gu.Roslyn.Asserts.Benchmark.Create(Code.AnalyzersProject, new Gu.Analyzers.GU0061EnumMemberValueOutOfRange()); 9 | 10 | [BenchmarkDotNet.Attributes.Benchmark] 11 | public void RunOnGuAnalyzersProject() 12 | { 13 | Benchmark.Run(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/GU0070DefaultConstructedValueTypeWithNoUsefulDefaultBenchmarks.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable RedundantNameQualifier 2 | // ReSharper disable InconsistentNaming 3 | namespace Gu.Analyzers.Benchmarks 4 | { 5 | [BenchmarkDotNet.Attributes.MemoryDiagnoser] 6 | public class GU0070DefaultConstructedValueTypeWithNoUsefulDefaultBenchmarks 7 | { 8 | private static readonly Gu.Roslyn.Asserts.Benchmark Benchmark = Gu.Roslyn.Asserts.Benchmark.Create(Code.AnalyzersProject, new Gu.Analyzers.GU0070DefaultConstructedValueTypeWithNoUsefulDefault()); 9 | 10 | [BenchmarkDotNet.Attributes.Benchmark] 11 | public void RunOnGuAnalyzersProject() 12 | { 13 | Benchmark.Run(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/GU0070DefaultConstructedValueTypeWithNoUsefulDefaultBenchmarks.md: -------------------------------------------------------------------------------- 1 | ``` ini 2 | 3 | BenchmarkDotNet=v0.10.13, OS=Windows 7 SP1 (6.1.7601.0) 4 | Intel Xeon CPU E5-2637 v4 3.50GHz, 2 CPU, 16 logical cores and 8 physical cores 5 | Frequency=3410117 Hz, Resolution=293.2451 ns, Timer=TSC 6 | [Host] : .NET Framework 4.7 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.2558.0 7 | DefaultJob : .NET Framework 4.7 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.2558.0 8 | 9 | 10 | ``` 11 | | Method | Mean | Error | StdDev | Gen 0 | Gen 1 | Allocated | 12 | |------------------------ |---------:|---------:|---------:|-------:|-------:|----------:| 13 | | RunOnGuAnalyzersProject | 524.7 us | 10.44 us | 28.59 us | 7.8125 | 0.9766 | 53.94 KB | 14 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/GU0071ForeachImplicitCastBenchmarks.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable RedundantNameQualifier 2 | // ReSharper disable InconsistentNaming 3 | namespace Gu.Analyzers.Benchmarks 4 | { 5 | [BenchmarkDotNet.Attributes.MemoryDiagnoser] 6 | public class GU0071ForeachImplicitCastBenchmarks 7 | { 8 | private static readonly Gu.Roslyn.Asserts.Benchmark Benchmark = Gu.Roslyn.Asserts.Benchmark.Create(Code.AnalyzersProject, new Gu.Analyzers.GU0071ForeachImplicitCast()); 9 | 10 | [BenchmarkDotNet.Attributes.Benchmark] 11 | public void RunOnGuAnalyzersProject() 12 | { 13 | Benchmark.Run(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/GU0071ForeachImplicitCastBenchmarks.md: -------------------------------------------------------------------------------- 1 | ``` ini 2 | 3 | BenchmarkDotNet=v0.10.13, OS=Windows 7 SP1 (6.1.7601.0) 4 | Intel Xeon CPU E5-2637 v4 3.50GHz, 2 CPU, 16 logical cores and 8 physical cores 5 | Frequency=3410117 Hz, Resolution=293.2451 ns, Timer=TSC 6 | [Host] : .NET Framework 4.7 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.2558.0 7 | DefaultJob : .NET Framework 4.7 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.2558.0 8 | 9 | 10 | ``` 11 | | Method | Mean | Error | StdDev | Allocated | 12 | |------------------------ |---------:|---------:|---------:|----------:| 13 | | RunOnGuAnalyzersProject | 98.66 us | 4.487 us | 4.197 us | 441 B | 14 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/GU0072AllTypesShouldBeInternalBenchmarks.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable RedundantNameQualifier 2 | // ReSharper disable InconsistentNaming 3 | namespace Gu.Analyzers.Benchmarks 4 | { 5 | [BenchmarkDotNet.Attributes.MemoryDiagnoser] 6 | public class GU0072AllTypesShouldBeInternalBenchmarks 7 | { 8 | private static readonly Gu.Roslyn.Asserts.Benchmark Benchmark = Gu.Roslyn.Asserts.Benchmark.Create(Code.AnalyzersProject, new Gu.Analyzers.GU0072AllTypesShouldBeInternal()); 9 | 10 | [BenchmarkDotNet.Attributes.Benchmark] 11 | public void RunOnGuAnalyzersProject() 12 | { 13 | Benchmark.Run(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/GU0073MemberShouldBeInternalBenchmarks.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable RedundantNameQualifier 2 | // ReSharper disable InconsistentNaming 3 | namespace Gu.Analyzers.Benchmarks 4 | { 5 | [BenchmarkDotNet.Attributes.MemoryDiagnoser] 6 | public class GU0073MemberShouldBeInternalBenchmarks 7 | { 8 | private static readonly Gu.Roslyn.Asserts.Benchmark Benchmark = Gu.Roslyn.Asserts.Benchmark.Create(Code.AnalyzersProject, new Gu.Analyzers.GU0073MemberShouldBeInternal()); 9 | 10 | [BenchmarkDotNet.Attributes.Benchmark] 11 | public void RunOnGuAnalyzersProject() 12 | { 13 | Benchmark.Run(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/IdentifierNameAnalyzerBenchmarks.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable RedundantNameQualifier 2 | // ReSharper disable InconsistentNaming 3 | namespace Gu.Analyzers.Benchmarks 4 | { 5 | [BenchmarkDotNet.Attributes.MemoryDiagnoser] 6 | public class IdentifierNameAnalyzerBenchmarks 7 | { 8 | private static readonly Gu.Roslyn.Asserts.Benchmark Benchmark = Gu.Roslyn.Asserts.Benchmark.Create(Code.AnalyzersProject, new Gu.Analyzers.IdentifierNameAnalyzer()); 9 | 10 | [BenchmarkDotNet.Attributes.Benchmark] 11 | public void RunOnGuAnalyzersProject() 12 | { 13 | Benchmark.Run(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/MethodGroupAnalyzerBenchmarks.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable RedundantNameQualifier 2 | // ReSharper disable InconsistentNaming 3 | namespace Gu.Analyzers.Benchmarks 4 | { 5 | [BenchmarkDotNet.Attributes.MemoryDiagnoser] 6 | public class MethodGroupAnalyzerBenchmarks 7 | { 8 | private static readonly Gu.Roslyn.Asserts.Benchmark Benchmark = Gu.Roslyn.Asserts.Benchmark.Create(Code.AnalyzersProject, new Gu.Analyzers.MethodGroupAnalyzer()); 9 | 10 | [BenchmarkDotNet.Attributes.Benchmark] 11 | public void RunOnGuAnalyzersProject() 12 | { 13 | Benchmark.Run(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/ObjectCreationAnalyzerBenchmarks.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable RedundantNameQualifier 2 | // ReSharper disable InconsistentNaming 3 | namespace Gu.Analyzers.Benchmarks 4 | { 5 | [BenchmarkDotNet.Attributes.MemoryDiagnoser] 6 | public class ObjectCreationAnalyzerBenchmarks 7 | { 8 | private static readonly Gu.Roslyn.Asserts.Benchmark Benchmark = Gu.Roslyn.Asserts.Benchmark.Create(Code.AnalyzersProject, new Gu.Analyzers.ObjectCreationAnalyzer()); 9 | 10 | [BenchmarkDotNet.Attributes.Benchmark] 11 | public void RunOnGuAnalyzersProject() 12 | { 13 | Benchmark.Run(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/ObjectCreationAnalyzerBenchmarks.md: -------------------------------------------------------------------------------- 1 | ``` ini 2 | 3 | BenchmarkDotNet=v0.10.13, OS=Windows 7 SP1 (6.1.7601.0) 4 | Intel Xeon CPU E5-2637 v4 3.50GHz, 2 CPU, 16 logical cores and 8 physical cores 5 | Frequency=3410117 Hz, Resolution=293.2451 ns, Timer=TSC 6 | [Host] : .NET Framework 4.7 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.2558.0 7 | DefaultJob : .NET Framework 4.7 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.2558.0 8 | 9 | 10 | ``` 11 | | Method | Mean | Error | StdDev | Gen 0 | Gen 1 | Allocated | 12 | |------------------------ |---------:|---------:|---------:|-------:|-------:|----------:| 13 | | RunOnGuAnalyzersProject | 427.8 us | 8.516 us | 23.17 us | 6.3477 | 1.4648 | 41.18 KB | 14 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/ParameterAnalyzerBenchmarks.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable RedundantNameQualifier 2 | // ReSharper disable InconsistentNaming 3 | namespace Gu.Analyzers.Benchmarks 4 | { 5 | [BenchmarkDotNet.Attributes.MemoryDiagnoser] 6 | public class ParameterAnalyzerBenchmarks 7 | { 8 | private static readonly Gu.Roslyn.Asserts.Benchmark Benchmark = Gu.Roslyn.Asserts.Benchmark.Create(Code.AnalyzersProject, new Gu.Analyzers.ParameterAnalyzer()); 9 | 10 | [BenchmarkDotNet.Attributes.Benchmark] 11 | public void RunOnGuAnalyzersProject() 12 | { 13 | Benchmark.Run(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/ParameterAnalyzerBenchmarks.md: -------------------------------------------------------------------------------- 1 | ``` ini 2 | 3 | BenchmarkDotNet=v0.10.13, OS=Windows 7 SP1 (6.1.7601.0) 4 | Intel Xeon CPU E5-2637 v4 3.50GHz, 2 CPU, 16 logical cores and 8 physical cores 5 | Frequency=3410117 Hz, Resolution=293.2451 ns, Timer=TSC 6 | [Host] : .NET Framework 4.7 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.2558.0 7 | DefaultJob : .NET Framework 4.7 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.2558.0 8 | 9 | 10 | ``` 11 | | Method | Mean | Error | StdDev | Median | Gen 0 | Gen 1 | Allocated | 12 | |------------------------ |---------:|----------:|----------:|---------:|--------:|-------:|----------:| 13 | | RunOnGuAnalyzersProject | 5.664 ms | 0.2025 ms | 0.5970 ms | 5.435 ms | 31.2500 | 7.8125 | 219.05 KB | 14 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/PropertyDeclarationAnalyzerBenchmarks.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable RedundantNameQualifier 2 | // ReSharper disable InconsistentNaming 3 | namespace Gu.Analyzers.Benchmarks 4 | { 5 | [BenchmarkDotNet.Attributes.MemoryDiagnoser] 6 | public class PropertyDeclarationAnalyzerBenchmarks 7 | { 8 | private static readonly Gu.Roslyn.Asserts.Benchmark Benchmark = Gu.Roslyn.Asserts.Benchmark.Create(Code.AnalyzersProject, new Gu.Analyzers.PropertyDeclarationAnalyzer()); 9 | 10 | [BenchmarkDotNet.Attributes.Benchmark] 11 | public void RunOnGuAnalyzersProject() 12 | { 13 | Benchmark.Run(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/SimpleAssignmentAnalyzerBenchmarks.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable RedundantNameQualifier 2 | // ReSharper disable InconsistentNaming 3 | namespace Gu.Analyzers.Benchmarks 4 | { 5 | [BenchmarkDotNet.Attributes.MemoryDiagnoser] 6 | public class SimpleAssignmentAnalyzerBenchmarks 7 | { 8 | private static readonly Gu.Roslyn.Asserts.Benchmark Benchmark = Gu.Roslyn.Asserts.Benchmark.Create(Code.AnalyzersProject, new Gu.Analyzers.SimpleAssignmentAnalyzer()); 9 | 10 | [BenchmarkDotNet.Attributes.Benchmark] 11 | public void RunOnGuAnalyzersProject() 12 | { 13 | Benchmark.Run(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/SimpleAssignmentAnalyzerBenchmarks.md: -------------------------------------------------------------------------------- 1 | ``` ini 2 | 3 | BenchmarkDotNet=v0.10.13, OS=Windows 7 SP1 (6.1.7601.0) 4 | Intel Xeon CPU E5-2637 v4 3.50GHz, 2 CPU, 16 logical cores and 8 physical cores 5 | Frequency=3410117 Hz, Resolution=293.2451 ns, Timer=TSC 6 | [Host] : .NET Framework 4.7 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.2558.0 7 | DefaultJob : .NET Framework 4.7 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.2558.0 8 | 9 | 10 | ``` 11 | | Method | Mean | Error | StdDev | Gen 0 | Gen 1 | Allocated | 12 | |------------------------ |---------:|---------:|---------:|-------:|-------:|----------:| 13 | | RunOnGuAnalyzersProject | 740.6 us | 14.79 us | 41.46 us | 2.9297 | 0.9766 | 21.44 KB | 14 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/StringLiteralExpressionAnalyzerBenchmarks.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable RedundantNameQualifier 2 | // ReSharper disable InconsistentNaming 3 | namespace Gu.Analyzers.Benchmarks 4 | { 5 | [BenchmarkDotNet.Attributes.MemoryDiagnoser] 6 | public class StringLiteralExpressionAnalyzerBenchmarks 7 | { 8 | private static readonly Gu.Roslyn.Asserts.Benchmark Benchmark = Gu.Roslyn.Asserts.Benchmark.Create(Code.AnalyzersProject, new Gu.Analyzers.StringLiteralExpressionAnalyzer()); 9 | 10 | [BenchmarkDotNet.Attributes.Benchmark] 11 | public void RunOnGuAnalyzersProject() 12 | { 13 | Benchmark.Run(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/TestMethodAnalyzerBenchmarks.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable RedundantNameQualifier 2 | // ReSharper disable InconsistentNaming 3 | namespace Gu.Analyzers.Benchmarks 4 | { 5 | [BenchmarkDotNet.Attributes.MemoryDiagnoser] 6 | public class TestMethodAnalyzerBenchmarks 7 | { 8 | private static readonly Gu.Roslyn.Asserts.Benchmark Benchmark = Gu.Roslyn.Asserts.Benchmark.Create(Code.AnalyzersProject, new Gu.Analyzers.TestMethodAnalyzer()); 9 | 10 | [BenchmarkDotNet.Attributes.Benchmark] 11 | public void RunOnGuAnalyzersProject() 12 | { 13 | Benchmark.Run(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/VariableDeclaratorAnalyzerBenchmarks.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable RedundantNameQualifier 2 | // ReSharper disable InconsistentNaming 3 | namespace Gu.Analyzers.Benchmarks 4 | { 5 | [BenchmarkDotNet.Attributes.MemoryDiagnoser] 6 | public class VariableDeclaratorAnalyzerBenchmarks 7 | { 8 | private static readonly Gu.Roslyn.Asserts.Benchmark Benchmark = Gu.Roslyn.Asserts.Benchmark.Create(Code.AnalyzersProject, new Gu.Analyzers.VariableDeclaratorAnalyzer()); 9 | 10 | [BenchmarkDotNet.Attributes.Benchmark] 11 | public void RunOnGuAnalyzersProject() 12 | { 13 | Benchmark.Run(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Benchmarks/WhenAnalyzerBenchmarks.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable RedundantNameQualifier 2 | // ReSharper disable InconsistentNaming 3 | namespace Gu.Analyzers.Benchmarks 4 | { 5 | [BenchmarkDotNet.Attributes.MemoryDiagnoser] 6 | public class WhenAnalyzerBenchmarks 7 | { 8 | private static readonly Gu.Roslyn.Asserts.Benchmark Benchmark = Gu.Roslyn.Asserts.Benchmark.Create(Code.AnalyzersProject, new Gu.Analyzers.WhenAnalyzer()); 9 | 10 | [BenchmarkDotNet.Attributes.Benchmark] 11 | public void RunOnGuAnalyzersProject() 12 | { 13 | Benchmark.Run(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Gu.Analyzers.Benchmarks.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | net6.0 4 | Exe 5 | latest 6 | Enable 7 | 8 | 9 | 10 | True 11 | AllEnabledByDefault 12 | latest 13 | 14 | 15 | 16 | true 17 | ..\Gu.Analyzers.snk 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Gu.Analyzers.Benchmarks/Gu.Analyzers.Benchmarks.csproj.DotSettings: -------------------------------------------------------------------------------- 1 |  2 | True 3 | True -------------------------------------------------------------------------------- /Gu.Analyzers.Test/.editorconfig: -------------------------------------------------------------------------------- 1 | [*.cs] 2 | 3 | # Default severity for analyzer diagnostics with category 'StyleCop.CSharp.DocumentationRules' 4 | dotnet_analyzer_diagnostic.category-StyleCop.CSharp.DocumentationRules.severity = none 5 | 6 | # SA0001: XML comment analysis is disabled due to project configuration 7 | dotnet_diagnostic.SA0001.severity = none 8 | 9 | # SA1203: Constant fields should appear before non-constant fields 10 | dotnet_diagnostic.SA1203.severity = none 11 | 12 | # CA1034: Do not nest type CodeFile. Alternatively, change its accessibility so that it is not externally visible. 13 | dotnet_diagnostic.CA1034.severity = none 14 | 15 | # CA1062: In externally visible method 'void DocumentationTests.Description(DescriptorInfo descriptorInfo)', validate parameter 'descriptorInfo' is non-null before using it. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument. 16 | dotnet_diagnostic.CA1062.severity = none 17 | 18 | # CA1720: Identifier 'String' contains type name 19 | dotnet_diagnostic.CA1720.severity = none 20 | 21 | 22 | 23 | # RS1029: Do not use reserved diagnostic IDs. 24 | dotnet_diagnostic.RS1029.severity = none 25 | 26 | # RS2008: Enable analyzer release tracking 27 | dotnet_diagnostic.RS2008.severity = none 28 | -------------------------------------------------------------------------------- /Gu.Analyzers.Test/AnalyzerExt.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers.Test; 2 | 3 | using System; 4 | using System.Collections.Immutable; 5 | using System.Linq; 6 | using System.Reflection; 7 | using Microsoft.CodeAnalysis; 8 | using Microsoft.CodeAnalysis.Diagnostics; 9 | 10 | public static class AnalyzerExt 11 | { 12 | public static T DefaultEnabled(this T analyzer) 13 | where T : DiagnosticAnalyzer 14 | { 15 | var field = analyzer.GetType() 16 | .GetField("k__BackingField", BindingFlags.Instance | BindingFlags.NonPublic) ?? 17 | throw new InvalidOperationException("did not find field"); 18 | field.SetValue(analyzer, EnabledDiagnostics(analyzer.SupportedDiagnostics)); 19 | return analyzer; 20 | 21 | static ImmutableArray EnabledDiagnostics(ImmutableArray source) 22 | { 23 | var builder = ImmutableArray.CreateBuilder(source.Length); 24 | foreach (var diagnostic in source) 25 | { 26 | builder.Add( 27 | new DiagnosticDescriptor( 28 | diagnostic.Id, 29 | diagnostic.Title, 30 | diagnostic.MessageFormat, 31 | diagnostic.Category, 32 | diagnostic.DefaultSeverity, 33 | isEnabledByDefault: true, 34 | diagnostic.Description, 35 | diagnostic.HelpLinkUri, 36 | diagnostic.CustomTags?.ToArray() ?? Array.Empty())); 37 | } 38 | 39 | return builder.MoveToImmutable(); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Gu.Analyzers.Test/AssemblyAttributes.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | [assembly: CLSCompliant(false)] 4 | -------------------------------------------------------------------------------- /Gu.Analyzers.Test/CodeFixes/GenerateUselessDocsFixTests/CodeFixWhenMissingParameterDocsSA1611.SpecialType.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers.Test.CodeFixes.GenerateUselessDocsFixTests; 2 | 3 | using Gu.Roslyn.Asserts; 4 | using NUnit.Framework; 5 | 6 | internal static partial class CodeFixWhenMissingParameterDocsSA1611 7 | { 8 | internal static class SpecialType 9 | { 10 | [Test] 11 | public static void StandardTextForCancellationToken() 12 | { 13 | var before = @" 14 | namespace N 15 | { 16 | using System.Threading; 17 | 18 | public class C 19 | { 20 | /// 21 | /// Does nothing 22 | /// 23 | public void M(CancellationToken ↓cancellationToken) 24 | { 25 | } 26 | } 27 | }"; 28 | 29 | var after = @" 30 | namespace N 31 | { 32 | using System.Threading; 33 | 34 | public class C 35 | { 36 | /// 37 | /// Does nothing 38 | /// 39 | /// The that cancels the operation. 40 | public void M(CancellationToken cancellationToken) 41 | { 42 | } 43 | } 44 | }"; 45 | RoslynAssert.CodeFix(Analyzer, Fix, before, after, fixTitle: "Generate standard xml documentation for parameter."); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Gu.Analyzers.Test/GU0001NameArgumentsTests/NoFix.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers.Test.GU0001NameArgumentsTests; 2 | 3 | using Gu.Roslyn.Asserts; 4 | using NUnit.Framework; 5 | 6 | internal static class NoFix 7 | { 8 | private static readonly ArgumentListAnalyzer Analyzer = new(); 9 | private static readonly NameArgumentsFix Fix = new(); 10 | private static readonly ExpectedDiagnostic ExpectedDiagnostic = ExpectedDiagnostic.Create(Descriptors.GU0001NameArguments); 11 | 12 | [Test] 13 | public static void ConstructorIgnoredIfAnyNamed() 14 | { 15 | var testCode = """ 16 | namespace N 17 | { 18 | public class Foo 19 | { 20 | public Foo(int a, int b, int c, int d) 21 | { 22 | this.A = a; 23 | this.B = b; 24 | this.C = c; 25 | this.D = d; 26 | } 27 | 28 | public int A { get; } 29 | 30 | public int B { get; } 31 | 32 | public int C { get; } 33 | 34 | public int D { get; } 35 | 36 | private Foo Create(int a, int b, int c, int d) 37 | { 38 | return new Foo↓( 39 | a, 40 | b, 41 | c, 42 | d: d); 43 | } 44 | } 45 | } 46 | """; 47 | RoslynAssert.NoFix(Analyzer, Fix, ExpectedDiagnostic, testCode); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Gu.Analyzers.Test/GU0002NamedArgumentPositionMatchesTests/NoFix.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers.Test.GU0002NamedArgumentPositionMatchesTests; 2 | 3 | using Gu.Roslyn.Asserts; 4 | using NUnit.Framework; 5 | 6 | internal static class NoFix 7 | { 8 | private static readonly ArgumentListAnalyzer Analyzer = new(); 9 | private static readonly MoveArgumentFix Fix = new(); 10 | private static readonly ExpectedDiagnostic ExpectedDiagnostic = ExpectedDiagnostic.Create(Descriptors.GU0002NamedArgumentPositionMatches); 11 | 12 | [Test] 13 | public static void ConstructorIgnoredIfNonWhitespaceTrivia() 14 | { 15 | var testCode = @" 16 | namespace N 17 | { 18 | public class Foo 19 | { 20 | public Foo(int a, int b, int c, int d) 21 | { 22 | this.A = a; 23 | this.B = b; 24 | this.C = c; 25 | this.D = d; 26 | } 27 | 28 | public int A { get; } 29 | 30 | public int B { get; } 31 | 32 | public int C { get; } 33 | 34 | public int D { get; } 35 | 36 | private Foo Create(int a, int b, int c, int d) 37 | { 38 | return new Foo↓( 39 | b: b, // some comment 40 | a: a, 41 | c: c, 42 | d: d); 43 | } 44 | } 45 | }"; 46 | RoslynAssert.NoFix(Analyzer, Fix, ExpectedDiagnostic, testCode); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Gu.Analyzers.Test/GU0005ExceptionArgumentsPositionsTests/Valid.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers.Test.GU0005ExceptionArgumentsPositionsTests; 2 | 3 | using Gu.Roslyn.Asserts; 4 | using NUnit.Framework; 5 | 6 | internal static class Valid 7 | { 8 | private static readonly ObjectCreationAnalyzer Analyzer = new(); 9 | 10 | [Test] 11 | public static void ArgumentExceptionWithMessageAndNameof() 12 | { 13 | var code = @" 14 | namespace N 15 | { 16 | using System; 17 | 18 | public class C 19 | { 20 | public C(object o) 21 | { 22 | throw new ArgumentException(""message"", nameof(o)); 23 | } 24 | } 25 | }"; 26 | RoslynAssert.Valid(Analyzer, code); 27 | } 28 | 29 | [Test] 30 | public static void ArgumentNullExceptionWithMessageAndNameof() 31 | { 32 | var code = @" 33 | namespace N 34 | { 35 | using System; 36 | 37 | public class C 38 | { 39 | public C(object o) 40 | { 41 | throw new ArgumentNullException(nameof(o), ""message""); 42 | } 43 | } 44 | }"; 45 | RoslynAssert.Valid(Analyzer, code); 46 | } 47 | 48 | [Test] 49 | public static void ArgumentOutOfRangeExceptionWithMessageAndNameof() 50 | { 51 | var code = @" 52 | namespace N 53 | { 54 | using System; 55 | 56 | public class C 57 | { 58 | public C(object o) 59 | { 60 | throw new ArgumentOutOfRangeException(nameof(o), ""message""); 61 | } 62 | } 63 | }"; 64 | RoslynAssert.Valid(Analyzer, code); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /Gu.Analyzers.Test/GU0007PreferInjectingTests/CodeFix.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers.Test.GU0007PreferInjectingTests; 2 | 3 | using Gu.Roslyn.Asserts; 4 | 5 | internal static partial class CodeFix 6 | { 7 | private static readonly GU0007PreferInjecting Analyzer = new GU0007PreferInjecting().DefaultEnabled(); 8 | private static readonly InjectFix Fix = new(); 9 | private static readonly ExpectedDiagnostic ExpectedDiagnostic = ExpectedDiagnostic.Create(Descriptors.GU0007PreferInjecting); 10 | } 11 | -------------------------------------------------------------------------------- /Gu.Analyzers.Test/GU0010DoNotAssignSameValueTests/Diagnostics.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers.Test.GU0010DoNotAssignSameValueTests; 2 | 3 | using Gu.Roslyn.Asserts; 4 | using NUnit.Framework; 5 | 6 | internal static class Diagnostics 7 | { 8 | private static readonly SimpleAssignmentAnalyzer Analyzer = new(); 9 | private static readonly ExpectedDiagnostic ExpectedDiagnostic = ExpectedDiagnostic.Create(Descriptors.GU0010DoNotAssignSameValue); 10 | 11 | [TestCase("this.A = this.A;")] 12 | [TestCase("this.A = A;")] 13 | [TestCase("A = A;")] 14 | [TestCase("A = this.A;")] 15 | public static void AssignToToSelf(string statement) 16 | { 17 | var code = """ 18 | namespace N 19 | { 20 | public class C 21 | { 22 | public int A { get; private set; } 23 | 24 | private void M() 25 | { 26 | ↓this.A = this.A; 27 | } 28 | } 29 | } 30 | """.AssertReplace("this.A = this.A;", statement); 31 | 32 | RoslynAssert.Diagnostics(Analyzer, ExpectedDiagnostic.WithMessage("Assigning made to same, did you mean to assign something else?"), code); 33 | } 34 | 35 | [Test] 36 | public static void SetPropertyToSelfWithThis() 37 | { 38 | var code = """ 39 | namespace N 40 | { 41 | public class C 42 | { 43 | public int A { get; private set; } 44 | 45 | private void M() 46 | { 47 | ↓this.A = this.A; 48 | } 49 | } 50 | } 51 | """; 52 | 53 | RoslynAssert.Diagnostics(Analyzer, ExpectedDiagnostic, code); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Gu.Analyzers.Test/GU0012NullCheckParameterTests/FixAll.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers.Test.GU0012NullCheckParameterTests; 2 | 3 | using Gu.Roslyn.Asserts; 4 | using NUnit.Framework; 5 | 6 | internal static partial class CodeFix 7 | { 8 | internal static class FixAll 9 | { 10 | private static readonly ParameterAnalyzer Analyzer = new(); 11 | private static readonly NullCheckParameterFix Fix = new(); 12 | private static readonly ExpectedDiagnostic ExpectedDiagnostic = ExpectedDiagnostic.Create(Descriptors.GU0012NullCheckParameter); 13 | 14 | [Test] 15 | public static void TwoParameters() 16 | { 17 | var before = @" 18 | namespace N 19 | { 20 | public sealed class C 21 | { 22 | public C(string ↓s1, string ↓s2) 23 | { 24 | } 25 | } 26 | }"; 27 | 28 | var after = @" 29 | namespace N 30 | { 31 | public sealed class C 32 | { 33 | public C(string s1, string s2) 34 | { 35 | if (s1 is null) 36 | { 37 | throw new System.ArgumentNullException(nameof(s1)); 38 | } 39 | 40 | if (s2 is null) 41 | { 42 | throw new System.ArgumentNullException(nameof(s2)); 43 | } 44 | } 45 | } 46 | }"; 47 | RoslynAssert.FixAll(Analyzer, Fix, ExpectedDiagnostic, before, after); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Gu.Analyzers.Test/GU0013CheckNameInThrowTests/Valid.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers.Test.GU0013CheckNameInThrowTests; 2 | 3 | using Gu.Roslyn.Asserts; 4 | using NUnit.Framework; 5 | 6 | internal static class Valid 7 | { 8 | private static readonly ObjectCreationAnalyzer Analyzer = new(); 9 | 10 | [Test] 11 | public static void WhenPrivate() 12 | { 13 | var code = @" 14 | namespace N 15 | { 16 | public class C 17 | { 18 | private readonly string text; 19 | 20 | private C(string text) 21 | { 22 | this.text = text; 23 | } 24 | } 25 | }"; 26 | RoslynAssert.Valid(Analyzer, code); 27 | } 28 | 29 | [Test] 30 | public static void WhenDefaultValue() 31 | { 32 | var code = @" 33 | namespace N 34 | { 35 | public class C 36 | { 37 | private readonly string? text; 38 | 39 | public C(string? text = null) 40 | { 41 | this.text = text; 42 | } 43 | } 44 | }"; 45 | RoslynAssert.Valid(Analyzer, code); 46 | } 47 | 48 | [Test] 49 | public static void WhenValueType() 50 | { 51 | var code = @" 52 | namespace N 53 | { 54 | public class C 55 | { 56 | private readonly int i; 57 | 58 | public C(int i) 59 | { 60 | this.i = i; 61 | } 62 | } 63 | }"; 64 | RoslynAssert.Valid(Analyzer, code); 65 | } 66 | 67 | [Test] 68 | public static void WhenThrowing() 69 | { 70 | var code = @" 71 | namespace N 72 | { 73 | using System; 74 | 75 | public class C 76 | { 77 | private readonly string text; 78 | 79 | public C(string text) 80 | { 81 | this.text = text ?? throw new ArgumentNullException(nameof(text)); 82 | } 83 | } 84 | }"; 85 | RoslynAssert.Valid(Analyzer, code); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /Gu.Analyzers.Test/GU0016PreferLambdaTests/Valid.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers.Test.GU0016PreferLambdaTests; 2 | 3 | using Gu.Roslyn.Asserts; 4 | using NUnit.Framework; 5 | 6 | internal static class Valid 7 | { 8 | private static readonly MethodGroupAnalyzer Analyzer = new(); 9 | 10 | [Test] 11 | public static void LinqWhereStaticMethod() 12 | { 13 | var code = @" 14 | namespace N 15 | { 16 | using System.Collections.Generic; 17 | using System.Linq; 18 | 19 | public class C 20 | { 21 | public C(IEnumerable ints) 22 | { 23 | var meh = ints.Where(x => IsEven(x)); 24 | } 25 | 26 | private static bool IsEven(int x) => x % 2 == 0; 27 | } 28 | }"; 29 | 30 | RoslynAssert.Valid(Analyzer, code); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Gu.Analyzers.Test/GU0019LinqOrDefaultStructs/Diagnostics.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers.Test.GU0019LinqOrDefaultStructs; 2 | 3 | using Gu.Roslyn.Asserts; 4 | using NUnit.Framework; 5 | 6 | internal static class Diagnostics 7 | { 8 | private static readonly InvocationAnalyzer Analyzer = new(); 9 | private static readonly ExpectedDiagnostic ExpectedDiagnostic = ExpectedDiagnostic.Create(Descriptors.GU0019LinqOrDefaultStructs); 10 | 11 | [Test] 12 | public static void Message() 13 | { 14 | var code = @" 15 | namespace N; 16 | 17 | using System.Collections.Generic; 18 | using System.Linq; 19 | 20 | public class C 21 | { 22 | public object M(IEnumerable xs) => ↓xs.FirstOrDefault(); 23 | }"; 24 | RoslynAssert.Diagnostics(Analyzer, ExpectedDiagnostic.WithMessage("The call never returns null"), code); 25 | } 26 | 27 | [TestCase("xs.FirstOrDefault()")] 28 | [TestCase("xs.FirstOrDefault(x => x > 1)")] 29 | [TestCase("xs.LastOrDefault()")] 30 | [TestCase("xs.SingleOrDefault()")] 31 | public static void Call(string expression) 32 | { 33 | var code = @" 34 | namespace N; 35 | 36 | using System.Collections.Generic; 37 | using System.Linq; 38 | 39 | public class C 40 | { 41 | public object M(IEnumerable xs) => ↓xs.FirstOrDefault(); 42 | }".AssertReplace("xs.FirstOrDefault()", expression); 43 | RoslynAssert.Diagnostics(Analyzer, ExpectedDiagnostic, code); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Gu.Analyzers.Test/GU0019LinqOrDefaultStructs/Valid.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers.Test.GU0019LinqOrDefaultStructs; 2 | 3 | using Gu.Roslyn.Asserts; 4 | 5 | using NUnit.Framework; 6 | 7 | internal static class Valid 8 | { 9 | private static readonly InvocationAnalyzer Analyzer = new(); 10 | 11 | [TestCase("IEnumerable", "xs.FirstOrDefault()")] 12 | [TestCase("IEnumerable", "xs.FirstOrDefault()")] 13 | [TestCase("IEnumerable", "xs.First()")] 14 | public static void Call(string type, string expression) 15 | { 16 | var code = @" 17 | namespace N; 18 | 19 | using System.Collections.Generic; 20 | using System.Linq; 21 | 22 | public class C 23 | { 24 | public object? M(IEnumerable xs) => xs.FirstOrDefault(); 25 | }".AssertReplace("IEnumerable", type) 26 | .AssertReplace("xs.FirstOrDefault()", expression); 27 | RoslynAssert.Valid(Analyzer, code); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Gu.Analyzers.Test/GU0024SealTypeWithDefaultMemberTests/CodeFix.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers.Test.GU0024SealTypeWithDefaultMemberTests; 2 | 3 | using Gu.Roslyn.Asserts; 4 | using NUnit.Framework; 5 | 6 | internal static class CodeFix 7 | { 8 | private static readonly ClassDeclarationAnalyzer Analyzer = new(); 9 | private static readonly ExpectedDiagnostic ExpectedDiagnostic = ExpectedDiagnostic.Create(Descriptors.GU0024SealTypeWithDefaultMember); 10 | private static readonly MakeSealedFix Fix = new(); 11 | 12 | [Test] 13 | public static void Field() 14 | { 15 | var before = @" 16 | namespace N 17 | { 18 | public class ↓C 19 | { 20 | public static readonly C Default = new C(); 21 | } 22 | }"; 23 | 24 | var after = @" 25 | namespace N 26 | { 27 | public sealed class C 28 | { 29 | public static readonly C Default = new C(); 30 | } 31 | }"; 32 | RoslynAssert.CodeFix(Analyzer, Fix, ExpectedDiagnostic, before, after, fixTitle: "Make sealed."); 33 | } 34 | 35 | [Test] 36 | public static void Property() 37 | { 38 | var before = @" 39 | namespace N 40 | { 41 | public class ↓C 42 | { 43 | public static C Default { get; } = new C(); 44 | } 45 | }"; 46 | 47 | var after = @" 48 | namespace N 49 | { 50 | public sealed class C 51 | { 52 | public static C Default { get; } = new C(); 53 | } 54 | }"; 55 | RoslynAssert.CodeFix(Analyzer, Fix, ExpectedDiagnostic, before, after, fixTitle: "Make sealed."); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Gu.Analyzers.Test/GU0024SealTypeWithDefaultMemberTests/Valid.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers.Test.GU0024SealTypeWithDefaultMemberTests; 2 | 3 | using Gu.Roslyn.Asserts; 4 | using NUnit.Framework; 5 | 6 | internal static class Valid 7 | { 8 | private static readonly ClassDeclarationAnalyzer Analyzer = new(); 9 | 10 | [Test] 11 | public static void WhenSealedWithProperty() 12 | { 13 | var code = @" 14 | namespace N 15 | { 16 | public sealed class C 17 | { 18 | public static C Default { get; } = new C(); 19 | } 20 | }"; 21 | RoslynAssert.Valid(Analyzer, code); 22 | } 23 | 24 | [Test] 25 | public static void WhenSealedWithField() 26 | { 27 | var code = @" 28 | namespace N 29 | { 30 | public sealed class C 31 | { 32 | public static readonly C Default = new C(); 33 | } 34 | }"; 35 | RoslynAssert.Valid(Analyzer, code); 36 | } 37 | 38 | [Test] 39 | public static void WhenNoDefaultField() 40 | { 41 | var code = @" 42 | namespace N 43 | { 44 | public class C 45 | { 46 | } 47 | }"; 48 | RoslynAssert.Valid(Analyzer, code); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Gu.Analyzers.Test/GU0025SealTypeWithOverridenEqualityTests/Valid.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers.Test.GU0025SealTypeWithOverridenEqualityTests; 2 | 3 | using Gu.Roslyn.Asserts; 4 | using NUnit.Framework; 5 | 6 | internal static class Valid 7 | { 8 | private static readonly ClassDeclarationAnalyzer Analyzer = new(); 9 | 10 | [Test] 11 | public static void WhenSealed() 12 | { 13 | var code = @" 14 | namespace N 15 | { 16 | public sealed class C 17 | { 18 | public int P { get; } 19 | 20 | public static bool operator ==(C left, C right) 21 | { 22 | return Equals(left, right); 23 | } 24 | 25 | public static bool operator !=(C left, C right) 26 | { 27 | return !Equals(left, right); 28 | } 29 | 30 | public override bool Equals(object? obj) => obj is C other && this.Equals(other); 31 | 32 | public override int GetHashCode() => this.P; 33 | 34 | private bool Equals(C other) => this.P == other.P; 35 | } 36 | }"; 37 | RoslynAssert.Valid(Analyzer, code); 38 | } 39 | 40 | [Test] 41 | public static void WhenNotOverridden() 42 | { 43 | var code = @" 44 | namespace N 45 | { 46 | public class C 47 | { 48 | } 49 | }"; 50 | RoslynAssert.Valid(Analyzer, code); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Gu.Analyzers.Test/GU0026RangeAllocation/Valid.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers.Test.GU0026RangeAllocation; 2 | 3 | using Gu.Roslyn.Asserts; 4 | using NUnit.Framework; 5 | 6 | internal static class Valid 7 | { 8 | private static readonly RangeAnalyzer Analyzer = new(); 9 | 10 | [Test] 11 | public static void Span() 12 | { 13 | var code = @" 14 | namespace N; 15 | 16 | using System; 17 | 18 | class C 19 | { 20 | public ReadOnlySpan M(ReadOnlySpan xs) => xs[1..]; 21 | }"; 22 | RoslynAssert.Valid(Analyzer, code); 23 | } 24 | 25 | [Test] 26 | public static void Index() 27 | { 28 | var code = @" 29 | namespace N; 30 | 31 | class C 32 | { 33 | public int M(int[] xs) => xs[1]; 34 | }"; 35 | RoslynAssert.Valid(Analyzer, code); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Gu.Analyzers.Test/GU0052ExceptionShouldBeSerializableTests/Diagnostics.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers.Test.GU0052ExceptionShouldBeSerializableTests; 2 | 3 | using Gu.Roslyn.Asserts; 4 | using NUnit.Framework; 5 | 6 | internal static class Diagnostics 7 | { 8 | private static readonly GU0052ExceptionShouldBeSerializable Analyzer = new(); 9 | private static readonly ExpectedDiagnostic ExpectedDiagnostic = ExpectedDiagnostic.Create(Descriptors.GU0052ExceptionShouldBeSerializable); 10 | 11 | [Test] 12 | public static void WhenNoAttribute() 13 | { 14 | var code = @" 15 | namespace N 16 | { 17 | using System; 18 | 19 | public class ↓FooException : Exception 20 | { 21 | public FooException() 22 | : base(string.Empty) 23 | { 24 | } 25 | } 26 | }"; 27 | RoslynAssert.Diagnostics(Analyzer, ExpectedDiagnostic, code); 28 | } 29 | 30 | [Test] 31 | public static void ExtendedNoAttribute() 32 | { 33 | var code = @" 34 | namespace N 35 | { 36 | using System; 37 | 38 | [Serializable] 39 | public class FooException : Exception 40 | { 41 | public FooException(string text) 42 | : base(text) 43 | { 44 | } 45 | } 46 | 47 | public class ↓BarException : FooException 48 | { 49 | public BarException() 50 | : base(string.Empty) 51 | { 52 | } 53 | } 54 | }"; 55 | RoslynAssert.Diagnostics(Analyzer, ExpectedDiagnostic, code); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Gu.Analyzers.Test/GU0061EnumMemberValueOutOfRangeTests/Diagnostics.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers.Test.GU0061EnumMemberValueOutOfRangeTests; 2 | 3 | using Gu.Roslyn.Asserts; 4 | using NUnit.Framework; 5 | 6 | internal static class Diagnostics 7 | { 8 | private static readonly GU0061EnumMemberValueOutOfRange Analyzer = new(); 9 | private static readonly ExpectedDiagnostic ExpectedDiagnostic = ExpectedDiagnostic.Create(Descriptors.GU0061EnumMemberValueOutOfRange); 10 | 11 | [Test] 12 | public static void BitShiftOutOfRange() 13 | { 14 | var code = @" 15 | namespace N 16 | { 17 | public enum EnumHigh 18 | { 19 | None = 0, 20 | A = 1<<1, 21 | B = 1<<2, 22 | Bad = ↓1<<31 23 | } 24 | }"; 25 | RoslynAssert.Diagnostics(Analyzer, ExpectedDiagnostic, code); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Gu.Analyzers.Test/GU0061EnumMemberValueOutOfRangeTests/Valid.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers.Test.GU0061EnumMemberValueOutOfRangeTests; 2 | 3 | using Gu.Roslyn.Asserts; 4 | using NUnit.Framework; 5 | 6 | internal static class Valid 7 | { 8 | private static readonly GU0061EnumMemberValueOutOfRange Analyzer = new(); 9 | 10 | [Test] 11 | public static void BitShiftWithinRange() 12 | { 13 | var code = @" 14 | namespace N 15 | { 16 | public enum EnumHigh 17 | { 18 | None = 0, 19 | A = 1<<1, 20 | B = 1<<2, 21 | Good = 1<<30 22 | } 23 | }"; 24 | RoslynAssert.Valid(Analyzer, code); 25 | } 26 | 27 | [Test] 28 | public static void DoNotAnalyzeLong() 29 | { 30 | var code = @" 31 | namespace N 32 | { 33 | public enum EnumHigh: long 34 | { 35 | None = 0, 36 | A = 1<<1, 37 | B = 1<<2, 38 | Bad = 1<<31 39 | } 40 | }"; 41 | RoslynAssert.Valid(Analyzer, code); 42 | } 43 | 44 | [Test] 45 | public static void StandardEnum() 46 | { 47 | var code = @" 48 | namespace N 49 | { 50 | public enum StandardEnum 51 | { 52 | None = 0, 53 | A, 54 | B, 55 | C, 56 | } 57 | }"; 58 | RoslynAssert.Valid(Analyzer, code); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Gu.Analyzers.Test/GU0070DefaultConstructedValueTypeWithNoUsefulDefaultTests/Diagnostics.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers.Test.GU0070DefaultConstructedValueTypeWithNoUsefulDefaultTests; 2 | 3 | using Gu.Roslyn.Asserts; 4 | using NUnit.Framework; 5 | 6 | internal static class Diagnostics 7 | { 8 | private static readonly GU0070DefaultConstructedValueTypeWithNoUsefulDefault Analyzer = new(); 9 | private static readonly ExpectedDiagnostic ExpectedDiagnostic = ExpectedDiagnostic.Create(Descriptors.GU0070DefaultConstructedValueTypeWithNoUsefulDefault); 10 | 11 | [TestCase("new Guid()")] 12 | [TestCase("new DateTime()")] 13 | public static void When(string expression) 14 | { 15 | var code = @" 16 | namespace N 17 | { 18 | using System; 19 | 20 | public class C 21 | { 22 | public C() 23 | { 24 | #pragma warning disable CS0219 25 | var unused = ↓new Guid(); 26 | } 27 | } 28 | }".AssertReplace("new Guid()", expression); 29 | RoslynAssert.Diagnostics(Analyzer, ExpectedDiagnostic, code); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Gu.Analyzers.Test/GU0070DefaultConstructedValueTypeWithNoUsefulDefaultTests/Valid.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers.Test.GU0070DefaultConstructedValueTypeWithNoUsefulDefaultTests; 2 | 3 | using Gu.Roslyn.Asserts; 4 | using NUnit.Framework; 5 | 6 | internal static class Valid 7 | { 8 | private static readonly GU0070DefaultConstructedValueTypeWithNoUsefulDefault Analyzer = new(); 9 | 10 | [TestCase("default(Guid)")] 11 | [TestCase("Guid.NewGuid()")] 12 | [TestCase("DateTime.Now")] 13 | public static void When(string expression) 14 | { 15 | var code = @" 16 | namespace N 17 | { 18 | using System; 19 | 20 | public class C 21 | { 22 | public C() 23 | { 24 | #pragma warning disable CS0219 25 | var unused = default(Guid); 26 | } 27 | } 28 | }".AssertReplace("default(Guid)", expression); 29 | 30 | RoslynAssert.Valid(Analyzer, code); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Gu.Analyzers.Test/GU0072AllTypesShouldBeInternalTests/CodeFix.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers.Test.GU0072AllTypesShouldBeInternalTests; 2 | 3 | using Gu.Roslyn.Asserts; 4 | using NUnit.Framework; 5 | 6 | internal static class CodeFix 7 | { 8 | private static readonly GU0072AllTypesShouldBeInternal Analyzer = new GU0072AllTypesShouldBeInternal().DefaultEnabled(); 9 | private static readonly MakeInternalFix Fix = new(); 10 | private static readonly ExpectedDiagnostic ExpectedDiagnostic = ExpectedDiagnostic.Create(Descriptors.GU0072AllTypesShouldBeInternal); 11 | 12 | [Test] 13 | public static void Class() 14 | { 15 | var before = """ 16 | namespace N; 17 | ↓public class C 18 | { 19 | } 20 | """; 21 | 22 | var after = """ 23 | namespace N; 24 | internal class C 25 | { 26 | } 27 | """; 28 | RoslynAssert.CodeFix(Analyzer, Fix, ExpectedDiagnostic, before, after); 29 | } 30 | 31 | [Test] 32 | public static void Struct() 33 | { 34 | var before = """ 35 | namespace N; 36 | ↓public struct S 37 | { 38 | } 39 | """; 40 | 41 | var after = """ 42 | namespace N; 43 | internal struct S 44 | { 45 | } 46 | """; 47 | RoslynAssert.CodeFix(Analyzer, Fix, ExpectedDiagnostic, before, after); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Gu.Analyzers.Test/GU0072AllTypesShouldBeInternalTests/Valid.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers.Test.GU0072AllTypesShouldBeInternalTests; 2 | 3 | using Gu.Roslyn.Asserts; 4 | using NUnit.Framework; 5 | 6 | internal static class Valid 7 | { 8 | private static readonly GU0072AllTypesShouldBeInternal Analyzer = new(); 9 | 10 | [TestCase("internal class C")] 11 | [TestCase("internal struct S")] 12 | public static void SimpleType(string signature) 13 | { 14 | var code = @" 15 | namespace N 16 | { 17 | internal class C 18 | { 19 | } 20 | }".AssertReplace("internal class C", signature); 21 | 22 | RoslynAssert.Valid(Analyzer, code); 23 | } 24 | 25 | [TestCase("internal class C2")] 26 | [TestCase("protected class C2")] 27 | [TestCase("private class C2")] 28 | [TestCase("internal struct S")] 29 | [TestCase("protected struct S")] 30 | [TestCase("private struct S")] 31 | public static void NestedType(string signature) 32 | { 33 | var code = @" 34 | namespace N 35 | { 36 | internal class C1 37 | { 38 | private class C2 39 | { 40 | } 41 | } 42 | }".AssertReplace("private class C2", signature); 43 | 44 | RoslynAssert.Valid(Analyzer, code); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Gu.Analyzers.Test/GU0077PreferIsNullTests/CodeFix.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers.Test.GU0077PreferIsNullTests; 2 | 3 | using Gu.Roslyn.Asserts; 4 | using NUnit.Framework; 5 | 6 | public static class CodeFix 7 | { 8 | private static readonly BinaryExpressionAnalyzer Analyzer = new(); 9 | private static readonly IsNullFix Fix = new(); 10 | private static readonly ExpectedDiagnostic ExpectedDiagnostic = ExpectedDiagnostic.Create(Descriptors.GU0077PreferIsNull); 11 | 12 | [Test] 13 | public static void IfNullThrow() 14 | { 15 | var before = @" 16 | namespace N 17 | { 18 | class C 19 | { 20 | C(string s) 21 | { 22 | if (↓s == null) 23 | { 24 | throw new System.ArgumentNullException(nameof(s)); 25 | } 26 | } 27 | } 28 | }"; 29 | 30 | var after = @" 31 | namespace N 32 | { 33 | class C 34 | { 35 | C(string s) 36 | { 37 | if (s is null) 38 | { 39 | throw new System.ArgumentNullException(nameof(s)); 40 | } 41 | } 42 | } 43 | }"; 44 | RoslynAssert.CodeFix(Analyzer, Fix, ExpectedDiagnostic, before, after); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Gu.Analyzers.Test/GU0081TestCasesAttributeMismatchTests/Diagnostics.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers.Test.GU0081TestCasesAttributeMismatchTests; 2 | 3 | using Gu.Roslyn.Asserts; 4 | using NUnit.Framework; 5 | 6 | internal static class Diagnostics 7 | { 8 | private static readonly TestMethodAnalyzer Analyzer = new(); 9 | private static readonly ExpectedDiagnostic ExpectedDiagnostic = ExpectedDiagnostic.Create(Descriptors.GU0081TestCasesAttributeMismatch); 10 | 11 | [Test] 12 | public static void TestCaseAttributeAndParameter() 13 | { 14 | var code = @" 15 | namespace N 16 | { 17 | using NUnit.Framework; 18 | 19 | public class C 20 | { 21 | [TestCase(1)] 22 | [↓TestCase(1, 2)] 23 | public void M(int i) 24 | { 25 | } 26 | } 27 | }"; 28 | RoslynAssert.Diagnostics(Analyzer, ExpectedDiagnostic, code); 29 | } 30 | 31 | [Test] 32 | public static void TestCaseAttributeWithAuthor() 33 | { 34 | var code = @" 35 | namespace N 36 | { 37 | using NUnit.Framework; 38 | 39 | public class C 40 | { 41 | [TestCase(1, Author = ""Author"")] 42 | [↓TestCase(1, 2, Author = ""Author"")] 43 | public void M(int i) 44 | { 45 | } 46 | } 47 | }"; 48 | RoslynAssert.Diagnostics(Analyzer, ExpectedDiagnostic, code); 49 | } 50 | 51 | [Test] 52 | public static void TestCaseParams() 53 | { 54 | var code = @" 55 | namespace N 56 | { 57 | using NUnit.Framework; 58 | 59 | class C 60 | { 61 | [TestCase(1, 2, 3)] 62 | [↓TestCase(1)] 63 | public void M(int i, int j, params int[] ints) 64 | { 65 | } 66 | } 67 | }"; 68 | RoslynAssert.Diagnostics(Analyzer, ExpectedDiagnostic, code); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /Gu.Analyzers.Test/GU0081TestCasesAttributeMismatchTests/Valid.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers.Test.GU0081TestCasesAttributeMismatchTests; 2 | 3 | using Gu.Roslyn.Asserts; 4 | using NUnit.Framework; 5 | 6 | internal static class Valid 7 | { 8 | private static readonly TestMethodAnalyzer Analyzer = new(); 9 | 10 | [Test] 11 | public static void TestCaseAttribute() 12 | { 13 | var code = @" 14 | namespace N 15 | { 16 | using NUnit.Framework; 17 | 18 | public class C 19 | { 20 | [TestCase(1)] 21 | [TestCase(2)] 22 | public void M(int i) 23 | { 24 | } 25 | } 26 | }"; 27 | RoslynAssert.Valid(Analyzer, code); 28 | } 29 | 30 | [Test] 31 | public static void TestCaseAttributeWithAuthor() 32 | { 33 | var code = @" 34 | namespace N 35 | { 36 | using NUnit.Framework; 37 | 38 | public class C 39 | { 40 | [TestCase(1, Author = ""Author"")] 41 | [TestCase(2, Author = ""Author"")] 42 | public void M(int i) 43 | { 44 | } 45 | } 46 | }"; 47 | RoslynAssert.Valid(Analyzer, code); 48 | } 49 | 50 | [TestCase("[TestCase(1)]")] 51 | [TestCase("[TestCase(1, 2)]")] 52 | [TestCase("[TestCase(1, 2, 3)]")] 53 | public static void TestCaseParams(string testCase) 54 | { 55 | var code = @" 56 | namespace N 57 | { 58 | using NUnit.Framework; 59 | 60 | class C 61 | { 62 | [TestCase(1, 2)] 63 | public void M(int i, params int[] ints) 64 | { 65 | } 66 | } 67 | }".AssertReplace("[TestCase(1, 2)]", testCase); 68 | 69 | RoslynAssert.Valid(Analyzer, code); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Gu.Analyzers.Test/GU0083TestCaseAttributeMismatchMethodTests/NoFix.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers.Test.GU0083TestCaseAttributeMismatchMethodTests; 2 | 3 | using Gu.Roslyn.Asserts; 4 | using NUnit.Framework; 5 | 6 | internal static class NoFix 7 | { 8 | private static readonly TestMethodAnalyzer Analyzer = new(); 9 | private static readonly TestMethodParametersFix Fix = new(); 10 | private static readonly ExpectedDiagnostic ExpectedDiagnostic = ExpectedDiagnostic.Create(Descriptors.GU0083TestCaseAttributeMismatchMethod); 11 | 12 | [TestCase("[TestCase(\"a\", ↓1, null)]")] 13 | [TestCase("[TestCase(null, \"a\", ↓1)]")] 14 | [TestCase("[TestCase(↓1, null, \"b\")]")] 15 | [TestCase("[TestCase(null, null, ↓1)]")] 16 | public static void NullArgument(string testCase) 17 | { 18 | var testCode = @" 19 | namespace N 20 | { 21 | using NUnit.Framework; 22 | 23 | public class C 24 | { 25 | [TestCase(""x"", ""y"", null)] 26 | public void M(string x, string y, string z) 27 | { 28 | } 29 | } 30 | }".AssertReplace("[TestCase(\"x\", \"y\", null)]", testCase); 31 | 32 | RoslynAssert.NoFix(Analyzer, Fix, ExpectedDiagnostic, testCode); 33 | } 34 | 35 | [Test] 36 | public static void ArgumentIsNullAndParameterIsInt() 37 | { 38 | var testCode = @" 39 | namespace N 40 | { 41 | using NUnit.Framework; 42 | 43 | public class C 44 | { 45 | [TestCase(↓null)] 46 | public void M(int obj) 47 | { 48 | } 49 | } 50 | }"; 51 | RoslynAssert.NoFix(Analyzer, Fix, ExpectedDiagnostic, testCode); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Gu.Analyzers.Test/GU0090DoNotThrowNotImplementedExceptionTests/Diagnostics.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers.Test.GU0090DoNotThrowNotImplementedExceptionTests; 2 | 3 | using Gu.Roslyn.Asserts; 4 | using NUnit.Framework; 5 | 6 | internal static class Diagnostics 7 | { 8 | private static readonly ExceptionAnalyzer Analyzer = new(); 9 | private static readonly ExpectedDiagnostic ExpectedDiagnostic = ExpectedDiagnostic.Create(Descriptors.GU0090DoNotThrowNotImplementedException); 10 | 11 | [Test] 12 | public static void ExceptionThrownInsideMethodBlock() 13 | { 14 | var code = @" 15 | namespace N 16 | { 17 | class C 18 | { 19 | void M() 20 | { 21 | throw ↓new System.NotImplementedException(); 22 | } 23 | } 24 | }"; 25 | RoslynAssert.Diagnostics(Analyzer, ExpectedDiagnostic, code); 26 | } 27 | 28 | [Test] 29 | public static void ExceptionThrownInline() 30 | { 31 | var code = @" 32 | namespace N 33 | { 34 | class C 35 | { 36 | int M() => throw ↓new System.NotImplementedException(); 37 | } 38 | }"; 39 | RoslynAssert.Diagnostics(Analyzer, ExpectedDiagnostic, code); 40 | } 41 | 42 | [Test] 43 | public static void ExceptionNullCoalescing() 44 | { 45 | var code = @" 46 | namespace N 47 | { 48 | class C 49 | { 50 | void M() 51 | { 52 | int? integer = null; 53 | 54 | int nonNull = integer ?? throw ↓new System.NotImplementedException(); 55 | } 56 | } 57 | }"; 58 | RoslynAssert.Diagnostics(Analyzer, ExpectedDiagnostic, code); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Gu.Analyzers.Test/GU0090DoNotThrowNotImplementedExceptionTests/Valid.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers.Test.GU0090DoNotThrowNotImplementedExceptionTests; 2 | 3 | using Gu.Roslyn.Asserts; 4 | using NUnit.Framework; 5 | 6 | public static class Valid 7 | { 8 | private static readonly ExceptionAnalyzer Analyzer = new(); 9 | 10 | [Test] 11 | public static void Rethrowing() 12 | { 13 | var code = @" 14 | namespace N 15 | { 16 | using System; 17 | using System.IO; 18 | 19 | internal class Exceptions 20 | { 21 | private readonly string path; 22 | 23 | public Exceptions(string text) 24 | { 25 | this.path = text ?? throw new System.ArgumentNullException(nameof(text)); 26 | } 27 | 28 | public void M() 29 | { 30 | try 31 | { 32 | _ = File.ReadAllText(this.path); 33 | } 34 | catch (FileNotFoundException e) 35 | { 36 | Console.WriteLine(e); 37 | throw; 38 | } 39 | 40 | try 41 | { 42 | _ = File.ReadAllText(this.path); 43 | } 44 | catch (FileNotFoundException) 45 | { 46 | throw; 47 | } 48 | 49 | try 50 | { 51 | _ = File.ReadAllText(this.path); 52 | } 53 | catch 54 | { 55 | throw; 56 | } 57 | } 58 | } 59 | } 60 | "; 61 | RoslynAssert.Valid(Analyzer, code); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Gu.Analyzers.Test/Gu.Analyzers.Test.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | net6.0-windows 4 | true 5 | enable 6 | latest 7 | 8 | 9 | 10 | True 11 | AllEnabledByDefault 12 | latest 13 | 14 | 15 | 16 | true 17 | ..\Gu.Analyzers.snk 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /Gu.Analyzers.Test/Gu.Analyzers.Test.csproj.DotSettings: -------------------------------------------------------------------------------- 1 |  2 | No 3 | False 4 | True 5 | True 6 | True 7 | True 8 | True -------------------------------------------------------------------------------- /Gu.Analyzers.Test/ModuleInitializer.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers.Test; 2 | 3 | using System.Runtime.CompilerServices; 4 | using Gu.Roslyn.Asserts; 5 | 6 | internal static class ModuleInitializer 7 | { 8 | [ModuleInitializer] 9 | internal static void Initialize() 10 | { 11 | Settings.Default = Settings.Default.WithMetadataReferences( 12 | MetadataReferences.Transitive( 13 | typeof(ModuleInitializer), 14 | typeof(System.Windows.Window), 15 | typeof(System.Reactive.Linq.Observable), 16 | typeof(Moq.Mock), 17 | typeof(Ninject.StandardKernel))); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Gu.Analyzers.Test/ReproBox.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers.Test; 2 | 3 | using System; 4 | using System.Collections.Generic; 5 | using System.IO; 6 | using System.Linq; 7 | using Gu.Roslyn.Asserts; 8 | using Microsoft.CodeAnalysis; 9 | using Microsoft.CodeAnalysis.Diagnostics; 10 | 11 | using NUnit.Framework; 12 | 13 | [Ignore("Only for digging out repros.")] 14 | internal static class ReproBox 15 | { 16 | // ReSharper disable once UnusedMember.Local 17 | private static readonly IReadOnlyList AllAnalyzers = 18 | typeof(KnownSymbols).Assembly.GetTypes() 19 | .Where(typeof(DiagnosticAnalyzer).IsAssignableFrom) 20 | .Select(t => (DiagnosticAnalyzer)Activator.CreateInstance(t)!) 21 | .ToArray(); 22 | 23 | private static readonly Solution Solution = CodeFactory.CreateSolution( 24 | new FileInfo("C:\\Git\\_GuOrg\\Gu.Inject\\Gu.Inject.sln")); 25 | 26 | [TestCaseSource(nameof(AllAnalyzers))] 27 | public static void SolutionRepro(DiagnosticAnalyzer analyzer) 28 | { 29 | RoslynAssert.Valid(analyzer, Solution); 30 | } 31 | 32 | [TestCaseSource(nameof(AllAnalyzers))] 33 | public static void Repro(DiagnosticAnalyzer analyzer) 34 | { 35 | var code = @" 36 | namespace N 37 | { 38 | public sealed class C 39 | { 40 | } 41 | }"; 42 | 43 | RoslynAssert.Valid(analyzer, code); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Gu.Analyzers.Vsix/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "Visual Studio Extension": { 4 | "executablePath": "$(DevEnvDir)devenv.exe", 5 | "commandLineArgs": "/rootsuffix $(VSSDKTargetPlatformRegRootSuffix) /log" 6 | } 7 | } 8 | } -------------------------------------------------------------------------------- /Gu.Analyzers.Vsix/Readme.txt: -------------------------------------------------------------------------------- 1 | For resetting the experimental instance: 2 | %comspec% /C "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VSSDK\VisualStudioIntegration\Tools\Bin\CreateExpInstance.exe" /Reset /VSInstance=15.0_ad6d5903 /RootSuffix=Roslyn -------------------------------------------------------------------------------- /Gu.Analyzers.Vsix/source.extension.vsixmanifest: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Gu.Analyzers 6 | Analyzers & codefixes. 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Gu.Analyzers.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GuOrg/Gu.Analyzers/85f645e252952af42a8712d60c264b0108ff6b44/Gu.Analyzers.snk -------------------------------------------------------------------------------- /Gu.Analyzers/.editorconfig: -------------------------------------------------------------------------------- 1 | [*.cs] 2 | 3 | # Default severity for analyzer diagnostics with category 'StyleCop.CSharp.DocumentationRules' 4 | dotnet_analyzer_diagnostic.category-StyleCop.CSharp.DocumentationRules.severity = none 5 | 6 | # SA0001: XML comment analysis is disabled due to project configuration 7 | dotnet_diagnostic.SA0001.severity = none 8 | 9 | # SA1401: Fields should be private 10 | dotnet_diagnostic.SA1401.severity = none 11 | 12 | # CA1308: In method 'M', replace the call to 'ToLowerInvariant' with 'ToUpperInvariant'. 13 | dotnet_diagnostic.CA1308.severity = none 14 | 15 | # RS2008: Enable analyzer release tracking 16 | dotnet_diagnostic.RS2008.severity = none 17 | -------------------------------------------------------------------------------- /Gu.Analyzers/AnalyzerCategory.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers; 2 | 3 | /// 4 | /// Class defining the analyzer category constants. 5 | /// 6 | internal static class AnalyzerCategory 7 | { 8 | internal const string Correctness = "Gu.Analyzers.Correctness"; 9 | } 10 | -------------------------------------------------------------------------------- /Gu.Analyzers/Analyzers/AssertAnalyzer.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers; 2 | 3 | using System; 4 | using System.Collections.Immutable; 5 | 6 | using Gu.Roslyn.AnalyzerExtensions; 7 | 8 | using Microsoft.CodeAnalysis; 9 | using Microsoft.CodeAnalysis.CSharp; 10 | using Microsoft.CodeAnalysis.CSharp.Syntax; 11 | using Microsoft.CodeAnalysis.Diagnostics; 12 | 13 | [DiagnosticAnalyzer(LanguageNames.CSharp)] 14 | internal class AssertAnalyzer : DiagnosticAnalyzer 15 | { 16 | public override ImmutableArray SupportedDiagnostics { get; } = ImmutableArray.Create( 17 | Descriptors.GU0084AssertExceptionMessage); 18 | 19 | public override void Initialize(AnalysisContext context) 20 | { 21 | context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None); 22 | context.EnableConcurrentExecution(); 23 | context.RegisterSyntaxNodeAction(c => Handle(c), SyntaxKind.InvocationExpression); 24 | } 25 | 26 | private static void Handle(SyntaxNodeAnalysisContext context) 27 | { 28 | if (!context.IsExcludedFromAnalysis() && 29 | context.Node is InvocationExpressionSyntax { Expression: MemberAccessExpressionSyntax { Expression: IdentifierNameSyntax { Identifier.ValueText: "Assert" }, Name: { } name } } invocation && 30 | name.Identifier.ValueText.StartsWith("Throws", StringComparison.InvariantCulture)) 31 | { 32 | if (invocation.Parent is ExpressionStatementSyntax or AssignmentExpressionSyntax { Left: IdentifierNameSyntax { Identifier.ValueText: "_" } }) 33 | { 34 | context.ReportDiagnostic(Diagnostic.Create(Descriptors.GU0084AssertExceptionMessage, invocation.GetLocation())); 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Gu.Analyzers/Analyzers/IdentifierNameAnalyzer.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers; 2 | 3 | using System.Collections.Immutable; 4 | 5 | using Gu.Roslyn.AnalyzerExtensions; 6 | using Microsoft.CodeAnalysis; 7 | using Microsoft.CodeAnalysis.CSharp; 8 | using Microsoft.CodeAnalysis.CSharp.Syntax; 9 | using Microsoft.CodeAnalysis.Diagnostics; 10 | 11 | [DiagnosticAnalyzer(LanguageNames.CSharp)] 12 | internal class IdentifierNameAnalyzer : DiagnosticAnalyzer 13 | { 14 | public override ImmutableArray SupportedDiagnostics { get; } = ImmutableArray.Create( 15 | Descriptors.GU0017DoNotUseDiscarded); 16 | 17 | public override void Initialize(AnalysisContext context) 18 | { 19 | context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None); 20 | context.EnableConcurrentExecution(); 21 | context.RegisterSyntaxNodeAction(c => Handle(c), SyntaxKind.IdentifierName); 22 | } 23 | 24 | private static void Handle(SyntaxNodeAnalysisContext context) 25 | { 26 | if (!context.IsExcludedFromAnalysis() && 27 | context.Node is IdentifierNameSyntax { Identifier.ValueText: "_" } name && 28 | IsUsed(name)) 29 | { 30 | context.ReportDiagnostic(Diagnostic.Create(Descriptors.GU0017DoNotUseDiscarded, name.Identifier.GetLocation())); 31 | } 32 | 33 | static bool IsUsed(IdentifierNameSyntax candidate) 34 | { 35 | return candidate.Parent switch 36 | { 37 | ArgumentSyntax arg when arg.RefOrOutKeyword.IsKind(SyntaxKind.None) => true, 38 | ExpressionSyntax e when !e.IsKind(SyntaxKind.SimpleAssignmentExpression) => true, 39 | _ => false, 40 | }; 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Gu.Analyzers/Analyzers/RangeAnalyzer.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers; 2 | 3 | using System.Collections.Immutable; 4 | 5 | using Gu.Roslyn.AnalyzerExtensions; 6 | 7 | using Microsoft.CodeAnalysis; 8 | using Microsoft.CodeAnalysis.CSharp; 9 | using Microsoft.CodeAnalysis.CSharp.Syntax; 10 | using Microsoft.CodeAnalysis.Diagnostics; 11 | 12 | [DiagnosticAnalyzer(LanguageNames.CSharp)] 13 | internal class RangeAnalyzer : DiagnosticAnalyzer 14 | { 15 | public override ImmutableArray SupportedDiagnostics { get; } = ImmutableArray.Create( 16 | Descriptors.GU0026RangeAllocation); 17 | 18 | public override void Initialize(AnalysisContext context) 19 | { 20 | context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None); 21 | context.EnableConcurrentExecution(); 22 | context.RegisterSyntaxNodeAction(c => Handle(c), SyntaxKind.BracketedArgumentList); 23 | } 24 | 25 | private static void Handle(SyntaxNodeAnalysisContext context) 26 | { 27 | if (!context.IsExcludedFromAnalysis() && 28 | context.Node is BracketedArgumentListSyntax { Arguments: { Count: 1 } arguments } range && 29 | arguments[0] is { Expression: RangeExpressionSyntax { } } && 30 | Allocates(range)) 31 | { 32 | context.ReportDiagnostic(Diagnostic.Create(Descriptors.GU0026RangeAllocation, range.GetLocation())); 33 | } 34 | 35 | bool Allocates(BracketedArgumentListSyntax candidate) 36 | { 37 | if (candidate.Parent is ElementAccessExpressionSyntax { Expression: { } expression } && 38 | context.SemanticModel.GetType(expression, context.CancellationToken) is IArrayTypeSymbol or INamedTypeSymbol { MetadataName: "string" }) 39 | { 40 | return true; 41 | } 42 | 43 | return false; 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Gu.Analyzers/AssemblyAttributes.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | [assembly: CLSCompliant(false)] 4 | -------------------------------------------------------------------------------- /Gu.Analyzers/CodeFixes/IsNullFix.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers; 2 | 3 | using System.Collections.Immutable; 4 | using System.Composition; 5 | using System.Threading.Tasks; 6 | 7 | using Gu.Roslyn.CodeFixExtensions; 8 | 9 | using Microsoft.CodeAnalysis; 10 | using Microsoft.CodeAnalysis.CodeFixes; 11 | using Microsoft.CodeAnalysis.CSharp; 12 | using Microsoft.CodeAnalysis.CSharp.Syntax; 13 | 14 | [ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(IsNullFix))] 15 | [Shared] 16 | internal class IsNullFix : DocumentEditorCodeFixProvider 17 | { 18 | public override ImmutableArray FixableDiagnosticIds { get; } = ImmutableArray.Create( 19 | Descriptors.GU0077PreferIsNull.Id); 20 | 21 | protected override DocumentEditorFixAllProvider FixAllProvider() => DocumentEditorFixAllProvider.Solution; 22 | 23 | protected override async Task RegisterCodeFixesAsync(DocumentEditorCodeFixContext context) 24 | { 25 | var syntaxRoot = await context.Document.GetSyntaxRootAsync(context.CancellationToken) 26 | .ConfigureAwait(false); 27 | 28 | foreach (var diagnostic in context.Diagnostics) 29 | { 30 | if (syntaxRoot?.FindNode(diagnostic.Location.SourceSpan) is BinaryExpressionSyntax binaryExpression) 31 | { 32 | context.RegisterCodeFix( 33 | binaryExpression.WithOperatorToken(SyntaxFactory.Token(SyntaxKind.IsKeyword).WithTrailingTrivia(SyntaxFactory.Space)).ToString(), 34 | e => e.ReplaceNode( 35 | binaryExpression, 36 | x => x.WithOperatorToken(SyntaxFactory.Token(SyntaxKind.IsKeyword))), 37 | nameof(IsNullFix), 38 | diagnostic); 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Gu.Analyzers/CodeFixes/MakeInternalFix.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers; 2 | 3 | using System.Collections.Immutable; 4 | using System.Composition; 5 | using System.Threading.Tasks; 6 | 7 | using Microsoft.CodeAnalysis; 8 | using Microsoft.CodeAnalysis.CodeActions; 9 | using Microsoft.CodeAnalysis.CodeFixes; 10 | using Microsoft.CodeAnalysis.CSharp; 11 | 12 | [ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(MakeInternalFix))] 13 | [Shared] 14 | internal class MakeInternalFix : CodeFixProvider 15 | { 16 | public override ImmutableArray FixableDiagnosticIds { get; } = ImmutableArray.Create( 17 | Descriptors.GU0072AllTypesShouldBeInternal.Id, 18 | Descriptors.GU0073MemberShouldBeInternal.Id); 19 | 20 | public override FixAllProvider GetFixAllProvider() => WellKnownFixAllProviders.BatchFixer; 21 | 22 | public override async Task RegisterCodeFixesAsync(CodeFixContext context) 23 | { 24 | var syntaxRoot = await context.Document.GetSyntaxRootAsync(context.CancellationToken) 25 | .ConfigureAwait(false); 26 | 27 | foreach (var diagnostic in context.Diagnostics) 28 | { 29 | if (syntaxRoot?.FindToken(diagnostic.Location.SourceSpan.Start) is { } token && 30 | token.IsKind(SyntaxKind.PublicKeyword)) 31 | { 32 | context.RegisterCodeFix( 33 | CodeAction.Create( 34 | "Make internal.", 35 | _ => Task.FromResult( 36 | context.Document.WithSyntaxRoot( 37 | syntaxRoot.ReplaceToken( 38 | token, 39 | SyntaxFactory.Token(SyntaxKind.InternalKeyword).WithTriviaFrom(token)))), 40 | nameof(MakeInternalFix)), 41 | diagnostic); 42 | } 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Gu.Analyzers/CodeFixes/MakeSealedFix.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers; 2 | 3 | using System.Collections.Immutable; 4 | using System.Composition; 5 | using System.Threading.Tasks; 6 | 7 | using Gu.Roslyn.CodeFixExtensions; 8 | 9 | using Microsoft.CodeAnalysis; 10 | using Microsoft.CodeAnalysis.CodeFixes; 11 | using Microsoft.CodeAnalysis.CSharp.Syntax; 12 | 13 | [ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(MakeSealedFix))] 14 | [Shared] 15 | internal class MakeSealedFix : DocumentEditorCodeFixProvider 16 | { 17 | public override ImmutableArray FixableDiagnosticIds { get; } = ImmutableArray.Create( 18 | Descriptors.GU0024SealTypeWithDefaultMember.Id, 19 | Descriptors.GU0025SealTypeWithOverridenEquality.Id); 20 | 21 | protected override async Task RegisterCodeFixesAsync(DocumentEditorCodeFixContext context) 22 | { 23 | var syntaxRoot = await context.Document.GetSyntaxRootAsync(context.CancellationToken) 24 | .ConfigureAwait(false); 25 | 26 | foreach (var diagnostic in context.Diagnostics) 27 | { 28 | if (syntaxRoot?.FindNode(diagnostic.Location.SourceSpan) is ClassDeclarationSyntax classDeclaration) 29 | { 30 | context.RegisterCodeFix( 31 | "Make sealed.", 32 | (editor, _) => editor.Seal(classDeclaration), 33 | "Make sealed.", 34 | diagnostic); 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Gu.Analyzers/GU0052ExceptionShouldBeSerializable.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers; 2 | 3 | using System.Collections.Immutable; 4 | using Gu.Roslyn.AnalyzerExtensions; 5 | using Microsoft.CodeAnalysis; 6 | using Microsoft.CodeAnalysis.CSharp; 7 | using Microsoft.CodeAnalysis.CSharp.Syntax; 8 | using Microsoft.CodeAnalysis.Diagnostics; 9 | 10 | [DiagnosticAnalyzer(LanguageNames.CSharp)] 11 | internal class GU0052ExceptionShouldBeSerializable : DiagnosticAnalyzer 12 | { 13 | public override ImmutableArray SupportedDiagnostics { get; } = 14 | ImmutableArray.Create(Descriptors.GU0052ExceptionShouldBeSerializable); 15 | 16 | public override void Initialize(AnalysisContext context) 17 | { 18 | context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics); 19 | context.EnableConcurrentExecution(); 20 | context.RegisterSyntaxNodeAction(c => Handle(c), SyntaxKind.ClassDeclaration); 21 | } 22 | 23 | private static void Handle(SyntaxNodeAnalysisContext context) 24 | { 25 | if (context.IsExcludedFromAnalysis()) 26 | { 27 | return; 28 | } 29 | 30 | if (context.Node is ClassDeclarationSyntax classDeclaration && 31 | context.ContainingSymbol is INamedTypeSymbol type && 32 | type.IsAssignableTo(KnownSymbols.Exception, context.Compilation) && 33 | !Attribute.TryFind(classDeclaration, KnownSymbols.SerializableAttribute, context.SemanticModel, context.CancellationToken, out _)) 34 | { 35 | context.ReportDiagnostic(Diagnostic.Create(Descriptors.GU0052ExceptionShouldBeSerializable, classDeclaration.Identifier.GetLocation())); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Gu.Analyzers/GU0061EnumMemberValueOutOfRange.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers; 2 | 3 | using System.Collections.Immutable; 4 | 5 | using Gu.Roslyn.AnalyzerExtensions; 6 | 7 | using Microsoft.CodeAnalysis; 8 | using Microsoft.CodeAnalysis.CSharp; 9 | using Microsoft.CodeAnalysis.CSharp.Syntax; 10 | using Microsoft.CodeAnalysis.Diagnostics; 11 | 12 | [DiagnosticAnalyzer(LanguageNames.CSharp)] 13 | internal class GU0061EnumMemberValueOutOfRange : DiagnosticAnalyzer 14 | { 15 | public override ImmutableArray SupportedDiagnostics { get; } = ImmutableArray.Create( 16 | Descriptors.GU0061EnumMemberValueOutOfRange); 17 | 18 | public override void Initialize(AnalysisContext context) 19 | { 20 | context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics); 21 | context.EnableConcurrentExecution(); 22 | context.RegisterSyntaxNodeAction(this.HandleEnumMember, SyntaxKind.EnumMemberDeclaration); 23 | } 24 | 25 | private void HandleEnumMember(SyntaxNodeAnalysisContext context) 26 | { 27 | if (!context.IsExcludedFromAnalysis() && 28 | context.Node is EnumMemberDeclarationSyntax { EqualsValue.Value: BinaryExpressionSyntax { Left: LiteralExpressionSyntax { Token.Value: 1 }, OperatorToken.ValueText: "<<", Right: LiteralExpressionSyntax right } leftShiftExpression } && 29 | context.ContainingSymbol is { ContainingType.EnumUnderlyingType.SpecialType: SpecialType.System_Int32 } && 30 | right is { Token.Value: int intValueRight } && 31 | intValueRight > 30) 32 | { 33 | context.ReportDiagnostic(Diagnostic.Create(Descriptors.GU0061EnumMemberValueOutOfRange, leftShiftExpression.GetLocation())); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Gu.Analyzers/GU0072AllTypesShouldBeInternal.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers; 2 | 3 | using System.Collections.Immutable; 4 | using Gu.Roslyn.AnalyzerExtensions; 5 | using Microsoft.CodeAnalysis; 6 | using Microsoft.CodeAnalysis.CSharp; 7 | using Microsoft.CodeAnalysis.CSharp.Syntax; 8 | using Microsoft.CodeAnalysis.Diagnostics; 9 | 10 | [DiagnosticAnalyzer(LanguageNames.CSharp)] 11 | internal class GU0072AllTypesShouldBeInternal : DiagnosticAnalyzer 12 | { 13 | public override ImmutableArray SupportedDiagnostics { get; } = 14 | ImmutableArray.Create(Descriptors.GU0072AllTypesShouldBeInternal); 15 | 16 | public override void Initialize(AnalysisContext context) 17 | { 18 | context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None); 19 | context.EnableConcurrentExecution(); 20 | context.RegisterSyntaxNodeAction(c => Handle(c), SyntaxKind.ClassDeclaration, SyntaxKind.StructDeclaration); 21 | } 22 | 23 | private static void Handle(SyntaxNodeAnalysisContext context) 24 | { 25 | if (!context.IsExcludedFromAnalysis() && 26 | context is { Node: TypeDeclarationSyntax typeDeclaration, ContainingSymbol: ITypeSymbol } && 27 | typeDeclaration.Modifiers.TrySingle(x => x.IsKind(SyntaxKind.PublicKeyword), out var modifier)) 28 | { 29 | context.ReportDiagnostic(Diagnostic.Create(Descriptors.GU0072AllTypesShouldBeInternal, modifier.GetLocation())); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Gu.Analyzers/Helpers/Inject.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers; 2 | 3 | using Gu.Roslyn.AnalyzerExtensions; 4 | using Microsoft.CodeAnalysis; 5 | using Microsoft.CodeAnalysis.CSharp; 6 | using Microsoft.CodeAnalysis.CSharp.Syntax; 7 | 8 | internal static class Inject 9 | { 10 | internal enum Injectable 11 | { 12 | No, 13 | Safe, 14 | Unsafe, 15 | } 16 | 17 | internal static ConstructorDeclarationSyntax? FindConstructor(SyntaxNode node) 18 | { 19 | if (node.TryFirstAncestor(out ClassDeclarationSyntax? classDeclaration) && 20 | !classDeclaration.Modifiers.Any(SyntaxKind.PartialKeyword) && 21 | classDeclaration.Members.TrySingleOfType(x => !x.Modifiers.Any(SyntaxKind.StaticKeyword), out var ctor) && 22 | !ctor.Modifiers.Any(SyntaxKind.PrivateKeyword)) 23 | { 24 | return ctor; 25 | } 26 | 27 | return null; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Gu.Analyzers/Helpers/KnownSymbols/DependencyObjectType.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers; 2 | 3 | using Gu.Roslyn.AnalyzerExtensions; 4 | 5 | internal class DependencyObjectType : QualifiedType 6 | { 7 | internal readonly QualifiedMethod GetValue; 8 | internal readonly QualifiedMethod SetValue; 9 | internal readonly QualifiedMethod SetCurrentValue; 10 | 11 | internal DependencyObjectType() 12 | : base("System.Windows.DependencyObject") 13 | { 14 | this.GetValue = new QualifiedMethod(this, nameof(this.GetValue)); 15 | this.SetValue = new QualifiedMethod(this, nameof(this.SetValue)); 16 | this.SetCurrentValue = new QualifiedMethod(this, nameof(this.SetCurrentValue)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Gu.Analyzers/Helpers/KnownSymbols/DependencyPropertyType.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers; 2 | 3 | using Gu.Roslyn.AnalyzerExtensions; 4 | 5 | internal class DependencyPropertyType : QualifiedType 6 | { 7 | internal readonly QualifiedMethod Register; 8 | internal readonly QualifiedMethod RegisterReadOnly; 9 | internal readonly QualifiedMethod RegisterAttached; 10 | internal readonly QualifiedMethod RegisterAttachedReadOnly; 11 | 12 | internal readonly QualifiedMethod AddOwner; 13 | 14 | internal DependencyPropertyType() 15 | : base("System.Windows.DependencyProperty") 16 | { 17 | this.Register = new QualifiedMethod(this, nameof(this.Register)); 18 | this.RegisterReadOnly = new QualifiedMethod(this, nameof(this.RegisterReadOnly)); 19 | this.RegisterAttached = new QualifiedMethod(this, nameof(this.RegisterAttached)); 20 | this.RegisterAttachedReadOnly = new QualifiedMethod(this, nameof(this.RegisterAttachedReadOnly)); 21 | 22 | this.AddOwner = new QualifiedMethod(this, nameof(this.AddOwner)); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Gu.Analyzers/Helpers/KnownSymbols/EnumerableType.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers; 2 | 3 | using Gu.Roslyn.AnalyzerExtensions; 4 | 5 | internal class EnumerableType : QualifiedType 6 | { 7 | internal readonly QualifiedMethod FirstOrDefault; 8 | internal readonly QualifiedMethod LastOrDefault; 9 | internal readonly QualifiedMethod SingleOrDefault; 10 | 11 | internal EnumerableType() 12 | : base("System.Linq.Enumerable") 13 | { 14 | this.FirstOrDefault = new QualifiedMethod(this, nameof(this.FirstOrDefault)); 15 | this.LastOrDefault = new QualifiedMethod(this, nameof(this.LastOrDefault)); 16 | this.SingleOrDefault = new QualifiedMethod(this, nameof(this.SingleOrDefault)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Gu.Analyzers/Helpers/KnownSymbols/IEnumerableType.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers; 2 | 3 | using Gu.Roslyn.AnalyzerExtensions; 4 | 5 | // ReSharper disable once InconsistentNaming 6 | internal class IEnumerableType : QualifiedType 7 | { 8 | internal readonly QualifiedMethod GetEnumerator; 9 | 10 | internal IEnumerableType() 11 | : base("System.Collections.IEnumerable") 12 | { 13 | this.GetEnumerator = new QualifiedMethod(this, nameof(this.GetEnumerator)); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Gu.Analyzers/Helpers/KnownSymbols/NUnitAssertType.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers; 2 | 3 | using Gu.Roslyn.AnalyzerExtensions; 4 | 5 | internal class NUnitAssertType : QualifiedType 6 | { 7 | internal readonly QualifiedMethod AreEqual; 8 | 9 | internal NUnitAssertType() 10 | : base("NUnit.Framework.Assert") 11 | { 12 | this.AreEqual = new QualifiedMethod(this, nameof(this.AreEqual)); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Gu.Analyzers/Helpers/KnownSymbols/StringBuilderType.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers; 2 | 3 | using Gu.Roslyn.AnalyzerExtensions; 4 | 5 | internal class StringBuilderType : QualifiedType 6 | { 7 | internal readonly QualifiedMethod AppendLine; 8 | internal readonly QualifiedMethod Append; 9 | internal readonly QualifiedMethod AppendFormat; 10 | 11 | internal StringBuilderType() 12 | : base("System.Text.StringBuilder") 13 | { 14 | this.AppendLine = new QualifiedMethod(this, nameof(this.AppendLine)); 15 | this.Append = new QualifiedMethod(this, nameof(this.Append)); 16 | this.AppendFormat = new QualifiedMethod(this, nameof(this.AppendFormat)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Gu.Analyzers/Helpers/KnownSymbols/StringType.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers; 2 | 3 | using Gu.Roslyn.AnalyzerExtensions; 4 | 5 | internal class StringType : QualifiedType 6 | { 7 | internal readonly QualifiedMethod Format; 8 | 9 | internal StringType() 10 | : base("System.String", "string") 11 | { 12 | this.Format = new QualifiedMethod(this, nameof(this.Format)); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Gu.Analyzers/Helpers/KnownSymbols/TaskType.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers; 2 | 3 | using Gu.Roslyn.AnalyzerExtensions; 4 | 5 | internal class TaskType : QualifiedType 6 | { 7 | internal readonly QualifiedMethod FromResult; 8 | internal readonly QualifiedMethod Run; 9 | internal readonly QualifiedMethod RunOfT; 10 | internal readonly QualifiedMethod ConfigureAwait; 11 | 12 | internal TaskType() 13 | : base("System.Threading.Tasks.Task") 14 | { 15 | this.FromResult = new QualifiedMethod(this, nameof(this.FromResult)); 16 | this.Run = new QualifiedMethod(this, nameof(this.Run)); 17 | this.RunOfT = new QualifiedMethod(this, $"{nameof(this.Run)}`1"); 18 | this.ConfigureAwait = new QualifiedMethod(this, nameof(this.ConfigureAwait)); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Gu.Analyzers/Helpers/KnownSymbols/XmlSerializerType.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers; 2 | 3 | using Gu.Roslyn.AnalyzerExtensions; 4 | 5 | // ReSharper disable once InconsistentNaming 6 | internal class XmlSerializerType : QualifiedType 7 | { 8 | internal XmlSerializerType() 9 | : base("System.Xml.Serialization.XmlSerializer") 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Gu.Analyzers/Helpers/KnownSymbols/XunitAssertType.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers; 2 | 3 | using Gu.Roslyn.AnalyzerExtensions; 4 | 5 | internal class XunitAssertType : QualifiedType 6 | { 7 | internal readonly QualifiedMethod Equal; 8 | 9 | internal XunitAssertType() 10 | : base("Xunit.Assert") 11 | { 12 | this.Equal = new QualifiedMethod(this, nameof(this.Equal)); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Gu.Analyzers/Helpers/StandardDocs.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers; 2 | 3 | using System.Collections.Generic; 4 | using System.Diagnostics.CodeAnalysis; 5 | using Gu.Roslyn.AnalyzerExtensions; 6 | using Microsoft.CodeAnalysis.CSharp.Syntax; 7 | 8 | internal static class StandardDocs 9 | { 10 | private static readonly List<(QualifiedType, string)> Cache = new() 11 | { 12 | (KnownSymbols.CancellationToken, "The that cancels the operation."), 13 | }; 14 | 15 | internal static bool TryGet(ParameterSyntax parameter, [NotNullWhen(true)] out string? text) 16 | { 17 | if (Cache.TryFirst(x => parameter.Type == x.Item1, out var tuple)) 18 | { 19 | text = tuple.Item2; 20 | return true; 21 | } 22 | 23 | text = null; 24 | return false; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Gu.Analyzers/Helpers/StringExt.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers; 2 | 3 | internal static class StringExt 4 | { 5 | internal static string Slice(this string text, int start, int end) => text.Substring(start, end - start); 6 | } 7 | -------------------------------------------------------------------------------- /Gu.Analyzers/Helpers/SyntaxtTreeHelpers/ArgumentSyntaxExt.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers; 2 | 3 | using System.Diagnostics.CodeAnalysis; 4 | using Gu.Roslyn.AnalyzerExtensions; 5 | using Microsoft.CodeAnalysis.CSharp.Syntax; 6 | 7 | internal static class ArgumentSyntaxExt 8 | { 9 | internal static bool TryGetNameOf(this ArgumentSyntax argument, [NotNullWhen(true)] out string? name) 10 | { 11 | name = null; 12 | if (argument.Expression is InvocationExpressionSyntax { Expression: IdentifierNameSyntax { Identifier.ValueText: "nameof" }, ArgumentList: { } } invocation && 13 | invocation.ArgumentList.Arguments.TryFirst(out var nameofArg)) 14 | { 15 | switch (nameofArg.Expression) 16 | { 17 | case IdentifierNameSyntax identifierName: 18 | name = identifierName.Identifier.ValueText; 19 | break; 20 | case MemberAccessExpressionSyntax { Name: { } memberName }: 21 | name = memberName.Identifier.ValueText; 22 | break; 23 | } 24 | } 25 | 26 | return name != null; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Gu.Analyzers/Helpers/SyntaxtTreeHelpers/BasePropertyDeclarationSyntaxExt.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers; 2 | 3 | using Microsoft.CodeAnalysis.CSharp.Syntax; 4 | 5 | internal static class BasePropertyDeclarationSyntaxExt 6 | { 7 | internal static bool IsPropertyOrIndexer(this BasePropertyDeclarationSyntax declaration) 8 | { 9 | return declaration is PropertyDeclarationSyntax || declaration is IndexerDeclarationSyntax; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Gu.Analyzers/Helpers/Temp.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers; 2 | 3 | using System; 4 | using System.Linq; 5 | using Gu.Roslyn.AnalyzerExtensions; 6 | using Microsoft.CodeAnalysis; 7 | using Microsoft.CodeAnalysis.CSharp; 8 | 9 | [Obsolete("Use Gu.Roslyn.Extensions")] 10 | internal static class Temp 11 | { 12 | /// 13 | /// Add leading line feed to . 14 | /// 15 | /// The type of . 16 | /// The . 17 | /// with leading line feed. 18 | internal static T WithoutTrailingLineFeed(this T node) 19 | where T : SyntaxNode 20 | { 21 | if (node is null) 22 | { 23 | throw new System.ArgumentNullException(nameof(node)); 24 | } 25 | 26 | if (node.HasTrailingTrivia && 27 | node.GetTrailingTrivia() is { } triviaList && 28 | triviaList.TryLast(out var first) && 29 | first.IsKind(SyntaxKind.EndOfLineTrivia)) 30 | { 31 | return node.WithTrailingTrivia(triviaList.Take(triviaList.Count - 2)); 32 | } 33 | 34 | return node; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Gu.Analyzers/Helpers/Walkers/ObjectCreationWalker.cs: -------------------------------------------------------------------------------- 1 | namespace Gu.Analyzers; 2 | 3 | using System.Collections.Generic; 4 | using Gu.Roslyn.AnalyzerExtensions; 5 | using Microsoft.CodeAnalysis; 6 | using Microsoft.CodeAnalysis.CSharp.Syntax; 7 | 8 | internal sealed class ObjectCreationWalker : PooledWalker 9 | { 10 | private readonly List objectCreations = new(); 11 | 12 | private ObjectCreationWalker() 13 | { 14 | } 15 | 16 | internal IReadOnlyList ObjectCreations => this.objectCreations; 17 | 18 | public override void VisitObjectCreationExpression(ObjectCreationExpressionSyntax node) 19 | { 20 | this.objectCreations.Add(node); 21 | base.VisitObjectCreationExpression(node); 22 | } 23 | 24 | internal static ObjectCreationWalker BorrowAndVisit(SyntaxNode scope) => BorrowAndVisit(scope, () => new ObjectCreationWalker()); 25 | 26 | protected override void Clear() 27 | { 28 | this.objectCreations.Clear(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Gu.Analyzers/InternalsVisibleTo.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.CompilerServices; 2 | 3 | [assembly: InternalsVisibleTo("Gu.Analyzers.CodeFixes, PublicKey=00240000048000009400000006020000002400005253413100040000010001002712CA3F14B4B920B49D64D0177BDB7DC36BF3C2B38D4797EF3D37DD81A7B7222CFD1CD75EFFFB5F49C86C5ACA668393232DAE04B30A1BCB49202F27B7D8C1CCEE5E6F2610CDD04437D076300F559134C08448B5BB13AAF737355A5F28B49E6582556AE2B34B67941E7B15D6B0F3BEAD6CB708CB4A2E862E12CEA60E9F47BBD7")] 4 | [assembly: InternalsVisibleTo("Gu.Analyzers.Benchmarks, PublicKey=00240000048000009400000006020000002400005253413100040000010001002712CA3F14B4B920B49D64D0177BDB7DC36BF3C2B38D4797EF3D37DD81A7B7222CFD1CD75EFFFB5F49C86C5ACA668393232DAE04B30A1BCB49202F27B7D8C1CCEE5E6F2610CDD04437D076300F559134C08448B5BB13AAF737355A5F28B49E6582556AE2B34B67941E7B15D6B0F3BEAD6CB708CB4A2E862E12CEA60E9F47BBD7")] 5 | [assembly: InternalsVisibleTo("Gu.Analyzers.Test, PublicKey=00240000048000009400000006020000002400005253413100040000010001002712CA3F14B4B920B49D64D0177BDB7DC36BF3C2B38D4797EF3D37DD81A7B7222CFD1CD75EFFFB5F49C86C5ACA668393232DAE04B30A1BCB49202F27B7D8C1CCEE5E6F2610CDD04437D076300F559134C08448B5BB13AAF737355A5F28B49E6582556AE2B34B67941E7B15D6B0F3BEAD6CB708CB4A2E862E12CEA60E9F47BBD7")] 6 | -------------------------------------------------------------------------------- /Gu.Analyzers/tools/install.ps1: -------------------------------------------------------------------------------- 1 | param($installPath, $toolsPath, $package, $project) 2 | 3 | $analyzersPaths = Join-Path (Join-Path (Split-Path -Path $toolsPath -Parent) "analyzers" ) * -Resolve 4 | 5 | foreach($analyzersPath in $analyzersPaths) 6 | { 7 | # Install the language agnostic analyzers. 8 | if (Test-Path $analyzersPath) 9 | { 10 | foreach ($analyzerFilePath in Get-ChildItem $analyzersPath -Filter *.dll) 11 | { 12 | if($project.Object.AnalyzerReferences) 13 | { 14 | $project.Object.AnalyzerReferences.Add($analyzerFilePath.FullName) 15 | } 16 | } 17 | } 18 | } 19 | 20 | $project.Type # gives the language name like (C# or VB.NET) 21 | $languageFolder = "" 22 | if($project.Type -eq "C#") 23 | { 24 | $languageFolder = "cs" 25 | } 26 | if($project.Type -eq "VB.NET") 27 | { 28 | $languageFolder = "vb" 29 | } 30 | if($languageFolder -eq "") 31 | { 32 | return 33 | } 34 | 35 | foreach($analyzersPath in $analyzersPaths) 36 | { 37 | # Install language specific analyzers. 38 | $languageAnalyzersPath = join-path $analyzersPath $languageFolder 39 | if (Test-Path $languageAnalyzersPath) 40 | { 41 | foreach ($analyzerFilePath in Get-ChildItem $languageAnalyzersPath -Filter *.dll) 42 | { 43 | if($project.Object.AnalyzerReferences) 44 | { 45 | $project.Object.AnalyzerReferences.Add($analyzerFilePath.FullName) 46 | } 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /Gu.Analyzers/tools/uninstall.ps1: -------------------------------------------------------------------------------- 1 | param($installPath, $toolsPath, $package, $project) 2 | 3 | $analyzersPaths = Join-Path (Join-Path (Split-Path -Path $toolsPath -Parent) "analyzers" ) * -Resolve 4 | 5 | foreach($analyzersPath in $analyzersPaths) 6 | { 7 | # Uninstall the language agnostic analyzers. 8 | if (Test-Path $analyzersPath) 9 | { 10 | foreach ($analyzerFilePath in Get-ChildItem $analyzersPath -Filter *.dll) 11 | { 12 | if($project.Object.AnalyzerReferences) 13 | { 14 | $project.Object.AnalyzerReferences.Remove($analyzerFilePath.FullName) 15 | } 16 | } 17 | } 18 | } 19 | 20 | $project.Type # gives the language name like (C# or VB.NET) 21 | $languageFolder = "" 22 | if($project.Type -eq "C#") 23 | { 24 | $languageFolder = "cs" 25 | } 26 | if($project.Type -eq "VB.NET") 27 | { 28 | $languageFolder = "vb" 29 | } 30 | if($languageFolder -eq "") 31 | { 32 | return 33 | } 34 | 35 | foreach($analyzersPath in $analyzersPaths) 36 | { 37 | # Uninstall language specific analyzers. 38 | $languageAnalyzersPath = join-path $analyzersPath $languageFolder 39 | if (Test-Path $languageAnalyzersPath) 40 | { 41 | foreach ($analyzerFilePath in Get-ChildItem $languageAnalyzersPath -Filter *.dll) 42 | { 43 | if($project.Object.AnalyzerReferences) 44 | { 45 | try 46 | { 47 | $project.Object.AnalyzerReferences.Remove($analyzerFilePath.FullName) 48 | } 49 | catch 50 | { 51 | 52 | } 53 | } 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 .NET Analyzers 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /RELEASE_NOTES.md: -------------------------------------------------------------------------------- 1 | #### 2.0.2 2 | * BUGFIX: Don't warn when indexing. 3 | 4 | #### 2.0.1 5 | * GU0019: Warn on IEnumerable<struct>.FirstOrDefault() 6 | * GU0026: Warn on array[1..] as it allocates 7 | 8 | #### 2.0.0 9 | * BREAKING: For VS2022+ now. 10 | * BUGFIX: AD0001 -> Could not load file or assembly 11 | 12 | #### 1.8.5 13 | * BUGFIX: Handle roslyn reporting different error. 14 | 15 | #### 1.8.2 16 | * BUGFIX: GU0011 should not warn on void returning. 17 | 18 | #### 1.8.0 19 | * FEATURE: Name mocks 20 | 21 | #### 1.5.5 22 | * FEATURE: GU0007 handle singletons. 23 | * BUGFIX GU0012: ignore out parameters. 24 | 25 | #### 1.5.4 26 | * FEATURE: Member of internal class should be internal, analyzer + fix. 27 | 28 | #### 1.5.3 29 | * BUGFIX: NRE in exception analyzer. 30 | 31 | #### 1.5.0 32 | * FEATURE: SplitStringRefactoring 33 | * FEATURE: MakeStaticFix 34 | 35 | #### 1.4.0 36 | * FEATURE: GU0017 Don't use discarded 37 | 38 | #### 1.3.2 39 | * BUGFIX: Garbage docs for SA1611. 40 | * Garbage docs for type parameter. 41 | 42 | #### 1.3.0 43 | * Generate useless docs for SA1614. 44 | * Fix: create parameter when adding testcase arg. 45 | 46 | #### 1.2.18 47 | * FEATURE: New analyzer GU0024. 48 | 49 | #### 1.2.13 50 | * BUGFIX: Static member order. 51 | 52 | #### 1.2.13 53 | * FEATURE: Code fix for GU0009. 54 | 55 | #### 1.2.10 56 | * BUGFIXES: Don't nag on fluent moq. 57 | 58 | #### 1.2.9 59 | * FEATURE: New analyzer: check that exceptions are [Serializable]. 60 | * BUGFIX: GU0082 handle enums. 61 | 62 | #### 1.2.6 63 | * FEATURE: New analyzer: check testcase attribute arguments & parameter types. 64 | 65 | #### 1.2.5 66 | * FEATURE: New analyzers for checking NUnit attribute usage. 67 | 68 | #### 1.2.1 69 | * BREAKING: Only VS2017+ from now on. 70 | * Bugfixes. 71 | 72 | #### 1.2.0 73 | * NEW ANALYZER: GU0071 74 | 75 | #### 1.0.0 76 | * BREAKING: Moved dispoable analyzers to https://www.nuget.org/packages/IDisposableAnalyzers/ -------------------------------------------------------------------------------- /ValidCode/.editorconfig: -------------------------------------------------------------------------------- 1 | [*.cs] 2 | 3 | # Default severity for analyzer diagnostics with category 'StyleCop.CSharp.DocumentationRules' 4 | dotnet_analyzer_diagnostic.category-StyleCop.CSharp.DocumentationRules.severity = none 5 | 6 | # SA0001: XML comment analysis is disabled due to project configuration 7 | dotnet_diagnostic.SA0001.severity = none 8 | 9 | # Default severity for analyzer diagnostics with category 'Style' 10 | dotnet_analyzer_diagnostic.category-Style.severity = none 11 | 12 | dotnet_diagnostic.GU0010.severity = none 13 | dotnet_diagnostic.GU0011.severity = none 14 | dotnet_diagnostic.GU0015.severity = none 15 | 16 | dotnet_diagnostic.IDE0052.severity = none 17 | dotnet_diagnostic.IDE0079.severity = none 18 | 19 | dotnet_diagnostic.CA1822.severity = none 20 | dotnet_diagnostic.CA2011.severity = none -------------------------------------------------------------------------------- /ValidCode/AssemblyAttributes.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | [assembly: CLSCompliant(false)] 4 | -------------------------------------------------------------------------------- /ValidCode/Bar.cs: -------------------------------------------------------------------------------- 1 | namespace ValidCode 2 | { 3 | using System; 4 | using System.Threading.Tasks; 5 | 6 | internal struct Bar : IDisposable 7 | { 8 | internal Bar(Task task) 9 | { 10 | this.Task = task; 11 | } 12 | 13 | internal Task Task { get; } 14 | 15 | public void Dispose() 16 | { 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /ValidCode/CompositeDisposableExt.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable All 2 | namespace ValidCode 3 | { 4 | using System; 5 | using System.Reactive.Disposables; 6 | 7 | internal static class CompositeDisposableExt 8 | { 9 | internal static T AddAndReturn(this CompositeDisposable disposable, T item) 10 | where T : IDisposable 11 | { 12 | if (item != null) 13 | { 14 | disposable.Add(item); 15 | } 16 | 17 | #pragma warning disable CS8603 // Possible null reference return. 18 | return item; 19 | #pragma warning restore CS8603 // Possible null reference return. 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /ValidCode/Disposable.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable All 2 | namespace ValidCode 3 | { 4 | using System; 5 | 6 | internal class Disposable : IDisposable 7 | { 8 | internal Disposable(string meh) 9 | : this() 10 | { 11 | } 12 | 13 | internal Disposable() 14 | { 15 | } 16 | 17 | public void Dispose() 18 | { 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /ValidCode/EmptyClass.cs: -------------------------------------------------------------------------------- 1 | namespace ValidCode 2 | { 3 | internal class EmptyClass 4 | { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /ValidCode/Exceptions.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable All 2 | namespace ValidCode 3 | { 4 | using System; 5 | using System.IO; 6 | 7 | internal class Exceptions 8 | { 9 | private readonly string path; 10 | 11 | internal Exceptions(string text) 12 | { 13 | this.path = text ?? throw new System.ArgumentNullException(nameof(text)); 14 | } 15 | 16 | internal void M() 17 | { 18 | try 19 | { 20 | _ = File.ReadAllText(this.path); 21 | } 22 | catch (FileNotFoundException e) 23 | { 24 | Console.WriteLine(e); 25 | throw; 26 | } 27 | 28 | try 29 | { 30 | _ = File.ReadAllText(this.path); 31 | } 32 | catch (FileNotFoundException) 33 | { 34 | throw; 35 | } 36 | 37 | try 38 | { 39 | _ = File.ReadAllText(this.path); 40 | } 41 | catch 42 | { 43 | throw; 44 | } 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /ValidCode/Foo.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable All 2 | namespace ValidCode 3 | { 4 | using System.Threading.Tasks; 5 | 6 | internal sealed class Foo 7 | { 8 | internal Foo() 9 | { 10 | using (new Bar(Task.Run(() => 1))) 11 | { 12 | } 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /ValidCode/FooAsync.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable All 2 | namespace ValidCode 3 | { 4 | using System.IO; 5 | using System.Threading.Tasks; 6 | 7 | internal static class FooAsync 8 | { 9 | internal static async Task Bar1Async() 10 | { 11 | using var stream = await ReadAsync(string.Empty); 12 | using var reader = new StreamReader(stream); 13 | return reader.ReadLine(); 14 | } 15 | 16 | internal static async Task Bar2Async() 17 | { 18 | using var stream = await ReadAsync(string.Empty).ConfigureAwait(false); 19 | using var reader = new StreamReader(stream); 20 | return reader.ReadLine(); 21 | } 22 | 23 | private static async Task ReadAsync(this string fileName) 24 | { 25 | var stream = new MemoryStream(); 26 | using (var fileStream = File.OpenRead(fileName)) 27 | { 28 | await fileStream.CopyToAsync(stream) 29 | .ConfigureAwait(false); 30 | } 31 | 32 | stream.Position = 0; 33 | return stream; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /ValidCode/FooBase.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable All 2 | namespace ValidCode 3 | { 4 | using System; 5 | using System.IO; 6 | 7 | internal abstract class FooBase : IDisposable 8 | { 9 | private readonly Stream stream = File.OpenRead(string.Empty); 10 | private bool disposed; 11 | 12 | public void Dispose() 13 | { 14 | this.Dispose(true); 15 | } 16 | 17 | protected virtual void Dispose(bool disposing) 18 | { 19 | if (this.disposed) 20 | { 21 | return; 22 | } 23 | 24 | this.disposed = true; 25 | 26 | if (disposing) 27 | { 28 | this.stream.Dispose(); 29 | } 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /ValidCode/FooCached.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable All 2 | namespace ValidCode 3 | { 4 | using System.Collections.Concurrent; 5 | using System.IO; 6 | 7 | internal class FooCached 8 | { 9 | private static readonly ConcurrentDictionary Cache = new ConcurrentDictionary(); 10 | private readonly ConcurrentDictionary cache = new ConcurrentDictionary(); 11 | 12 | internal static long Bar() 13 | { 14 | var stream = Cache.GetOrAdd(1, _ => File.OpenRead(string.Empty)); 15 | return stream.Length; 16 | } 17 | 18 | internal long Bar1() 19 | { 20 | var stream = this.cache.GetOrAdd(1, _ => File.OpenRead(string.Empty)); 21 | return stream.Length; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /ValidCode/FooImpl.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable All 2 | namespace ValidCode 3 | { 4 | using System.IO; 5 | 6 | internal class FooImpl : FooBase 7 | { 8 | private readonly Stream stream = File.OpenRead(string.Empty); 9 | private bool disposed; 10 | 11 | protected override void Dispose(bool disposing) 12 | { 13 | if (this.disposed) 14 | { 15 | return; 16 | } 17 | 18 | this.disposed = true; 19 | if (disposing) 20 | { 21 | this.stream.Dispose(); 22 | } 23 | 24 | base.Dispose(disposing); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /ValidCode/FooList.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable All 2 | namespace ValidCode 3 | { 4 | using System.Collections; 5 | using System.Collections.Generic; 6 | 7 | internal class FooList : IReadOnlyList 8 | { 9 | private readonly List inner = new List(); 10 | 11 | public int Count => this.inner.Count; 12 | 13 | public T this[int index] => this.inner[index]; 14 | 15 | public IEnumerator GetEnumerator() 16 | { 17 | return this.inner.GetEnumerator(); 18 | } 19 | 20 | IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /ValidCode/FooOut.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable All 2 | namespace ValidCode 3 | { 4 | using System; 5 | using System.IO; 6 | 7 | internal class FooOut 8 | { 9 | internal static bool TryGetStream(out Stream stream) 10 | { 11 | return TryGetStreamCore(out stream); 12 | } 13 | 14 | internal void Bar() 15 | { 16 | IDisposable disposable; 17 | using (disposable = new Disposable()) 18 | { 19 | } 20 | } 21 | 22 | internal void Baz() 23 | { 24 | Stream disposable; 25 | if (TryGetStreamCore(out disposable)) 26 | { 27 | using (disposable) 28 | { 29 | } 30 | } 31 | } 32 | 33 | private static bool TryGetStreamCore(out Stream stream) 34 | { 35 | stream = File.OpenRead(string.Empty); 36 | return true; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /ValidCode/Inheritance/Bar.cs: -------------------------------------------------------------------------------- 1 | namespace ValidCode.Inheritance 2 | { 3 | internal class Bar : Foo 4 | { 5 | internal Bar(int a, int b, int c, int d) 6 | : base(a, b, c, d) 7 | { 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /ValidCode/Inheritance/Foo.cs: -------------------------------------------------------------------------------- 1 | namespace ValidCode.Inheritance 2 | { 3 | internal class Foo 4 | { 5 | internal Foo(int a, int b, int c, int d) 6 | { 7 | this.A = a; 8 | this.B = b; 9 | this.C = c; 10 | this.D = d; 11 | } 12 | 13 | internal int A { get; } 14 | 15 | internal int B { get; } 16 | 17 | internal int C { get; } 18 | 19 | internal int D { get; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /ValidCode/LazyFoo.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable All 2 | namespace ValidCode 3 | { 4 | using System; 5 | 6 | internal sealed class LazyFoo : IDisposable 7 | { 8 | private readonly IDisposable? created; 9 | private bool disposed; 10 | private IDisposable? lazyDisposable; 11 | 12 | internal LazyFoo(IDisposable injected) 13 | { 14 | this.Disposable = injected ?? (this.created = new Disposable()); 15 | } 16 | 17 | internal IDisposable Disposable { get; } 18 | 19 | internal IDisposable LazyDisposable => this.lazyDisposable ?? (this.lazyDisposable = new Disposable()); 20 | 21 | public void Dispose() 22 | { 23 | if (this.disposed) 24 | { 25 | return; 26 | } 27 | 28 | this.disposed = true; 29 | this.created?.Dispose(); 30 | this.lazyDisposable?.Dispose(); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /ValidCode/ReturnValue/C.cs: -------------------------------------------------------------------------------- 1 | namespace ValidCode.ReturnValue 2 | { 3 | using System; 4 | 5 | internal class C : IDisposable 6 | { 7 | internal C M1(Type t) => this; 8 | internal C M2(Type t) 9 | { 10 | this.M1(t); 11 | return this; 12 | } 13 | 14 | public void Dispose() 15 | { 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /ValidCode/ReturnValue/C1.cs: -------------------------------------------------------------------------------- 1 | namespace ValidCode.ReturnValue 2 | { 3 | internal class C1 4 | { 5 | internal void M1() 6 | { 7 | using var c1 = new C().M1(typeof(C)); 8 | using var c2 = new C(); 9 | c2.M1(typeof(C)); 10 | } 11 | 12 | internal void M2() 13 | { 14 | using var c1 = new C().M2(typeof(C)); 15 | using var c2 = new C(); 16 | c2.M2(typeof(C)); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /ValidCode/ReturnValue/Ext.cs: -------------------------------------------------------------------------------- 1 | namespace ValidCode.ReturnValue 2 | { 3 | using System; 4 | 5 | internal static class Ext 6 | { 7 | internal static C M1Ext(this C c, Type t) => c; 8 | internal static C M2Ext(this C c, Type t) 9 | { 10 | return c; 11 | } 12 | 13 | internal static void M1() 14 | { 15 | using var c1 = new C().M1Ext(typeof(C)); 16 | using var c2 = new C(); 17 | c2.M1Ext(typeof(C)); 18 | } 19 | 20 | internal static void M2() 21 | { 22 | using var c1 = new C().M2Ext(typeof(C)); 23 | using var c2 = new C(); 24 | c2.M2Ext(typeof(C)); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /ValidCode/Tests.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable All 2 | namespace ValidCode 3 | { 4 | using NUnit.Framework; 5 | 6 | internal class Tests 7 | { 8 | [TestCase(double.NegativeInfinity)] 9 | [TestCase(double.MinValue)] 10 | [TestCase(int.MinValue)] 11 | [TestCase(-1.2)] 12 | [TestCase(-1)] 13 | [TestCase(-0.1)] 14 | [TestCase(-1.2E-123)] 15 | [TestCase(-0.0)] 16 | [TestCase(0.0)] 17 | [TestCase(1.2E-123)] 18 | [TestCase(0.1)] 19 | [TestCase(1)] 20 | [TestCase(1.2)] 21 | [TestCase(1.2E123)] 22 | [TestCase(int.MaxValue)] 23 | [TestCase(double.MaxValue)] 24 | [TestCase(double.NaN)] 25 | internal void WithDouble(double value) 26 | { 27 | Assert.AreEqual(value, 1* value); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /ValidCode/UsingReactive.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable All 2 | namespace ValidCode 3 | { 4 | using System; 5 | using System.Reactive.Concurrency; 6 | using System.Reactive.Disposables; 7 | using System.Reactive.Linq; 8 | using System.Threading.Tasks; 9 | 10 | internal abstract class UsingReactive : IDisposable 11 | { 12 | private readonly IDisposable subscription; 13 | private readonly SingleAssignmentDisposable singleAssignmentDisposable = new SingleAssignmentDisposable(); 14 | 15 | internal UsingReactive(int no) 16 | : this(Create(no)) 17 | { 18 | } 19 | 20 | internal UsingReactive(IObservable observable) 21 | { 22 | this.subscription = observable.Subscribe(_ => { }); 23 | this.singleAssignmentDisposable.Disposable = observable.Subscribe(_ => { }); 24 | } 25 | 26 | public void Dispose() 27 | { 28 | this.subscription.Dispose(); 29 | this.singleAssignmentDisposable.Dispose(); 30 | } 31 | 32 | internal static async Task SleepAsync(IScheduler scheduler, TimeSpan dueTime) 33 | { 34 | await scheduler.Sleep(dueTime).ConfigureAwait(false); 35 | } 36 | 37 | private static IObservable Create(int i) 38 | { 39 | return Observable.Empty(); 40 | } 41 | } 42 | } 43 | 44 | -------------------------------------------------------------------------------- /ValidCode/ValidCode.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | net6.0 4 | enable 5 | latest 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /ValidCode/WithCustomDelegate.cs: -------------------------------------------------------------------------------- 1 | namespace ValidCode 2 | { 3 | using System; 4 | 5 | internal delegate void ValueChangedEventHandler(object sender, ValueChangedEventArgs e); 6 | 7 | internal class ValueChangedEventArgs : EventArgs 8 | { 9 | internal ValueChangedEventArgs(T oldValue, T newValue) 10 | { 11 | this.OldValue = oldValue; 12 | this.NewValue = newValue; 13 | } 14 | 15 | internal T OldValue { get; } 16 | 17 | internal T NewValue { get; } 18 | } 19 | } 20 | 21 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | image: Visual Studio 2022 2 | before_build: 3 | - ps: dotnet restore 4 | 5 | configuration: Release 6 | platform: Any CPU 7 | build: 8 | verbosity: minimal 9 | -------------------------------------------------------------------------------- /azure-pipelines.yml: -------------------------------------------------------------------------------- 1 | pool: 2 | vmImage: 'windows-2022' 3 | 4 | steps: 5 | 6 | - task: VSBuild@1 7 | displayName: build 8 | inputs: 9 | configuration: 'Release' 10 | msbuildArgs: '/restore' 11 | 12 | - task: DotNetCoreCLI@2 13 | displayName: test 14 | inputs: 15 | command: 'test' 16 | nobuild: true -------------------------------------------------------------------------------- /documentation/GU0002.md: -------------------------------------------------------------------------------- 1 | # GU0002 2 | ## The position of a named argument should match 3 | 4 | | Topic | Value 5 | | :-- | :-- 6 | | Id | GU0002 7 | | Severity | Hidden 8 | | Enabled | True 9 | | Category | Gu.Analyzers.Correctness 10 | | Code | [ArgumentListAnalyzer](https://github.com/GuOrg/Gu.Analyzers/blob/master/Gu.Analyzers/Analyzers/ArgumentListAnalyzer.cs) 11 | 12 | ## Description 13 | 14 | The position of a named argument should match parameter position. 15 | 16 | ## Motivation 17 | 18 | This is just an OCD-thing. Enable the analyzer if you want named argument's position to match the parameter position. 19 | 20 | ## How to fix violations 21 | 22 | Use the code fix. 23 | 24 | 25 | ## Configure severity 26 | 27 | ### Via ruleset file. 28 | 29 | Configure the severity per project, for more info see [MSDN](https://msdn.microsoft.com/en-us/library/dd264949.aspx). 30 | 31 | ### Via #pragma directive. 32 | ```C# 33 | #pragma warning disable GU0002 // The position of a named argument should match 34 | Code violating the rule here 35 | #pragma warning restore GU0002 // The position of a named argument should match 36 | ``` 37 | 38 | Or put this at the top of the file to disable all instances. 39 | ```C# 40 | #pragma warning disable GU0002 // The position of a named argument should match 41 | ``` 42 | 43 | ### Via attribute `[SuppressMessage]`. 44 | 45 | ```C# 46 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Gu.Analyzers.Correctness", 47 | "GU0002:The position of a named argument should match", 48 | Justification = "Reason...")] 49 | ``` 50 | -------------------------------------------------------------------------------- /documentation/GU0005.md: -------------------------------------------------------------------------------- 1 | # GU0005 2 | ## Use correct argument positions 3 | 4 | | Topic | Value 5 | | :-- | :-- 6 | | Id | GU0005 7 | | Severity | Warning 8 | | Enabled | True 9 | | Category | Gu.Analyzers.Correctness 10 | | Code | [ObjectCreationAnalyzer](https://github.com/GuOrg/Gu.Analyzers/blob/master/Gu.Analyzers/Analyzers/ObjectCreationAnalyzer.cs) 11 | 12 | ## Description 13 | 14 | Use correct position for name and message. 15 | 16 | ## Motivation 17 | 18 | `ArgumentException` & `ArgumentNullException` has different positions for `parameterName` and `message`. 19 | Changing exception type between the two is very likely to introduce an error. 20 | 21 | ## How to fix violations 22 | 23 | Use the code fix or manually change the argument positions. 24 | 25 | 26 | ## Configure severity 27 | 28 | ### Via ruleset file. 29 | 30 | Configure the severity per project, for more info see [MSDN](https://msdn.microsoft.com/en-us/library/dd264949.aspx). 31 | 32 | ### Via #pragma directive. 33 | ```C# 34 | #pragma warning disable GU0005 // Use correct argument positions 35 | Code violating the rule here 36 | #pragma warning restore GU0005 // Use correct argument positions 37 | ``` 38 | 39 | Or put this at the top of the file to disable all instances. 40 | ```C# 41 | #pragma warning disable GU0005 // Use correct argument positions 42 | ``` 43 | 44 | ### Via attribute `[SuppressMessage]`. 45 | 46 | ```C# 47 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Gu.Analyzers.Correctness", 48 | "GU0005:Use correct argument positions", 49 | Justification = "Reason...")] 50 | ``` 51 | -------------------------------------------------------------------------------- /documentation/GU0006.md: -------------------------------------------------------------------------------- 1 | # GU0006 2 | ## Use nameof 3 | 4 | | Topic | Value 5 | | :-- | :-- 6 | | Id | GU0006 7 | | Severity | Hidden 8 | | Enabled | True 9 | | Category | Gu.Analyzers.Correctness 10 | | Code | [StringLiteralExpressionAnalyzer](https://github.com/GuOrg/Gu.Analyzers/blob/master/Gu.Analyzers/Analyzers/StringLiteralExpressionAnalyzer.cs) 11 | 12 | ## Description 13 | 14 | Use nameof. 15 | 16 | ## Motivation 17 | 18 | Using nameof is more refactoring friendly than string literals. 19 | In the following snippet nameof is preferable for parameter name. 20 | 21 | ```C# 22 | public class C 23 | { 24 | public void M(object value) 25 | { 26 | if (value is null) 27 | { 28 | throw new ArgumentNullException(""value""); 29 | } 30 | } 31 | } 32 | ``` 33 | 34 | ## How to fix violations 35 | 36 | Use the cod fix or manually change it to: 37 | 38 | ```C# 39 | public class C 40 | { 41 | public void M(object value) 42 | { 43 | if (value is null) 44 | { 45 | throw new ArgumentNullException(nameof(value)); 46 | } 47 | } 48 | } 49 | ``` 50 | 51 | 52 | ## Configure severity 53 | 54 | ### Via ruleset file. 55 | 56 | Configure the severity per project, for more info see [MSDN](https://msdn.microsoft.com/en-us/library/dd264949.aspx). 57 | 58 | ### Via #pragma directive. 59 | ```C# 60 | #pragma warning disable GU0006 // Use nameof 61 | Code violating the rule here 62 | #pragma warning restore GU0006 // Use nameof 63 | ``` 64 | 65 | Or put this at the top of the file to disable all instances. 66 | ```C# 67 | #pragma warning disable GU0006 // Use nameof 68 | ``` 69 | 70 | ### Via attribute `[SuppressMessage]`. 71 | 72 | ```C# 73 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Gu.Analyzers.Correctness", 74 | "GU0006:Use nameof", 75 | Justification = "Reason...")] 76 | ``` 77 | 78 | -------------------------------------------------------------------------------- /documentation/GU0008.md: -------------------------------------------------------------------------------- 1 | # GU0008 2 | ## Avoid relay properties 3 | 4 | | Topic | Value 5 | | :-- | :-- 6 | | Id | GU0008 7 | | Severity | Hidden 8 | | Enabled | False 9 | | Category | Gu.Analyzers.Correctness 10 | | Code | [PropertyDeclarationAnalyzer](https://github.com/GuOrg/Gu.Analyzers/blob/master/Gu.Analyzers/Analyzers/PropertyDeclarationAnalyzer.cs) 11 | 12 | ## Description 13 | 14 | Avoid relay properties. 15 | 16 | ## Motivation 17 | 18 | This is just a refactoring aid and disabled by default. 19 | Relay properties can be a sign of service locator complicating the graph. Example: 20 | 21 | ```C# 22 | public class Foo 23 | { 24 | private readonly Bar bar; 25 | 26 | public Foo() 27 | { 28 | this.bar = new Bar(); 29 | } 30 | 31 | public int Value => this.bar.Value; 32 | } 33 | ``` 34 | 35 | ## How to fix violations 36 | 37 | Where appropriate inject Bar where it is needed. 38 | 39 | 40 | ## Configure severity 41 | 42 | ### Via ruleset file. 43 | 44 | Configure the severity per project, for more info see [MSDN](https://msdn.microsoft.com/en-us/library/dd264949.aspx). 45 | 46 | ### Via #pragma directive. 47 | ```C# 48 | #pragma warning disable GU0008 // Avoid relay properties 49 | Code violating the rule here 50 | #pragma warning restore GU0008 // Avoid relay properties 51 | ``` 52 | 53 | Or put this at the top of the file to disable all instances. 54 | ```C# 55 | #pragma warning disable GU0008 // Avoid relay properties 56 | ``` 57 | 58 | ### Via attribute `[SuppressMessage]`. 59 | 60 | ```C# 61 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Gu.Analyzers.Correctness", 62 | "GU0008:Avoid relay properties", 63 | Justification = "Reason...")] 64 | ``` 65 | -------------------------------------------------------------------------------- /documentation/GU0009.md: -------------------------------------------------------------------------------- 1 | # GU0009 2 | ## Name the boolean argument 3 | 4 | | Topic | Value 5 | | :-- | :-- 6 | | Id | GU0009 7 | | Severity | Warning 8 | | Enabled | True 9 | | Category | Gu.Analyzers.Correctness 10 | | Code | [ArgumentAnalyzer](https://github.com/GuOrg/Gu.Analyzers/blob/master/Gu.Analyzers/Analyzers/ArgumentAnalyzer.cs) 11 | 12 | ## Description 13 | 14 | The unnamed boolean argument aren't obvious about their purpose. Consider naming the boolean argument for clarity. 15 | 16 | ## Motivation 17 | 18 | ADD MOTIVATION HERE 19 | 20 | ## How to fix violations 21 | 22 | ADD HOW TO FIX VIOLATIONS HERE 23 | 24 | 25 | ## Configure severity 26 | 27 | ### Via ruleset file. 28 | 29 | Configure the severity per project, for more info see [MSDN](https://msdn.microsoft.com/en-us/library/dd264949.aspx). 30 | 31 | ### Via #pragma directive. 32 | ```C# 33 | #pragma warning disable GU0009 // Name the boolean argument 34 | Code violating the rule here 35 | #pragma warning restore GU0009 // Name the boolean argument 36 | ``` 37 | 38 | Or put this at the top of the file to disable all instances. 39 | ```C# 40 | #pragma warning disable GU0009 // Name the boolean argument 41 | ``` 42 | 43 | ### Via attribute `[SuppressMessage]`. 44 | 45 | ```C# 46 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Gu.Analyzers.Correctness", 47 | "GU0009:Name the boolean argument", 48 | Justification = "Reason...")] 49 | ``` 50 | -------------------------------------------------------------------------------- /documentation/GU0010.md: -------------------------------------------------------------------------------- 1 | # GU0010 2 | ## Assigning same value 3 | 4 | | Topic | Value 5 | | :-- | :-- 6 | | Id | GU0010 7 | | Severity | Error 8 | | Enabled | True 9 | | Category | Gu.Analyzers.Correctness 10 | | Code | [SimpleAssignmentAnalyzer](https://github.com/GuOrg/Gu.Analyzers/blob/master/Gu.Analyzers/Analyzers/SimpleAssignmentAnalyzer.cs) 11 | 12 | ## Description 13 | 14 | Assigning same value does not make sense and is sign of a bug. 15 | 16 | ## Motivation 17 | 18 | While not a common bug this happens: 19 | 20 | ```C# 21 | public class Foo 22 | { 23 | public Foo(int a) 24 | { 25 | this.A = A; 26 | } 27 | 28 | public int A { get; private set; } 29 | } 30 | ``` 31 | 32 | ## How to fix violations 33 | 34 | You probably meant: 35 | 36 | ```C# 37 | public class Foo 38 | { 39 | public Foo(int a) 40 | { 41 | this.A = a; 42 | } 43 | 44 | public int A { get; private set; } 45 | } 46 | ``` 47 | 48 | 49 | ## Configure severity 50 | 51 | ### Via ruleset file. 52 | 53 | Configure the severity per project, for more info see [MSDN](https://msdn.microsoft.com/en-us/library/dd264949.aspx). 54 | 55 | ### Via #pragma directive. 56 | ```C# 57 | #pragma warning disable GU0010 // Assigning same value 58 | Code violating the rule here 59 | #pragma warning restore GU0010 // Assigning same value 60 | ``` 61 | 62 | Or put this at the top of the file to disable all instances. 63 | ```C# 64 | #pragma warning disable GU0010 // Assigning same value 65 | ``` 66 | 67 | ### Via attribute `[SuppressMessage]`. 68 | 69 | ```C# 70 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Gu.Analyzers.Correctness", 71 | "GU0010:Assigning same value", 72 | Justification = "Reason...")] 73 | ``` 74 | -------------------------------------------------------------------------------- /documentation/GU0012.md: -------------------------------------------------------------------------------- 1 | # GU0012 2 | ## Check if parameter is null 3 | 4 | | Topic | Value 5 | | :-- | :-- 6 | | Id | GU0012 7 | | Severity | Hidden 8 | | Enabled | True 9 | | Category | Gu.Analyzers.Correctness 10 | | Code | [ParameterAnalyzer](https://github.com/GuOrg/Gu.Analyzers/blob/master/Gu.Analyzers/Analyzers/ParameterAnalyzer.cs) 11 | | | [SimpleAssignmentAnalyzer](https://github.com/GuOrg/Gu.Analyzers/blob/master/Gu.Analyzers/Analyzers/SimpleAssignmentAnalyzer.cs) 12 | 13 | ## Description 14 | 15 | Check if parameter is null. 16 | 17 | ## Motivation 18 | 19 | ADD MOTIVATION HERE 20 | 21 | ## How to fix violations 22 | 23 | ADD HOW TO FIX VIOLATIONS HERE 24 | 25 | 26 | ## Configure severity 27 | 28 | ### Via ruleset file. 29 | 30 | Configure the severity per project, for more info see [MSDN](https://msdn.microsoft.com/en-us/library/dd264949.aspx). 31 | 32 | ### Via #pragma directive. 33 | ```C# 34 | #pragma warning disable GU0012 // Check if parameter is null 35 | Code violating the rule here 36 | #pragma warning restore GU0012 // Check if parameter is null 37 | ``` 38 | 39 | Or put this at the top of the file to disable all instances. 40 | ```C# 41 | #pragma warning disable GU0012 // Check if parameter is null 42 | ``` 43 | 44 | ### Via attribute `[SuppressMessage]`. 45 | 46 | ```C# 47 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Gu.Analyzers.Correctness", 48 | "GU0012:Check if parameter is null", 49 | Justification = "Reason...")] 50 | ``` 51 | -------------------------------------------------------------------------------- /documentation/GU0013.md: -------------------------------------------------------------------------------- 1 | # GU0013 2 | ## Throw for correct parameter 3 | 4 | | Topic | Value 5 | | :-- | :-- 6 | | Id | GU0013 7 | | Severity | Warning 8 | | Enabled | True 9 | | Category | Gu.Analyzers.Correctness 10 | | Code | [ObjectCreationAnalyzer](https://github.com/GuOrg/Gu.Analyzers/blob/master/Gu.Analyzers/Analyzers/ObjectCreationAnalyzer.cs) 11 | 12 | ## Description 13 | 14 | Throw for correct parameter. 15 | 16 | ## Motivation 17 | 18 | In the below code the wrong name is used. 19 | ```cs 20 | public Foo(string bar) 21 | { 22 | this.bar = bar ?? throw new ArgumentNullException(nameof(Foo)); 23 | } 24 | ``` 25 | 26 | ## How to fix violations 27 | 28 | Use the code fix to change it to: 29 | 30 | ```cs 31 | public Foo(string bar) 32 | { 33 | this.bar = bar ?? throw new ArgumentNullException(nameof(bar)); 34 | } 35 | ``` 36 | 37 | 38 | ## Configure severity 39 | 40 | ### Via ruleset file. 41 | 42 | Configure the severity per project, for more info see [MSDN](https://msdn.microsoft.com/en-us/library/dd264949.aspx). 43 | 44 | ### Via #pragma directive. 45 | ```C# 46 | #pragma warning disable GU0013 // Throw for correct parameter 47 | Code violating the rule here 48 | #pragma warning restore GU0013 // Throw for correct parameter 49 | ``` 50 | 51 | Or put this at the top of the file to disable all instances. 52 | ```C# 53 | #pragma warning disable GU0013 // Throw for correct parameter 54 | ``` 55 | 56 | ### Via attribute `[SuppressMessage]`. 57 | 58 | ```C# 59 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Gu.Analyzers.Correctness", 60 | "GU0013:Throw for correct parameter", 61 | Justification = "Reason...")] 62 | ``` 63 | -------------------------------------------------------------------------------- /documentation/GU0014.md: -------------------------------------------------------------------------------- 1 | # GU0014 2 | ## Prefer using parameter 3 | 4 | | Topic | Value 5 | | :-- | :-- 6 | | Id | GU0014 7 | | Severity | Warning 8 | | Enabled | True 9 | | Category | Gu.Analyzers.Correctness 10 | | Code | [ConstructorAnalyzer](https://github.com/GuOrg/Gu.Analyzers/blob/master/Gu.Analyzers/Analyzers/ConstructorAnalyzer.cs) 11 | 12 | ## Description 13 | 14 | Prefer using parameter. 15 | 16 | ## Motivation 17 | 18 | ADD MOTIVATION HERE 19 | 20 | ## How to fix violations 21 | 22 | ADD HOW TO FIX VIOLATIONS HERE 23 | 24 | 25 | ## Configure severity 26 | 27 | ### Via ruleset file. 28 | 29 | Configure the severity per project, for more info see [MSDN](https://msdn.microsoft.com/en-us/library/dd264949.aspx). 30 | 31 | ### Via #pragma directive. 32 | ```C# 33 | #pragma warning disable GU0014 // Prefer using parameter 34 | Code violating the rule here 35 | #pragma warning restore GU0014 // Prefer using parameter 36 | ``` 37 | 38 | Or put this at the top of the file to disable all instances. 39 | ```C# 40 | #pragma warning disable GU0014 // Prefer using parameter 41 | ``` 42 | 43 | ### Via attribute `[SuppressMessage]`. 44 | 45 | ```C# 46 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Gu.Analyzers.Correctness", 47 | "GU0014:Prefer using parameter", 48 | Justification = "Reason...")] 49 | ``` 50 | -------------------------------------------------------------------------------- /documentation/GU0015.md: -------------------------------------------------------------------------------- 1 | # GU0015 2 | ## Don't assign same more than once 3 | 4 | | Topic | Value 5 | | :-- | :-- 6 | | Id | GU0015 7 | | Severity | Warning 8 | | Enabled | False 9 | | Category | Gu.Analyzers.Correctness 10 | | Code | [SimpleAssignmentAnalyzer](https://github.com/GuOrg/Gu.Analyzers/blob/master/Gu.Analyzers/Analyzers/SimpleAssignmentAnalyzer.cs) 11 | 12 | ## Description 13 | 14 | Don't assign same more than once. 15 | 16 | ## Motivation 17 | 18 | Assigning more than once in the same scope makes reasoning harder. 19 | ```cs 20 | public class Foo 21 | { 22 | public Foo() 23 | { 24 | this.Bar = 1; 25 | ... 26 | this.Bar = 2; 27 | ... 28 | } 29 | 30 | public int Bar { get; } 31 | } 32 | ``` 33 | 34 | ## How to fix violations 35 | 36 | Assign only once. 37 | 38 | 39 | ## Configure severity 40 | 41 | ### Via ruleset file. 42 | 43 | Configure the severity per project, for more info see [MSDN](https://msdn.microsoft.com/en-us/library/dd264949.aspx). 44 | 45 | ### Via #pragma directive. 46 | ```C# 47 | #pragma warning disable GU0015 // Don't assign same more than once 48 | Code violating the rule here 49 | #pragma warning restore GU0015 // Don't assign same more than once 50 | ``` 51 | 52 | Or put this at the top of the file to disable all instances. 53 | ```C# 54 | #pragma warning disable GU0015 // Don't assign same more than once 55 | ``` 56 | 57 | ### Via attribute `[SuppressMessage]`. 58 | 59 | ```C# 60 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Gu.Analyzers.Correctness", 61 | "GU0015:Don't assign same more than once", 62 | Justification = "Reason...")] 63 | ``` 64 | -------------------------------------------------------------------------------- /documentation/GU0016.md: -------------------------------------------------------------------------------- 1 | # GU0016 2 | ## Prefer lambda 3 | 4 | | Topic | Value 5 | | :-- | :-- 6 | | Id | GU0016 7 | | Severity | Info 8 | | Enabled | False 9 | | Category | Gu.Analyzers.Correctness 10 | | Code | [MethodGroupAnalyzer](https://github.com/GuOrg/Gu.Analyzers/blob/master/Gu.Analyzers/Analyzers/MethodGroupAnalyzer.cs) 11 | 12 | ## Description 13 | 14 | Prefer lambda to reduce allocations. 15 | 16 | ## Motivation 17 | 18 | The generated IL does not cache the delegate. 19 | https://github.com/dotnet/roslyn/issues/5835 20 | 21 | ### Remark 22 | Note that method group is nicer syntax, fewer ways to get things wrong. Hence the analyzer is default disabled. 23 | Enable it for performance sensitive code. 24 | 25 | ## How to fix violations 26 | 27 | Use the code fix. 28 | 29 | 30 | ## Configure severity 31 | 32 | ### Via ruleset file. 33 | 34 | Configure the severity per project, for more info see [MSDN](https://msdn.microsoft.com/en-us/library/dd264949.aspx). 35 | 36 | ### Via #pragma directive. 37 | ```C# 38 | #pragma warning disable GU0016 // Prefer lambda 39 | Code violating the rule here 40 | #pragma warning restore GU0016 // Prefer lambda 41 | ``` 42 | 43 | Or put this at the top of the file to disable all instances. 44 | ```C# 45 | #pragma warning disable GU0016 // Prefer lambda 46 | ``` 47 | 48 | ### Via attribute `[SuppressMessage]`. 49 | 50 | ```C# 51 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Gu.Analyzers.Correctness", 52 | "GU0016:Prefer lambda", 53 | Justification = "Reason...")] 54 | ``` 55 | -------------------------------------------------------------------------------- /documentation/GU0017.md: -------------------------------------------------------------------------------- 1 | # GU0017 2 | ## Don't use discarded 3 | 4 | | Topic | Value 5 | | :-- | :-- 6 | | Id | GU0017 7 | | Severity | Warning 8 | | Enabled | True 9 | | Category | Gu.Analyzers.Correctness 10 | | Code | [IdentifierNameAnalyzer](https://github.com/GuOrg/Gu.Analyzers/blob/master/Gu.Analyzers/Analyzers/IdentifierNameAnalyzer.cs) 11 | 12 | 13 | ## Description 14 | 15 | Don't use discarded. 16 | 17 | ## Motivation 18 | 19 | ADD MOTIVATION HERE 20 | 21 | ## How to fix violations 22 | 23 | ADD HOW TO FIX VIOLATIONS HERE 24 | 25 | 26 | ## Configure severity 27 | 28 | ### Via ruleset file. 29 | 30 | Configure the severity per project, for more info see [MSDN](https://msdn.microsoft.com/en-us/library/dd264949.aspx). 31 | 32 | ### Via #pragma directive. 33 | ```C# 34 | #pragma warning disable GU0017 // Don't use discarded 35 | Code violating the rule here 36 | #pragma warning restore GU0017 // Don't use discarded 37 | ``` 38 | 39 | Or put this at the top of the file to disable all instances. 40 | ```C# 41 | #pragma warning disable GU0017 // Don't use discarded 42 | ``` 43 | 44 | ### Via attribute `[SuppressMessage]`. 45 | 46 | ```C# 47 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Gu.Analyzers.Correctness", 48 | "GU0017:Don't use discarded", 49 | Justification = "Reason...")] 50 | ``` 51 | -------------------------------------------------------------------------------- /documentation/GU0018a.md: -------------------------------------------------------------------------------- 1 | # GU0018a 2 | ## Name mock 3 | 4 | | Topic | Value 5 | | :-- | :-- 6 | | Id | GU0018a 7 | | Severity | Warning 8 | | Enabled | True 9 | | Category | Gu.Analyzers.Correctness 10 | | Code | [VariableDeclaratorAnalyzer](https://github.com/GuOrg/Gu.Analyzers/blob/master/Gu.Analyzers/Analyzers/VariableDeclaratorAnalyzer.cs) 11 | 12 | 13 | ## Description 14 | 15 | Name mock. 16 | 17 | ## Motivation 18 | 19 | namespace N 20 | { 21 | using Moq; 22 | using NUnit.Framework; 23 | 24 | public class C 25 | { 26 | [Test] 27 | public void M() 28 | { 29 | var ↓wrongName = new Mock(MockBehavior.Strict); 30 | } 31 | } 32 | } 33 | 34 | ## How to fix violations 35 | 36 | namespace N 37 | { 38 | using Moq; 39 | using NUnit.Framework; 40 | 41 | public class C 42 | { 43 | [Test] 44 | public void M() 45 | { 46 | var plcMock = new Mock(MockBehavior.Strict); 47 | } 48 | } 49 | } 50 | 51 | 52 | ## Configure severity 53 | 54 | ### Via ruleset file. 55 | 56 | Configure the severity per project, for more info see [MSDN](https://msdn.microsoft.com/en-us/library/dd264949.aspx). 57 | 58 | ### Via #pragma directive. 59 | ```C# 60 | #pragma warning disable GU0018a // Name mock 61 | Code violating the rule here 62 | #pragma warning restore GU0018a // Name mock 63 | ``` 64 | 65 | Or put this at the top of the file to disable all instances. 66 | ```C# 67 | #pragma warning disable GU0018a // Name mock 68 | ``` 69 | 70 | ### Via attribute `[SuppressMessage]`. 71 | 72 | ```C# 73 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Gu.Analyzers.Correctness", 74 | "GU0018a:Name mock", 75 | Justification = "Reason...")] 76 | ``` 77 | -------------------------------------------------------------------------------- /documentation/GU0018b.md: -------------------------------------------------------------------------------- 1 | # GU0018b 2 | ## Name mock 3 | 4 | | Topic | Value 5 | | :-- | :-- 6 | | Id | GU0018b 7 | | Severity | Hidden 8 | | Enabled | True 9 | | Category | Gu.Analyzers.Correctness 10 | | Code | [VariableDeclaratorAnalyzer](https://github.com/GuOrg/Gu.Analyzers/blob/master/Gu.Analyzers/Analyzers/VariableDeclaratorAnalyzer.cs) 11 | 12 | 13 | ## Description 14 | 15 | Name mock. 16 | 17 | ## Motivation 18 | 19 | namespace N 20 | { 21 | using Moq; 22 | using NUnit.Framework; 23 | 24 | public class C 25 | { 26 | [Test] 27 | public void M() 28 | { 29 | var ↓mock = new Mock(MockBehavior.Strict); 30 | } 31 | } 32 | } 33 | 34 | ## How to fix violations 35 | 36 | namespace N 37 | { 38 | using Moq; 39 | using NUnit.Framework; 40 | 41 | public class C 42 | { 43 | [Test] 44 | public void M() 45 | { 46 | var plcMock = new Mock(MockBehavior.Strict); 47 | } 48 | } 49 | } 50 | 51 | 52 | ## Configure severity 53 | 54 | ### Via ruleset file. 55 | 56 | Configure the severity per project, for more info see [MSDN](https://msdn.microsoft.com/en-us/library/dd264949.aspx). 57 | 58 | ### Via #pragma directive. 59 | ```C# 60 | #pragma warning disable GU0018b // Name mock 61 | Code violating the rule here 62 | #pragma warning restore GU0018b // Name mock 63 | ``` 64 | 65 | Or put this at the top of the file to disable all instances. 66 | ```C# 67 | #pragma warning disable GU0018b // Name mock 68 | ``` 69 | 70 | ### Via attribute `[SuppressMessage]`. 71 | 72 | ```C# 73 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Gu.Analyzers.Correctness", 74 | "GU0018b:Name mock", 75 | Justification = "Reason...")] 76 | ``` 77 | -------------------------------------------------------------------------------- /documentation/GU0019.md: -------------------------------------------------------------------------------- 1 | # GU0019 2 | ## LinqOrDefault when IEnumerable 3 | 4 | | Topic | Value 5 | | :-- | :-- 6 | | Id | GU0019 7 | | Severity | Warning 8 | | Enabled | True 9 | | Category | Gu.Analyzers.Correctness 10 | | Code | [InvocationAnalyzer](https://github.com/GuOrg/Gu.Analyzers/blob/master/Gu.Analyzers/Analyzers/InvocationAnalyzer.cs) 11 | 12 | 13 | ## Description 14 | 15 | Methods like FirstOrDefault is a common regression when changing from class to struct. 16 | 17 | ## Motivation 18 | 19 | Code like below has frequent regressions when refactoring from `class` to `struct` 20 | 21 | ```cs 22 | if (xs.FirstOrDefault() is { } x) 23 | { 24 | ... 25 | } 26 | 27 | ## How to fix violations 28 | 29 | Adding `FirstOrNull()` is clearer. 30 | 31 | ```cs 32 | if (xs.FirstOrNull() is { } x) 33 | { 34 | ... 35 | } 36 | 37 | 38 | ## Configure severity 39 | 40 | ### Via ruleset file. 41 | 42 | Configure the severity per project, for more info see [MSDN](https://msdn.microsoft.com/en-us/library/dd264949.aspx). 43 | 44 | ### Via #pragma directive. 45 | ```C# 46 | #pragma warning disable GU0019 // LinqOrDefault when IEnumerable 47 | Code violating the rule here 48 | #pragma warning restore GU0019 // LinqOrDefault when IEnumerable 49 | ``` 50 | 51 | Or put this at the top of the file to disable all instances. 52 | ```C# 53 | #pragma warning disable GU0019 // LinqOrDefault when IEnumerable 54 | ``` 55 | 56 | ### Via attribute `[SuppressMessage]`. 57 | 58 | ```C# 59 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Gu.Analyzers.Correctness", 60 | "GU0019:LinqOrDefault when IEnumerable", 61 | Justification = "Reason...")] 62 | ``` 63 | -------------------------------------------------------------------------------- /documentation/GU0020.md: -------------------------------------------------------------------------------- 1 | # GU0020 2 | ## Sort properties 3 | 4 | | Topic | Value 5 | | :-- | :-- 6 | | Id | GU0020 7 | | Severity | Hidden 8 | | Enabled | True 9 | | Category | Gu.Analyzers.Correctness 10 | | Code | [GU0020SortProperties](https://github.com/GuOrg/Gu.Analyzers/blob/master/Gu.Analyzers/GU0020SortProperties.cs) 11 | 12 | ## Description 13 | 14 | Sort properties by StyleCop rules then by mutability. 15 | 16 | Order: 17 | 1. get-only 18 | 2. Expression body. 19 | 3. private set;, protected set, internal set, public set. 20 | 21 | ## Motivation 22 | 23 | To make it easier to keep an eye on state if any. 24 | 25 | ## How to fix violations 26 | 27 | Sort the properties. 28 | 29 | 30 | ## Configure severity 31 | 32 | ### Via ruleset file. 33 | 34 | Configure the severity per project, for more info see [MSDN](https://msdn.microsoft.com/en-us/library/dd264949.aspx). 35 | 36 | ### Via #pragma directive. 37 | ```C# 38 | #pragma warning disable GU0020 // Sort properties 39 | Code violating the rule here 40 | #pragma warning restore GU0020 // Sort properties 41 | ``` 42 | 43 | Or put this at the top of the file to disable all instances. 44 | ```C# 45 | #pragma warning disable GU0020 // Sort properties 46 | ``` 47 | 48 | ### Via attribute `[SuppressMessage]`. 49 | 50 | ```C# 51 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Gu.Analyzers.Correctness", 52 | "GU0020:Sort properties", 53 | Justification = "Reason...")] 54 | ``` 55 | -------------------------------------------------------------------------------- /documentation/GU0022.md: -------------------------------------------------------------------------------- 1 | # GU0022 2 | ## Use get-only 3 | 4 | | Topic | Value 5 | | :-- | :-- 6 | | Id | GU0022 7 | | Severity | Hidden 8 | | Enabled | True 9 | | Category | Gu.Analyzers.Correctness 10 | | Code | [GU0022UseGetOnly](https://github.com/GuOrg/Gu.Analyzers/blob/master/Gu.Analyzers/GU0022UseGetOnly.cs) 11 | 12 | ## Description 13 | 14 | Use get-only. 15 | 16 | ## Motivation 17 | 18 | The property is only assigned in constructor or in property initializer and can be made get-only. 19 | 20 | ## How to fix violations 21 | 22 | Use the code fix. 23 | 24 | 25 | ## Configure severity 26 | 27 | ### Via ruleset file. 28 | 29 | Configure the severity per project, for more info see [MSDN](https://msdn.microsoft.com/en-us/library/dd264949.aspx). 30 | 31 | ### Via #pragma directive. 32 | ```C# 33 | #pragma warning disable GU0022 // Use get-only 34 | Code violating the rule here 35 | #pragma warning restore GU0022 // Use get-only 36 | ``` 37 | 38 | Or put this at the top of the file to disable all instances. 39 | ```C# 40 | #pragma warning disable GU0022 // Use get-only 41 | ``` 42 | 43 | ### Via attribute `[SuppressMessage]`. 44 | 45 | ```C# 46 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Gu.Analyzers.Correctness", 47 | "GU0022:Use get-only", 48 | Justification = "Reason...")] 49 | ``` 50 | -------------------------------------------------------------------------------- /documentation/GU0024.md: -------------------------------------------------------------------------------- 1 | # GU0024 2 | ## Seal type with default member 3 | 4 | | Topic | Value 5 | | :-- | :-- 6 | | Id | GU0024 7 | | Severity | Info 8 | | Enabled | True 9 | | Category | Gu.Analyzers.Correctness 10 | | Code | [ClassDeclarationAnalyzer](https://github.com/GuOrg/Gu.Analyzers/blob/master/Gu.Analyzers/Analyzers/ClassDeclarationAnalyzer.cs) 11 | ## Description 12 | 13 | Seal type with default member. 14 | 15 | ## Motivation 16 | 17 | When doing `SomeType.Default` the expectation is to get an instance of type `SomeType`. 18 | 19 | ## How to fix violations 20 | 21 | Use the code fix. 22 | 23 | 24 | ## Configure severity 25 | 26 | ### Via ruleset file. 27 | 28 | Configure the severity per project, for more info see [MSDN](https://msdn.microsoft.com/en-us/library/dd264949.aspx). 29 | 30 | ### Via #pragma directive. 31 | ```C# 32 | #pragma warning disable GU0024 // Seal type with default member 33 | Code violating the rule here 34 | #pragma warning restore GU0024 // Seal type with default member 35 | ``` 36 | 37 | Or put this at the top of the file to disable all instances. 38 | ```C# 39 | #pragma warning disable GU0024 // Seal type with default member 40 | ``` 41 | 42 | ### Via attribute `[SuppressMessage]`. 43 | 44 | ```C# 45 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Gu.Analyzers.Correctness", 46 | "GU0024:Seal type with default member", 47 | Justification = "Reason...")] 48 | ``` 49 | -------------------------------------------------------------------------------- /documentation/GU0025.md: -------------------------------------------------------------------------------- 1 | # GU0025 2 | ## Seal type with overridden equality 3 | 4 | | Topic | Value 5 | | :-- | :-- 6 | | Id | GU0025 7 | | Severity | Info 8 | | Enabled | True 9 | | Category | Gu.Analyzers.Correctness 10 | | Code | [ClassDeclarationAnalyzer](https://github.com/GuOrg/Gu.Analyzers/blob/master/Gu.Analyzers/Analyzers/ClassDeclarationAnalyzer.cs) 11 | 12 | 13 | ## Description 14 | 15 | Seal type with overridden equality. 16 | 17 | ## Motivation 18 | 19 | If `Equals` or `GetHashCode` are overriden it often makes sense to seal the type as subclassing gest messy with equality. 20 | 21 | 22 | ## How to fix violations 23 | 24 | Use the code fix. 25 | 26 | 27 | ## Configure severity 28 | 29 | ### Via ruleset file. 30 | 31 | Configure the severity per project, for more info see [MSDN](https://msdn.microsoft.com/en-us/library/dd264949.aspx). 32 | 33 | ### Via #pragma directive. 34 | ```C# 35 | #pragma warning disable GU0025 // Seal type with overridden equality 36 | Code violating the rule here 37 | #pragma warning restore GU0025 // Seal type with overridden equality 38 | ``` 39 | 40 | Or put this at the top of the file to disable all instances. 41 | ```C# 42 | #pragma warning disable GU0025 // Seal type with overridden equality 43 | ``` 44 | 45 | ### Via attribute `[SuppressMessage]`. 46 | 47 | ```C# 48 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Gu.Analyzers.Correctness", 49 | "GU0025:Seal type with overridden equality", 50 | Justification = "Reason...")] 51 | ``` 52 | -------------------------------------------------------------------------------- /documentation/GU0026.md: -------------------------------------------------------------------------------- 1 | # GU0026 2 | ## Range operator allocates 3 | 4 | | Topic | Value 5 | | :-- | :-- 6 | | Id | GU0026 7 | | Severity | Warning 8 | | Enabled | True 9 | | Category | Gu.Analyzers.Correctness 10 | | Code | [RangeAnalyzer](https://github.com/GuOrg/Gu.Analyzers/blob/master/Gu.Analyzers/Analyzers/RangeAnalyzer.cs) 11 | 12 | 13 | ## Description 14 | 15 | Range operator on array or string allocates. 16 | 17 | ## Motivation 18 | 19 | `xs[1..]` returns a new array not a span of the original array which is different from `xs[1..]` when a span which can be confusing. 20 | 21 | ## How to fix violations 22 | 23 | One way is `xs.AsSpan()[1..]` 24 | 25 | 26 | ## Configure severity 27 | 28 | ### Via ruleset file. 29 | 30 | Configure the severity per project, for more info see [MSDN](https://msdn.microsoft.com/en-us/library/dd264949.aspx). 31 | 32 | ### Via #pragma directive. 33 | ```C# 34 | #pragma warning disable GU0026 // Range operator allocates 35 | Code violating the rule here 36 | #pragma warning restore GU0026 // Range operator allocates 37 | ``` 38 | 39 | Or put this at the top of the file to disable all instances. 40 | ```C# 41 | #pragma warning disable GU0026 // Range operator allocates 42 | ``` 43 | 44 | ### Via attribute `[SuppressMessage]`. 45 | 46 | ```C# 47 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Gu.Analyzers.Correctness", 48 | "GU0026:Range operator allocates", 49 | Justification = "Reason...")] 50 | ``` 51 | -------------------------------------------------------------------------------- /documentation/GU0050.md: -------------------------------------------------------------------------------- 1 | # GU0050 2 | ## Ignore events when serializing 3 | 4 | | Topic | Value 5 | | :-- | :-- 6 | | Id | GU0050 7 | | Severity | Warning 8 | | Enabled | True 9 | | Category | Gu.Analyzers.Correctness 10 | | Code | [GU0050IgnoreEventsWhenSerializing](https://github.com/GuOrg/Gu.Analyzers/blob/master/Gu.Analyzers/GU0050IgnoreEventsWhenSerializing.cs) 11 | 12 | ## Description 13 | 14 | Ignore events when serializing. 15 | 16 | ## Motivation 17 | 18 | ADD MOTIVATION HERE 19 | 20 | ## How to fix violations 21 | 22 | ADD HOW TO FIX VIOLATIONS HERE 23 | 24 | 25 | ## Configure severity 26 | 27 | ### Via ruleset file. 28 | 29 | Configure the severity per project, for more info see [MSDN](https://msdn.microsoft.com/en-us/library/dd264949.aspx). 30 | 31 | ### Via #pragma directive. 32 | ```C# 33 | #pragma warning disable GU0050 // Ignore events when serializing 34 | Code violating the rule here 35 | #pragma warning restore GU0050 // Ignore events when serializing 36 | ``` 37 | 38 | Or put this at the top of the file to disable all instances. 39 | ```C# 40 | #pragma warning disable GU0050 // Ignore events when serializing 41 | ``` 42 | 43 | ### Via attribute `[SuppressMessage]`. 44 | 45 | ```C# 46 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Gu.Analyzers.Correctness", 47 | "GU0050:Ignore events when serializing", 48 | Justification = "Reason...")] 49 | ``` 50 | -------------------------------------------------------------------------------- /documentation/GU0051.md: -------------------------------------------------------------------------------- 1 | # GU0051 2 | ## Cache the XmlSerializer 3 | 4 | | Topic | Value 5 | | :-- | :-- 6 | | Id | GU0051 7 | | Severity | Warning 8 | | Enabled | True 9 | | Category | Gu.Analyzers.Correctness 10 | | Code | [GU0051XmlSerializerNotCached](https://github.com/GuOrg/Gu.Analyzers/blob/master/Gu.Analyzers/GU0051XmlSerializerNotCached.cs) 11 | 12 | ## Description 13 | 14 | This constructor loads assemblies in non-GC memory, which may cause memory leaks. 15 | 16 | ## Motivation 17 | 18 | ADD MOTIVATION HERE 19 | 20 | ## How to fix violations 21 | 22 | ADD HOW TO FIX VIOLATIONS HERE 23 | 24 | 25 | ## Configure severity 26 | 27 | ### Via ruleset file. 28 | 29 | Configure the severity per project, for more info see [MSDN](https://msdn.microsoft.com/en-us/library/dd264949.aspx). 30 | 31 | ### Via #pragma directive. 32 | ```C# 33 | #pragma warning disable GU0051 // Cache the XmlSerializer 34 | Code violating the rule here 35 | #pragma warning restore GU0051 // Cache the XmlSerializer 36 | ``` 37 | 38 | Or put this at the top of the file to disable all instances. 39 | ```C# 40 | #pragma warning disable GU0051 // Cache the XmlSerializer 41 | ``` 42 | 43 | ### Via attribute `[SuppressMessage]`. 44 | 45 | ```C# 46 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Gu.Analyzers.Correctness", 47 | "GU0051:Cache the XmlSerializer", 48 | Justification = "Reason...")] 49 | ``` 50 | -------------------------------------------------------------------------------- /documentation/GU0052.md: -------------------------------------------------------------------------------- 1 | # GU0052 2 | ## Mark exception with [Serializable] 3 | 4 | | Topic | Value 5 | | :-- | :-- 6 | | Id | GU0052 7 | | Severity | Warning 8 | | Enabled | True 9 | | Category | Gu.Analyzers.Correctness 10 | | Code | [GU0052ExceptionShouldBeSerializable](https://github.com/GuOrg/Gu.Analyzers/blob/master/Gu.Analyzers/GU0052ExceptionShouldBeSerializable.cs) 11 | 12 | ## Description 13 | 14 | Mark exception with [Serializable]. 15 | 16 | ## Motivation 17 | 18 | ADD MOTIVATION HERE 19 | 20 | ## How to fix violations 21 | 22 | ADD HOW TO FIX VIOLATIONS HERE 23 | 24 | 25 | ## Configure severity 26 | 27 | ### Via ruleset file. 28 | 29 | Configure the severity per project, for more info see [MSDN](https://msdn.microsoft.com/en-us/library/dd264949.aspx). 30 | 31 | ### Via #pragma directive. 32 | ```C# 33 | #pragma warning disable GU0052 // Mark exception with [Serializable] 34 | Code violating the rule here 35 | #pragma warning restore GU0052 // Mark exception with [Serializable] 36 | ``` 37 | 38 | Or put this at the top of the file to disable all instances. 39 | ```C# 40 | #pragma warning disable GU0052 // Mark exception with [Serializable] 41 | ``` 42 | 43 | ### Via attribute `[SuppressMessage]`. 44 | 45 | ```C# 46 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Gu.Analyzers.Correctness", 47 | "GU0052:Mark exception with [Serializable]", 48 | Justification = "Reason...")] 49 | ``` 50 | -------------------------------------------------------------------------------- /documentation/GU0060.md: -------------------------------------------------------------------------------- 1 | # GU0060 2 | ## Enum member value conflict 3 | 4 | | Topic | Value 5 | | :-- | :-- 6 | | Id | GU0060 7 | | Severity | Warning 8 | | Enabled | True 9 | | Category | Gu.Analyzers.Correctness 10 | | Code | [GU0060EnumMemberValueConflictsWithAnother](https://github.com/GuOrg/Gu.Analyzers/blob/master/Gu.Analyzers/GU0060EnumMemberValueConflictsWithAnother.cs) 11 | 12 | ## Description 13 | 14 | The enum member has a value shared with the other enum member, but it's not explicitly declared as its alias. To fix this, assign a enum member. 15 | 16 | ## Motivation 17 | 18 | ADD MOTIVATION HERE 19 | 20 | ## How to fix violations 21 | 22 | ADD HOW TO FIX VIOLATIONS HERE 23 | 24 | 25 | ## Configure severity 26 | 27 | ### Via ruleset file. 28 | 29 | Configure the severity per project, for more info see [MSDN](https://msdn.microsoft.com/en-us/library/dd264949.aspx). 30 | 31 | ### Via #pragma directive. 32 | ```C# 33 | #pragma warning disable GU0060 // Enum member value conflict 34 | Code violating the rule here 35 | #pragma warning restore GU0060 // Enum member value conflict 36 | ``` 37 | 38 | Or put this at the top of the file to disable all instances. 39 | ```C# 40 | #pragma warning disable GU0060 // Enum member value conflict 41 | ``` 42 | 43 | ### Via attribute `[SuppressMessage]`. 44 | 45 | ```C# 46 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Gu.Analyzers.Correctness", 47 | "GU0060:Enum member value conflict", 48 | Justification = "Reason...")] 49 | ``` 50 | -------------------------------------------------------------------------------- /documentation/GU0061.md: -------------------------------------------------------------------------------- 1 | # GU0061 2 | ## Enum member value out of range 3 | 4 | | Topic | Value 5 | | :-- | :-- 6 | | Id | GU0061 7 | | Severity | Warning 8 | | Enabled | True 9 | | Category | Gu.Analyzers.Correctness 10 | | Code | [GU0061EnumMemberValueOutOfRange](https://github.com/GuOrg/Gu.Analyzers/blob/master/Gu.Analyzers/GU0061EnumMemberValueOutOfRange.cs) 11 | 12 | 13 | ## Description 14 | 15 | The enum member value will overflow at runtime. Probably not intended. Change enum type to long (int is default). 16 | 17 | ## Motivation 18 | 19 | ADD MOTIVATION HERE 20 | 21 | ## How to fix violations 22 | 23 | ADD HOW TO FIX VIOLATIONS HERE 24 | 25 | 26 | ## Configure severity 27 | 28 | ### Via ruleset file. 29 | 30 | Configure the severity per project, for more info see [MSDN](https://msdn.microsoft.com/en-us/library/dd264949.aspx). 31 | 32 | ### Via #pragma directive. 33 | ```C# 34 | #pragma warning disable GU0061 // Enum member value out of range 35 | Code violating the rule here 36 | #pragma warning restore GU0061 // Enum member value out of range 37 | ``` 38 | 39 | Or put this at the top of the file to disable all instances. 40 | ```C# 41 | #pragma warning disable GU0061 // Enum member value out of range 42 | ``` 43 | 44 | ### Via attribute `[SuppressMessage]`. 45 | 46 | ```C# 47 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Gu.Analyzers.Correctness", 48 | "GU0061:Enum member value out of range", 49 | Justification = "Reason...")] 50 | ``` 51 | -------------------------------------------------------------------------------- /documentation/GU0070.md: -------------------------------------------------------------------------------- 1 | # GU0070 2 | ## Default-constructed value type with no useful default 3 | 4 | | Topic | Value 5 | | :-- | :-- 6 | | Id | GU0070 7 | | Severity | Warning 8 | | Enabled | True 9 | | Category | Gu.Analyzers.Correctness 10 | | Code | [GU0070DefaultConstructedValueTypeWithNoUsefulDefault](https://github.com/GuOrg/Gu.Analyzers/blob/master/Gu.Analyzers/GU0070DefaultConstructedValueTypeWithNoUsefulDefault.cs) 11 | 12 | ## Description 13 | 14 | Types declared with struct must have a default constructor, even if there is no semantically sensible default value for that type. Examples include System.Guid and System.DateTime. 15 | 16 | ## Motivation 17 | 18 | ADD MOTIVATION HERE 19 | 20 | ## How to fix violations 21 | 22 | ADD HOW TO FIX VIOLATIONS HERE 23 | 24 | 25 | ## Configure severity 26 | 27 | ### Via ruleset file. 28 | 29 | Configure the severity per project, for more info see [MSDN](https://msdn.microsoft.com/en-us/library/dd264949.aspx). 30 | 31 | ### Via #pragma directive. 32 | ```C# 33 | #pragma warning disable GU0070 // Default-constructed value type with no useful default 34 | Code violating the rule here 35 | #pragma warning restore GU0070 // Default-constructed value type with no useful default 36 | ``` 37 | 38 | Or put this at the top of the file to disable all instances. 39 | ```C# 40 | #pragma warning disable GU0070 // Default-constructed value type with no useful default 41 | ``` 42 | 43 | ### Via attribute `[SuppressMessage]`. 44 | 45 | ```C# 46 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Gu.Analyzers.Correctness", 47 | "GU0070:Default-constructed value type with no useful default", 48 | Justification = "Reason...")] 49 | ``` 50 | -------------------------------------------------------------------------------- /documentation/GU0071.md: -------------------------------------------------------------------------------- 1 | # GU0071 2 | ## Implicit casting done by the foreach 3 | 4 | | Topic | Value 5 | | :-- | :-- 6 | | Id | GU0071 7 | | Severity | Warning 8 | | Enabled | True 9 | | Category | Gu.Analyzers.Correctness 10 | | Code | [GU0071ForeachImplicitCast](https://github.com/GuOrg/Gu.Analyzers/blob/master/Gu.Analyzers/GU0071ForeachImplicitCast.cs) 11 | 12 | ## Description 13 | 14 | If an explicit type is used, the compiler inserts a cast. This was possibly useful in the pre-generic C# 1.0 era, but now it's a misfeature. 15 | 16 | ## Motivation 17 | 18 | ADD MOTIVATION HERE 19 | 20 | ## How to fix violations 21 | 22 | ADD HOW TO FIX VIOLATIONS HERE 23 | 24 | 25 | ## Configure severity 26 | 27 | ### Via ruleset file. 28 | 29 | Configure the severity per project, for more info see [MSDN](https://msdn.microsoft.com/en-us/library/dd264949.aspx). 30 | 31 | ### Via #pragma directive. 32 | ```C# 33 | #pragma warning disable GU0071 // Implicit casting done by the foreach 34 | Code violating the rule here 35 | #pragma warning restore GU0071 // Implicit casting done by the foreach 36 | ``` 37 | 38 | Or put this at the top of the file to disable all instances. 39 | ```C# 40 | #pragma warning disable GU0071 // Implicit casting done by the foreach 41 | ``` 42 | 43 | ### Via attribute `[SuppressMessage]`. 44 | 45 | ```C# 46 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Gu.Analyzers.Correctness", 47 | "GU0071:Implicit casting done by the foreach", 48 | Justification = "Reason...")] 49 | ``` 50 | -------------------------------------------------------------------------------- /documentation/GU0072.md: -------------------------------------------------------------------------------- 1 | # GU0072 2 | ## All types should be internal 3 | 4 | | Topic | Value 5 | | :-- | :-- 6 | | Id | GU0072 7 | | Severity | Warning 8 | | Enabled | False 9 | | Category | Gu.Analyzers.Correctness 10 | | Code | [GU0072AllTypesShouldBeInternal](https://github.com/GuOrg/Gu.Analyzers/blob/master/Gu.Analyzers/GU0072AllTypesShouldBeInternal.cs) 11 | 12 | ## Description 13 | 14 | All types should be internal. 15 | This analyzer is default disabled as we normally do not want this. If for some reason you want all types internal you can enable it. 16 | 17 | ## Motivation 18 | 19 | Not sure when this is useful. 20 | 21 | ## How to fix violations 22 | 23 | Make classes and structs internal. 24 | 25 | 26 | ## Configure severity 27 | 28 | ### Via ruleset file. 29 | 30 | Configure the severity per project, for more info see [MSDN](https://msdn.microsoft.com/en-us/library/dd264949.aspx). 31 | 32 | ### Via #pragma directive. 33 | ```C# 34 | #pragma warning disable GU0072 // All types should be internal 35 | Code violating the rule here 36 | #pragma warning restore GU0072 // All types should be internal 37 | ``` 38 | 39 | Or put this at the top of the file to disable all instances. 40 | ```C# 41 | #pragma warning disable GU0072 // All types should be internal 42 | ``` 43 | 44 | ### Via attribute `[SuppressMessage]`. 45 | 46 | ```C# 47 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Gu.Analyzers.Correctness", 48 | "GU0072:All types should be internal", 49 | Justification = "Reason...")] 50 | ``` 51 | -------------------------------------------------------------------------------- /documentation/GU0073.md: -------------------------------------------------------------------------------- 1 | # GU0073 2 | ## Member of non-public type should be internal 3 | 4 | | Topic | Value 5 | | :-- | :-- 6 | | Id | GU0073 7 | | Severity | Warning 8 | | Enabled | True 9 | | Category | Gu.Analyzers.Correctness 10 | | Code | [GU0073MemberShouldBeInternal](https://github.com/GuOrg/Gu.Analyzers/blob/master/Gu.Analyzers/GU0073MemberShouldBeInternal.cs) 11 | 12 | 13 | ## Description 14 | 15 | Member of non-public type should be internal. 16 | 17 | ## Motivation 18 | 19 | ADD MOTIVATION HERE 20 | 21 | ## How to fix violations 22 | 23 | ADD HOW TO FIX VIOLATIONS HERE 24 | 25 | 26 | ## Configure severity 27 | 28 | ### Via ruleset file. 29 | 30 | Configure the severity per project, for more info see [MSDN](https://msdn.microsoft.com/en-us/library/dd264949.aspx). 31 | 32 | ### Via #pragma directive. 33 | ```C# 34 | #pragma warning disable GU0073 // Member of non-public type should be internal 35 | Code violating the rule here 36 | #pragma warning restore GU0073 // Member of non-public type should be internal 37 | ``` 38 | 39 | Or put this at the top of the file to disable all instances. 40 | ```C# 41 | #pragma warning disable GU0073 // Member of non-public type should be internal 42 | ``` 43 | 44 | ### Via attribute `[SuppressMessage]`. 45 | 46 | ```C# 47 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Gu.Analyzers.Correctness", 48 | "GU0073:Member of non-public type should be internal", 49 | Justification = "Reason...")] 50 | ``` 51 | -------------------------------------------------------------------------------- /documentation/GU0074.md: -------------------------------------------------------------------------------- 1 | # GU0074 2 | ## Prefer pattern 3 | 4 | | Topic | Value 5 | | :-- | :-- 6 | | Id | GU0074 7 | | Severity | Hidden 8 | | Enabled | True 9 | | Category | Gu.Analyzers.Correctness 10 | | Code | [BinaryExpressionAnalyzer](https://github.com/GuOrg/Gu.Analyzers/blob/master/Gu.Analyzers/Analyzers/BinaryExpressionAnalyzer.cs) 11 | 12 | 13 | ## Description 14 | 15 | Prefer C#8 pattern syntax. 16 | Convenience fix for refactoring to pattern syntax. Supports a few simple common cases like: 17 | 18 | ![and](https://user-images.githubusercontent.com/1640096/69165683-47221200-0af2-11ea-8a1d-a9dfd301af91.gif) 19 | 20 | ![when](https://user-images.githubusercontent.com/1640096/69165681-45584e80-0af2-11ea-8c3b-8b44ca32b357.gif) 21 | 22 | The analyzer is default hidden meaning it will work as a refactoring. 23 | 24 | ## Motivation 25 | 26 | Pattern syntax is nicer many times. Avoids putting locals in scope. 27 | 28 | ## How to fix violations 29 | 30 | Use the fix. 31 | 32 | 33 | ## Configure severity 34 | 35 | ### Via ruleset file. 36 | 37 | Configure the severity per project, for more info see [MSDN](https://msdn.microsoft.com/en-us/library/dd264949.aspx). 38 | 39 | ### Via #pragma directive. 40 | ```C# 41 | #pragma warning disable GU0074 // Prefer pattern 42 | Code violating the rule here 43 | #pragma warning restore GU0074 // Prefer pattern 44 | ``` 45 | 46 | Or put this at the top of the file to disable all instances. 47 | ```C# 48 | #pragma warning disable GU0074 // Prefer pattern 49 | ``` 50 | 51 | ### Via attribute `[SuppressMessage]`. 52 | 53 | ```C# 54 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Gu.Analyzers.Correctness", 55 | "GU0074:Prefer pattern", 56 | Justification = "Reason...")] 57 | ``` 58 | 59 | -------------------------------------------------------------------------------- /documentation/GU0075.md: -------------------------------------------------------------------------------- 1 | # GU0075 2 | ## Prefer return nullable 3 | 4 | | Topic | Value 5 | | :-- | :-- 6 | | Id | GU0075 7 | | Severity | Hidden 8 | | Enabled | True 9 | | Category | Gu.Analyzers.Correctness 10 | | Code | [ParameterAnalyzer](https://github.com/GuOrg/Gu.Analyzers/blob/master/Gu.Analyzers/Analyzers/ParameterAnalyzer.cs) 11 | 12 | 13 | ## Description 14 | 15 | Prefer return nullable Nicer for pattern matching. 16 | 17 | ## Motivation 18 | 19 | ADD MOTIVATION HERE 20 | 21 | ## How to fix violations 22 | 23 | ADD HOW TO FIX VIOLATIONS HERE 24 | 25 | 26 | ## Configure severity 27 | 28 | ### Via ruleset file. 29 | 30 | Configure the severity per project, for more info see [MSDN](https://msdn.microsoft.com/en-us/library/dd264949.aspx). 31 | 32 | ### Via #pragma directive. 33 | ```C# 34 | #pragma warning disable GU0075 // Prefer return nullable 35 | Code violating the rule here 36 | #pragma warning restore GU0075 // Prefer return nullable 37 | ``` 38 | 39 | Or put this at the top of the file to disable all instances. 40 | ```C# 41 | #pragma warning disable GU0075 // Prefer return nullable 42 | ``` 43 | 44 | ### Via attribute `[SuppressMessage]`. 45 | 46 | ```C# 47 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Gu.Analyzers.Correctness", 48 | "GU0075:Prefer return nullable", 49 | Justification = "Reason...")] 50 | ``` 51 | -------------------------------------------------------------------------------- /documentation/GU0076.md: -------------------------------------------------------------------------------- 1 | # GU0076 2 | ## Merge pattern 3 | 4 | | Topic | Value 5 | | :-- | :-- 6 | | Id | GU0076 7 | | Severity | Info 8 | | Enabled | True 9 | | Category | Gu.Analyzers.Correctness 10 | | Code | [BinaryExpressionAnalyzer](https://github.com/GuOrg/Gu.Analyzers/blob/master/Gu.Analyzers/Analyzers/BinaryExpressionAnalyzer.cs) 11 | | | [WhenAnalyzer](https://github.com/GuOrg/Gu.Analyzers/blob/master/Gu.Analyzers/Analyzers/WhenAnalyzer.cs) 12 | 13 | 14 | ## Description 15 | 16 | Merge pattern. 17 | 18 | ## Motivation 19 | 20 | ADD MOTIVATION HERE 21 | 22 | ## How to fix violations 23 | 24 | ADD HOW TO FIX VIOLATIONS HERE 25 | 26 | 27 | ## Configure severity 28 | 29 | ### Via ruleset file. 30 | 31 | Configure the severity per project, for more info see [MSDN](https://msdn.microsoft.com/en-us/library/dd264949.aspx). 32 | 33 | ### Via #pragma directive. 34 | ```C# 35 | #pragma warning disable GU0076 // Merge pattern 36 | Code violating the rule here 37 | #pragma warning restore GU0076 // Merge pattern 38 | ``` 39 | 40 | Or put this at the top of the file to disable all instances. 41 | ```C# 42 | #pragma warning disable GU0076 // Merge pattern 43 | ``` 44 | 45 | ### Via attribute `[SuppressMessage]`. 46 | 47 | ```C# 48 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Gu.Analyzers.Correctness", 49 | "GU0076:Merge pattern", 50 | Justification = "Reason...")] 51 | ``` 52 | -------------------------------------------------------------------------------- /documentation/GU0077.md: -------------------------------------------------------------------------------- 1 | # GU0077 2 | ## Prefer is null 3 | 4 | | Topic | Value 5 | | :-- | :-- 6 | | Id | GU0077 7 | | Severity | Info 8 | | Enabled | True 9 | | Category | Gu.Analyzers.Correctness 10 | | Code | [BinaryExpressionAnalyzer](https://github.com/GuOrg/Gu.Analyzers/blob/master/Gu.Analyzers/Analyzers/BinaryExpressionAnalyzer.cs) 11 | 12 | 13 | ## Description 14 | 15 | Prefer is null for consistency. 16 | 17 | ## Motivation 18 | 19 | ADD MOTIVATION HERE 20 | 21 | ## How to fix violations 22 | 23 | ADD HOW TO FIX VIOLATIONS HERE 24 | 25 | 26 | ## Configure severity 27 | 28 | ### Via ruleset file. 29 | 30 | Configure the severity per project, for more info see [MSDN](https://msdn.microsoft.com/en-us/library/dd264949.aspx). 31 | 32 | ### Via #pragma directive. 33 | ```C# 34 | #pragma warning disable GU0077 // Prefer is null 35 | Code violating the rule here 36 | #pragma warning restore GU0077 // Prefer is null 37 | ``` 38 | 39 | Or put this at the top of the file to disable all instances. 40 | ```C# 41 | #pragma warning disable GU0077 // Prefer is null 42 | ``` 43 | 44 | ### Via attribute `[SuppressMessage]`. 45 | 46 | ```C# 47 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Gu.Analyzers.Correctness", 48 | "GU0077:Prefer is null", 49 | Justification = "Reason...")] 50 | ``` 51 | -------------------------------------------------------------------------------- /documentation/GU0080.md: -------------------------------------------------------------------------------- 1 | # GU0080 2 | ## Parameter count does not match attribute 3 | 4 | | Topic | Value 5 | | :-- | :-- 6 | | Id | GU0080 7 | | Severity | Warning 8 | | Enabled | True 9 | | Category | Gu.Analyzers.Correctness 10 | | Code | [TestMethodAnalyzer](https://github.com/GuOrg/Gu.Analyzers/blob/master/Gu.Analyzers/Analyzers/TestMethodAnalyzer.cs) 11 | 12 | ## Description 13 | 14 | Parameter count does not match attribute. 15 | 16 | ## Motivation 17 | 18 | ADD MOTIVATION HERE 19 | 20 | ## How to fix violations 21 | 22 | ADD HOW TO FIX VIOLATIONS HERE 23 | 24 | 25 | ## Configure severity 26 | 27 | ### Via ruleset file. 28 | 29 | Configure the severity per project, for more info see [MSDN](https://msdn.microsoft.com/en-us/library/dd264949.aspx). 30 | 31 | ### Via #pragma directive. 32 | ```C# 33 | #pragma warning disable GU0080 // Parameter count does not match attribute 34 | Code violating the rule here 35 | #pragma warning restore GU0080 // Parameter count does not match attribute 36 | ``` 37 | 38 | Or put this at the top of the file to disable all instances. 39 | ```C# 40 | #pragma warning disable GU0080 // Parameter count does not match attribute 41 | ``` 42 | 43 | ### Via attribute `[SuppressMessage]`. 44 | 45 | ```C# 46 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Gu.Analyzers.Correctness", 47 | "GU0080:Parameter count does not match attribute", 48 | Justification = "Reason...")] 49 | ``` 50 | -------------------------------------------------------------------------------- /documentation/GU0081.md: -------------------------------------------------------------------------------- 1 | # GU0081 2 | ## TestCase does not match parameters 3 | 4 | | Topic | Value 5 | | :-- | :-- 6 | | Id | GU0081 7 | | Severity | Warning 8 | | Enabled | True 9 | | Category | Gu.Analyzers.Correctness 10 | | Code | [TestMethodAnalyzer](https://github.com/GuOrg/Gu.Analyzers/blob/master/Gu.Analyzers/Analyzers/TestMethodAnalyzer.cs) 11 | 12 | ## Description 13 | 14 | TestCase does not match parameters. 15 | 16 | ## Motivation 17 | 18 | ADD MOTIVATION HERE 19 | 20 | ## How to fix violations 21 | 22 | ADD HOW TO FIX VIOLATIONS HERE 23 | 24 | 25 | ## Configure severity 26 | 27 | ### Via ruleset file. 28 | 29 | Configure the severity per project, for more info see [MSDN](https://msdn.microsoft.com/en-us/library/dd264949.aspx). 30 | 31 | ### Via #pragma directive. 32 | ```C# 33 | #pragma warning disable GU0081 // TestCase does not match parameters 34 | Code violating the rule here 35 | #pragma warning restore GU0081 // TestCase does not match parameters 36 | ``` 37 | 38 | Or put this at the top of the file to disable all instances. 39 | ```C# 40 | #pragma warning disable GU0081 // TestCase does not match parameters 41 | ``` 42 | 43 | ### Via attribute `[SuppressMessage]`. 44 | 45 | ```C# 46 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Gu.Analyzers.Correctness", 47 | "GU0081:TestCase does not match parameters", 48 | Justification = "Reason...")] 49 | ``` 50 | -------------------------------------------------------------------------------- /documentation/GU0082.md: -------------------------------------------------------------------------------- 1 | # GU0082 2 | ## TestCase is identical to other 3 | 4 | | Topic | Value 5 | | :-- | :-- 6 | | Id | GU0082 7 | | Severity | Warning 8 | | Enabled | True 9 | | Category | Gu.Analyzers.Correctness 10 | | Code | [TestMethodAnalyzer](https://github.com/GuOrg/Gu.Analyzers/blob/master/Gu.Analyzers/Analyzers/TestMethodAnalyzer.cs) 11 | 12 | ## Description 13 | 14 | TestCase is identical to other. 15 | 16 | ## Motivation 17 | 18 | ADD MOTIVATION HERE 19 | 20 | ## How to fix violations 21 | 22 | ADD HOW TO FIX VIOLATIONS HERE 23 | 24 | 25 | ## Configure severity 26 | 27 | ### Via ruleset file. 28 | 29 | Configure the severity per project, for more info see [MSDN](https://msdn.microsoft.com/en-us/library/dd264949.aspx). 30 | 31 | ### Via #pragma directive. 32 | ```C# 33 | #pragma warning disable GU0082 // TestCase is identical to other 34 | Code violating the rule here 35 | #pragma warning restore GU0082 // TestCase is identical to other 36 | ``` 37 | 38 | Or put this at the top of the file to disable all instances. 39 | ```C# 40 | #pragma warning disable GU0082 // TestCase is identical to other 41 | ``` 42 | 43 | ### Via attribute `[SuppressMessage]`. 44 | 45 | ```C# 46 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Gu.Analyzers.Correctness", 47 | "GU0082:TestCase is identical to other", 48 | Justification = "Reason...")] 49 | ``` 50 | -------------------------------------------------------------------------------- /documentation/GU0083.md: -------------------------------------------------------------------------------- 1 | # GU0083 2 | ## TestCase Arguments Mismatch Method Parameters 3 | 4 | | Topic | Value 5 | | :-- | :-- 6 | | Id | GU0083 7 | | Severity | Warning 8 | | Enabled | True 9 | | Category | Gu.Analyzers.Correctness 10 | | Code | [TestMethodAnalyzer](https://github.com/GuOrg/Gu.Analyzers/blob/master/Gu.Analyzers/Analyzers/TestMethodAnalyzer.cs) 11 | 12 | ## Description 13 | 14 | TestCase Mismatches Method Parameters. 15 | 16 | ## Motivation 17 | 18 | ADD MOTIVATION HERE 19 | 20 | ## How to fix violations 21 | 22 | ADD HOW TO FIX VIOLATIONS HERE 23 | 24 | 25 | ## Configure severity 26 | 27 | ### Via ruleset file. 28 | 29 | Configure the severity per project, for more info see [MSDN](https://msdn.microsoft.com/en-us/library/dd264949.aspx). 30 | 31 | ### Via #pragma directive. 32 | ```C# 33 | #pragma warning disable GU0083 // TestCase Arguments Mismatch Method Parameters 34 | Code violating the rule here 35 | #pragma warning restore GU0083 // TestCase Arguments Mismatch Method Parameters 36 | ``` 37 | 38 | Or put this at the top of the file to disable all instances. 39 | ```C# 40 | #pragma warning disable GU0083 // TestCase Arguments Mismatch Method Parameters 41 | ``` 42 | 43 | ### Via attribute `[SuppressMessage]`. 44 | 45 | ```C# 46 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Gu.Analyzers.Correctness", 47 | "GU0083:TestCase Arguments Mismatch Method Parameters", 48 | Justification = "Reason...")] 49 | ``` 50 | -------------------------------------------------------------------------------- /documentation/GU0084.md: -------------------------------------------------------------------------------- 1 | # GU0084 2 | ## Assert exception message 3 | 4 | | Topic | Value 5 | | :-- | :-- 6 | | Id | GU0084 7 | | Severity | Hidden 8 | | Enabled | True 9 | | Category | Gu.Analyzers.Correctness 10 | | Code | [AssertAnalyzer](https://github.com/GuOrg/Gu.Analyzers/blob/master/Gu.Analyzers/Analyzers/AssertAnalyzer.cs) 11 | 12 | 13 | ## Description 14 | 15 | Test that the exception message is the expected with an assert. 16 | 17 | ## Motivation 18 | 19 | ADD MOTIVATION HERE 20 | 21 | ## How to fix violations 22 | 23 | ADD HOW TO FIX VIOLATIONS HERE 24 | 25 | 26 | ## Configure severity 27 | 28 | ### Via ruleset file. 29 | 30 | Configure the severity per project, for more info see [MSDN](https://msdn.microsoft.com/en-us/library/dd264949.aspx). 31 | 32 | ### Via #pragma directive. 33 | ```C# 34 | #pragma warning disable GU0084 // Assert exception message 35 | Code violating the rule here 36 | #pragma warning restore GU0084 // Assert exception message 37 | ``` 38 | 39 | Or put this at the top of the file to disable all instances. 40 | ```C# 41 | #pragma warning disable GU0084 // Assert exception message 42 | ``` 43 | 44 | ### Via attribute `[SuppressMessage]`. 45 | 46 | ```C# 47 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Gu.Analyzers.Correctness", 48 | "GU0084:Assert exception message", 49 | Justification = "Reason...")] 50 | ``` 51 | -------------------------------------------------------------------------------- /documentation/GU0090.md: -------------------------------------------------------------------------------- 1 | # GU0090 2 | ## Don't throw NotImplementedException 3 | 4 | | Topic | Value 5 | | :-- | :-- 6 | | Id | GU0090 7 | | Severity | Warning 8 | | Enabled | True 9 | | Category | Gu.Analyzers.Correctness 10 | | Code | [ExceptionAnalyzer](https://github.com/GuOrg/Gu.Analyzers/blob/master/Gu.Analyzers/Analyzers/ExceptionAnalyzer.cs) 11 | 12 | 13 | ## Description 14 | 15 | Don't throw NotImplementedException. 16 | 17 | ## Motivation 18 | 19 | ADD MOTIVATION HERE 20 | 21 | ## How to fix violations 22 | 23 | ADD HOW TO FIX VIOLATIONS HERE 24 | 25 | 26 | ## Configure severity 27 | 28 | ### Via ruleset file. 29 | 30 | Configure the severity per project, for more info see [MSDN](https://msdn.microsoft.com/en-us/library/dd264949.aspx). 31 | 32 | ### Via #pragma directive. 33 | ```C# 34 | #pragma warning disable GU0090 // Don't throw NotImplementedException 35 | Code violating the rule here 36 | #pragma warning restore GU0090 // Don't throw NotImplementedException 37 | ``` 38 | 39 | Or put this at the top of the file to disable all instances. 40 | ```C# 41 | #pragma warning disable GU0090 // Don't throw NotImplementedException 42 | ``` 43 | 44 | ### Via attribute `[SuppressMessage]`. 45 | 46 | ```C# 47 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Gu.Analyzers.Correctness", 48 | "GU0090:Don't throw NotImplementedException", 49 | Justification = "Reason...")] 50 | ``` 51 | -------------------------------------------------------------------------------- /documentation/GU0100.md: -------------------------------------------------------------------------------- 1 | # GU0100 2 | ## Wrong cref type 3 | 4 | | Topic | Value 5 | | :-- | :-- 6 | | Id | GU0100 7 | | Severity | Warning 8 | | Enabled | True 9 | | Category | Gu.Analyzers.Correctness 10 | | Code | [DocsAnalyzer](https://github.com/GuOrg/Gu.Analyzers/blob/master/Gu.Analyzers/Analyzers/DocsAnalyzer.cs) 11 | 12 | 13 | ## Description 14 | 15 | Wrong cref type. 16 | 17 | ## Motivation 18 | 19 | ADD MOTIVATION HERE 20 | 21 | ## How to fix violations 22 | 23 | ADD HOW TO FIX VIOLATIONS HERE 24 | 25 | 26 | ## Configure severity 27 | 28 | ### Via ruleset file. 29 | 30 | Configure the severity per project, for more info see [MSDN](https://msdn.microsoft.com/en-us/library/dd264949.aspx). 31 | 32 | ### Via #pragma directive. 33 | ```C# 34 | #pragma warning disable GU0100 // Wrong cref type 35 | Code violating the rule here 36 | #pragma warning restore GU0100 // Wrong cref type 37 | ``` 38 | 39 | Or put this at the top of the file to disable all instances. 40 | ```C# 41 | #pragma warning disable GU0100 // Wrong cref type 42 | ``` 43 | 44 | ### Via attribute `[SuppressMessage]`. 45 | 46 | ```C# 47 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Gu.Analyzers.Correctness", 48 | "GU0100:Wrong cref type", 49 | Justification = "Reason...")] 50 | ``` 51 | --------------------------------------------------------------------------------