mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-08-09 12:08:38 +08:00
Fix #1369 (Use file extension to detect shell)
The precedence order that is used to determine the shell is the following: 1. ShellCheck directive 2. Shebang 3. File extension A new field `asFallbackShell` has been added to the record type `AnalysisSpec`.
This commit is contained in:
@@ -48,6 +48,15 @@ tokenToPosition startMap t = fromMaybe fail $ do
|
||||
where
|
||||
fail = error "Internal shellcheck error: id doesn't exist. Please report!"
|
||||
|
||||
shellFromFilename filename = foldl mplus Nothing candidates
|
||||
where
|
||||
shellExtensions = [(".ksh", Ksh)
|
||||
,(".sh", Sh)
|
||||
,(".bash", Bash)
|
||||
,(".dash", Dash)]
|
||||
candidates =
|
||||
map (\(ext,sh) -> if ext `isSuffixOf` filename then Just sh else Nothing) shellExtensions
|
||||
|
||||
checkScript :: Monad m => SystemInterface m -> CheckSpec -> m CheckResult
|
||||
checkScript sys spec = do
|
||||
results <- checkScript (csScript spec)
|
||||
@@ -69,6 +78,7 @@ checkScript sys spec = do
|
||||
as {
|
||||
asScript = root,
|
||||
asShellType = csShellTypeOverride spec,
|
||||
asFallbackShell = shellFromFilename $ csFilename spec,
|
||||
asCheckSourced = csCheckSourced spec,
|
||||
asExecutionMode = Executed,
|
||||
asTokenPositions = tokenPositions
|
||||
|
Reference in New Issue
Block a user