From 9ad06d721c1e481c82b4f43df819d76e35757282 Mon Sep 17 00:00:00 2001 From: Akshay Date: Sun, 14 Jul 2024 13:01:23 +0100 Subject: add examples --- examples/static-analysis/none_comparisons.tbsp | 24 ++++++++++++++++++++++++ examples/static-analysis/sample.py | 3 +++ 2 files changed, 27 insertions(+) create mode 100644 examples/static-analysis/none_comparisons.tbsp create mode 100644 examples/static-analysis/sample.py (limited to 'examples/static-analysis') diff --git a/examples/static-analysis/none_comparisons.tbsp b/examples/static-analysis/none_comparisons.tbsp new file mode 100644 index 0000000..2d65426 --- /dev/null +++ b/examples/static-analysis/none_comparisons.tbsp @@ -0,0 +1,24 @@ +BEGIN { + bool in_equal_compare = false; + string comparison_text = ""; +} + +enter comparison_operator { + if (text(node.operators) == "==") { + in_equal_compare = true; + comparison_text = text(node); + }; +} + +leave comparison_operator { + in_equal_compare = false; +} + +enter none { + if (in_equal_compare) { + print("using `==` to compare with None, use `is None` instead:\n\t"); + print(comparison_text); + print("\n"); + } else { + }; +} diff --git a/examples/static-analysis/sample.py b/examples/static-analysis/sample.py new file mode 100644 index 0000000..7c3ed09 --- /dev/null +++ b/examples/static-analysis/sample.py @@ -0,0 +1,3 @@ +def foo(): + if bar == None: + print("none") -- cgit v1.2.3