Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify rule S4018: modify message to make it clear the rule is about type inference #1503

Merged
merged 4 commits into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

andrei-epure-sonarsource marked this conversation as resolved.
Show resolved Hide resolved

== 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