comparison contrib/check-code.py @ 36949:35d814fe2f30

contrib: open a hole in the open().read() ban for open().close() It turns out open().close() is both fine and something we occasionally do to verify something can be written. The few cases in the codebase were getting missed due to a regular expression bug (which I discussed in my previous change), but since I'm about to fix the bug, I need to fix the patterns. Differential Revision: https://phab.mercurial-scm.org/D2864
author Augie Fackler <augie@google.com>
date Wed, 14 Mar 2018 15:42:23 -0400
parents c38e9248f531
children a8d540d2628c
comparison
equal deleted inserted replaced
36948:0585337ea787 36949:35d814fe2f30
317 "use opener.write() instead"), 317 "use opener.write() instead"),
318 (r'[\s\(](open|file)\([^)]*\)\.read\(', 318 (r'[\s\(](open|file)\([^)]*\)\.read\(',
319 "use util.readfile() instead"), 319 "use util.readfile() instead"),
320 (r'[\s\(](open|file)\([^)]*\)\.write\(', 320 (r'[\s\(](open|file)\([^)]*\)\.write\(',
321 "use util.writefile() instead"), 321 "use util.writefile() instead"),
322 (r'^[\s\(]*(open(er)?|file)\([^)]*\)', 322 (r'^[\s\(]*(open(er)?|file)\([^)]*\)(?!\.close\(\))',
323 "always assign an opened file to a variable, and close it afterwards"), 323 "always assign an opened file to a variable, and close it afterwards"),
324 (r'[\s\(](open|file)\([^)]*\)\.', 324 (r'[\s\(](open|file)\([^)]*\)\.(?!close\(\))',
325 "always assign an opened file to a variable, and close it afterwards"), 325 "always assign an opened file to a variable, and close it afterwards"),
326 (r'(?i)descend[e]nt', "the proper spelling is descendAnt"), 326 (r'(?i)descend[e]nt', "the proper spelling is descendAnt"),
327 (r'\.debug\(\_', "don't mark debug messages for translation"), 327 (r'\.debug\(\_', "don't mark debug messages for translation"),
328 (r'\.strip\(\)\.split\(\)', "no need to strip before splitting"), 328 (r'\.strip\(\)\.split\(\)', "no need to strip before splitting"),
329 (r'^\s*except\s*:', "naked except clause", r'#.*re-raises'), 329 (r'^\s*except\s*:', "naked except clause", r'#.*re-raises'),