Python: Recognize shebangs in module usage detection

This commit is contained in:
Rasmus Wriedt Larsen
2020-02-13 17:44:56 +01:00
parent 01f5b3dc63
commit 82b29b5698
2 changed files with 7 additions and 2 deletions

View File

@@ -210,7 +210,12 @@ class ModuleValue extends Value {
i.getTest().(Compare).compares(name, op, main) and
name.getId() = "__name__" and main.getText() = "__main__"
)
// TODO: Add she-bang handling
or
exists(Comment c |
c.getLocation().getFile() = this.getPath() and
c.getLocation().getStartLine() = 1 and
c.getText().regexpMatch("^#!/.*python(2|3)?[ \\\\t]*$")
)
)
}
}