Skip to content

Commit 0aa7de2

Browse files
authored
Merge pull request #16004 from tamasvajk/feature/adjust-incorrect-compare-to
C#: Simplify the output of `cs/wrong-compareto-signature` to remove e…
2 parents 4e3a6e2 + 9d65552 commit 0aa7de2

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

csharp/ql/src/API Abuse/IncorrectCompareToSignature.ql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ predicate compareToMethod(Method m, Type paramType) {
3333
paramType = m.getAParameter().getType()
3434
}
3535

36-
from Method m, RefType declaringType, Type actualParamType
36+
from Method m, RefType declaringType, Type actualParamType, string paramTypeName
3737
where
3838
m.isSourceDeclaration() and
3939
declaringType = m.getDeclaringType() and
4040
compareToMethod(m, actualParamType) and
41-
not implementsIComparable(declaringType, actualParamType)
41+
not implementsIComparable(declaringType, actualParamType) and
42+
paramTypeName = actualParamType.getName()
4243
select m,
43-
"The parameter of this 'CompareTo' method is of type $@, but $@ does not implement 'IComparable<$@>'.",
44-
actualParamType, actualParamType.getName(), declaringType, declaringType.getName(),
45-
actualParamType, actualParamType.getName()
44+
"The parameter of this 'CompareTo' method is of type '" + paramTypeName +
45+
"', but the declaring type does not implement 'IComparable<" + paramTypeName + ">'."
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The alert message of `cs/wrong-compareto-signature` has been changed to remove unnecessary element references.
5+
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
| 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 |
2-
| 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 |
1+
| 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>'. |
2+
| 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>'. |

0 commit comments

Comments
 (0)