From 2362544c348f44cc2154c62d56561594d5e829bd Mon Sep 17 00:00:00 2001 From: Zsolt Kolbay Date: Mon, 16 Jan 2023 11:27:44 +0100 Subject: [PATCH 1/4] Fix S4018 message to make it clear it's about type inference. --- rules/S4018/message.adoc | 2 +- rules/S4018/metadata.json | 2 +- rules/S4018/rule.adoc | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/rules/S4018/message.adoc b/rules/S4018/message.adoc index b8521417577..db48271f029 100644 --- a/rules/S4018/message.adoc +++ b/rules/S4018/message.adoc @@ -1,4 +1,4 @@ === Message -Refactor this method to have parameters matching all the type parameters. +Use all type parameters in the parameter list to enable type inference. diff --git a/rules/S4018/metadata.json b/rules/S4018/metadata.json index 66e53a4b6f5..3b42c80dcd7 100644 --- a/rules/S4018/metadata.json +++ b/rules/S4018/metadata.json @@ -1,5 +1,5 @@ { - "title": "Generic methods should provide type parameters", + "title": "All type parameters should be used in the parameter list to enable type inference", "type": "CODE_SMELL", "status": "ready", "remediation": { diff --git a/rules/S4018/rule.adoc b/rules/S4018/rule.adoc index 5134a2fced2..8e564b831c2 100644 --- a/rules/S4018/rule.adoc +++ b/rules/S4018/rule.adoc @@ -1,4 +1,4 @@ -The best way to determine the type of a generic method is by inference based on the type of argument that is passed to the method. This is not possible when a parameter type is missing from the argument list. +Type inference enables the call of a generic method without explicitly specifying its type arguments. This is not possible when a parameter type is missing from the argument list. == Noncompliant Code Example From 88c7fe0c14682fd5ffca663ee9d881298050b72d Mon Sep 17 00:00:00 2001 From: Zsolt Kolbay Date: Mon, 16 Jan 2023 13:46:44 +0100 Subject: [PATCH 2/4] Added more comments to code sample. --- rules/S4018/rule.adoc | 1 + 1 file changed, 1 insertion(+) diff --git a/rules/S4018/rule.adoc b/rules/S4018/rule.adoc index 8e564b831c2..ef610b0bc82 100644 --- a/rules/S4018/rule.adoc +++ b/rules/S4018/rule.adoc @@ -13,6 +13,7 @@ namespace MyLibrary { public void MyMethod() // Noncompliant { + // this method can only be invoked by providing the type argument e.g. 'MyMethod()' } } } From 8c8b19d0cf257fad54e0454412e583220a20146f Mon Sep 17 00:00:00 2001 From: Zsolt Kolbay Date: Mon, 16 Jan 2023 13:50:14 +0100 Subject: [PATCH 3/4] And more... --- rules/S4018/rule.adoc | 1 + 1 file changed, 1 insertion(+) diff --git a/rules/S4018/rule.adoc b/rules/S4018/rule.adoc index ef610b0bc82..19e7f18abf5 100644 --- a/rules/S4018/rule.adoc +++ b/rules/S4018/rule.adoc @@ -32,6 +32,7 @@ namespace MyLibrary { public void MyMethod(T param) { + // type inference allows this to be invoked 'MyMethod(arg)' } } } From 6887bb21da8c9e115656036009eaa43f36f5d5ab Mon Sep 17 00:00:00 2001 From: Zsolt Kolbay Date: Mon, 16 Jan 2023 14:56:53 +0100 Subject: [PATCH 4/4] Updated message to include refactoring. --- rules/S4018/message.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rules/S4018/message.adoc b/rules/S4018/message.adoc index db48271f029..881f3a986bc 100644 --- a/rules/S4018/message.adoc +++ b/rules/S4018/message.adoc @@ -1,4 +1,4 @@ === Message -Use all type parameters in the parameter list to enable type inference. +Refactor this method to use all type parameters in the parameter list to enable type inference.