Not determine the shell from `.sh` extension

See discussion on issue #1369 for details.
This commit is contained in:
Tito Sacchi 2019-01-18 09:21:07 +01:00
parent 1e6a30905a
commit 9f45dc4c8b
2 changed files with 3 additions and 2 deletions

View File

@ -484,7 +484,7 @@ checkShebang params (T_Annotation _ list t) =
checkShebang params (T_Script id sb _) = execWriter $ do
unless (shellTypeSpecified params) $ do
when (sb == "") $
err id 2148 "Tips depend on target shell and yours is unknown. Add a shebang or an extension to the filename."
err id 2148 "Tips depend on target shell and yours is unknown. Add a shebang or a .bash, .ksh, .dash extension to the filename."
when (executableFromShebang sb == "ash") $
warn id 2187 "Ash scripts will be checked as Dash. Add '# shellcheck shell=dash' to silence."
unless (null sb) $ do

View File

@ -51,9 +51,10 @@ tokenToPosition startMap t = fromMaybe fail $ do
shellFromFilename filename = foldl mplus Nothing candidates
where
shellExtensions = [(".ksh", Ksh)
,(".sh", Sh)
,(".bash", Bash)
,(".dash", Dash)]
-- The `.sh` is too generic to determine the shell:
-- We fallback to Bash in this case and emit SC2148 if there is no shebang
candidates =
map (\(ext,sh) -> if ext `isSuffixOf` filename then Just sh else Nothing) shellExtensions