From 8ffcea449d6cbc6fce9fcd685fdfe16b9e600eba Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Fri, 25 Oct 2024 14:17:58 -0700 Subject: [PATCH] Use `OverloadedRecordDot` & `NoFieldSelectors` (#93) --- app/Main.hs | 2 +- nix-diff.cabal | 2 ++ src/Nix/Diff.hs | 6 +++--- src/Nix/Diff/Render/HumanReadable.hs | 4 ++-- src/Nix/Diff/Transformations.hs | 2 +- src/Nix/Diff/Types.hs | 4 ++-- test/Golden/Utils.hs | 2 +- 7 files changed, 12 insertions(+), 10 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index b4f035f..a44f9fd 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -180,7 +180,7 @@ main = do let renderContext = RenderContext {..} let status = Status Data.Set.empty let action = diff True (StorePath left) (OutputNames (Data.Set.singleton "out")) (StorePath right) (OutputNames (Data.Set.singleton "out")) - diffTree <- Control.Monad.State.evalStateT (Control.Monad.Reader.runReaderT (unDiff action) diffContext) status + diffTree <- Control.Monad.State.evalStateT (Control.Monad.Reader.runReaderT action.unDiff diffContext) status let diffTree' = transformDiff transformOptions diffTree renderDiff renderRunner renderContext diffTree' diff --git a/nix-diff.cabal b/nix-diff.cabal index 84381b9..a95df77 100644 --- a/nix-diff.cabal +++ b/nix-diff.cabal @@ -31,6 +31,8 @@ common language LambdaCase, MultiWayIf, NamedFieldPuns, + NoFieldSelectors, + OverloadedRecordDot, OverloadedStrings, RecordWildCards, ghc-options: -Wall diff --git a/src/Nix/Diff.hs b/src/Nix/Diff.hs index 5ddd0dd..76ff193 100644 --- a/src/Nix/Diff.hs +++ b/src/Nix/Diff.hs @@ -90,7 +90,7 @@ data Orientation = Character | Word | Line underneath `/nix/store`, but this is the overwhelmingly common use case -} derivationName :: StorePath -> Text -derivationName = Text.dropEnd 4 . Text.drop 44 . Text.pack . unsafeStorePathFile +derivationName storePath = Text.dropEnd 4 (Text.drop 44 (Text.pack storePath.unsafeStorePathFile)) -- | Group paths by their name groupByName :: Map StorePath a -> Map Text (Map StorePath a) @@ -109,7 +109,7 @@ groupByName m = Data.Map.fromList assocs > /nix/store/${32_CHARACTER_HASH}-${NAME}.drv -} buildProductName :: StorePath -> Text -buildProductName = Text.drop 44 . Text.pack . unsafeStorePathFile +buildProductName storePath = Text.drop 44 (Text.pack storePath.unsafeStorePathFile) -- | Like `groupByName`, but for `Set`s groupSetsByName :: Set StorePath -> Map Text (Set StorePath) @@ -157,7 +157,7 @@ readDerivation sp = do -- queried. readInput :: StorePath -> Diff (Derivation StorePath Text) readInput pathAndMaybeOutput = do - let (path, _) = List.break (== '!') (Store.unsafeStorePathFile pathAndMaybeOutput) + let (path, _) = List.break (== '!') pathAndMaybeOutput.unsafeStorePathFile if FilePath.isExtensionOf ".drv" path then readDerivation (StorePath path) else do diff --git a/src/Nix/Diff/Render/HumanReadable.hs b/src/Nix/Diff/Render/HumanReadable.hs index abc17d9..e7ab7bf 100644 --- a/src/Nix/Diff/Render/HumanReadable.hs +++ b/src/Nix/Diff/Render/HumanReadable.hs @@ -40,7 +40,7 @@ newtype Render a = Render { unRender :: ReaderT RenderContext (Writer Text) a} ) runRender :: Render a -> RenderContext -> (a, Text) -runRender render rc = runWriter $ runReaderT (unRender render) rc +runRender render rc = runWriter $ runReaderT render.unRender rc runRender' :: Render () -> RenderContext -> Text runRender' render = snd . runRender render @@ -56,7 +56,7 @@ echo text = do indented :: Natural -> Render a -> Render a indented n = local adapt where - adapt context = context { indent = indent context + n } + adapt context = context { indent = context.indent + n } data TTY = IsTTY | NotTTY diff --git a/src/Nix/Diff/Transformations.hs b/src/Nix/Diff/Transformations.hs index 98e353a..d56dd33 100644 --- a/src/Nix/Diff/Transformations.hs +++ b/src/Nix/Diff/Transformations.hs @@ -107,7 +107,7 @@ foldManyInputDerivationsAlreadyCompared dd = case dd of { inputsDiff = inputsDiff' { inputDerivationDiffs = - helper [] (inputDerivationDiffs inputsDiff') + helper [] inputsDiff'.inputDerivationDiffs } , .. } diff --git a/src/Nix/Diff/Types.hs b/src/Nix/Diff/Types.hs index 089a1ae..f9a95e0 100644 --- a/src/Nix/Diff/Types.hs +++ b/src/Nix/Diff/Types.hs @@ -54,7 +54,7 @@ instance Arbitrary TextDiff where arbitrary = TextDiff <$> listOf arbitraryItem instance ToJSON TextDiff where - toJSON = listValue itemToJSON . unTextDiff + toJSON textDiff = listValue itemToJSON textDiff.unTextDiff instance FromJSON TextDiff where parseJSON v = TextDiff <$> (traverse itemFromJSON =<< parseJSON v) @@ -187,7 +187,7 @@ instance Arbitrary ArgumentsDiff where arbitrary = ArgumentsDiff . NonEmpty.fromList <$> listOf1 arbitraryItem instance ToJSON ArgumentsDiff where - toJSON = listValue itemToJSON . toList . unArgumetsDiff + toJSON argumentsDiff = listValue itemToJSON (toList argumentsDiff.unArgumetsDiff) instance FromJSON ArgumentsDiff where parseJSON v = ArgumentsDiff <$> (traverse itemFromJSON =<< parseJSON v) diff --git a/test/Golden/Utils.hs b/test/Golden/Utils.hs index 974038b..4c802d8 100644 --- a/test/Golden/Utils.hs +++ b/test/Golden/Utils.hs @@ -44,7 +44,7 @@ makeDiffTree :: TestableDerivations -> DiffContext -> IO DerivationDiff makeDiffTree TestableDerivations{..} diffContext = do let status = Status Data.Set.empty let action = diff True oldDerivation (OutputNames (Data.Set.singleton "out")) newDerivation (OutputNames (Data.Set.singleton "out")) - Control.Monad.State.evalStateT (Control.Monad.Reader.runReaderT (unDiff action) diffContext) status + Control.Monad.State.evalStateT (Control.Monad.Reader.runReaderT action.unDiff diffContext) status -- | Drop conventional stdout newline, convert to StorePath storePathFromCLI :: BS.ByteString -> StorePath