check-code: disallow calling opener(...).read() and opener(..).write()
authorDan Villiom Podlaski Christiansen <danchr@gmail.com>
Mon, 02 May 2011 10:11:24 +0200
changeset 14169 1b4b82063ce2
parent 14168 135e244776f0
child 14172 1a919c3271bf
check-code: disallow calling opener(...).read() and opener(..).write()
contrib/check-code.py
--- a/contrib/check-code.py	Mon May 02 10:11:18 2011 +0200
+++ b/contrib/check-code.py	Mon May 02 10:11:24 2011 +0200
@@ -161,6 +161,18 @@
     (r' is\s+(not\s+)?["\'0-9-]', "object comparison with literal"),
     (r' [=!]=\s+(True|False|None)',
      "comparison with singleton, use 'is' or 'is not' instead"),
+    (r'opener\([^)]*\).read\(',
+     "use opener.read() instead"),
+    (r'opener\([^)]*\).write\(',
+     "use opener.write() instead"),
+    (r'[\s\(](open|file)\([^)]*\)\.read\(',
+     "use util.readfile() instead"),
+    (r'[\s\(](open|file)\([^)]*\)\.write\(',
+     "use util.readfile() instead"),
+    (r'^[\s\(]*(open(er)?|file)\([^)]*\)',
+     "always assign an opened file to a variable, and close it afterwards"),
+    (r'[\s\(](open|file)\([^)]*\)\.',
+     "always assign an opened file to a variable, and close it afterwards"),
   ],
   # warnings
   [