Skip to content

Commit fa58d6d

Browse files
author
Philip Cunningham
committed
marshal between checkresult and issue, freeze deps and enable overloaded strings.
my .ghci config had enabled overloaded strings everwhere which meant it was compiling only on my machine. sorry!
1 parent 12bb4f6 commit fa58d6d

File tree

5 files changed

+98
-24
lines changed

5 files changed

+98
-24
lines changed

cabal.config

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
constraints: Glob ==0.7.5,
2+
QuickCheck ==2.8.1,
3+
ShellCheck ==0.4.1,
4+
aeson ==0.9.0.1,
5+
array ==0.5.0.0,
6+
attoparsec ==0.13.0.1,
7+
base ==4.7.0.2,
8+
binary ==0.7.1.0,
9+
bytestring ==0.10.4.0,
10+
containers ==0.5.5.1,
11+
deepseq ==1.3.0.2,
12+
directory ==1.2.1.0,
13+
dlist ==0.7.1.2,
14+
filepath ==1.3.0.2,
15+
ghc-prim ==0.3.1.0,
16+
hashable ==1.2.3.3,
17+
integer-gmp ==0.5.1.0,
18+
json ==0.9.1,
19+
mtl ==2.2.1,
20+
old-locale ==1.0.0.6,
21+
parsec ==3.1.9,
22+
pretty ==1.1.1.1,
23+
primitive ==0.6,
24+
random ==1.1,
25+
regex-base ==0.93.2,
26+
regex-tdfa ==1.2.1,
27+
rts ==1.0,
28+
scientific ==0.3.3.8,
29+
syb ==0.5.1,
30+
template-haskell ==2.9.0.0,
31+
text ==1.2.1.3,
32+
tf-random ==0.5,
33+
time ==1.4.2,
34+
transformers ==0.4.3.0,
35+
unix ==2.7.0.1,
36+
unordered-containers ==0.2.5.1,
37+
vector ==0.11.0.0

codeclimate-shellcheck.cabal

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ executable engine
1313
main-is:
1414
Main.hs
1515
other-modules:
16+
CC.Analyse
1617
CC.Types
1718
build-depends:
1819
aeson
1920
, base >= 4.7 && < 5
2021
, bytestring
2122
, Glob
22-
, text
23+
, ShellCheck >= 0.4.0 && < 0.5.0
2324
hs-source-dirs: src
2425
default-language: Haskell2010

src/CC/Analyse.hs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{-# LANGUAGE RecordWildCards #-}
2+
3+
module CC.Analyse where
4+
5+
import CC.Types as CC
6+
import Data.Monoid ((<>))
7+
import ShellCheck.Interface ( CheckResult(..)
8+
, Comment(..)
9+
, Position(..)
10+
, PositionedComment(..)
11+
, Severity(..)
12+
)
13+
14+
toCategory :: Severity -> Category
15+
toCategory ErrorC = BugRisk
16+
toCategory InfoC = BugRisk
17+
toCategory StyleC = Style
18+
toCategory WarningC = BugRisk
19+
20+
toIssue :: PositionedComment -> Issue
21+
toIssue (PositionedComment Position{..} (Comment severity code description)) =
22+
Issue {
23+
_check_name = "ShellCheck/" <> show code
24+
, _description = description
25+
, _categories = [toCategory severity]
26+
, _location = Location posFile (PositionBased coords coords)
27+
, _remediation_points = Nothing
28+
, _content = Nothing
29+
, _other_locations = Nothing
30+
}
31+
where
32+
coords :: CC.Position
33+
coords = Coords (LineColumn { _line = posLine, _column = posColumn })
34+
35+
toIssues :: CheckResult -> [Issue]
36+
toIssues CheckResult{..} = fmap toIssue crComments

src/CC/Types.hs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{-# LANGUAGE DeriveGeneric #-}
2+
{-# LANGUAGE OverloadedStrings #-}
23
{-# LANGUAGE RecordWildCards #-}
34

45
module CC.Types where
@@ -7,7 +8,6 @@ import Data.Aeson (ToJSON(..), (.=), genericToJSON, object)
78
import Data.Aeson.Types (Pair, Value(Null), defaultOptions, fieldLabelModifier)
89
import Data.Char (isUpper, toLower)
910
import GHC.Generics (Generic)
10-
import Data.Text (pack)
1111

1212
-- | Issues must be associated with one or more categories.
1313
data Category = BugRisk
@@ -20,13 +20,13 @@ data Category = BugRisk
2020
deriving Show
2121

2222
instance ToJSON Category where
23-
toJSON BugRisk = toJSON "Bug Risk"
23+
toJSON BugRisk = "Bug Risk"
2424
toJSON x = toJSON $ show x
2525

2626
-- | Line and column numbers are 1-based.
2727
data LineColumn = LineColumn {
28-
_line :: Int
29-
, _column :: Int
28+
_line :: Integer
29+
, _column :: Integer
3030
} deriving (Generic, Show)
3131

3232
instance ToJSON LineColumn where
@@ -36,18 +36,18 @@ instance ToJSON LineColumn where
3636
-- expressed in two ways.
3737
data Position = Coords LineColumn
3838
-- ^ Line and column coordinates.
39-
| Offset Int
39+
| Offset Integer
4040
-- ^ Absolute character offsets, for the entire source buffer.
4141
deriving Show
4242

4343
instance ToJSON Position where
4444
toJSON (Coords x) = toJSON x
45-
toJSON (Offset x) = toJSON $ object [ (pack "offset") .= x ]
45+
toJSON (Offset x) = object [ "offset" .= x ]
4646

4747
-- | Line-based locations emit a beginning and end line number for the issue,
4848
-- whereas position-based locations allow more precision.
4949
data BeginEnd = PositionBased Position Position
50-
| LineBased Int Int
50+
| LineBased Integer Integer
5151
deriving Show
5252

5353
instance ToJSON BeginEnd where
@@ -56,18 +56,18 @@ instance ToJSON BeginEnd where
5656
LineBased x y -> f x y
5757
where
5858
f :: (ToJSON a) => a -> a -> [Pair]
59-
f x y = [ (pack "begin") .= x, (pack "end") .= y ]
59+
f x y = [ "begin" .= x, "end" .= y ]
6060

6161
-- | Locations refer to ranges of a source code file.
6262
data Location = Location FilePath BeginEnd deriving Show
6363

6464
instance ToJSON Location where
6565
toJSON (Location x y) = object $ case y of
66-
PositionBased _ _ -> [ f x, (pack "positions") .= y ]
67-
LineBased _ _ -> [ f x, (pack "lines") .= y ]
66+
PositionBased _ _ -> [ f x, "positions" .= y ]
67+
LineBased _ _ -> [ f x, "lines" .= y ]
6868
where
6969
f :: FilePath -> Pair
70-
f = (.=) (pack "path")
70+
f = (.=) "path"
7171

7272
-- | An issue represents a single instance of a real or potential code problem,
7373
-- detected by a static analysis Engine.
@@ -76,21 +76,21 @@ data Issue = Issue {
7676
, _description :: String
7777
, _categories :: [Category]
7878
, _location :: Location
79-
, _remediation_points :: Maybe Int
79+
, _remediation_points :: Maybe Integer
8080
, _content :: Maybe String
8181
, _other_locations :: Maybe [Location]
8282
} deriving Show
8383

8484
instance ToJSON Issue where
8585
toJSON Issue{..} = object . withoutNulls $ [
86-
pack "type" .= ("issue" :: String)
87-
, pack "check_name" .= _check_name
88-
, pack "description" .= _description
89-
, pack "categories" .= _categories
90-
, pack "location" .= _location
91-
, pack "remediation_points" .= _remediation_points
92-
, pack "content" .= _content
93-
, pack "other_locations" .= _other_locations
86+
"type" .= ("issue" :: String)
87+
, "check_name" .= _check_name
88+
, "description" .= _description
89+
, "categories" .= _categories
90+
, "location" .= _location
91+
, "remediation_points" .= _remediation_points
92+
, "content" .= _content
93+
, "other_locations" .= _other_locations
9494
]
9595
where
9696
withoutNulls :: [(a, Value)] -> [(a, Value)]

src/Main.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
{-# LANGUAGE RecordWildCards #-}
2+
13
module Main where
24

5+
import CC.Analyse
36
import CC.Types
4-
5-
main :: IO ()
6-
main = putStrLn "hey"

0 commit comments

Comments
 (0)