diff --git a/src/python/detectors/notebook_invalid_execution_order/notebook_invalid_execution_order.py b/src/python/detectors/notebook_invalid_execution_order/notebook_invalid_execution_order.py new file mode 100644 index 0000000..f9efae6 --- /dev/null +++ b/src/python/detectors/notebook_invalid_execution_order/notebook_invalid_execution_order.py @@ -0,0 +1,30 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +# {fact rule=notebook-invalid-execution-order@v1.0 defects=1} +# Noncompliant: execution order of cells is not linear. When executing +# cells in linear order, variables `x` and `y` are undefined before use. +# —— Code Cell 1, Execution Count 2 —— # +sum = x + y +product = x * y +exp = x ** y +# —— Code Cell 2, Execution Count 1 —— # +x = 12 +y = 13 +# —— Code Cell 3, Execution Count 3 —— # +print(sum, product, exp) +# {/fact} + + +# {fact rule=notebook-invalid-execution-order@v1.0 defects=0} +# Compliant: execution order of cells is linear. +# —— Code Cell 1, Execution Count 1 —— # +x = 12 +y = 13 +# —— Code Cell 2, Execution Count 2 —— # +sum = x + y +product = x * y +exp = x ** y +# —— Code Cell 3, Execution Count 3 —— # +print(sum, product, exp) +# {/fact}