Skip to content

Commit 10a27d9

Browse files
pbrisbinmcfilib
authored andcommittedSep 7, 2019
Update to latest LTS and ShellCheck-0.7.0 (wfleming#65)
* Update to latest LTS and ShellCheck-0.7.0 * Fix for removed env values If we have an existing value in the old env, but it's not in the updated env, this line would fail. It's been replaced by a no-op. Since we only write new-env, those will be removed by the process. * Update env.yml * Fixup! Update * Address -Wall errors
1 parent a3c62a1 commit 10a27d9

File tree

13 files changed

+2516
-5401
lines changed

13 files changed

+2516
-5401
lines changed
 

Diff for: ‎app/CLI.hs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
module CLI where
22

3-
import Data.Monoid
43
import Options.Applicative
54

65
--------------------------------------------------------------------------------

Diff for: ‎codeclimate-shellcheck.cabal

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ library
3939
, filepath
4040
, Glob
4141
, pureMD5
42-
, ShellCheck
42+
, ShellCheck == 0.7.0
4343
, text
4444
, yaml
4545
hs-source-dirs: src

Diff for: ‎data/env.yml

+2,460-5,369
Large diffs are not rendered by default.

Diff for: ‎data/prepare.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@
3939

4040
# IO ()
4141
old_env.each do |key, val|
42-
new_env[key]['remediation_points'] = val['remediation_points']
42+
if (new_val = new_env[key])
43+
new_val['remediation_points'] = val['remediation_points']
44+
end
4345
end
4446

4547
# String

Diff for: ‎docker/Build.plan

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM fpco/stack-build:lts-3.18
1+
FROM fpco/stack-build:lts-14.1
22
MAINTAINER Philip Cunningham <hello@filib.io>
33

44
ADD . /home/app

Diff for: ‎src/CC.hs

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import CC.Types
1313
import Data.Aeson
1414
import qualified Data.ByteString.Lazy as BSL
1515
import Data.Maybe
16-
import Data.Monoid
1716
import System.Directory
1817

1918
--------------------------------------------------------------------------------

Diff for: ‎src/CC/ShellCheck/Analyze.hs

+15-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{-# LANGUAGE OverloadedStrings #-}
2-
{-# LANGUAGE RecordWildCards #-}
32

43
module CC.ShellCheck.Analyze where
54

@@ -8,7 +7,6 @@ import CC.ShellCheck.Types as CC
87
import CC.Types as CC
98
import Control.Exception.Base
109
import qualified Data.Map.Strict as DM
11-
import Data.Monoid
1210
import qualified Data.Text as T
1311
import ShellCheck.Checker
1412
import ShellCheck.Interface
@@ -26,7 +24,11 @@ analyze env path = do
2624
checkSpec x = emptyCheckSpec { csFilename = path, csScript = x }
2725

2826
interface :: SystemInterface IO
29-
interface = SystemInterface { siReadFile = defaultInterface }
27+
interface = SystemInterface
28+
{ siReadFile = defaultInterface
29+
, siFindSource = error "TODO"
30+
, siGetConfig = error "TODO"
31+
}
3032

3133
--------------------------------------------------------------------------------
3234

@@ -60,13 +62,13 @@ fromSeverity WarningC = BugRisk
6062

6163
-- | Maps CheckResult into issues.
6264
fromCheckResult :: Env -> CheckResult -> String -> [Issue]
63-
fromCheckResult env CheckResult{..} shellScript = fmap (fromPositionedComment env shellScript) crComments
65+
fromCheckResult env cr shellScript = fromPositionedComment env shellScript <$> crComments cr
6466

6567
--------------------------------------------------------------------------------
6668

6769
-- | Maps from a PositionedComment to an Issue.
6870
fromPositionedComment :: Env -> String -> PositionedComment -> Issue
69-
fromPositionedComment env shellScript p@(PositionedComment Position{..} _ (Comment severity code desc)) =
71+
fromPositionedComment env shellScript p =
7072
Issue { _check_name = checkName
7173
, _description = description
7274
, _categories = categories
@@ -87,10 +89,10 @@ fromPositionedComment env shellScript p@(PositionedComment Position{..} _ (Comme
8789
categories = [fromSeverity severity]
8890

8991
coords :: CC.Position
90-
coords = Coords (LineColumn (fromIntegral posLine) (fromIntegral posColumn))
92+
coords = Coords (LineColumn (fromIntegral $ posLine pos) (fromIntegral $ posColumn pos))
9193

9294
location :: Location
93-
location = Location posFile $! PositionBased coords coords
95+
location = Location (posFile pos) $! PositionBased coords coords
9496

9597
mapping :: Maybe Mapping
9698
mapping = DM.lookup checkName env
@@ -106,3 +108,9 @@ fromPositionedComment env shellScript p@(PositionedComment Position{..} _ (Comme
106108

107109
content :: Maybe Content
108110
content = fmap (\(Mapping _ x) -> x) mapping
111+
112+
pos = pcStartPos p
113+
comment = pcComment p
114+
code = cCode comment
115+
severity = cSeverity comment
116+
desc = cMessage comment

Diff for: ‎src/CC/ShellCheck/Env.hs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
{-# LANGUAGE OverloadedStrings #-}
2-
31
module CC.ShellCheck.Env where
42

53
import CC.ShellCheck.Types
@@ -15,6 +13,6 @@ loadEnv :: FilePath -> IO Env
1513
loadEnv path = do
1614
fileExists <- doesFileExist path
1715
config <- if fileExists
18-
then YML.decodeFile path
16+
then either (const Nothing) Just <$> YML.decodeFileEither path
1917
else return Nothing
2018
return $! fromMaybe DM.empty config

Diff for: ‎src/CC/ShellCheck/Fingerprint.hs

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{-# LANGUAGE OverloadedStrings #-}
2-
{-# LANGUAGE RecordWildCards #-}
32

43
module CC.ShellCheck.Fingerprint
54
( issueFingerprint
@@ -22,12 +21,16 @@ import qualified Data.Text as T
2221
-- | Given a positioned comment and the file's contents, generate a fingerprint
2322
-- unique to that issue
2423
issueFingerprint :: PositionedComment -> Text -> Text
25-
issueFingerprint (PositionedComment Position{..} _ (Comment _ code _)) script =
24+
issueFingerprint pc script =
2625
md5 $ T.intercalate "|"
27-
[ T.pack $ posFile
26+
[ T.pack $ posFile pos
2827
, T.pack $ show code
29-
, T.filter (not . isSpace) $ fetchLine (fromIntegral posLine) script
28+
, T.filter (not . isSpace) $ fetchLine (fromIntegral $ posLine pos) script
3029
]
30+
where
31+
pos = pcStartPos pc
32+
comment = pcComment pc
33+
code = cCode comment
3134

3235
md5 :: Text -> Text
3336
md5 = T.pack . show . MD5.md5 . encodeUtf8 . fromStrict

Diff for: ‎src/CC/ShellCheck/ShellScript.hs

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import Control.Monad.Extra
1313
import qualified Data.ByteString as BS
1414
import qualified Data.ByteString.Char8 as Char8
1515
import Data.List
16-
import Data.Monoid
1716
import Data.Shebang (Shebang(..), Interpretter(..), Argument(..))
1817
import qualified Data.Shebang as Shebang
1918
import System.Directory
@@ -70,7 +69,7 @@ isShellScript path =
7069
-- | Retrieve shell scripts for a list of paths.
7170
findShellScripts :: [FilePath] -> IO [FilePath]
7271
findShellScripts paths = do
73-
dotShFiles <- concat . fst <$> globDir patterns "."
72+
dotShFiles <- concat <$> globDir patterns "."
7473
allScripts <- filterM validateScript $! dotShFiles ++ otherFiles
7574
return $ fmap clean allScripts
7675
where

Diff for: ‎stack.yaml

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
resolver: lts-3.18
1+
resolver: lts-14.1
22
system-ghc: false
33
install-ghc: true
4-
packages:
5-
- '.'
6-
extra-deps:
7-
- aeson-0.10.0.0
8-
- attoparsec-0.13.0.1
9-
- ShellCheck-0.4.6
10-
- string-qq-0.0.2

Diff for: ‎stack.yaml.lock

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# This file was autogenerated by Stack.
2+
# You should not edit this file by hand.
3+
# For more information, please see the documentation at:
4+
# https://docs.haskellstack.org/en/stable/lock_files
5+
6+
packages: []
7+
snapshots:
8+
- completed:
9+
size: 523448
10+
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/14/1.yaml
11+
sha256: 0045b9bae36c3bb2dd374c29b586389845af1557eea0423958d152fc500d4fbf
12+
original: lts-14.1

Diff for: ‎test/CC/ShellCheck/FingerprintSpec.hs

+14-3
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ import Data.Text (Text)
1111
import ShellCheck.Interface
1212
( Code
1313
, Comment(..)
14+
, newComment
1415
, Position(..)
16+
, newPosition
1517
, PositionedComment(..)
18+
, newPositionedComment
1619
, Severity(..)
1720
)
1821
import Test.Hspec
@@ -72,17 +75,25 @@ fingerprintSpecs = describe "issueFingerprint" $ do
7275

7376
fingerprint :: Integer -> Code -> Text -> Text
7477
fingerprint ln code =
75-
issueFingerprint $ PositionedComment (position ln) unused (comment code)
78+
issueFingerprint $ newPositionedComment
79+
{ pcStartPos = position ln
80+
, pcEndPos = unused
81+
, pcComment = comment code
82+
}
7683
where
7784
unused :: a
7885
unused = error "end position comment not implemented"
7986

8087
position :: Integer -> Position
81-
position ln = Position
88+
position ln = newPosition
8289
{ posFile = "foo.sh"
8390
, posLine = ln
8491
, posColumn = 0
8592
}
8693

8794
comment :: Code -> Comment
88-
comment code = Comment ErrorC code ""
95+
comment code = newComment
96+
{ cSeverity = ErrorC
97+
, cCode = code
98+
, cMessage = ""
99+
}

0 commit comments

Comments
 (0)
Please sign in to comment.