File tree Expand file tree Collapse file tree 4 files changed +5
-6
lines changed
lib/semmle/code/csharp/commons
test/query-tests/Useless Code/RedundantToStringCall Expand file tree Collapse file tree 4 files changed +5
-6
lines changed Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ class ImplicitToStringExpr extends Expr {
2929 m = p .getCallable ( )
3030 |
3131 m = any ( SystemTextStringBuilderClass c ) .getAMethod ( ) and
32- m .getName ( ) . regexpMatch ( "Append(Line)?" ) and
32+ m .getName ( ) = "Append" and
3333 not p .getType ( ) instanceof ArrayType
3434 or
3535 p instanceof StringFormatItemParameter and
Original file line number Diff line number Diff line change @@ -18,5 +18,6 @@ import semmle.code.csharp.frameworks.System
1818from MethodCall mc
1919where
2020 mc instanceof ImplicitToStringExpr and
21- mc .getTarget ( ) instanceof ToStringMethod
21+ mc .getTarget ( ) instanceof ToStringMethod and
22+ not mc .getQualifier ( ) instanceof BaseAccess
2223select mc , "Redundant call to 'ToString' on a String object."
Original file line number Diff line number Diff line change @@ -17,8 +17,8 @@ public void M(object o)
1717 var sb = new StringBuilder ( ) ;
1818 sb . Append ( o . ToString ( ) ) ; // $ Alert
1919 sb . Append ( o ) ; // GOOD
20- sb . AppendLine ( o . ToString ( ) ) ; // $ SPURIOUS: Alert
20+ sb . AppendLine ( o . ToString ( ) ) ; // GOOD
2121
22- Console . WriteLine ( $ "Hello: { base . ToString ( ) } ") ; // $ SPURIOUS: Alert
22+ Console . WriteLine ( $ "Hello: { base . ToString ( ) } ") ; // GOOD
2323 }
2424}
Original file line number Diff line number Diff line change 22| RedundantToStringCall.cs:11:37:11:48 | call to method ToString | Redundant call to 'ToString' on a String object. |
33| RedundantToStringCall.cs:14:39:14:50 | call to method ToString | Redundant call to 'ToString' on a String object. |
44| RedundantToStringCall.cs:18:19:18:30 | call to method ToString | Redundant call to 'ToString' on a String object. |
5- | RedundantToStringCall.cs:20:23:20:34 | call to method ToString | Redundant call to 'ToString' on a String object. |
6- | RedundantToStringCall.cs:22:37:22:51 | call to method ToString | Redundant call to 'ToString' on a String object. |
75| RedundantToStringCallBad.cs:7:45:7:56 | call to method ToString | Redundant call to 'ToString' on a String object. |
You can’t perform that action at this time.
0 commit comments