Skip to content

Commit

Permalink
Modify rule S4018: modify message to make it clear the rule is about …
Browse files Browse the repository at this point in the history
…type inference (#1503)

* Fix S4018 message to make it clear it's about type inference.

* Added more comments to code sample.

* And more...

* Updated message to include refactoring.
  • Loading branch information
zsolt-kolbay-sonarsource authored Jan 16, 2023
1 parent 331d20a commit dc26f15
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion rules/S4018/message.adoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
=== Message

Refactor this method to have parameters matching all the type parameters.
Refactor this method to use all type parameters in the parameter list to enable type inference.

2 changes: 1 addition & 1 deletion rules/S4018/metadata.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
4 changes: 3 additions & 1 deletion rules/S4018/rule.adoc
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -13,6 +13,7 @@ namespace MyLibrary
{
public void MyMethod<T>() // Noncompliant
{
// this method can only be invoked by providing the type argument e.g. 'MyMethod<int>()'
}
}
}
Expand All @@ -31,6 +32,7 @@ namespace MyLibrary
{
public void MyMethod<T>(T param)
{
// type inference allows this to be invoked 'MyMethod(arg)'
}
}
}
Expand Down

0 comments on commit dc26f15

Please sign in to comment.