"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/ShellCheck/Checker.hs" between
shellcheck-0.8.0.tar.gz and shellcheck-0.9.0.tar.gz

About: ShellCheck is a static analysis and linting tool for sh/bash scripts (written in Haskell).

Checker.hs  (shellcheck-0.8.0):Checker.hs  (shellcheck-0.9.0)
{- {-
Copyright 2012-2020 Vidar Holen Copyright 2012-2022 Vidar Holen
This file is part of ShellCheck. This file is part of ShellCheck.
https://www.shellcheck.net https://www.shellcheck.net
ShellCheck is free software: you can redistribute it and/or modify ShellCheck is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
ShellCheck is distributed in the hope that it will be useful, ShellCheck is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
-} -}
{-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TemplateHaskell #-}
module ShellCheck.Checker (checkScript, ShellCheck.Checker.runTests) where module ShellCheck.Checker (checkScript, ShellCheck.Checker.runTests) where
import ShellCheck.Analyzer
import ShellCheck.ASTLib
import ShellCheck.Interface import ShellCheck.Interface
import ShellCheck.Parser import ShellCheck.Parser
import ShellCheck.Analyzer
import Data.Either import Data.Either
import Data.Functor import Data.Functor
import Data.List import Data.List
import Data.Maybe import Data.Maybe
import Data.Ord import Data.Ord
import Control.Monad.Identity import Control.Monad.Identity
import qualified Data.Map as Map import qualified Data.Map as Map
import qualified System.IO import qualified System.IO
import Prelude hiding (readFile) import Prelude hiding (readFile)
skipping to change at line 88 skipping to change at line 89
let parseMessages = prComments result let parseMessages = prComments result
let tokenPositions = prTokenPositions result let tokenPositions = prTokenPositions result
let analysisSpec root = let analysisSpec root =
as { as {
asScript = root, asScript = root,
asShellType = csShellTypeOverride spec, asShellType = csShellTypeOverride spec,
asFallbackShell = shellFromFilename $ csFilename spec, asFallbackShell = shellFromFilename $ csFilename spec,
asCheckSourced = csCheckSourced spec, asCheckSourced = csCheckSourced spec,
asExecutionMode = Executed, asExecutionMode = Executed,
asTokenPositions = tokenPositions, asTokenPositions = tokenPositions,
asOptionalChecks = csOptionalChecks spec asOptionalChecks = getEnableDirectives root ++ csOptionalChe cks spec
} where as = newAnalysisSpec root } where as = newAnalysisSpec root
let analysisMessages = let analysisMessages =
maybe [] maybe []
(arComments . analyzeScript . analysisSpec) (arComments . analyzeScript . analysisSpec)
$ prRoot result $ prRoot result
let translator = tokenToPosition tokenPositions let translator = tokenToPosition tokenPositions
return . nub . sortMessages . filter shouldInclude $ return . nub . sortMessages . filter shouldInclude $
(parseMessages ++ map translator analysisMessages) (parseMessages ++ map translator analysisMessages)
shouldInclude pc = shouldInclude pc =
skipping to change at line 244 skipping to change at line 245
prop_canStripPrefixAndSource = prop_canStripPrefixAndSource =
null $ checkWithIncludes [("./lib", "")] "source \"$MYDIR/lib\"" null $ checkWithIncludes [("./lib", "")] "source \"$MYDIR/lib\""
prop_canStripPrefixAndSource2 = prop_canStripPrefixAndSource2 =
null $ checkWithIncludes [("./utils.sh", "")] "source \"$(dirname \"${BASH_S OURCE[0]}\")/utils.sh\"" null $ checkWithIncludes [("./utils.sh", "")] "source \"$(dirname \"${BASH_S OURCE[0]}\")/utils.sh\""
prop_canSourceDynamicWhenRedirected = prop_canSourceDynamicWhenRedirected =
null $ checkWithIncludes [("lib", "")] "#shellcheck source=lib\n. \"$1\"" null $ checkWithIncludes [("lib", "")] "#shellcheck source=lib\n. \"$1\""
prop_canRedirectWithSpaces =
null $ checkWithIncludes [("my file", "")] "#shellcheck source=\"my file\"\n
. \"$1\""
prop_recursiveAnalysis = prop_recursiveAnalysis =
[2086] == checkRecursive [("lib", "echo $1")] "source lib" [2086] == checkRecursive [("lib", "echo $1")] "source lib"
prop_recursiveParsing = prop_recursiveParsing =
[1037] == checkRecursive [("lib", "echo \"$10\"")] "source lib" [1037] == checkRecursive [("lib", "echo \"$10\"")] "source lib"
prop_nonRecursiveAnalysis = prop_nonRecursiveAnalysis =
null $ checkWithIncludes [("lib", "echo $1")] "source lib" null $ checkWithIncludes [("lib", "echo $1")] "source lib"
prop_nonRecursiveParsing = prop_nonRecursiveParsing =
skipping to change at line 412 skipping to change at line 416
prop_sourcePathAddsAnnotation = result == [2086] prop_sourcePathAddsAnnotation = result == [2086]
where where
f "dir/myscript" _ ["mypath"] "lib" = return "foo/lib" f "dir/myscript" _ ["mypath"] "lib" = return "foo/lib"
result = checkWithIncludesAndSourcePath [("foo/lib", "echo $1")] f emptyChec kSpec { result = checkWithIncludesAndSourcePath [("foo/lib", "echo $1")] f emptyChec kSpec {
csScript = "#!/bin/bash\n# shellcheck source-path=mypath\nsource lib", csScript = "#!/bin/bash\n# shellcheck source-path=mypath\nsource lib",
csFilename = "dir/myscript", csFilename = "dir/myscript",
csCheckSourced = True csCheckSourced = True
} }
prop_sourcePathWorksWithSpaces = result == [2086]
where
f "dir/myscript" _ ["my path"] "lib" = return "foo/lib"
result = checkWithIncludesAndSourcePath [("foo/lib", "echo $1")] f emptyChec
kSpec {
csScript = "#!/bin/bash\n# shellcheck source-path='my path'\nsource lib"
,
csFilename = "dir/myscript",
csCheckSourced = True
}
prop_sourcePathRedirectsDirective = result == [2086] prop_sourcePathRedirectsDirective = result == [2086]
where where
f "dir/myscript" _ _ "lib" = return "foo/lib" f "dir/myscript" _ _ "lib" = return "foo/lib"
f _ _ _ _ = return "/dev/null" f _ _ _ _ = return "/dev/null"
result = checkWithIncludesAndSourcePath [("foo/lib", "echo $1")] f emptyChec kSpec { result = checkWithIncludesAndSourcePath [("foo/lib", "echo $1")] f emptyChec kSpec {
csScript = "#!/bin/bash\n# shellcheck source=lib\nsource kittens", csScript = "#!/bin/bash\n# shellcheck source=lib\nsource kittens",
csFilename = "dir/myscript", csFilename = "dir/myscript",
csCheckSourced = True csCheckSourced = True
} }
skipping to change at line 483 skipping to change at line 496
prop_fileCannotEnableExternalSources2 = result == [1144] prop_fileCannotEnableExternalSources2 = result == [1144]
where where
f "dir/myscript" (Just False) _ "foo" = return "foo" f "dir/myscript" (Just False) _ "foo" = return "foo"
f a b c d = error $ show ("Unexpected", a, b, c, d) f a b c d = error $ show ("Unexpected", a, b, c, d)
result = checkWithRcIncludesAndSourcePath "external-sources=false" [("foo", "true")] f emptyCheckSpec { result = checkWithRcIncludesAndSourcePath "external-sources=false" [("foo", "true")] f emptyCheckSpec {
csScript = "#!/bin/bash\n# shellcheck external-sources=true\nsource foo" , csScript = "#!/bin/bash\n# shellcheck external-sources=true\nsource foo" ,
csFilename = "dir/myscript", csFilename = "dir/myscript",
csCheckSourced = True csCheckSourced = True
} }
prop_rcCanSuppressEarlyProblems1 = null result
where
result = checkWithRc "disable=1071" emptyCheckSpec {
csScript = "#!/bin/zsh\necho $1"
}
prop_rcCanSuppressEarlyProblems2 = null result
where
result = checkWithRc "disable=1104" emptyCheckSpec {
csScript = "!/bin/bash\necho 'hello world'"
}
return [] return []
runTests = $quickCheckAll runTests = $quickCheckAll
 End of changes. 7 change blocks. 
3 lines changed or deleted 31 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)