forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntGetHashCode.ql
More file actions
28 lines (26 loc) · 783 Bytes
/
IntGetHashCode.ql
File metadata and controls
28 lines (26 loc) · 783 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/**
* @name Useless call to GetHashCode()
* @description Calling 'GetHashCode()' on integer types is redundant because the method always returns
* the original value.
* @kind problem
* @problem.severity recommendation
* @precision high
* @id cs/useless-gethashcode-call
* @tags readability
* useless-code
* quality
*/
import csharp
import semmle.code.csharp.frameworks.System
from MethodCall mc, IntegralType t
where
mc.getTarget() instanceof GetHashCodeMethod and
t = mc.getQualifier().getType() and
(
t instanceof ByteType or
t instanceof SByteType or
t instanceof ShortType or
t instanceof UShortType or
t instanceof IntType
)
select mc, "Calling GetHashCode() on type " + t.toStringWithTypes() + " is redundant."