Files
codeql/csharp/ql/src/Linq/RedundantSelect.ql
Erik Krogh Kristensen 63ecae5426 update imports
2021-11-18 17:31:17 +01:00

24 lines
632 B
Plaintext

/**
* @name Redundant Select
* @description Writing 'seq.Select(e => e)' or 'from e in seq select e' is redundant.
* @kind problem
* @problem.severity warning
* @precision very-high
* @id cs/linq/useless-select
* @tags maintainability
* language-features
* external/cwe/cwe-561
*/
import csharp
import Linq.Helpers
predicate isIdentityFunction(AnonymousFunctionExpr afe) {
afe.getNumberOfParameters() = 1 and
afe.getExpressionBody() = afe.getParameter(0).getAnAccess()
}
from SelectCall sc
where isIdentityFunction(sc.getFunctionExpr())
select sc, "This LINQ selection is redundant and can be removed."