mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
Python: Autoformat all .ql files.
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
* builtin
|
||||
* object
|
||||
*/
|
||||
|
||||
|
||||
import python
|
||||
|
||||
from Expr e, string name
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* @tags call
|
||||
* function
|
||||
*/
|
||||
|
||||
|
||||
import python
|
||||
|
||||
from Value len, CallNode call
|
||||
|
||||
@@ -6,11 +6,11 @@
|
||||
* try
|
||||
* exception
|
||||
*/
|
||||
|
||||
|
||||
import python
|
||||
|
||||
from ExceptStmt ex, ClassValue cls
|
||||
where
|
||||
where
|
||||
cls.getName() = "MyExceptionClass" and
|
||||
ex.getType().pointsTo(cls)
|
||||
select ex
|
||||
|
||||
@@ -11,7 +11,8 @@
|
||||
import python
|
||||
|
||||
from IfExp e, ClassObject cls1, ClassObject cls2
|
||||
where
|
||||
e.getBody().refersTo(_, cls1, _) and e.getOrelse().refersTo(_, cls2, _) and
|
||||
where
|
||||
e.getBody().refersTo(_, cls1, _) and
|
||||
e.getOrelse().refersTo(_, cls2, _) and
|
||||
cls1 != cls2
|
||||
select e
|
||||
select e
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* block
|
||||
* statement
|
||||
*/
|
||||
|
||||
|
||||
import python
|
||||
|
||||
from StmtList blk
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* @id py/examples/emptythen
|
||||
* @name If statements with empty then branch
|
||||
* @description Finds 'if' statements where the "then" branch
|
||||
* @description Finds 'if' statements where the "then" branch
|
||||
* consists entirely of Pass statements
|
||||
* @tags if
|
||||
* then
|
||||
@@ -9,13 +9,13 @@
|
||||
* conditional
|
||||
* branch
|
||||
*/
|
||||
|
||||
|
||||
import python
|
||||
|
||||
from If i
|
||||
where
|
||||
not exists(Stmt s |
|
||||
i.getStmt(_) = s and
|
||||
i.getStmt(_) = s and
|
||||
not s instanceof Pass
|
||||
)
|
||||
select i
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* test
|
||||
* boolean
|
||||
*/
|
||||
|
||||
|
||||
import python
|
||||
|
||||
from Compare eq
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* equality
|
||||
* expression statement
|
||||
*/
|
||||
|
||||
|
||||
import python
|
||||
|
||||
from ExprStmt e, Compare eq
|
||||
|
||||
@@ -9,11 +9,11 @@
|
||||
* subtype
|
||||
* supertype
|
||||
*/
|
||||
|
||||
|
||||
import python
|
||||
|
||||
from ClassObject sub, ClassObject base
|
||||
where
|
||||
where
|
||||
base.getName() = "MyClass" and
|
||||
sub.getABaseType() = base
|
||||
select sub
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* @description Finds files called `spam.py`
|
||||
* @tags file
|
||||
*/
|
||||
|
||||
|
||||
import python
|
||||
|
||||
from File f
|
||||
|
||||
@@ -10,4 +10,4 @@ import python
|
||||
|
||||
from Function f
|
||||
where f.isGenerator()
|
||||
select f
|
||||
select f
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* @tags integer
|
||||
* literal
|
||||
*/
|
||||
|
||||
|
||||
import python
|
||||
|
||||
from IntegerLiteral literal
|
||||
|
||||
@@ -5,11 +5,11 @@
|
||||
* @tags call
|
||||
* method
|
||||
*/
|
||||
|
||||
|
||||
import python
|
||||
|
||||
from AstNode call, PythonFunctionValue method
|
||||
where
|
||||
where
|
||||
method.getQualifiedName() = "MyClass.methodName" and
|
||||
method.getACall().getNode() = call
|
||||
select call
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* constructor
|
||||
* new
|
||||
*/
|
||||
|
||||
|
||||
import python
|
||||
|
||||
from Call new, ClassValue cls
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* @tags method
|
||||
* override
|
||||
*/
|
||||
|
||||
|
||||
import python
|
||||
|
||||
from FunctionObject override, FunctionObject base
|
||||
|
||||
@@ -4,11 +4,11 @@
|
||||
* @description Find print statements or calls to the builtin function 'print'
|
||||
* @tags print
|
||||
*/
|
||||
|
||||
|
||||
import python
|
||||
|
||||
from AstNode print
|
||||
where
|
||||
where
|
||||
/* Python 2 without `from __future__ import print_function` */
|
||||
print instanceof Print
|
||||
or
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
/**
|
||||
* @id py/examples/private-access
|
||||
* @name Private access
|
||||
* @description Find accesses to "private" attributes (those starting with an underscore)
|
||||
* @description Find accesses to "private" attributes (those starting with an underscore)
|
||||
* @tags access
|
||||
* private
|
||||
*/
|
||||
|
||||
|
||||
import python
|
||||
|
||||
predicate is_private(Attribute a) {
|
||||
a.getName().matches("\\_%") and
|
||||
a.getName().matches("\\_%") and
|
||||
not a.getName().matches("\\_\\_%\\_\\_")
|
||||
}
|
||||
|
||||
from Attribute access
|
||||
where is_private(access) and
|
||||
not access.getObject().(Name).getId() = "self"
|
||||
where
|
||||
is_private(access) and
|
||||
not access.getObject().(Name).getId() = "self"
|
||||
select access
|
||||
|
||||
@@ -6,13 +6,11 @@
|
||||
* raise
|
||||
* exception
|
||||
*/
|
||||
|
||||
|
||||
import python
|
||||
|
||||
from Raise raise, ClassValue ex
|
||||
where
|
||||
ex.getName() = "AnException" and
|
||||
(
|
||||
raise.getException().pointsTo(ex.getASuperType())
|
||||
)
|
||||
raise.getException().pointsTo(ex.getASuperType())
|
||||
select raise, "Don't raise instances of 'AnException'"
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/**
|
||||
* @id py/examples/raw-string
|
||||
* @name Raw string literals
|
||||
* @description Finds string literals with an 'r' prefix
|
||||
* @description Finds string literals with an 'r' prefix
|
||||
* @tags string
|
||||
* raw
|
||||
*/
|
||||
|
||||
|
||||
import python
|
||||
|
||||
from StrConst s
|
||||
|
||||
@@ -8,11 +8,11 @@
|
||||
* collection
|
||||
* add
|
||||
*/
|
||||
|
||||
|
||||
import python
|
||||
|
||||
from SubscriptNode store
|
||||
where
|
||||
where
|
||||
store.isStore() and
|
||||
store.getIndex().pointsTo(Value::named("None"))
|
||||
select store
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
import python
|
||||
|
||||
from Try t
|
||||
where exists(t.getFinalbody())
|
||||
and not exists(t.getAHandler())
|
||||
where
|
||||
exists(t.getFinalbody()) and
|
||||
not exists(t.getAHandler())
|
||||
select t
|
||||
|
||||
Reference in New Issue
Block a user