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

Lukas Bulwahn lukas.bulwahn at gmail.com
Wed Jul 22 10:23:40 UTC 2020



On Tue, 21 Jul 2020, Mrinal Pandey wrote:

> 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\)/) {

yaml files do not have a shebang...

This whole check can probably placed elsewhere better.

> +                        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
> 
> 


More information about the Linux-kernel-mentees mailing list