diff options
Diffstat (limited to 'examples/static-analysis')
-rw-r--r-- | examples/static-analysis/none_comparisons.tbsp | 24 | ||||
-rw-r--r-- | examples/static-analysis/sample.py | 3 |
2 files changed, 27 insertions, 0 deletions
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 @@ | |||
1 | BEGIN { | ||
2 | bool in_equal_compare = false; | ||
3 | string comparison_text = ""; | ||
4 | } | ||
5 | |||
6 | enter comparison_operator { | ||
7 | if (text(node.operators) == "==") { | ||
8 | in_equal_compare = true; | ||
9 | comparison_text = text(node); | ||
10 | }; | ||
11 | } | ||
12 | |||
13 | leave comparison_operator { | ||
14 | in_equal_compare = false; | ||
15 | } | ||
16 | |||
17 | enter none { | ||
18 | if (in_equal_compare) { | ||
19 | print("using `==` to compare with None, use `is None` instead:\n\t"); | ||
20 | print(comparison_text); | ||
21 | print("\n"); | ||
22 | } else { | ||
23 | }; | ||
24 | } | ||
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 @@ | |||
1 | def foo(): | ||
2 | if bar == None: | ||
3 | print("none") | ||