changeset 34648:4889b84b15f2

check-code: suggest pycompat.is(posix|windows|darwin) Differential Revision: https://phab.mercurial-scm.org/D1037
author Jun Wu <quark@fb.com>
date Thu, 12 Oct 2017 09:34:58 -0700
parents dacfcdd8b94e
children 586645e0589c
files contrib/check-code.py
diffstat 1 files changed, 13 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/check-code.py	Thu Oct 12 23:34:34 2017 -0700
+++ b/contrib/check-code.py	Thu Oct 12 09:34:58 2017 -0700
@@ -397,6 +397,18 @@
           (?P=quote))""", reppython),
 ]
 
+# non-filter patterns
+pynfpats = [
+    [
+    (r'pycompat\.osname\s*[=!]=\s*[\'"]nt[\'"]', "use pycompat.iswindows"),
+    (r'pycompat\.osname\s*[=!]=\s*[\'"]posix[\'"]', "use pycompat.isposix"),
+    (r'pycompat\.sysplatform\s*[!=]=\s*[\'"]darwin[\'"]',
+     "use pycompat.isdarwin"),
+    ],
+    # warnings
+    [],
+]
+
 # extension non-filter patterns
 pyextnfpats = [
     [(r'^"""\n?[A-Z]', "don't capitalize docstring title")],
@@ -513,6 +525,7 @@
 
 checks = [
     ('python', r'.*\.(py|cgi)$', r'^#!.*python', pyfilters, pypats),
+    ('python', r'.*\.(py|cgi)$', r'^#!.*python', [], pynfpats),
     ('python', r'.*hgext.*\.py$', '', [], pyextnfpats),
     ('python 3', r'.*(hgext|mercurial)/(?!demandimport|policy|pycompat).*\.py',
      '', pyfilters, py3pats),