mirror of
https://github.com/github/codeql.git
synced 2026-08-02 00:13:00 +02:00
23 lines
760 B
Plaintext
23 lines
760 B
Plaintext
/**
|
|
* @name Missed opportunity to use Cast
|
|
* @description The intent of a foreach loop that immediately casts its iteration variable to another type and then
|
|
* never uses the iteration variable again can often be better expressed using LINQ's 'Cast' method.
|
|
* @kind problem
|
|
* @problem.severity recommendation
|
|
* @precision high
|
|
* @id cs/linq/missed-cast
|
|
* @tags quality
|
|
* maintainability
|
|
* readability
|
|
* language-features
|
|
*/
|
|
|
|
import csharp
|
|
import Linq.Helpers
|
|
|
|
from ForeachStmtEnumerable fes, LocalVariableDeclStmt s
|
|
where missedCastOpportunity(fes, s)
|
|
select fes,
|
|
"This foreach loop immediately $@ - consider casting the sequence explicitly using '.Cast(...)'.",
|
|
s, "casts its iteration variable to another type"
|