Python: Stop py/import-deprecated-module from double alerting

This changes the location from the import statement, to the actual expression
This commit is contained in:
Rasmus Wriedt Larsen
2020-01-28 16:14:01 +01:00
parent 7949acc3ef
commit e92d6c0459
3 changed files with 13 additions and 11 deletions

View File

@@ -12,6 +12,10 @@
import python
/**
* The module `name` was deprecated in Python version `major`.`minor`,
* and module `instead` should be used instead (or `instead = "no replacement"`)
*/
predicate deprecated_module(string name, string instead, int major, int minor) {
name = "posixfile" and instead = "email" and major = 1 and minor = 5
or
@@ -69,8 +73,8 @@ string replacement_message(string mod) {
)
}
from ImportExpr imp, Stmt s, Expr e
from ImportExpr imp, string name
where
s.getASubExpression() = e and
(e = imp or e.contains(imp))
select s, deprecation_message(imp.getName()) + replacement_message(imp.getName())
name = imp.getName() and
deprecated_module(name, _, _, _)
select imp, deprecation_message(name) + replacement_message(name)