@@ -11,7 +11,9 @@ module CC.ShellCheck.ShellScript (
11
11
12
12
import Control.Monad.Extra
13
13
import qualified Data.ByteString as BS
14
+ import qualified Data.ByteString.Char8 as Char8
14
15
import Data.List
16
+ import Data.Monoid
15
17
import Data.Shebang (Shebang (.. ), Interpretter (.. ), Argument (.. ))
16
18
import qualified Data.Shebang as Shebang
17
19
import System.Directory
@@ -20,9 +22,24 @@ import System.FilePath.Posix
20
22
21
23
--------------------------------------------------------------------------------
22
24
25
+ -- | List of shells the engine should be able to handle.
26
+ validShells :: [BS. ByteString ]
27
+ validShells = [" sh" , " ash" , " dash" , " bash" , " ksh" ]
28
+
29
+ --------------------------------------------------------------------------------
30
+
31
+ -- | List of valid shell file extensions.
32
+ validShellExtensions :: [BS. ByteString ]
33
+ validShellExtensions = (" ." <> ) <$> validShells
34
+
35
+ --------------------------------------------------------------------------------
36
+
23
37
-- | Checks to see if file has correct extension.
24
38
hasShellExtension :: FilePath -> Bool
25
- hasShellExtension path = takeExtension path == " .sh" || takeExtension path == " .bash" || takeExtension path == " .dash" || takeExtension path == " .ksh" || takeExtension path == " .ash"
39
+ hasShellExtension path = extension `elem` validShellExtensions
40
+ where
41
+ extension :: BS. ByteString
42
+ extension = Char8. pack $ takeExtension path
26
43
27
44
--------------------------------------------------------------------------------
28
45
@@ -32,11 +49,8 @@ hasValidInterpretter (Shebang (Interpretter int) maybeArgument) =
32
49
if BS. isSuffixOf " env" int
33
50
then case maybeArgument of
34
51
Nothing -> False
35
- Just (Argument arg) -> any (`BS.isPrefixOf` arg) shellScriptWhitelist
36
- else any (`BS.isSuffixOf` int) shellScriptWhitelist
37
- where
38
- shellScriptWhitelist :: [BS. ByteString ]
39
- shellScriptWhitelist = [" sh" , " ash" , " dash" , " bash" , " ksh" ]
52
+ Just (Argument arg) -> any (`BS.isPrefixOf` arg) validShells
53
+ else any (`BS.isSuffixOf` int) validShells
40
54
41
55
--------------------------------------------------------------------------------
42
56
0 commit comments