Skip to content

Commit

Permalink
Compile with -werror.
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasdicioccio committed Apr 25, 2024
1 parent 8c3bce2 commit 16b8524
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 21 deletions.
3 changes: 2 additions & 1 deletion dhall-csv/src/Dhall/CsvToDhall.hs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ import Prettyprinter (Pretty)

import qualified Data.Csv
import qualified Data.HashMap.Strict as HashMap
import qualified Data.List.NonEmpty as NonEmpty
import qualified Data.Sequence as Sequence
import qualified Data.Text
import qualified Dhall.Core as Core
Expand Down Expand Up @@ -273,7 +274,7 @@ dhallFromCsv Conversion{..} typeExpr = listConvert (Core.normalize typeExpr)
recordConvert (Core.Record record) csvRecord
| badKeys <- lefts (map decodeUtf8' (HashMap.keys csvRecord))
, not (null badKeys)
= Left $ UnicodeError (head badKeys) -- Only report first key that failed to be decoded
= Left $ UnicodeError (NonEmpty.head . NonEmpty.fromList $ badKeys) -- Only report first key that failed to be decoded
| extraKeys <- (map decodeUtf8 $ HashMap.keys csvRecord) \\ Map.keys record
, strictRecs && not (null extraKeys)
= Left $ UnhandledFields extraKeys
Expand Down
3 changes: 2 additions & 1 deletion dhall-docs/src/Dhall/Docs/CodeRenderer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import Text.Megaparsec.Pos (SourcePos (..))

import qualified Control.Monad.Trans.Writer.Strict as Writer
import qualified Data.List
import qualified Data.List.NonEmpty as NonEmpty
import qualified Data.Maybe as Maybe
import qualified Data.Set as Set
import qualified Data.Text as Text
Expand Down Expand Up @@ -374,7 +375,7 @@ renderCodeWithHyperLinks contents expr = pre_ $ go (1, 1) lines_ imports

-- calls to `head` and `last` here should never fail since `importLines`
-- have at least one element
let (firstImportLine, lastImportLine) = (head importLines, last importLines)
let (firstImportLine, lastImportLine) = (NonEmpty.head . NonEmpty.fromList $ importLines, last importLines)
let prefixCols = Text.take (importStartCol - currCol) firstImportLine
let suffixCols = Text.drop (importEndCol - currCol) lastImportLine

Expand Down
2 changes: 1 addition & 1 deletion dhall-docs/src/Dhall/Docs/Comment.hs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ parseDhallDocsText (BlockComment blockComment) =
Just e -> DhallDocsText e
where
joinedText = Data.Text.strip $ Data.Text.unlines reIndentedLines
commentLines = tail $ Data.Text.lines blockComment
commentLines = NonEmpty.tail $ NonEmpty.fromList $ Data.Text.lines blockComment

leadingSpaces = Data.Text.takeWhile isSpace
where
Expand Down
23 changes: 12 additions & 11 deletions dhall-openapi/src/Dhall/Kubernetes/Convert.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@ import Data.Text (Text)
import Dhall.Kubernetes.Types
import GHC.Generics (Generic, Rep)

import qualified Data.Char as Char
import qualified Data.List as List
import qualified Data.Map.Strict as Data.Map
import qualified Data.Maybe as Maybe
import qualified Data.Set as Set
import qualified Data.Sort as Sort
import qualified Data.Text as Text
import qualified Data.Tuple as Tuple
import qualified Dhall.Core as Dhall
import qualified Data.Char as Char
import qualified Data.List as List
import qualified Data.List.NonEmpty as NonEmpty
import qualified Data.Map.Strict as Data.Map
import qualified Data.Maybe as Maybe
import qualified Data.Set as Set
import qualified Data.Sort as Sort
import qualified Data.Text as Text
import qualified Data.Tuple as Tuple
import qualified Dhall.Core as Dhall
import qualified Dhall.Map
import qualified Dhall.Optics
import qualified Data.Map as Map
Expand Down Expand Up @@ -112,7 +113,7 @@ mkImport :: Data.Map.Map Prefix Dhall.Import -> [Text] -> Text -> Dhall.Import
mkImport prefixMap components file =
case Data.Map.toList filteredPrefixMap of
[] -> localImport
xs -> (snd . head $ Sort.sortOn (Text.length . fst) xs) <> localImport
xs -> (snd . NonEmpty.head . NonEmpty.fromList $ Sort.sortOn (Text.length . fst) xs) <> localImport
where
localImport = Dhall.Import{..}
importMode = Dhall.Code
Expand Down Expand Up @@ -206,7 +207,7 @@ toTypes' prefixMap typeSplitter preferNaturalInt natIntExceptions definitions to
case hierarchy of
[] -> ""
[ModelName{..}] -> Text.unpack (last $ Text.splitOn "." unModelName)
_ -> getModelName (tail hierarchy)
_ -> getModelName (NonEmpty.tail . NonEmpty.fromList $ hierarchy)

convertAndAccumWithKey :: ModelHierarchy -> Data.Map.Map ModelName Definition -> ModelName -> Definition -> (Data.Map.Map ModelName Definition, Expr)
convertAndAccumWithKey modelHierarchy accDefs k v = (mergeNoConflicts equalsIgnoringDescription accDefs leftOverDefs, expr)
Expand Down
18 changes: 11 additions & 7 deletions dhall-openapi/src/Dhall/Kubernetes/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,14 @@ data BaseData = BaseData
} deriving (Generic, Show, Eq)

instance FromJSON BaseData where
parseJSON = withArray "array of values" $ \arr -> withObject "baseData" (\o -> do
group <- o .:? "group" .!= ""
kind <- o .: "kind"
version <- o .: "version"
let apiVersion = (if Text.null group then "" else group <> "/") <> version
pure BaseData{..})
(head $ Vector.toList arr)
parseJSON = withArray "array of values" $ \arr -> do
case Vector.toList arr of
[] -> fail "missing baseData object in array"
(item:_) ->
withObject "baseData" (\o -> do
group <- o .:? "group" .!= ""
kind <- o .: "kind"
version <- o .: "version"
let apiVersion = (if Text.null group then "" else group <> "/") <> version
pure BaseData{..})
item

0 comments on commit 16b8524

Please sign in to comment.