File tree Expand file tree Collapse file tree 2 files changed +21
-18
lines changed Expand file tree Collapse file tree 2 files changed +21
-18
lines changed Original file line number Diff line number Diff line change @@ -9,23 +9,18 @@ describe('hasBashShebang', () => {
9
9
expect ( hasBashShebang ( `#!/usr/bin/env python2.7\n# set -x` ) ) . toBe ( false )
10
10
} )
11
11
12
- it ( 'returns true for "#!/bin/sh -"' , ( ) => {
13
- expect ( hasBashShebang ( '#!/bin/sh -' ) ) . toBe ( true )
14
- expect ( hasBashShebang ( '#!/bin/sh - ' ) ) . toBe ( true )
12
+ it ( 'returns false for "#!/usr/bin/pwsh"' , ( ) => {
13
+ expect ( hasBashShebang ( '#!/usr/bin/pwsh' ) ) . toBe ( false )
15
14
} )
16
15
17
- it ( 'returns true for "#!/usr/bin/env bash"' , ( ) => {
18
- expect ( hasBashShebang ( '#!/usr/bin/env bash' ) ) . toBe ( true )
19
- expect ( hasBashShebang ( '#!/usr/bin/env bash ' ) ) . toBe ( true )
20
- } )
21
-
22
- it ( 'returns true for "#!/bin/sh"' , ( ) => {
23
- expect ( hasBashShebang ( '#!/bin/sh' ) ) . toBe ( true )
24
- expect ( hasBashShebang ( '#!/bin/sh ' ) ) . toBe ( true )
25
- } )
26
-
27
- it ( 'returns true for "#!/bin/bash"' , ( ) => {
28
- expect ( hasBashShebang ( '#!/bin/bash' ) ) . toBe ( true )
29
- expect ( hasBashShebang ( '#!/bin/bash ' ) ) . toBe ( true )
16
+ test . each ( [
17
+ [ '#!/bin/sh -' ] ,
18
+ [ '#!/usr/bin/env bash' ] ,
19
+ [ '#!/bin/sh' ] ,
20
+ [ '#!/bin/bash' ] ,
21
+ [ '#!/bin/bash -u' ] ,
22
+ ] ) ( 'returns true for %p' , ( command ) => {
23
+ expect ( hasBashShebang ( command ) ) . toBe ( true )
24
+ expect ( hasBashShebang ( `${ command } ` ) ) . toBe ( true )
30
25
} )
31
26
} )
Original file line number Diff line number Diff line change @@ -6,11 +6,19 @@ export function getShebang(fileContent: string): string | null {
6
6
return null
7
7
}
8
8
9
- return match [ 1 ] . replace ( '-' , '' ) . trim ( )
9
+ return match [ 1 ]
10
10
}
11
11
12
+ /**
13
+ * Check if the given shebang is a bash shebang.
14
+ */
12
15
export function isBashShebang ( shebang : string ) : boolean {
13
- return shebang . endsWith ( 'bash' ) || shebang . endsWith ( 'sh' )
16
+ return (
17
+ shebang . startsWith ( '/bin/bash' ) ||
18
+ shebang . startsWith ( '/bin/sh' ) ||
19
+ shebang . startsWith ( '/usr/bin/env bash' ) ||
20
+ shebang . startsWith ( '/usr/bin/env sh' )
21
+ )
14
22
}
15
23
16
24
export function hasBashShebang ( fileContent : string ) : boolean {
You can’t perform that action at this time.
0 commit comments