Skip to content

Instantly share code, notes, and snippets.

@mallamanis
Created April 30, 2020 17:42
Show Gist options
  • Save mallamanis/250f40b58a108d0f1acdf3c07cb0857d to your computer and use it in GitHub Desktop.
Save mallamanis/250f40b58a108d0f1acdf3c07cb0857d to your computer and use it in GitHub Desktop.
Do not check for leap year with modulo.
/**
* @name Do not check leap year using modulo
* @description Use the system functions to check for leap years instead of modulo. Very low precision.
* @kind problem
* @tags reliability
* maintainability
* @problem.severity recommendation
* @sub-severity low
* @precision low
* @id py/no-leap-check-with-modulo
*/
import python
from BinaryExpr expr
where
expr.getRight().(IntegerLiteral).getValue() = 4 and
exists(Operator o | o = expr.getOp() and o.getSpecialMethodName() = "__mod__")
select expr, "It is possible that you are checking for a leap year with modulo. Use the `datetime` functions instead."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment