From a5e2f387d2e57a5bf6fc272ac6e3be0eb08f77f6 Mon Sep 17 00:00:00 2001 From: Zsolt Kolbay Date: Wed, 29 Mar 2023 09:01:21 +0200 Subject: [PATCH 01/10] Add test cases --- ...icMethodArgumentsShouldBeCheckedForNull.cs | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/SymbolicExecution/Roslyn/PublicMethodArgumentsShouldBeCheckedForNull.cs b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/SymbolicExecution/Roslyn/PublicMethodArgumentsShouldBeCheckedForNull.cs index 8ca43946631..50ac571bf3f 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/SymbolicExecution/Roslyn/PublicMethodArgumentsShouldBeCheckedForNull.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/SymbolicExecution/Roslyn/PublicMethodArgumentsShouldBeCheckedForNull.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Text; using System.Threading.Tasks; @@ -93,6 +94,11 @@ public void MoreCompliantCases(string s1, string s2) } } + public void ForEachLoop(object[] array) + { + foreach (object o in array) { } // Noncompliant + } + public async void AsyncTest(Task task1, Task task2, Task task3, Task task4) { if (task1 != null) @@ -627,3 +633,45 @@ public void Method(object o) } } } + +public class Conversion +{ + public void DownCast(object o) + { + ((string)o).ToString(); // Noncompliant + } + + public void UpCast(string s) + { + ((object)s).ToString(); // Noncompliant + } + + public void CastWithRedundantParentheses(object o) + { + (((string)o)).ToString(); // Noncompliant + } + + public void AsOperatorDownCast(object o) + { + (o as string).ToString(); // Noncompliant + } + + public void AsOperatorUpCast(string s) + { + (s as object).ToString(); // Noncompliant + } + + public void ForEachLoop(object[] arr) + { + foreach (object o in arr) // Noncompliant - the array is first cast to an IEnumerable, then the GetEnumerator method is invoked on it + { + } + } + + public void ForEachLoopWithCast(object[] arr) + { + foreach (object o in (IEnumerable)arr) // Noncompliant + { + } + } +} From 8b9526f89cbaf01c9b33be09ef9641fdbb780494 Mon Sep 17 00:00:00 2001 From: Zsolt Kolbay Date: Wed, 29 Mar 2023 09:02:29 +0200 Subject: [PATCH 02/10] Update PreProcessSimple() to support conversion operators --- .../Roslyn/PublicMethodArgumentsShouldBeCheckedForNull.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/analyzers/src/SonarAnalyzer.CSharp/SymbolicExecution/Roslyn/PublicMethodArgumentsShouldBeCheckedForNull.cs b/analyzers/src/SonarAnalyzer.CSharp/SymbolicExecution/Roslyn/PublicMethodArgumentsShouldBeCheckedForNull.cs index 64029a03bf9..79a1950eaec 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/SymbolicExecution/Roslyn/PublicMethodArgumentsShouldBeCheckedForNull.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/SymbolicExecution/Roslyn/PublicMethodArgumentsShouldBeCheckedForNull.cs @@ -93,13 +93,14 @@ bool NullableStateIsNotKnownForParameter(IParameterSymbol symbol) => private static bool IsParameterDereferenced(IOperationWrapperSonar operation) => operation.Parent != null - && operation.Parent.IsAnyKind( + && (operation.Parent.IsAnyKind( OperationKindEx.Invocation, OperationKindEx.FieldReference, OperationKindEx.PropertyReference, OperationKindEx.EventReference, OperationKindEx.Await, - OperationKindEx.ArrayElementReference); + OperationKindEx.ArrayElementReference) + || (operation.Parent.Kind == OperationKindEx.Conversion && IsParameterDereferenced(operation.Parent.ToSonar()))); private sealed class ArgumentDereferenceWalker : SafeCSharpSyntaxWalker { From 623b3c3fb6e8a5fc59c61dc022a015d720571262 Mon Sep 17 00:00:00 2001 From: Zsolt Kolbay Date: Wed, 29 Mar 2023 09:03:18 +0200 Subject: [PATCH 03/10] Update ShouldExecute to support conversion syntax --- .../Roslyn/PublicMethodArgumentsShouldBeCheckedForNull.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/analyzers/src/SonarAnalyzer.CSharp/SymbolicExecution/Roslyn/PublicMethodArgumentsShouldBeCheckedForNull.cs b/analyzers/src/SonarAnalyzer.CSharp/SymbolicExecution/Roslyn/PublicMethodArgumentsShouldBeCheckedForNull.cs index 79a1950eaec..c3c9fe387b1 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/SymbolicExecution/Roslyn/PublicMethodArgumentsShouldBeCheckedForNull.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/SymbolicExecution/Roslyn/PublicMethodArgumentsShouldBeCheckedForNull.cs @@ -122,11 +122,11 @@ public override void Visit(SyntaxNode node) public override void VisitIdentifierName(IdentifierNameSyntax node) => DereferencesMethodArguments |= argumentNames.Contains(node.GetName()) - && node.Parent.IsAnyKind( + && node.Ancestors().Any(x => x.IsAnyKind( AwaitExpression, ElementAccessExpression, ForEachStatement, ThrowStatement, - SimpleMemberAccessExpression); + SimpleMemberAccessExpression)); } } From ce031c05319c2e3c6781a3f0c47839aeec261372 Mon Sep 17 00:00:00 2001 From: Zsolt Kolbay Date: Wed, 29 Mar 2023 09:06:15 +0200 Subject: [PATCH 04/10] Fix namespace in test case --- .../Roslyn/PublicMethodArgumentsShouldBeCheckedForNull.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/SymbolicExecution/Roslyn/PublicMethodArgumentsShouldBeCheckedForNull.cs b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/SymbolicExecution/Roslyn/PublicMethodArgumentsShouldBeCheckedForNull.cs index 50ac571bf3f..d020bf8cb5d 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/SymbolicExecution/Roslyn/PublicMethodArgumentsShouldBeCheckedForNull.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/SymbolicExecution/Roslyn/PublicMethodArgumentsShouldBeCheckedForNull.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; using System.Text; using System.Threading.Tasks; From 46c25ea94af0101134520152c450efbec8833e1b Mon Sep 17 00:00:00 2001 From: Zsolt Kolbay Date: Wed, 29 Mar 2023 09:13:47 +0200 Subject: [PATCH 05/10] Update ITs --- .../Automapper/AutoMapper--net461-S3900.json | 78 +++++++++ .../AutoMapper--netstandard2.0-S3900.json | 78 +++++++++ .../expected/Nancy/Nancy--net452-S3900.json | 156 ++++++++++++++++++ .../Nancy/Nancy--netstandard2.0-S3900.json | 156 ++++++++++++++++++ .../Nancy.Hosting.Aspnet--net452-S3900.json | 52 ++++++ .../Nancy/Nancy.Testing--net452-S3900.json | 156 ++++++++++++++++++ .../Nancy.Testing--netstandard2.0-S3900.json | 156 ++++++++++++++++++ ...idation.DataAnnotations--net452-S3900.json | 26 +++ ...dation.FluentValidation--net452-S3900.json | 156 ++++++++++++++++++ ...luentValidation--netstandard2.0-S3900.json | 156 ++++++++++++++++++ .../its/expected/Net5/Net5--net5.0-S3900.json | 26 +++ ...leReferenceTypesExample--net6.0-S3900.json | 17 ++ .../akka.net/Akka--netstandard2.0-S3900.json | 156 ++++++++++++++++++ .../Akka.Cluster--netstandard2.0-S3900.json | 13 ++ ...stRunner.Shared--netstandard2.0-S3900.json | 26 +++ ...kka.Persistence--netstandard2.0-S3900.json | 13 ++ ...ence.Sql.Common--netstandard2.0-S3900.json | 39 +++++ ...istence.TestKit--netstandard2.0-S3900.json | 26 +++ ....Remote.TestKit--netstandard2.0-S3900.json | 39 +++++ ...Streams.TestKit--netstandard2.0-S3900.json | 13 ++ ...hared.Internals--netstandard2.0-S3900.json | 26 +++ 21 files changed, 1564 insertions(+) create mode 100644 analyzers/its/expected/Net6/NullableReferenceTypesExample--net6.0-S3900.json diff --git a/analyzers/its/expected/Automapper/AutoMapper--net461-S3900.json b/analyzers/its/expected/Automapper/AutoMapper--net461-S3900.json index 4d1cf7e3eef..6e09cb18631 100644 --- a/analyzers/its/expected/Automapper/AutoMapper--net461-S3900.json +++ b/analyzers/its/expected/Automapper/AutoMapper--net461-S3900.json @@ -392,6 +392,32 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'enumerableOfProfiles' before using it.", +"location": { +"uri": "sources\Automapper\src\AutoMapper\Configuration\MapperConfigurationExpression.cs", +"region": { +"startLine": 161, +"startColumn": 37, +"endLine": 161, +"endColumn": 57 +} +} +}, +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'memberNames' before using it.", +"location": { +"uri": "sources\Automapper\src\AutoMapper\Configuration\MappingExpression.cs", +"region": { +"startLine": 37, +"startColumn": 39, +"endLine": 37, +"endColumn": 50 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'memberOptions' before using it.", "location": { "uri": "sources\Automapper\src\AutoMapper\Configuration\MappingExpression.cs", @@ -613,6 +639,19 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'members' before using it.", +"location": { +"uri": "sources\Automapper\src\AutoMapper\Execution\ExpressionBuilder.cs", +"region": { +"startLine": 170, +"startColumn": 36, +"endLine": 170, +"endColumn": 43 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'lambda' before using it.", "location": { "uri": "sources\Automapper\src\AutoMapper\Execution\ExpressionBuilder.cs", @@ -652,6 +691,19 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'members' before using it.", +"location": { +"uri": "sources\Automapper\src\AutoMapper\Execution\ExpressionBuilder.cs", +"region": { +"startLine": 232, +"startColumn": 36, +"endLine": 232, +"endColumn": 43 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'collection' before using it.", "location": { "uri": "sources\Automapper\src\AutoMapper\Execution\ExpressionBuilder.cs", @@ -964,6 +1016,19 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'member' before using it.", +"location": { +"uri": "sources\Automapper\src\AutoMapper\Internal\ReflectionHelper.cs", +"region": { +"startLine": 17, +"startColumn": 131, +"endLine": 17, +"endColumn": 137 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'parameter' before using it.", "location": { "uri": "sources\Automapper\src\AutoMapper\Internal\ReflectionHelper.cs", @@ -1029,6 +1094,19 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'prefixes' before using it.", +"location": { +"uri": "sources\Automapper\src\AutoMapper\Internal\TypeDetails.cs", +"region": { +"startLine": 75, +"startColumn": 36, +"endLine": 75, +"endColumn": 44 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'memberName' before using it.", "location": { "uri": "sources\Automapper\src\AutoMapper\Internal\TypeDetails.cs", diff --git a/analyzers/its/expected/Automapper/AutoMapper--netstandard2.0-S3900.json b/analyzers/its/expected/Automapper/AutoMapper--netstandard2.0-S3900.json index 4d1cf7e3eef..6e09cb18631 100644 --- a/analyzers/its/expected/Automapper/AutoMapper--netstandard2.0-S3900.json +++ b/analyzers/its/expected/Automapper/AutoMapper--netstandard2.0-S3900.json @@ -392,6 +392,32 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'enumerableOfProfiles' before using it.", +"location": { +"uri": "sources\Automapper\src\AutoMapper\Configuration\MapperConfigurationExpression.cs", +"region": { +"startLine": 161, +"startColumn": 37, +"endLine": 161, +"endColumn": 57 +} +} +}, +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'memberNames' before using it.", +"location": { +"uri": "sources\Automapper\src\AutoMapper\Configuration\MappingExpression.cs", +"region": { +"startLine": 37, +"startColumn": 39, +"endLine": 37, +"endColumn": 50 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'memberOptions' before using it.", "location": { "uri": "sources\Automapper\src\AutoMapper\Configuration\MappingExpression.cs", @@ -613,6 +639,19 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'members' before using it.", +"location": { +"uri": "sources\Automapper\src\AutoMapper\Execution\ExpressionBuilder.cs", +"region": { +"startLine": 170, +"startColumn": 36, +"endLine": 170, +"endColumn": 43 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'lambda' before using it.", "location": { "uri": "sources\Automapper\src\AutoMapper\Execution\ExpressionBuilder.cs", @@ -652,6 +691,19 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'members' before using it.", +"location": { +"uri": "sources\Automapper\src\AutoMapper\Execution\ExpressionBuilder.cs", +"region": { +"startLine": 232, +"startColumn": 36, +"endLine": 232, +"endColumn": 43 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'collection' before using it.", "location": { "uri": "sources\Automapper\src\AutoMapper\Execution\ExpressionBuilder.cs", @@ -964,6 +1016,19 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'member' before using it.", +"location": { +"uri": "sources\Automapper\src\AutoMapper\Internal\ReflectionHelper.cs", +"region": { +"startLine": 17, +"startColumn": 131, +"endLine": 17, +"endColumn": 137 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'parameter' before using it.", "location": { "uri": "sources\Automapper\src\AutoMapper\Internal\ReflectionHelper.cs", @@ -1029,6 +1094,19 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'prefixes' before using it.", +"location": { +"uri": "sources\Automapper\src\AutoMapper\Internal\TypeDetails.cs", +"region": { +"startLine": 75, +"startColumn": 36, +"endLine": 75, +"endColumn": 44 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'memberName' before using it.", "location": { "uri": "sources\Automapper\src\AutoMapper\Internal\TypeDetails.cs", diff --git a/analyzers/its/expected/Nancy/Nancy--net452-S3900.json b/analyzers/its/expected/Nancy/Nancy--net452-S3900.json index cafb0ff6557..bd4532cf945 100644 --- a/analyzers/its/expected/Nancy/Nancy--net452-S3900.json +++ b/analyzers/its/expected/Nancy/Nancy--net452-S3900.json @@ -574,6 +574,19 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'typeRegistrations' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy\DefaultNancyBootstrapper.cs", +"region": { +"startLine": 109, +"startColumn": 46, +"endLine": 109, +"endColumn": 63 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'container' before using it.", "location": { "uri": "sources\Nancy\src\Nancy\DefaultNancyBootstrapper.cs", @@ -600,6 +613,19 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'collectionTypeRegistrations' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy\DefaultNancyBootstrapper.cs", +"region": { +"startLine": 135, +"startColumn": 56, +"endLine": 135, +"endColumn": 83 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'container' before using it.", "location": { "uri": "sources\Nancy\src\Nancy\DefaultNancyBootstrapper.cs", @@ -626,6 +652,19 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'moduleRegistrationTypes' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy\DefaultNancyBootstrapper.cs", +"region": { +"startLine": 160, +"startColumn": 52, +"endLine": 160, +"endColumn": 75 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'container' before using it.", "location": { "uri": "sources\Nancy\src\Nancy\DefaultNancyBootstrapper.cs", @@ -639,6 +678,19 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'instanceRegistrations' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy\DefaultNancyBootstrapper.cs", +"region": { +"startLine": 177, +"startColumn": 50, +"endLine": 177, +"endColumn": 71 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'container' before using it.", "location": { "uri": "sources\Nancy\src\Nancy\DefaultNancyBootstrapper.cs", @@ -1328,6 +1380,19 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'source' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy\Extensions\CollectionExtensions.cs", +"region": { +"startLine": 79, +"startColumn": 41, +"endLine": 79, +"endColumn": 47 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'keySelector' before using it.", "location": { "uri": "sources\Nancy\src\Nancy\Extensions\CollectionExtensions.cs", @@ -2199,6 +2264,32 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'cookies' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy\NegotiatorExtensions.cs", +"region": { +"startLine": 35, +"startColumn": 36, +"endLine": 35, +"endColumn": 43 +} +} +}, +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'headers' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy\NegotiatorExtensions.cs", +"region": { +"startLine": 90, +"startColumn": 42, +"endLine": 90, +"endColumn": 49 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'negotiator' before using it.", "location": { "uri": "sources\Nancy\src\Nancy\NegotiatorExtensions.cs", @@ -2420,6 +2511,19 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'headers' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy\ResponseExtensions.cs", +"region": { +"startLine": 138, +"startColumn": 42, +"endLine": 138, +"endColumn": 49 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'response' before using it.", "location": { "uri": "sources\Nancy\src\Nancy\ResponseExtensions.cs", @@ -2511,6 +2615,19 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'linkProcessors' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy\Responses\Negotiation\DefaultResponseNegotiator.cs", +"region": { +"startLine": 377, +"startColumn": 43, +"endLine": 377, +"endColumn": 57 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'other' before using it.", "location": { "uri": "sources\Nancy\src\Nancy\Responses\Negotiation\MediaRange.cs", @@ -3057,6 +3174,45 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'localCaptures' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy\Routing\Trie\Nodes\TrieNode.cs", +"region": { +"startLine": 224, +"startColumn": 46, +"endLine": 224, +"endColumn": 59 +} +} +}, +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'localCaptures' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy\Routing\Trie\Nodes\TrieNode.cs", +"region": { +"startLine": 249, +"startColumn": 48, +"endLine": 249, +"endColumn": 61 +} +} +}, +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'cache' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy\Routing\Trie\RouteResolverTrie.cs", +"region": { +"startLine": 35, +"startColumn": 39, +"endLine": 35, +"endColumn": 44 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'path' before using it.", "location": { "uri": "sources\Nancy\src\Nancy\Routing\Trie\RouteResolverTrie.cs", diff --git a/analyzers/its/expected/Nancy/Nancy--netstandard2.0-S3900.json b/analyzers/its/expected/Nancy/Nancy--netstandard2.0-S3900.json index 709e455d505..5ff44d9d6c5 100644 --- a/analyzers/its/expected/Nancy/Nancy--netstandard2.0-S3900.json +++ b/analyzers/its/expected/Nancy/Nancy--netstandard2.0-S3900.json @@ -574,6 +574,19 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'typeRegistrations' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy\DefaultNancyBootstrapper.cs", +"region": { +"startLine": 109, +"startColumn": 46, +"endLine": 109, +"endColumn": 63 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'container' before using it.", "location": { "uri": "sources\Nancy\src\Nancy\DefaultNancyBootstrapper.cs", @@ -600,6 +613,19 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'collectionTypeRegistrations' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy\DefaultNancyBootstrapper.cs", +"region": { +"startLine": 135, +"startColumn": 56, +"endLine": 135, +"endColumn": 83 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'container' before using it.", "location": { "uri": "sources\Nancy\src\Nancy\DefaultNancyBootstrapper.cs", @@ -626,6 +652,19 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'moduleRegistrationTypes' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy\DefaultNancyBootstrapper.cs", +"region": { +"startLine": 160, +"startColumn": 52, +"endLine": 160, +"endColumn": 75 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'container' before using it.", "location": { "uri": "sources\Nancy\src\Nancy\DefaultNancyBootstrapper.cs", @@ -639,6 +678,19 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'instanceRegistrations' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy\DefaultNancyBootstrapper.cs", +"region": { +"startLine": 177, +"startColumn": 50, +"endLine": 177, +"endColumn": 71 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'container' before using it.", "location": { "uri": "sources\Nancy\src\Nancy\DefaultNancyBootstrapper.cs", @@ -1315,6 +1367,19 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'source' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy\Extensions\CollectionExtensions.cs", +"region": { +"startLine": 79, +"startColumn": 41, +"endLine": 79, +"endColumn": 47 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'keySelector' before using it.", "location": { "uri": "sources\Nancy\src\Nancy\Extensions\CollectionExtensions.cs", @@ -2199,6 +2264,32 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'cookies' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy\NegotiatorExtensions.cs", +"region": { +"startLine": 35, +"startColumn": 36, +"endLine": 35, +"endColumn": 43 +} +} +}, +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'headers' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy\NegotiatorExtensions.cs", +"region": { +"startLine": 90, +"startColumn": 42, +"endLine": 90, +"endColumn": 49 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'negotiator' before using it.", "location": { "uri": "sources\Nancy\src\Nancy\NegotiatorExtensions.cs", @@ -2420,6 +2511,19 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'headers' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy\ResponseExtensions.cs", +"region": { +"startLine": 138, +"startColumn": 42, +"endLine": 138, +"endColumn": 49 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'response' before using it.", "location": { "uri": "sources\Nancy\src\Nancy\ResponseExtensions.cs", @@ -2511,6 +2615,19 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'linkProcessors' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy\Responses\Negotiation\DefaultResponseNegotiator.cs", +"region": { +"startLine": 377, +"startColumn": 43, +"endLine": 377, +"endColumn": 57 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'other' before using it.", "location": { "uri": "sources\Nancy\src\Nancy\Responses\Negotiation\MediaRange.cs", @@ -3057,6 +3174,45 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'localCaptures' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy\Routing\Trie\Nodes\TrieNode.cs", +"region": { +"startLine": 224, +"startColumn": 46, +"endLine": 224, +"endColumn": 59 +} +} +}, +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'localCaptures' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy\Routing\Trie\Nodes\TrieNode.cs", +"region": { +"startLine": 249, +"startColumn": 48, +"endLine": 249, +"endColumn": 61 +} +} +}, +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'cache' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy\Routing\Trie\RouteResolverTrie.cs", +"region": { +"startLine": 35, +"startColumn": 39, +"endLine": 35, +"endColumn": 44 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'path' before using it.", "location": { "uri": "sources\Nancy\src\Nancy\Routing\Trie\RouteResolverTrie.cs", diff --git a/analyzers/its/expected/Nancy/Nancy.Hosting.Aspnet--net452-S3900.json b/analyzers/its/expected/Nancy/Nancy.Hosting.Aspnet--net452-S3900.json index d0762fee2b4..784caeb7da2 100644 --- a/analyzers/its/expected/Nancy/Nancy.Hosting.Aspnet--net452-S3900.json +++ b/analyzers/its/expected/Nancy/Nancy.Hosting.Aspnet--net452-S3900.json @@ -67,6 +67,19 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'typeRegistrations' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Hosting.Aspnet\DefaultNancyAspNetBootstrapper.cs", +"region": { +"startLine": 178, +"startColumn": 46, +"endLine": 178, +"endColumn": 63 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'container' before using it.", "location": { "uri": "sources\Nancy\src\Nancy.Hosting.Aspnet\DefaultNancyAspNetBootstrapper.cs", @@ -106,6 +119,19 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'collectionTypeRegistrations' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Hosting.Aspnet\DefaultNancyAspNetBootstrapper.cs", +"region": { +"startLine": 205, +"startColumn": 56, +"endLine": 205, +"endColumn": 83 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'container' before using it.", "location": { "uri": "sources\Nancy\src\Nancy.Hosting.Aspnet\DefaultNancyAspNetBootstrapper.cs", @@ -145,6 +171,19 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'moduleRegistrationTypes' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Hosting.Aspnet\DefaultNancyAspNetBootstrapper.cs", +"region": { +"startLine": 231, +"startColumn": 46, +"endLine": 231, +"endColumn": 69 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'container' before using it.", "location": { "uri": "sources\Nancy\src\Nancy.Hosting.Aspnet\DefaultNancyAspNetBootstrapper.cs", @@ -158,6 +197,19 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'instanceRegistrations' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Hosting.Aspnet\DefaultNancyAspNetBootstrapper.cs", +"region": { +"startLine": 244, +"startColumn": 50, +"endLine": 244, +"endColumn": 71 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'container' before using it.", "location": { "uri": "sources\Nancy\src\Nancy.Hosting.Aspnet\DefaultNancyAspNetBootstrapper.cs", diff --git a/analyzers/its/expected/Nancy/Nancy.Testing--net452-S3900.json b/analyzers/its/expected/Nancy/Nancy.Testing--net452-S3900.json index 400616a718d..c7b6aca7378 100644 --- a/analyzers/its/expected/Nancy/Nancy.Testing--net452-S3900.json +++ b/analyzers/its/expected/Nancy/Nancy.Testing--net452-S3900.json @@ -15,6 +15,19 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'query' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Testing\AssertExtensions.cs", +"region": { +"startLine": 83, +"startColumn": 34, +"endLine": 83, +"endColumn": 39 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'node' before using it.", "location": { "uri": "sources\Nancy\src\Nancy.Testing\AssertExtensions.cs", @@ -54,6 +67,32 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'query' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Testing\AssertExtensions.cs", +"region": { +"startLine": 152, +"startColumn": 34, +"endLine": 152, +"endColumn": 39 +} +} +}, +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'query' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Testing\AssertExtensions.cs", +"region": { +"startLine": 167, +"startColumn": 34, +"endLine": 167, +"endColumn": 39 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'actual' before using it.", "location": { "uri": "sources\Nancy\src\Nancy.Testing\Asserts.cs", @@ -158,6 +197,19 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'cookies' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Testing\BrowserContextExtensions.cs", +"region": { +"startLine": 119, +"startColumn": 36, +"endLine": 119, +"endColumn": 43 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'browserContext' before using it.", "location": { "uri": "sources\Nancy\src\Nancy.Testing\BrowserContextExtensions.cs", @@ -379,6 +431,19 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'moduleRegistrationTypes' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Testing\ConfigurableBootstrapper.cs", +"region": { +"startLine": 540, +"startColumn": 52, +"endLine": 540, +"endColumn": 75 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'container' before using it.", "location": { "uri": "sources\Nancy\src\Nancy.Testing\ConfigurableBootstrapper.cs", @@ -405,6 +470,19 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'defaultConfigurationProviders' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Testing\ConfigurableBootstrapper.cs", +"region": { +"startLine": 737, +"startColumn": 62, +"endLine": 737, +"endColumn": 91 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'instance' before using it.", "location": { "uri": "sources\Nancy\src\Nancy.Testing\ConfigurableBootstrapper.cs", @@ -418,6 +496,84 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'dependencies' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Testing\ConfigurableBootstrapper.cs", +"region": { +"startLine": 809, +"startColumn": 44, +"endLine": 809, +"endColumn": 56 +} +} +}, +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'dependencies' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Testing\ConfigurableBootstrapper.cs", +"region": { +"startLine": 826, +"startColumn": 44, +"endLine": 826, +"endColumn": 56 +} +} +}, +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'dependencies' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Testing\ConfigurableBootstrapper.cs", +"region": { +"startLine": 842, +"startColumn": 44, +"endLine": 842, +"endColumn": 56 +} +} +}, +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'routeMetadataProviders' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Testing\ConfigurableBootstrapper.cs", +"region": { +"startLine": 1428, +"startColumn": 55, +"endLine": 1428, +"endColumn": 77 +} +} +}, +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'applicationStartupTypes' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Testing\ConfigurableBootstrapper.cs", +"region": { +"startLine": 1977, +"startColumn": 38, +"endLine": 1977, +"endColumn": 61 +} +} +}, +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'requestStartupTypes' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Testing\ConfigurableBootstrapper.cs", +"region": { +"startLine": 2006, +"startColumn": 38, +"endLine": 2006, +"endColumn": 57 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'moduleType' before using it.", "location": { "uri": "sources\Nancy\src\Nancy.Testing\ConfigurableBootstrapper.cs", diff --git a/analyzers/its/expected/Nancy/Nancy.Testing--netstandard2.0-S3900.json b/analyzers/its/expected/Nancy/Nancy.Testing--netstandard2.0-S3900.json index 400616a718d..c7b6aca7378 100644 --- a/analyzers/its/expected/Nancy/Nancy.Testing--netstandard2.0-S3900.json +++ b/analyzers/its/expected/Nancy/Nancy.Testing--netstandard2.0-S3900.json @@ -15,6 +15,19 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'query' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Testing\AssertExtensions.cs", +"region": { +"startLine": 83, +"startColumn": 34, +"endLine": 83, +"endColumn": 39 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'node' before using it.", "location": { "uri": "sources\Nancy\src\Nancy.Testing\AssertExtensions.cs", @@ -54,6 +67,32 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'query' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Testing\AssertExtensions.cs", +"region": { +"startLine": 152, +"startColumn": 34, +"endLine": 152, +"endColumn": 39 +} +} +}, +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'query' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Testing\AssertExtensions.cs", +"region": { +"startLine": 167, +"startColumn": 34, +"endLine": 167, +"endColumn": 39 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'actual' before using it.", "location": { "uri": "sources\Nancy\src\Nancy.Testing\Asserts.cs", @@ -158,6 +197,19 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'cookies' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Testing\BrowserContextExtensions.cs", +"region": { +"startLine": 119, +"startColumn": 36, +"endLine": 119, +"endColumn": 43 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'browserContext' before using it.", "location": { "uri": "sources\Nancy\src\Nancy.Testing\BrowserContextExtensions.cs", @@ -379,6 +431,19 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'moduleRegistrationTypes' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Testing\ConfigurableBootstrapper.cs", +"region": { +"startLine": 540, +"startColumn": 52, +"endLine": 540, +"endColumn": 75 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'container' before using it.", "location": { "uri": "sources\Nancy\src\Nancy.Testing\ConfigurableBootstrapper.cs", @@ -405,6 +470,19 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'defaultConfigurationProviders' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Testing\ConfigurableBootstrapper.cs", +"region": { +"startLine": 737, +"startColumn": 62, +"endLine": 737, +"endColumn": 91 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'instance' before using it.", "location": { "uri": "sources\Nancy\src\Nancy.Testing\ConfigurableBootstrapper.cs", @@ -418,6 +496,84 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'dependencies' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Testing\ConfigurableBootstrapper.cs", +"region": { +"startLine": 809, +"startColumn": 44, +"endLine": 809, +"endColumn": 56 +} +} +}, +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'dependencies' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Testing\ConfigurableBootstrapper.cs", +"region": { +"startLine": 826, +"startColumn": 44, +"endLine": 826, +"endColumn": 56 +} +} +}, +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'dependencies' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Testing\ConfigurableBootstrapper.cs", +"region": { +"startLine": 842, +"startColumn": 44, +"endLine": 842, +"endColumn": 56 +} +} +}, +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'routeMetadataProviders' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Testing\ConfigurableBootstrapper.cs", +"region": { +"startLine": 1428, +"startColumn": 55, +"endLine": 1428, +"endColumn": 77 +} +} +}, +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'applicationStartupTypes' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Testing\ConfigurableBootstrapper.cs", +"region": { +"startLine": 1977, +"startColumn": 38, +"endLine": 1977, +"endColumn": 61 +} +} +}, +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'requestStartupTypes' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Testing\ConfigurableBootstrapper.cs", +"region": { +"startLine": 2006, +"startColumn": 38, +"endLine": 2006, +"endColumn": 57 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'moduleType' before using it.", "location": { "uri": "sources\Nancy\src\Nancy.Testing\ConfigurableBootstrapper.cs", diff --git a/analyzers/its/expected/Nancy/Nancy.Validation.DataAnnotations--net452-S3900.json b/analyzers/its/expected/Nancy/Nancy.Validation.DataAnnotations--net452-S3900.json index b161e757e4c..68a149e4ba3 100644 --- a/analyzers/its/expected/Nancy/Nancy.Validation.DataAnnotations--net452-S3900.json +++ b/analyzers/its/expected/Nancy/Nancy.Validation.DataAnnotations--net452-S3900.json @@ -67,6 +67,19 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'attribute' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Validation.DataAnnotations\RegexValidatorAdapter.cs", +"region": { +"startLine": 42, +"startColumn": 46, +"endLine": 42, +"endColumn": 55 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'descriptor' before using it.", "location": { "uri": "sources\Nancy\src\Nancy.Validation.DataAnnotations\RequiredValidatorAdapter.cs", @@ -90,6 +103,19 @@ "endColumn": 35 } } +}, +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'attribute' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Validation.DataAnnotations\StringLengthValidatorAdapter.cs", +"region": { +"startLine": 42, +"startColumn": 41, +"endLine": 42, +"endColumn": 50 +} +} } ] } diff --git a/analyzers/its/expected/Nancy/Nancy.Validation.FluentValidation--net452-S3900.json b/analyzers/its/expected/Nancy/Nancy.Validation.FluentValidation--net452-S3900.json index 8e96f96b2e4..d6348563d7e 100644 --- a/analyzers/its/expected/Nancy/Nancy.Validation.FluentValidation--net452-S3900.json +++ b/analyzers/its/expected/Nancy/Nancy.Validation.FluentValidation--net452-S3900.json @@ -12,6 +12,162 @@ "endColumn": 30 } } +}, +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'validator' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Validation.FluentValidation\EmailAdapter.cs", +"region": { +"startLine": 34, +"startColumn": 35, +"endLine": 34, +"endColumn": 44 +} +} +}, +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'validator' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Validation.FluentValidation\EqualAdapter.cs", +"region": { +"startLine": 35, +"startColumn": 34, +"endLine": 35, +"endColumn": 43 +} +} +}, +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'validator' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Validation.FluentValidation\ExactLengthAdapater.cs", +"region": { +"startLine": 34, +"startColumn": 40, +"endLine": 34, +"endColumn": 49 +} +} +}, +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'validator' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Validation.FluentValidation\ExclusiveBetweenAdapter.cs", +"region": { +"startLine": 35, +"startColumn": 45, +"endLine": 35, +"endColumn": 54 +} +} +}, +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'validator' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Validation.FluentValidation\GreaterThanAdapter.cs", +"region": { +"startLine": 35, +"startColumn": 40, +"endLine": 35, +"endColumn": 49 +} +} +}, +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'validator' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Validation.FluentValidation\GreaterThanOrEqualAdapter.cs", +"region": { +"startLine": 35, +"startColumn": 47, +"endLine": 35, +"endColumn": 56 +} +} +}, +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'validator' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Validation.FluentValidation\InclusiveBetweenAdapter.cs", +"region": { +"startLine": 35, +"startColumn": 45, +"endLine": 35, +"endColumn": 54 +} +} +}, +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'validator' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Validation.FluentValidation\LengthAdapter.cs", +"region": { +"startLine": 34, +"startColumn": 36, +"endLine": 34, +"endColumn": 45 +} +} +}, +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'validator' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Validation.FluentValidation\LessThanAdapter.cs", +"region": { +"startLine": 35, +"startColumn": 37, +"endLine": 35, +"endColumn": 46 +} +} +}, +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'validator' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Validation.FluentValidation\LessThanOrEqualAdapter.cs", +"region": { +"startLine": 35, +"startColumn": 44, +"endLine": 35, +"endColumn": 53 +} +} +}, +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'validator' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Validation.FluentValidation\NotEqualAdapter.cs", +"region": { +"startLine": 35, +"startColumn": 37, +"endLine": 35, +"endColumn": 46 +} +} +}, +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'validator' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Validation.FluentValidation\RegularExpressionAdapter.cs", +"region": { +"startLine": 34, +"startColumn": 47, +"endLine": 34, +"endColumn": 56 +} +} } ] } diff --git a/analyzers/its/expected/Nancy/Nancy.Validation.FluentValidation--netstandard2.0-S3900.json b/analyzers/its/expected/Nancy/Nancy.Validation.FluentValidation--netstandard2.0-S3900.json index 8e96f96b2e4..d6348563d7e 100644 --- a/analyzers/its/expected/Nancy/Nancy.Validation.FluentValidation--netstandard2.0-S3900.json +++ b/analyzers/its/expected/Nancy/Nancy.Validation.FluentValidation--netstandard2.0-S3900.json @@ -12,6 +12,162 @@ "endColumn": 30 } } +}, +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'validator' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Validation.FluentValidation\EmailAdapter.cs", +"region": { +"startLine": 34, +"startColumn": 35, +"endLine": 34, +"endColumn": 44 +} +} +}, +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'validator' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Validation.FluentValidation\EqualAdapter.cs", +"region": { +"startLine": 35, +"startColumn": 34, +"endLine": 35, +"endColumn": 43 +} +} +}, +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'validator' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Validation.FluentValidation\ExactLengthAdapater.cs", +"region": { +"startLine": 34, +"startColumn": 40, +"endLine": 34, +"endColumn": 49 +} +} +}, +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'validator' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Validation.FluentValidation\ExclusiveBetweenAdapter.cs", +"region": { +"startLine": 35, +"startColumn": 45, +"endLine": 35, +"endColumn": 54 +} +} +}, +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'validator' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Validation.FluentValidation\GreaterThanAdapter.cs", +"region": { +"startLine": 35, +"startColumn": 40, +"endLine": 35, +"endColumn": 49 +} +} +}, +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'validator' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Validation.FluentValidation\GreaterThanOrEqualAdapter.cs", +"region": { +"startLine": 35, +"startColumn": 47, +"endLine": 35, +"endColumn": 56 +} +} +}, +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'validator' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Validation.FluentValidation\InclusiveBetweenAdapter.cs", +"region": { +"startLine": 35, +"startColumn": 45, +"endLine": 35, +"endColumn": 54 +} +} +}, +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'validator' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Validation.FluentValidation\LengthAdapter.cs", +"region": { +"startLine": 34, +"startColumn": 36, +"endLine": 34, +"endColumn": 45 +} +} +}, +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'validator' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Validation.FluentValidation\LessThanAdapter.cs", +"region": { +"startLine": 35, +"startColumn": 37, +"endLine": 35, +"endColumn": 46 +} +} +}, +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'validator' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Validation.FluentValidation\LessThanOrEqualAdapter.cs", +"region": { +"startLine": 35, +"startColumn": 44, +"endLine": 35, +"endColumn": 53 +} +} +}, +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'validator' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Validation.FluentValidation\NotEqualAdapter.cs", +"region": { +"startLine": 35, +"startColumn": 37, +"endLine": 35, +"endColumn": 46 +} +} +}, +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'validator' before using it.", +"location": { +"uri": "sources\Nancy\src\Nancy.Validation.FluentValidation\RegularExpressionAdapter.cs", +"region": { +"startLine": 34, +"startColumn": 47, +"endLine": 34, +"endColumn": 56 +} +} } ] } diff --git a/analyzers/its/expected/Net5/Net5--net5.0-S3900.json b/analyzers/its/expected/Net5/Net5--net5.0-S3900.json index bb3d3b851cf..bfd163d4ca0 100644 --- a/analyzers/its/expected/Net5/Net5--net5.0-S3900.json +++ b/analyzers/its/expected/Net5/Net5--net5.0-S3900.json @@ -2,6 +2,19 @@ "issues": [ { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'collection' before using it.", +"location": { +"uri": "sources\Net5\Net5\S3267.cs", +"region": { +"startLine": 12, +"startColumn": 37, +"endLine": 12, +"endColumn": 47 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'condition' before using it.", "location": { "uri": "sources\Net5\Net5\S3267.cs", @@ -12,6 +25,19 @@ "endColumn": 30 } } +}, +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'collection' before using it.", +"location": { +"uri": "sources\Net5\Net5\S3267.cs", +"region": { +"startLine": 27, +"startColumn": 37, +"endLine": 27, +"endColumn": 47 +} +} } ] } diff --git a/analyzers/its/expected/Net6/NullableReferenceTypesExample--net6.0-S3900.json b/analyzers/its/expected/Net6/NullableReferenceTypesExample--net6.0-S3900.json new file mode 100644 index 00000000000..9c9d9911ba5 --- /dev/null +++ b/analyzers/its/expected/Net6/NullableReferenceTypesExample--net6.0-S3900.json @@ -0,0 +1,17 @@ +{ +"issues": [ +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'someString' before using it.", +"location": { +"uri": "sources\Net6\NullableReferenceTypesExample\NullableReferenceTypesExample.cs", +"region": { +"startLine": 20, +"startColumn": 31, +"endLine": 20, +"endColumn": 41 +} +} +} +] +} diff --git a/analyzers/its/expected/akka.net/Akka--netstandard2.0-S3900.json b/analyzers/its/expected/akka.net/Akka--netstandard2.0-S3900.json index df9f0b8c77c..112ead660a6 100644 --- a/analyzers/its/expected/akka.net/Akka--netstandard2.0-S3900.json +++ b/analyzers/its/expected/akka.net/Akka--netstandard2.0-S3900.json @@ -2,6 +2,19 @@ "issues": [ { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'child' before using it.", +"location": { +"uri": "sources\akka.net\src\core\Akka\Actor\ActorCell.Children.cs", +"region": { +"startLine": 163, +"startColumn": 33, +"endLine": 163, +"endColumn": 38 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'actor' before using it.", "location": { "uri": "sources\akka.net\src\core\Akka\Actor\ActorCell.Children.cs", @@ -158,6 +171,19 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'name' before using it.", +"location": { +"uri": "sources\akka.net\src\core\Akka\Actor\ActorPath.cs", +"region": { +"startLine": 293, +"startColumn": 40, +"endLine": 293, +"endColumn": 44 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'other' before using it.", "location": { "uri": "sources\akka.net\src\core\Akka\Actor\ActorPath.cs", @@ -197,6 +223,19 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'system' before using it.", +"location": { +"uri": "sources\akka.net\src\core\Akka\Actor\ActorRef.cs", +"region": { +"startLine": 264, +"startColumn": 42, +"endLine": 264, +"endColumn": 48 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'elseValue' before using it.", "location": { "uri": "sources\akka.net\src\core\Akka\Actor\ActorRef.Extensions.cs", @@ -223,6 +262,19 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'system' before using it.", +"location": { +"uri": "sources\akka.net\src\core\Akka\Actor\ActorRefFactoryShared.cs", +"region": { +"startLine": 34, +"startColumn": 57, +"endLine": 34, +"endColumn": 63 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'actorPath' before using it.", "location": { "uri": "sources\akka.net\src\core\Akka\Actor\ActorRefFactoryShared.cs", @@ -236,6 +288,19 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'system' before using it.", +"location": { +"uri": "sources\akka.net\src\core\Akka\Actor\ActorRefFactoryShared.cs", +"region": { +"startLine": 50, +"startColumn": 46, +"endLine": 50, +"endColumn": 52 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'path' before using it.", "location": { "uri": "sources\akka.net\src\core\Akka\Actor\ActorRefProvider.cs", @@ -340,6 +405,19 @@ }, { "id": "S3900", +"message": "Refactor this constructor to avoid using members of parameter 'elements' because it could be null.", +"location": { +"uri": "sources\akka.net\src\core\Akka\Actor\ActorSelection.cs", +"region": { +"startLine": 82, +"startColumn": 31, +"endLine": 82, +"endColumn": 39 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'obj' before using it.", "location": { "uri": "sources\akka.net\src\core\Akka\Actor\ActorSelection.cs", @@ -925,6 +1003,19 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'name' before using it.", +"location": { +"uri": "sources\akka.net\src\core\Akka\Actor\LocalActorRef.cs", +"region": { +"startLine": 218, +"startColumn": 40, +"endLine": 218, +"endColumn": 44 +} +} +}, +{ +"id": "S3900", "message": "Refactor this constructor to avoid using members of parameter 'system' because it could be null.", "location": { "uri": "sources\akka.net\src\core\Akka\Actor\Message.cs", @@ -1497,6 +1588,19 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'patterns' before using it.", +"location": { +"uri": "sources\akka.net\src\core\Akka\Configuration\Hocon\HoconTokenizer.cs", +"region": { +"startLine": 121, +"startColumn": 40, +"endLine": 121, +"endColumn": 48 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'ex' before using it.", "location": { "uri": "sources\akka.net\src\core\Akka\Dispatch\AbstractDispatcher.cs", @@ -2446,6 +2550,19 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'nodes' before using it.", +"location": { +"uri": "sources\akka.net\src\core\Akka\Routing\ConsistentHash.cs", +"region": { +"startLine": 215, +"startColumn": 34, +"endLine": 215, +"endColumn": 39 +} +} +}, +{ +"id": "S3900", "message": "Refactor this constructor to avoid using members of parameter 'system' because it could be null.", "location": { "uri": "sources\akka.net\src\core\Akka\Routing\ConsistentHashRouter.cs", @@ -3369,6 +3486,19 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'fun' before using it.", +"location": { +"uri": "sources\akka.net\src\core\Akka\Util\Index.cs", +"region": { +"startLine": 123, +"startColumn": 21, +"endLine": 123, +"endColumn": 24 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'path' before using it.", "location": { "uri": "sources\akka.net\src\core\Akka\Util\Internal\Extensions.cs", @@ -3408,6 +3538,19 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'source' before using it.", +"location": { +"uri": "sources\akka.net\src\core\Akka\Util\Internal\Extensions.cs", +"region": { +"startLine": 198, +"startColumn": 34, +"endLine": 198, +"endColumn": 40 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'action' before using it.", "location": { "uri": "sources\akka.net\src\core\Akka\Util\Internal\Extensions.cs", @@ -3447,6 +3590,19 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'xs' before using it.", +"location": { +"uri": "sources\akka.net\src\core\Akka\Util\MurmurHash.cs", +"region": { +"startLine": 237, +"startColumn": 35, +"endLine": 237, +"endColumn": 37 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'arr' before using it.", "location": { "uri": "sources\akka.net\src\core\Akka\Util\MurmurHash.cs", diff --git a/analyzers/its/expected/akka.net/Akka.Cluster--netstandard2.0-S3900.json b/analyzers/its/expected/akka.net/Akka.Cluster--netstandard2.0-S3900.json index 685ace5e4ac..8ff21db2ada 100644 --- a/analyzers/its/expected/akka.net/Akka.Cluster--netstandard2.0-S3900.json +++ b/analyzers/its/expected/akka.net/Akka.Cluster--netstandard2.0-S3900.json @@ -340,6 +340,19 @@ }, { "id": "S3900", +"message": "Refactor this constructor to avoid using members of parameter 'value' because it could be null.", +"location": { +"uri": "sources\akka.net\src\core\Akka.Cluster\VectorClock.cs", +"region": { +"startLine": 90, +"startColumn": 39, +"endLine": 90, +"endColumn": 44 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'other' before using it.", "location": { "uri": "sources\akka.net\src\core\Akka.Cluster\VectorClock.cs", diff --git a/analyzers/its/expected/akka.net/Akka.MultiNodeTestRunner.Shared--netstandard2.0-S3900.json b/analyzers/its/expected/akka.net/Akka.MultiNodeTestRunner.Shared--netstandard2.0-S3900.json index 0d878637d44..7e7b2a15eff 100644 --- a/analyzers/its/expected/akka.net/Akka.MultiNodeTestRunner.Shared--netstandard2.0-S3900.json +++ b/analyzers/its/expected/akka.net/Akka.MultiNodeTestRunner.Shared--netstandard2.0-S3900.json @@ -2,6 +2,19 @@ "issues": [ { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'source' before using it.", +"location": { +"uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner.Shared\Persistence\EnumerableExtensions.cs", +"region": { +"startLine": 16, +"startColumn": 33, +"endLine": 16, +"endColumn": 39 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'assemblyName' before using it.", "location": { "uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner.Shared\Persistence\FileNameGenerator.cs", @@ -158,6 +171,19 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'nodeDatum' before using it.", +"location": { +"uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner.Shared\Reporting\TestRunTree.cs", +"region": { +"startLine": 212, +"startColumn": 33, +"endLine": 212, +"endColumn": 42 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'nodeData' before using it.", "location": { "uri": "sources\akka.net\src\core\Akka.MultiNodeTestRunner.Shared\Reporting\TestRunTree.cs", diff --git a/analyzers/its/expected/akka.net/Akka.Persistence--netstandard2.0-S3900.json b/analyzers/its/expected/akka.net/Akka.Persistence--netstandard2.0-S3900.json index 65c59fc0535..59d33e0382a 100644 --- a/analyzers/its/expected/akka.net/Akka.Persistence--netstandard2.0-S3900.json +++ b/analyzers/its/expected/akka.net/Akka.Persistence--netstandard2.0-S3900.json @@ -314,6 +314,19 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'messages' before using it.", +"location": { +"uri": "sources\akka.net\src\core\Akka.Persistence\Journal\MemoryJournal.cs", +"region": { +"startLine": 84, +"startColumn": 31, +"endLine": 84, +"endColumn": 39 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'persistent' before using it.", "location": { "uri": "sources\akka.net\src\core\Akka.Persistence\Journal\MemoryJournal.cs", diff --git a/analyzers/its/expected/akka.net/Akka.Persistence.Sql.Common--netstandard2.0-S3900.json b/analyzers/its/expected/akka.net/Akka.Persistence.Sql.Common--netstandard2.0-S3900.json index 28db438cf37..6ed4609e8bd 100644 --- a/analyzers/its/expected/akka.net/Akka.Persistence.Sql.Common--netstandard2.0-S3900.json +++ b/analyzers/its/expected/akka.net/Akka.Persistence.Sql.Common--netstandard2.0-S3900.json @@ -262,6 +262,45 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'callback' before using it.", +"location": { +"uri": "sources\akka.net\src\contrib\persistence\Akka.Persistence.Sql.Common\Journal\QueryExecutor.cs", +"region": { +"startLine": 544, +"startColumn": 25, +"endLine": 544, +"endColumn": 33 +} +} +}, +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'callback' before using it.", +"location": { +"uri": "sources\akka.net\src\contrib\persistence\Akka.Persistence.Sql.Common\Journal\QueryExecutor.cs", +"region": { +"startLine": 588, +"startColumn": 25, +"endLine": 588, +"endColumn": 33 +} +} +}, +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'callback' before using it.", +"location": { +"uri": "sources\akka.net\src\contrib\persistence\Akka.Persistence.Sql.Common\Journal\QueryExecutor.cs", +"region": { +"startLine": 633, +"startColumn": 25, +"endLine": 633, +"endColumn": 33 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'connection' before using it.", "location": { "uri": "sources\akka.net\src\contrib\persistence\Akka.Persistence.Sql.Common\Journal\QueryExecutor.cs", diff --git a/analyzers/its/expected/akka.net/Akka.Persistence.TestKit--netstandard2.0-S3900.json b/analyzers/its/expected/akka.net/Akka.Persistence.TestKit--netstandard2.0-S3900.json index bc8a3c1c4d1..bdc195739bd 100644 --- a/analyzers/its/expected/akka.net/Akka.Persistence.TestKit--netstandard2.0-S3900.json +++ b/analyzers/its/expected/akka.net/Akka.Persistence.TestKit--netstandard2.0-S3900.json @@ -2,6 +2,32 @@ "issues": [ { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'messages' before using it.", +"location": { +"uri": "sources\akka.net\src\core\Akka.Persistence.TestKit\Journal\TestJournal.cs", +"region": { +"startLine": 48, +"startColumn": 31, +"endLine": 48, +"endColumn": 39 +} +} +}, +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'recoveryCallback' before using it.", +"location": { +"uri": "sources\akka.net\src\core\Akka.Persistence.TestKit\Journal\TestJournal.cs", +"region": { +"startLine": 86, +"startColumn": 25, +"endLine": 86, +"endColumn": 41 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'metadata' before using it.", "location": { "uri": "sources\akka.net\src\core\Akka.Persistence.TestKit\SnapshotStore\TestSnapshotStore.cs", diff --git a/analyzers/its/expected/akka.net/Akka.Remote.TestKit--netstandard2.0-S3900.json b/analyzers/its/expected/akka.net/Akka.Remote.TestKit--netstandard2.0-S3900.json index 3d51df508f7..b408df9d538 100644 --- a/analyzers/its/expected/akka.net/Akka.Remote.TestKit--netstandard2.0-S3900.json +++ b/analyzers/its/expected/akka.net/Akka.Remote.TestKit--netstandard2.0-S3900.json @@ -93,6 +93,19 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'thunkAsync' before using it.", +"location": { +"uri": "sources\akka.net\src\core\Akka.Remote.TestKit\MultiNodeSpec.cs", +"region": { +"startLine": 514, +"startColumn": 38, +"endLine": 514, +"endColumn": 48 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'system' before using it.", "location": { "uri": "sources\akka.net\src\core\Akka.Remote.TestKit\MultiNodeSpec.cs", @@ -106,6 +119,19 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'messageClasses' before using it.", +"location": { +"uri": "sources\akka.net\src\core\Akka.Remote.TestKit\MultiNodeSpec.cs", +"region": { +"startLine": 552, +"startColumn": 44, +"endLine": 552, +"endColumn": 58 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'tc' before using it.", "location": { "uri": "sources\akka.net\src\core\Akka.Remote.TestKit\MultiNodeSpec.cs", @@ -116,6 +142,19 @@ "endColumn": 29 } } +}, +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'names' before using it.", +"location": { +"uri": "sources\akka.net\src\core\Akka.Remote.TestKit\Player.cs", +"region": { +"startLine": 127, +"startColumn": 34, +"endLine": 127, +"endColumn": 39 +} +} } ] } diff --git a/analyzers/its/expected/akka.net/Akka.Streams.TestKit--netstandard2.0-S3900.json b/analyzers/its/expected/akka.net/Akka.Streams.TestKit--netstandard2.0-S3900.json index 5f71960e899..5021580d7a3 100644 --- a/analyzers/its/expected/akka.net/Akka.Streams.TestKit--netstandard2.0-S3900.json +++ b/analyzers/its/expected/akka.net/Akka.Streams.TestKit--netstandard2.0-S3900.json @@ -54,6 +54,19 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'all' before using it.", +"location": { +"uri": "sources\akka.net\src\core\Akka.Streams.TestKit\TestSubscriber.cs", +"region": { +"startLine": 262, +"startColumn": 35, +"endLine": 262, +"endColumn": 38 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'cause' before using it.", "location": { "uri": "sources\akka.net\src\core\Akka.Streams.TestKit\TestSubscriber.cs", diff --git a/analyzers/its/expected/akka.net/Akka.Tests.Shared.Internals--netstandard2.0-S3900.json b/analyzers/its/expected/akka.net/Akka.Tests.Shared.Internals--netstandard2.0-S3900.json index c7f7fc6392d..bcb30efbf40 100644 --- a/analyzers/its/expected/akka.net/Akka.Tests.Shared.Internals--netstandard2.0-S3900.json +++ b/analyzers/its/expected/akka.net/Akka.Tests.Shared.Internals--netstandard2.0-S3900.json @@ -41,6 +41,19 @@ }, { "id": "S3900", +"message": "Refactor this method to add validation of parameter 'asyncActionThatThrows' before using it.", +"location": { +"uri": "sources\akka.net\src\core\Akka.Tests.Shared.Internals\AkkaSpec.cs", +"region": { +"startLine": 162, +"startColumn": 23, +"endLine": 162, +"endColumn": 44 +} +} +}, +{ +"id": "S3900", "message": "Refactor this method to add validation of parameter 'messageClasses' before using it.", "location": { "uri": "sources\akka.net\src\core\Akka.Tests.Shared.Internals\AkkaSpec.cs", @@ -155,6 +168,19 @@ "endColumn": 65 } } +}, +{ +"id": "S3900", +"message": "Refactor this method to add validation of parameter 'func' before using it.", +"location": { +"uri": "sources\akka.net\src\core\Akka.Tests.Shared.Internals\AkkaSpecExtensions.cs", +"region": { +"startLine": 224, +"startColumn": 23, +"endLine": 224, +"endColumn": 27 +} +} } ] } From f8d6f1006938db7bfc325d8fd3ee49cab0de133b Mon Sep 17 00:00:00 2001 From: Zsolt Kolbay Date: Wed, 29 Mar 2023 10:35:07 +0200 Subject: [PATCH 06/10] Add more test cases --- .../PublicMethodArgumentsShouldBeCheckedForNull.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/SymbolicExecution/Roslyn/PublicMethodArgumentsShouldBeCheckedForNull.cs b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/SymbolicExecution/Roslyn/PublicMethodArgumentsShouldBeCheckedForNull.cs index d020bf8cb5d..487765b103d 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/SymbolicExecution/Roslyn/PublicMethodArgumentsShouldBeCheckedForNull.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/SymbolicExecution/Roslyn/PublicMethodArgumentsShouldBeCheckedForNull.cs @@ -646,11 +646,21 @@ public void UpCast(string s) ((object)s).ToString(); // Noncompliant } + public void CastWithPropertyAccess(object o) + { + _ = ((Exception)o).Message; // Noncompliant + } + public void CastWithRedundantParentheses(object o) { (((string)o)).ToString(); // Noncompliant } + public void MultipleCasts(object o) + { + ((string)((object)((string)o))).ToString(); // Noncompliant + } + public void AsOperatorDownCast(object o) { (o as string).ToString(); // Noncompliant From 92536e24a387aa744281a59e0a2e78b6b37d280b Mon Sep 17 00:00:00 2001 From: Zsolt Kolbay Date: Wed, 29 Mar 2023 14:42:52 +0200 Subject: [PATCH 07/10] Review: simplify operator method --- ...icMethodArgumentsShouldBeCheckedForNull.cs | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/analyzers/src/SonarAnalyzer.CSharp/SymbolicExecution/Roslyn/PublicMethodArgumentsShouldBeCheckedForNull.cs b/analyzers/src/SonarAnalyzer.CSharp/SymbolicExecution/Roslyn/PublicMethodArgumentsShouldBeCheckedForNull.cs index c3c9fe387b1..8eb9165ced4 100644 --- a/analyzers/src/SonarAnalyzer.CSharp/SymbolicExecution/Roslyn/PublicMethodArgumentsShouldBeCheckedForNull.cs +++ b/analyzers/src/SonarAnalyzer.CSharp/SymbolicExecution/Roslyn/PublicMethodArgumentsShouldBeCheckedForNull.cs @@ -30,6 +30,16 @@ public class PublicMethodArgumentsShouldBeCheckedForNull : SymbolicRuleCheck private const string DiagnosticId = "S3900"; private const string MessageFormat = "{0}"; + private static readonly OperationKind[] DereferenceOperations = new[] + { + OperationKindEx.Invocation, + OperationKindEx.FieldReference, + OperationKindEx.PropertyReference, + OperationKindEx.EventReference, + OperationKindEx.Await, + OperationKindEx.ArrayElementReference + }; + internal static readonly DiagnosticDescriptor S3900 = DescriptorFactory.Create(DiagnosticId, MessageFormat); protected override DiagnosticDescriptor Rule => S3900; @@ -92,15 +102,9 @@ bool NullableStateIsNotKnownForParameter(IParameterSymbol symbol) => } private static bool IsParameterDereferenced(IOperationWrapperSonar operation) => - operation.Parent != null - && (operation.Parent.IsAnyKind( - OperationKindEx.Invocation, - OperationKindEx.FieldReference, - OperationKindEx.PropertyReference, - OperationKindEx.EventReference, - OperationKindEx.Await, - OperationKindEx.ArrayElementReference) - || (operation.Parent.Kind == OperationKindEx.Conversion && IsParameterDereferenced(operation.Parent.ToSonar()))); + operation.Parent is { } parent + && (parent.IsAnyKind(DereferenceOperations) + || (parent.Kind == OperationKindEx.Conversion && IsParameterDereferenced(parent.ToSonar()))); private sealed class ArgumentDereferenceWalker : SafeCSharpSyntaxWalker { From 73030fd537d678085b96bbfd8baec07f13b091f7 Mon Sep 17 00:00:00 2001 From: Zsolt Kolbay Date: Wed, 29 Mar 2023 14:43:03 +0200 Subject: [PATCH 08/10] Review: add more test cases --- ...icMethodArgumentsShouldBeCheckedForNull.cs | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/SymbolicExecution/Roslyn/PublicMethodArgumentsShouldBeCheckedForNull.cs b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/SymbolicExecution/Roslyn/PublicMethodArgumentsShouldBeCheckedForNull.cs index 487765b103d..4ae3f625314 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/SymbolicExecution/Roslyn/PublicMethodArgumentsShouldBeCheckedForNull.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/SymbolicExecution/Roslyn/PublicMethodArgumentsShouldBeCheckedForNull.cs @@ -638,49 +638,63 @@ public class Conversion { public void DownCast(object o) { - ((string)o).ToString(); // Noncompliant + ((string)o).ToString(); // Noncompliant } public void UpCast(string s) { - ((object)s).ToString(); // Noncompliant + ((object)s).ToString(); // Noncompliant } public void CastWithPropertyAccess(object o) { - _ = ((Exception)o).Message; // Noncompliant + _ = ((Exception)o).Message; // Noncompliant } public void CastWithRedundantParentheses(object o) { - (((string)o)).ToString(); // Noncompliant + (((string)o)).ToString(); // Noncompliant } public void MultipleCasts(object o) { - ((string)((object)((string)o))).ToString(); // Noncompliant + ((string)((object)((string)o))).ToString(); // Noncompliant } public void AsOperatorDownCast(object o) { - (o as string).ToString(); // Noncompliant + (o as string).ToString(); // Noncompliant } public void AsOperatorUpCast(string s) { - (s as object).ToString(); // Noncompliant + (s as object).ToString(); // Noncompliant } public void ForEachLoop(object[] arr) { - foreach (object o in arr) // Noncompliant - the array is first cast to an IEnumerable, then the GetEnumerator method is invoked on it + foreach (object o in arr) // Noncompliant - the array is first cast to an IEnumerable, then the GetEnumerator method is invoked on it { } } public void ForEachLoopWithCast(object[] arr) { - foreach (object o in (IEnumerable)arr) // Noncompliant + foreach (object o in (IEnumerable)arr) // Noncompliant + { + } + } + + public void ForEachLoopWithParentheses(object[] arr) + { + foreach (object o in ((arr))) // Noncompliant + { + } + } + + public void ForEachLoopWithCastAndParentheses(object[] arr) + { + foreach (object o in ((object[])(object)((arr)))) // Noncompliant { } } From a850e0739a03109a0f320f7c460b2946676e0699 Mon Sep 17 00:00:00 2001 From: Zsolt Kolbay Date: Wed, 29 Mar 2023 16:45:50 +0200 Subject: [PATCH 09/10] Review: add more test cases --- ...icMethodArgumentsShouldBeCheckedForNull.cs | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/SymbolicExecution/Roslyn/PublicMethodArgumentsShouldBeCheckedForNull.cs b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/SymbolicExecution/Roslyn/PublicMethodArgumentsShouldBeCheckedForNull.cs index 4ae3f625314..7bef55e608f 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/SymbolicExecution/Roslyn/PublicMethodArgumentsShouldBeCheckedForNull.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/SymbolicExecution/Roslyn/PublicMethodArgumentsShouldBeCheckedForNull.cs @@ -646,9 +646,13 @@ public void UpCast(string s) ((object)s).ToString(); // Noncompliant } - public void CastWithPropertyAccess(object o) + public void CastWithMemberAccess(object o1, object o2, object o3, object o4) { - _ = ((Exception)o).Message; // Noncompliant + _ = ((CustomClass)o1).Property; // Noncompliant + ((CustomClass)o2).CustomEvent += // Noncompliant + (sender, args) => { }; + _ = ((CustomClass)o3).field; // Noncompliant + _ = ((CustomClass)o3).MethodReference; // FN } public void CastWithRedundantParentheses(object o) @@ -671,11 +675,15 @@ public void AsOperatorUpCast(string s) (s as object).ToString(); // Noncompliant } - public void ForEachLoop(object[] arr) + public void ForEachLoop(object[] arr, IEnumerable enumerable) { foreach (object o in arr) // Noncompliant - the array is first cast to an IEnumerable, then the GetEnumerator method is invoked on it { } + + foreach (object o in enumerable) // Noncompliant + { + } } public void ForEachLoopWithCast(object[] arr) @@ -698,4 +706,12 @@ public void ForEachLoopWithCastAndParentheses(object[] arr) { } } + + private class CustomClass + { + public int field; + public int Property { get; set; } + public Action MethodReference { get; set; } + public event EventHandler CustomEvent; + } } From d738fa271b619b3c891b7a98aa4db2349f7ef827 Mon Sep 17 00:00:00 2001 From: Zsolt Kolbay Date: Wed, 29 Mar 2023 16:50:25 +0200 Subject: [PATCH 10/10] Simplify test case --- .../Roslyn/PublicMethodArgumentsShouldBeCheckedForNull.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/SymbolicExecution/Roslyn/PublicMethodArgumentsShouldBeCheckedForNull.cs b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/SymbolicExecution/Roslyn/PublicMethodArgumentsShouldBeCheckedForNull.cs index 7bef55e608f..cd8b6dc2697 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/SymbolicExecution/Roslyn/PublicMethodArgumentsShouldBeCheckedForNull.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/SymbolicExecution/Roslyn/PublicMethodArgumentsShouldBeCheckedForNull.cs @@ -652,7 +652,7 @@ public void CastWithMemberAccess(object o1, object o2, object o3, object o4) ((CustomClass)o2).CustomEvent += // Noncompliant (sender, args) => { }; _ = ((CustomClass)o3).field; // Noncompliant - _ = ((CustomClass)o3).MethodReference; // FN + Func method = ((CustomClass)o3).ToString; // FN } public void CastWithRedundantParentheses(object o) @@ -711,7 +711,6 @@ private class CustomClass { public int field; public int Property { get; set; } - public Action MethodReference { get; set; } public event EventHandler CustomEvent; } }