Merge pull request #16004 from tamasvajk/feature/adjust-incorrect-compare-to

C#: Simplify the output of `cs/wrong-compareto-signature` to remove e…
This commit is contained in:
Tamás Vajk
2024-03-21 14:38:54 +01:00
committed by GitHub
3 changed files with 12 additions and 7 deletions

View File

@@ -33,13 +33,13 @@ predicate compareToMethod(Method m, Type paramType) {
paramType = m.getAParameter().getType()
}
from Method m, RefType declaringType, Type actualParamType
from Method m, RefType declaringType, Type actualParamType, string paramTypeName
where
m.isSourceDeclaration() and
declaringType = m.getDeclaringType() and
compareToMethod(m, actualParamType) and
not implementsIComparable(declaringType, actualParamType)
not implementsIComparable(declaringType, actualParamType) and
paramTypeName = actualParamType.getName()
select m,
"The parameter of this 'CompareTo' method is of type $@, but $@ does not implement 'IComparable<$@>'.",
actualParamType, actualParamType.getName(), declaringType, declaringType.getName(),
actualParamType, actualParamType.getName()
"The parameter of this 'CompareTo' method is of type '" + paramTypeName +
"', but the declaring type does not implement 'IComparable<" + paramTypeName + ">'."

View File

@@ -0,0 +1,5 @@
---
category: minorAnalysis
---
* The alert message of `cs/wrong-compareto-signature` has been changed to remove unnecessary element references.

View File

@@ -1,2 +1,2 @@
| IncorrectCompareToSignature.cs:5:16:5:24 | CompareTo | The parameter of this 'CompareTo' method is of type $@, but $@ does not implement 'IComparable<$@>'. | IncorrectCompareToSignature.cs:3:10:3:10 | T | T | IncorrectCompareToSignature.cs:3:7:3:11 | C1`1 | C1`1 | IncorrectCompareToSignature.cs:3:10:3:10 | T | T |
| IncorrectCompareToSignatureBad.cs:5:16:5:24 | CompareTo | The parameter of this 'CompareTo' method is of type $@, but $@ does not implement 'IComparable<$@>'. | IncorrectCompareToSignatureBad.cs:3:7:3:9 | Bad | Bad | IncorrectCompareToSignatureBad.cs:3:7:3:9 | Bad | Bad | IncorrectCompareToSignatureBad.cs:3:7:3:9 | Bad | Bad |
| IncorrectCompareToSignature.cs:5:16:5:24 | CompareTo | The parameter of this 'CompareTo' method is of type 'T', but the declaring type does not implement 'IComparable<T>'. |
| IncorrectCompareToSignatureBad.cs:5:16:5:24 | CompareTo | The parameter of this 'CompareTo' method is of type 'Bad', but the declaring type does not implement 'IComparable<Bad>'. |