-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathWriteOnlyContainer.ql
More file actions
30 lines (28 loc) · 954 Bytes
/
WriteOnlyContainer.ql
File metadata and controls
30 lines (28 loc) · 954 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
29
30
/**
* @name Container contents are never accessed
* @description A collection or map whose contents are never queried or accessed is useless.
* @kind problem
* @problem.severity error
* @precision high
* @id cs/unused-collection
* @tags maintainability
* useless-code
* external/cwe/cwe-561
*/
import csharp
import semmle.code.csharp.commons.Collections
from Variable v
where
v.getType() instanceof CollectionType and
(
v instanceof LocalVariable or
v = any(Field f | not f.isEffectivelyPublic())
) and
forex(Access a | a = v.getAnAccess() |
a = any(ModifierMethodCall m).getQualifier() or
a = any(Assignment ass | ass.getRValue() instanceof ObjectCreation).getLValue()
) and
not v = any(ForeachStmt fs).getVariable() and
not v = any(BindingPatternExpr vpe).getVariableDeclExpr().getVariable() and
not v = any(Attribute a).getTarget()
select v, "The contents of this container are never accessed."