Created
April 30, 2020 17:42
-
-
Save mallamanis/250f40b58a108d0f1acdf3c07cb0857d to your computer and use it in GitHub Desktop.
Do not check for leap year with modulo.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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