[Linux-kernel-mentees] [PATCH] checkpatch: Warn about missing shebang in scripts

Mrinal Pandey mrinalmni at gmail.com
Tue Jul 21 05:44:38 UTC 2020


checkpatch should warn if a script doesn't seem to have a shebang in the
first line. There is no such check present currently.

Issue this warning by checking if the file is a script and checking
`$realline` to be `1`, i.e. the first line. If these conditions are
satisfied and the first line is not a shebang, issue a missing or
mispaced shebang warning.

Signed-off-by: Mrinal Pandey <mrinalmni at gmail.com>
---
 scripts/checkpatch.pl | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 4c820607540b..c79233c64cee 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3165,6 +3165,13 @@ sub process {
 			}
 		}
 
+# check for missing shebang in scripts
+                if ($realline == 1 && $realfile =~ /.*\.\(py\|sh\|pl\|awk\|tc\|yaml\)/) {
+                        if ($rawline !~ /^[ \+]\s*\#\!\s*\//) {
+                                WARN("MISSING_SHEBANG", "Missing or misplaced shebang for '$realfile'");
+                        }
+                }
+
 # check for using SPDX license tag at beginning of files
 		if ($realline == $checklicenseline) {
 			if ($rawline =~ /^[ \+]\s*\#\!\s*\//) {
-- 
2.25.1

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.linuxfoundation.org/pipermail/linux-kernel-mentees/attachments/20200721/eb55dbe8/attachment.sig>


More information about the Linux-kernel-mentees mailing list