hadolint 1.11.2 → 1.12.0
raw patch · 3 files changed
+80/−4 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Hadolint.Formatter.Codacy: formatResult :: (ShowToken t, Ord t, ShowErrorComponent e) => Result t e -> Seq Issue
+ Hadolint.Formatter.Codacy: instance Data.Aeson.Types.ToJSON.ToJSON Hadolint.Formatter.Codacy.Issue
+ Hadolint.Formatter.Codacy: printResult :: (ShowToken t, Ord t, ShowErrorComponent e) => Result t e -> IO ()
Files
- app/Main.hs +7/−2
- hadolint.cabal +3/−2
- src/Hadolint/Formatter/Codacy.hs +70/−0
app/Main.hs view
@@ -31,6 +31,7 @@ import qualified Hadolint.Formatter.Format as Format import qualified Hadolint.Formatter.Json as Json import qualified Hadolint.Formatter.TTY as TTY+import qualified Hadolint.Formatter.Codacy as Codacy import qualified Hadolint.Rules as Rules type IgnoreRule = Text@@ -42,6 +43,7 @@ | TTY | CodeclimateJson | Checkstyle+ | Codacy deriving (Show, Eq) data LintOptions = LintOptions@@ -69,6 +71,7 @@ toOutputFormat "tty" = Just TTY toOutputFormat "codeclimate" = Just CodeclimateJson toOutputFormat "checkstyle" = Just Checkstyle+toOutputFormat "codacy" = Just Codacy toOutputFormat _ = Nothing showFormat :: OutputFormat -> String@@ -76,6 +79,7 @@ showFormat TTY = "tty" showFormat CodeclimateJson = "codeclimate" showFormat Checkstyle = "checkstyle"+showFormat Codacy = "codacy" parseOptions :: Parser LintOptions parseOptions =@@ -102,10 +106,10 @@ (maybeReader toOutputFormat) (long "format" <> -- options for the output format short 'f' <>- help "The output format for the results [tty | json | checkstyle | codeclimate]" <>+ help "The output format for the results [tty | json | checkstyle | codeclimate | codacy]" <> value TTY <> -- The default value showDefaultWith showFormat <>- completeWith ["tty", "json", "checkstyle", "codeclimate"])+ completeWith ["tty", "json", "checkstyle", "codeclimate", "codacy"]) -- -- | Parse a list of ignored rules ignoreList =@@ -226,6 +230,7 @@ Json -> Json.printResult res Checkstyle -> Checkstyle.printResult res CodeclimateJson -> Codeclimate.printResult res >> exitSuccess+ Codacy -> Codacy.printResult res >> exitSuccess lintDockerfile ignoreRules dockerFile = do ast <- Docker.parseFile (parseFilename dockerFile) return (processedFile ast)
hadolint.cabal view
@@ -2,10 +2,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 3617c4ad1e8f8732140c07b827400df490da5de7511e79c1b509176b5a6d01c6+-- hash: 4ff12972c5a652d9e4a6df3e276fdb1a565eaf408b15b14f6e7f9c22a20ade5d name: hadolint-version: 1.11.2+version: 1.12.0 synopsis: Dockerfile Linter JavaScript API description: A smarter Dockerfile linter that helps you build best practice Docker images. category: Development@@ -42,6 +42,7 @@ , void exposed-modules: Hadolint.Formatter.Checkstyle+ Hadolint.Formatter.Codacy Hadolint.Formatter.Codeclimate Hadolint.Formatter.Format Hadolint.Formatter.Json
+ src/Hadolint/Formatter/Codacy.hs view
@@ -0,0 +1,70 @@+{-# LANGUAGE RecordWildCards #-}+{-# LANGUAGE OverloadedStrings #-}++module Hadolint.Formatter.Codacy+ ( printResult+ , formatResult+ ) where++import Data.Aeson hiding (Result)+import qualified Data.ByteString.Lazy.Char8 as B+import qualified Data.List.NonEmpty as NE+import Data.Monoid ((<>))+import Data.Sequence (Seq)+import qualified Data.Text as Text+import Hadolint.Formatter.Format (Result(..))+import Hadolint.Rules (Metadata(..), RuleCheck(..))+import Text.Megaparsec.Error+ (ParseError, ShowErrorComponent, ShowToken, errorPos,+ parseErrorTextPretty)+import Text.Megaparsec.Pos+ (sourceLine, sourceName, unPos)++data Issue = Issue+ { filename :: String+ , msg :: String+ , patternId :: String+ , line :: Int+ }++instance ToJSON Issue where+ toJSON Issue {..} =+ object+ [ "filename" .= filename+ , "patternId" .= patternId+ , "message" .= msg+ , "line" .= line+ ]++errorToIssue :: (ShowToken t, Ord t, ShowErrorComponent e) => ParseError t e -> Issue+errorToIssue err =+ Issue+ { filename = sourceName pos+ , patternId = "DL1000"+ , msg = parseErrorTextPretty err+ , line = linenumber+ }+ where+ pos = NE.head (errorPos err)+ linenumber = unPos (sourceLine pos)+ +checkToIssue :: RuleCheck -> Issue+checkToIssue RuleCheck {..} =+ Issue+ { filename = Text.unpack filename+ , patternId = Text.unpack (code metadata)+ , msg = Text.unpack (message metadata)+ , line = linenumber+ }++formatResult :: (ShowToken t, Ord t, ShowErrorComponent e) => Result t e -> Seq Issue+formatResult (Result errors checks) = allIssues+ where+ allIssues = errorMessages <> checkMessages+ errorMessages = fmap errorToIssue errors+ checkMessages = fmap checkToIssue checks++printResult :: (ShowToken t, Ord t, ShowErrorComponent e) => Result t e -> IO ()+printResult result = mapM_ output (formatResult result)+ where+ output value = B.putStrLn (encode value)