mirror of
https://github.com/github/codeql.git
synced 2026-03-17 13:06:48 +01:00
Rename files by style guide and change query metadata
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
# invalid class with return outside of a function
|
||||
# invalid class with return outside a function
|
||||
class InvalidClass1(object):
|
||||
if [1, 2, 3]:
|
||||
return "Exists"
|
||||
|
||||
# invalid statement with yield outside of a function
|
||||
# invalid statement with yield outside a function
|
||||
for i in [1, 2, 3]:
|
||||
yield i
|
||||
@@ -18,7 +18,7 @@ Consequently, it is not possible to suggest a general fix.</p>
|
||||
<p>In this example, a <code>return</code> statement is used outside a class method in a class and
|
||||
a <code>yield</code> statement is used outside a function in a scope of a module which would result
|
||||
in a <code>SyntaxError</code> when running this code.</p>
|
||||
<sample src="ReturnOrYieldOutsideOfFunction.py" />
|
||||
<sample src="ReturnOrYieldOutsideFunction.py" />
|
||||
</example>
|
||||
|
||||
<references>
|
||||
@@ -1,13 +1,13 @@
|
||||
/**
|
||||
* @name Using 'return' or 'yield' outside a function causes a 'SyntaxError' at runtime
|
||||
* @description Statements 'return' and 'yield' should be used only within a function.
|
||||
* @name Use of 'return' or 'yield' outside a function
|
||||
* @description Using 'return' or 'yield' outside a function causes a 'SyntaxError' at runtime.
|
||||
* @kind problem
|
||||
* @tags reliability
|
||||
* correctness
|
||||
* @problem.severity error
|
||||
* @sub-severity low
|
||||
* @precision very-high
|
||||
* @id py/return-or-yield-outside-of-function
|
||||
* @precision medium
|
||||
* @id py/return-or-yield-outside-function
|
||||
*/
|
||||
|
||||
import python
|
||||
@@ -22,4 +22,4 @@ where
|
||||
or
|
||||
node instanceof YieldFrom and kind = "yield from"
|
||||
)
|
||||
select node, "'" + kind + "' is used outside of a function."
|
||||
select node, "'" + kind + "' is used outside a function."
|
||||
@@ -0,0 +1,9 @@
|
||||
| ReturnOrYieldOutsideFunction_test.py:31:9:31:23 | Return | 'return' is used outside a function. |
|
||||
| ReturnOrYieldOutsideFunction_test.py:36:9:36:15 | Yield | 'yield' is used outside a function. |
|
||||
| ReturnOrYieldOutsideFunction_test.py:41:9:41:25 | YieldFrom | 'yield from' is used outside a function. |
|
||||
| ReturnOrYieldOutsideFunction_test.py:45:5:45:12 | Return | 'return' is used outside a function. |
|
||||
| ReturnOrYieldOutsideFunction_test.py:49:5:49:11 | Yield | 'yield' is used outside a function. |
|
||||
| ReturnOrYieldOutsideFunction_test.py:53:5:53:16 | YieldFrom | 'yield from' is used outside a function. |
|
||||
| ReturnOrYieldOutsideFunction_test.py:57:1:57:14 | YieldFrom | 'yield from' is used outside a function. |
|
||||
| ReturnOrYieldOutsideFunction_test.py:60:1:60:12 | Return | 'return' is used outside a function. |
|
||||
| ReturnOrYieldOutsideFunction_test.py:63:1:63:11 | Yield | 'yield' is used outside a function. |
|
||||
@@ -0,0 +1 @@
|
||||
Statements/ReturnOrYieldOutsideFunction.ql
|
||||
@@ -25,39 +25,39 @@ def valid_func2():
|
||||
def valid_func3():
|
||||
yield from [1, 2]
|
||||
|
||||
# invalid class with return outside of a function
|
||||
# invalid class with return outside a function
|
||||
class InvalidClass1(object):
|
||||
if [1, 2, 3]:
|
||||
return "Exists"
|
||||
|
||||
# invalid class with yield outside of a function
|
||||
# invalid class with yield outside a function
|
||||
class InvalidClass2(object):
|
||||
while True:
|
||||
yield 1
|
||||
|
||||
# invalid class with yield from outside of a function
|
||||
# invalid class with yield from outside a function
|
||||
class InvalidClass3(object):
|
||||
while True:
|
||||
yield from [1, 2]
|
||||
|
||||
# invalid statement with return outside of a function
|
||||
# invalid statement with return outside a function
|
||||
for i in [1, 2, 3]:
|
||||
return i
|
||||
|
||||
# invalid statement with yield outside of a function
|
||||
# invalid statement with yield outside a function
|
||||
for i in [1, 2, 3]:
|
||||
yield i
|
||||
|
||||
# invalid statement with yield from outside of a function
|
||||
# invalid statement with yield from outside a function
|
||||
for i in [1, 2, 3]:
|
||||
yield from i
|
||||
|
||||
# invalid statement with yield from outside of a function
|
||||
# invalid statement with yield from outside a function
|
||||
var = [1,2,3]
|
||||
yield from var
|
||||
|
||||
# invalid statement with return outside of a function
|
||||
# invalid statement with return outside a function
|
||||
return False
|
||||
|
||||
# invalid statement with yield outside of a function
|
||||
# invalid statement with yield outside a function
|
||||
yield False
|
||||
@@ -1 +0,0 @@
|
||||
Statements/ReturnOrYieldOutsideOfFunction.ql
|
||||
Reference in New Issue
Block a user