changeset 34077:e267d4ee4f2d

check-code: forbid using bash in shebang Some platforms (ex. FreeBSD) do not have `bash` by default. Therefore it should not be used in test scripts. Differential Revision: https://phab.mercurial-scm.org/D609
author Jun Wu <quark@fb.com>
date Fri, 01 Sep 2017 15:47:32 -0700
parents 6fb5a06b92c6
children 11499bad0359
files contrib/check-code.py
diffstat 1 files changed, 4 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/check-code.py	Fri Sep 01 12:34:34 2017 -0700
+++ b/contrib/check-code.py	Fri Sep 01 15:47:32 2017 -0700
@@ -119,7 +119,8 @@
     (r'\[[^\]]+==', '[ foo == bar ] is a bashism, use [ foo = bar ] instead'),
     (r'(^|\|\s*)grep (-\w\s+)*[^|]*[(|]\w',
      "use egrep for extended grep syntax"),
-    (r'/bin/', "don't use explicit paths for tools"),
+    (r'(?<!!)/bin/', "don't use explicit paths for tools"),
+    (r'#!.*/bash', "don't use bash in shebang, use sh"),
     (r'[^\n]\Z', "no trailing newline"),
     (r'export .*=', "don't export and assign at once"),
     (r'^source\b', "don't use 'source', use '.'"),
@@ -159,7 +160,7 @@
 ]
 
 testfilters = [
-    (r"( *)(#([^\n]*\S)?)", repcomment),
+    (r"( *)(#([^!][^\n]*\S)?)", repcomment),
     (r"<<(\S+)((.|\n)*?\n\1)", rephere),
 ]
 
@@ -232,7 +233,7 @@
 
 utestfilters = [
     (r"<<(\S+)((.|\n)*?\n  > \1)", rephere),
-    (r"( +)(#([^\n]*\S)?)", repcomment),
+    (r"( +)(#([^!][^\n]*\S)?)", repcomment),
 ]
 
 pypats = [