linux-kernel-mentees.lists.linuxfoundation.org archive mirror
 help / color / mirror / Atom feed
* [Linux-kernel-mentees] [PATCH] checkpatch: Warn about missing shebang in scripts
@ 2020-07-21  5:44 Mrinal Pandey
  2020-07-22 10:23 ` Lukas Bulwahn
  0 siblings, 1 reply; 3+ messages in thread
From: Mrinal Pandey @ 2020-07-21  5:44 UTC (permalink / raw)
  To: lukas.bulwahn, skhan, Linux-kernel-mentees


[-- Attachment #1.1: Type: text/plain, Size: 1225 bytes --]

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


[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

[-- Attachment #2: Type: text/plain, Size: 201 bytes --]

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Linux-kernel-mentees] [PATCH] checkpatch: Warn about missing shebang in scripts
  2020-07-21  5:44 [Linux-kernel-mentees] [PATCH] checkpatch: Warn about missing shebang in scripts Mrinal Pandey
@ 2020-07-22 10:23 ` Lukas Bulwahn
  2020-07-24  4:59   ` Mrinal Pandey
  0 siblings, 1 reply; 3+ messages in thread
From: Lukas Bulwahn @ 2020-07-22 10:23 UTC (permalink / raw)
  To: Mrinal Pandey; +Cc: Linux-kernel-mentees



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@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
> 
> 
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Linux-kernel-mentees] [PATCH] checkpatch: Warn about missing shebang in scripts
  2020-07-22 10:23 ` Lukas Bulwahn
@ 2020-07-24  4:59   ` Mrinal Pandey
  0 siblings, 0 replies; 3+ messages in thread
From: Mrinal Pandey @ 2020-07-24  4:59 UTC (permalink / raw)
  To: Lukas Bulwahn, Shuah Khan, Linux-kernel-mentees


[-- Attachment #1.1: Type: text/plain, Size: 1755 bytes --]

On Wed, Jul 22, 2020 at 3:53 PM Lukas Bulwahn <lukas.bulwahn@gmail.com>
wrote:

>
>
> 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@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...
>

Sir,

Yes, I will remove that from the list.

>
> This whole check can probably placed elsewhere better.
>

Should I place it on line 2657 as the check just above it also deals with
scripts?

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

[-- Attachment #1.2: Type: text/html, Size: 3194 bytes --]

[-- Attachment #2: Type: text/plain, Size: 201 bytes --]

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-07-24  4:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-21  5:44 [Linux-kernel-mentees] [PATCH] checkpatch: Warn about missing shebang in scripts Mrinal Pandey
2020-07-22 10:23 ` Lukas Bulwahn
2020-07-24  4:59   ` Mrinal Pandey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).