Skip to content

Instantly share code, notes, and snippets.

@erik-krogh
Created December 20, 2021 22:53
Show Gist options
  • Save erik-krogh/78a9e543a3543dc98c29fb7afb1fda2f to your computer and use it in GitHub Desktop.
Save erik-krogh/78a9e543a3543dc98c29fb7afb1fda2f to your computer and use it in GitHub Desktop.
/**
* @name Using exists instead of any
* @description TODO
* @kind problem
* @problem.severity warning
* @id ql/exists-instead-of-any
* @precision high
*/
import ql
from Exists ex, ComparisonFormula comp, AstNode operand
where
count(ex.getArgument(_)) = 1 and
exists(ex.getRange()) and
not exists(ex.getFormula()) and
comp = ex.getRange() and
comp.getOperator() = "=" and
comp.getAnOperand().(VarAccess).getDeclaration() = ex.getArgument(0) and
not operand.(VarAccess).getDeclaration() = ex.getArgument(0) and
operand = comp.getAnOperand() and
count(VarAccess access | access.getDeclaration() = ex.getArgument(0)) = 1
select ex, "This exists can be simplfied an any(..)."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment