Formatter is giving parse error when deriving stock or anyclass
mayank-17 opened this issue · comments
I have a file named Types.hs
And the file contains this
module Types where
import GHC.Generics
import Data.Text
import Data.Aeson
data Create = Create {
amount :: Double,
currency :: Text,
id :: Text,
description :: Text
}
deriving stock (Generic, Eq, Show)
deriving anyclass (ToJSON, FromJSON)
I use this command haskell-formatter < Types.hs
to format the file.
When I run this it gives
haskell-formatter < Types.hs
<stdin>:16:14: Parse error: stock
But on building(nix-build
or ghcide
) there is no error or warning.
Can anyone help
Hi @mayank-17
It looks like you're using language extensions that affect what is considered valid code. The formatter only looks at a given source file when parsing, that is, any extensions configured otherwise are not considered. If you configure the extensions in the source file like this, it works:
+{-# LANGUAGE DeriveAnyClass #-}
+{-# LANGUAGE DerivingStrategies #-}
+
module Types where
import GHC.Generics
@@ -10,5 +13,5 @@ data Create = Create {
id :: Text,
description :: Text
}
-deriving stock (Generic, Eq, Show)
-deriving anyclass (ToJSON, FromJSON)
+ deriving stock (Generic, Eq, Show)
+ deriving anyclass (ToJSON, FromJSON)
Please also note that this project is deprecated. See the deprecation notice with migration guide.
I hope that helps anyway.