File: explicit_compare_with_boolean_constant.py

package info (click to toggle)
widelands 2%3A1.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 600,516 kB
  • sloc: cpp: 166,473; ansic: 18,683; python: 7,697; sh: 1,363; xml: 467; makefile: 45
file content (37 lines) | stat: -rw-r--r-- 869 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/python


"""
This detects redundant code like "if (a == true)" (shoud be "if (a)") and
"while (b = false)" (should be "while (not b)").
"""

error_msg = 'Do not explicitly check for boolean state. Use if (a) instead of if (a == true).'

strip_comments_and_strings = True

regexp = r'''(?:[!=]= *(?:false|true)[^_0-9a-zA-Z])|(?:[^_0-9a-zA-Z](?:false|true) *[!=]=)'''

forbidden = [
    'if (abc == false)',
    'if (abc != false)',
    'if (false == abc)',
    'if (false != abc)',
    'if (abc == true)',
    'if (abc != true)',
    'if (true == abc)',
    'if (true != abc)',
]

allowed = [
    'if (abc)',
    'if (not abc)',
    'if (is_false == abc)',
    'if (is_false != abc)',
    'if (abc == falsevity)',
    'if (abc != falsevity)',
    'if (obstrue == abc)',
    'if (obstrue != abc)',
    'if (abc == true_thing)',
    'if (abc != true_thing)',
]