-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathMissedSelectOpportunity.ql
More file actions
31 lines (28 loc) · 967 Bytes
/
MissedSelectOpportunity.ql
File metadata and controls
31 lines (28 loc) · 967 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
31
/**
* @name Missed opportunity to use Select
* @description The intent of a foreach loop that immediately maps its iteration variable to another variable and then
* never uses the iteration variable again can often be better expressed using LINQ's 'Select' method.
* @kind problem
* @problem.severity recommendation
* @precision high
* @id cs/linq/missed-select
* @tags quality
* maintainability
* readability
* language-features
*/
import csharp
import Linq.Helpers
predicate oversized(LocalVariableDeclStmt s) {
exists(Location loc |
loc = s.getLocation() and
loc.getEndColumn() - loc.getStartColumn() > 65
)
}
from ForeachStmtGenericEnumerable fes, LocalVariableDeclStmt s
where
missedSelectOpportunity(fes, s) and
not oversized(s)
select fes,
"This foreach loop immediately $@ - consider mapping the sequence explicitly using '.Select(...)'.",
s, "maps its iteration variable to another variable"