pre-commit icon indicating copy to clipboard operation
pre-commit copied to clipboard

Shellcheck does not allow for shebangs with a space

Open thibmaek opened this issue 3 years ago • 7 comments

The custom regex check will fail if the shebang is in the format of #! /usr/bin/bash and only work when removing the space e.g #!/usr/bin/bash.

Spaces in shebangs are valid.

thibmaek avatar Dec 16 '20 15:12 thibmaek

Do we have a script with a space after the shebang somewhere?

brikis98 avatar Dec 17 '20 08:12 brikis98

Not in this repo maybe, but if I try to use this hook in a repo it will not work unless removing the space. I tried to test by changing the regex and validating on regexr but I'm not sure which format of regex that is (PCRE?)

thibmaek avatar Dec 17 '20 10:12 thibmaek

Ohhh, I think I misunderstood. What you're saying is that the regex we use to identify shell scripts is what would need to be fixed?

brikis98 avatar Dec 18 '20 18:12 brikis98

Yep indeed, the regex needs to option to allow a space between right after the bang symbol:

  • regex validates: #!/usr/bin/env bash
  • regex invalidates: #! /usr/bin/env bash

thibmaek avatar Dec 21 '20 14:12 thibmaek

Understood! And, indeed, spaces after shebang are allowed, as you mentioned. Would you be up for a PR to tweak the regex?

brikis98 avatar Jan 06 '21 15:01 brikis98

Yeah sure, do you know what format the regex is? I tried it on regexr but it didn't validate. Maybe its perl regex?

thibmaek avatar Jan 06 '21 19:01 thibmaek

It's grep format: https://stackoverflow.com/a/4192817/483528.

brikis98 avatar Jan 07 '21 08:01 brikis98