module Hadolint.Rule.DL3056 (rule) where import Data.Either import qualified Data.Map as Map import qualified Data.SemVer as SemVer import qualified Data.Text as Text import Hadolint.Rule import Language.Docker.Syntax rule :: LabelSchema -> Rule args rule :: forall args. LabelSchema -> Rule args rule LabelSchema labelschema = forall a. Monoid a => [a] -> a mconcat forall a b. (a -> b) -> a -> b $ forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap forall args. Text -> Rule args labelIsNotSemVerRule (forall k a. Map k a -> [k] Map.keys (forall a k. (a -> Bool) -> Map k a -> Map k a Map.filter (forall a. Eq a => a -> a -> Bool == LabelType SemVer) LabelSchema labelschema)) {-# INLINEABLE rule #-} labelIsNotSemVerRule :: LabelName -> Rule args labelIsNotSemVerRule :: forall args. Text -> Rule args labelIsNotSemVerRule Text label = forall args. RuleCode -> DLSeverity -> Text -> (Instruction args -> Bool) -> Rule args simpleRule RuleCode code DLSeverity severity Text message forall {args}. Instruction args -> Bool check where code :: RuleCode code = RuleCode "DL3056" severity :: DLSeverity severity = DLSeverity DLWarningC message :: Text message = String -> Text Text.pack String "Label `" forall a. Semigroup a => a -> a -> a <> Text label forall a. Semigroup a => a -> a -> a <> String -> Text Text.pack String "` does not conform to semantic versioning." check :: Instruction args -> Bool check (Label Pairs pairs) = Text -> Pairs -> Bool hasNoBadVersioning Text label Pairs pairs check Instruction args _ = Bool True hasNoBadVersioning :: LabelName -> Pairs -> Bool hasNoBadVersioning :: Text -> Pairs -> Bool hasNoBadVersioning Text lbl Pairs prs = forall (t :: * -> *) a. Foldable t => t a -> Bool null [(Text l, Text v) | (Text l, Text v) <- Pairs prs, Text l forall a. Eq a => a -> a -> Bool == Text lbl, forall a b. Either a b -> Bool isLeft forall a b. (a -> b) -> a -> b $ Text -> Either String Version SemVer.fromText Text v]