Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#269] Use 'ghc-options' instead of 'warnings' #294

Merged
merged 3 commits into from
Mar 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ Below you can see highlighted features in different categories.
+ Ability to include your `.stylish-haskell.yaml` file.
+ Usage of the `ghc-options` field with sensible defaults.

If warnings are not explicitly stated in the configuration file, then the following list of GHC flags is added to all stanzas:
If `ghc-options` are not explicitly stated in the configuration file, then the following list of GHC flags is added to all stanzas:

```
-Wall
Expand Down Expand Up @@ -330,7 +330,7 @@ Here is the list of the options that can be configured to suit your needs. If op
| `test` | Bool | Create `test` folder with simple `Spec.hs` file and test target? |
| `bench` | Bool | Create `benchmark` folder with `Main.hs` file with [`gauge`](https://hackage.haskell.org/package/gauge) library usage example? |
| `extensions` | [Text] | List of the default extensions to add into `default-extensions` section in the `.cabal`. |
| `warnings` | [Text] | List of the default checks and warnings to add into `ghc-options` section in the `.cabal`. |
| `ghc-options` | [Text] | List of the default GHC options to add into `ghc-options` section in the `.cabal`. |
| `stylish.*` | Text | `stylish.file` to provide the absolute file path OR `stylish.url` to download the `.stylish-haskell.yaml` file to use in the project. |
| `contributing.*` | Text | `contributing.file` to provide the absolute file path OR `contributing.url` download OR `contribuint.link` to link the `CONTRIBUTING.md` file to use in the project. |
|`[prelude]` | | |
Expand Down
5 changes: 5 additions & 0 deletions summoner-cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ The changelog is available [on GitHub][2].
Allow users to extend the .gitignore file.
* [#285](https://github.com/kowainik/summoner/issues/285):
Implement `summon script` command.
* [#269](https://github.com/kowainik/summoner/issues/269):
__Important:__ Introduce `ghc-options` configuration parameter. Deprecate `warnings` field in TOML file.

_Migration guide:_ Please, rename `warnings` field if you use one, it will be
removed in the very next release. Use `ghc-options` instead.

## 1.2.0 — Nov 30, 2018

Expand Down
46 changes: 25 additions & 21 deletions summoner-cli/src/Summoner/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,28 @@ data Phase = Partial | Final

-- | Potentially incomplete configuration.
data ConfigP (p :: Phase) = Config
{ cOwner :: p :- Text
, cFullName :: p :- Text
, cEmail :: p :- Text
, cLicense :: p :- LicenseName
, cGhcVer :: p :- [GhcVer]
, cCabal :: Decision
, cStack :: Decision
, cGitHub :: Decision
, cTravis :: Decision
, cAppVey :: Decision
, cPrivate :: Decision
, cLib :: Decision
, cExe :: Decision
, cTest :: Decision
, cBench :: Decision
, cPrelude :: Last CustomPrelude
, cExtensions :: [Text]
, cWarnings :: [Text]
, cGitignore :: [Text]
, cStylish :: Last Source
, cContributing :: Last Source
{ cOwner :: !(p :- Text)
, cFullName :: !(p :- Text)
, cEmail :: !(p :- Text)
, cLicense :: !(p :- LicenseName)
, cGhcVer :: !(p :- [GhcVer])
, cCabal :: !Decision
, cStack :: !Decision
, cGitHub :: !Decision
, cTravis :: !Decision
, cAppVey :: !Decision
, cPrivate :: !Decision
, cLib :: !Decision
, cExe :: !Decision
, cTest :: !Decision
, cBench :: !Decision
, cPrelude :: !(Last CustomPrelude)
, cExtensions :: ![Text]
, cWarnings :: ![Text]
, cGhcOptions :: ![Text] -- ^ GHC options to add every stanza
, cGitignore :: ![Text]
, cStylish :: !(Last Source)
, cContributing :: !(Last Source)
} deriving (Generic)

deriving instance
Expand Down Expand Up @@ -123,6 +124,7 @@ defaultConfig = Config
, cPrelude = Last Nothing
, cExtensions = []
, cWarnings = []
, cGhcOptions = []
, cGitignore = []
, cStylish = Last Nothing
, cContributing = Last Nothing
Expand All @@ -149,6 +151,7 @@ configT = Config
<*> lastT preludeT "prelude" .= cPrelude
<*> textArr "extensions" .= cExtensions
<*> textArr "warnings" .= cWarnings
<*> textArr "ghc-options" .= cGhcOptions
<*> textArr "gitignore" .= cGitignore
<*> lastT sourceT "stylish" .= cStylish
<*> lastT sourceT "contributing" .= cContributing
Expand Down Expand Up @@ -208,6 +211,7 @@ finalise Config{..} = Config
<*> pure cPrelude
<*> pure cExtensions
<*> pure cWarnings
<*> pure cGhcOptions
<*> pure cGitignore
<*> pure cStylish
<*> pure cContributing
Expand Down
6 changes: 5 additions & 1 deletion summoner-cli/src/Summoner/Project.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ generateProject
-> Config -- ^ Given configurations.
-> IO ()
generateProject settingsNoUpload isOffline projectName Config{..} = do
unless (null cWarnings) $
warningMessage "Please, rename 'warnings' field if you use one, it will be removed in the very next release. Use 'ghc-options' instead."

settingsRepo <- checkUniqueName projectName
-- decide cabal stack or both
(settingsCabal, settingsStack) <- getCabalStack (cCabal, cStack)
Expand Down Expand Up @@ -86,9 +89,10 @@ generateProject settingsNoUpload isOffline projectName Config{..} = do
Just _ -> "base-noprelude"

let settingsExtensions = cExtensions
let settingsWarnings = cWarnings
let settingsGhcOptions = cWarnings ++ cGhcOptions
let settingsGitignore = cGitignore


putTextLn $ "The project will be created with GHC-" <> showGhcVer defaultGHC
settingsTestedVersions <- sortNub . (defaultGHC :) <$> case cGhcVer of
[] -> do
Expand Down
2 changes: 1 addition & 1 deletion summoner-cli/src/Summoner/Settings.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ data Settings = Settings
, settingsBaseType :: !Text -- ^ Base library to use
, settingsPrelude :: !(Maybe CustomPrelude) -- ^ custom prelude to be used
, settingsExtensions :: ![Text] -- ^ default extensions
, settingsWarnings :: ![Text] -- ^ default warnings
, settingsGhcOptions :: ![Text] -- ^ default GHC options
, settingsGitignore :: ![Text] -- ^ .gitignore file
, settingsCabal :: !Bool
, settingsStack :: !Bool
Expand Down
14 changes: 7 additions & 7 deletions summoner-cli/src/Summoner/Template/Cabal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -172,22 +172,22 @@ cabalFile Settings{..} = File (toString settingsRepo ++ ".cabal") cabalFileConte
<> "\n"

ghcOptions :: Text
ghcOptions = case settingsWarnings of
[] -> defaultWarnings
ghcOptions = case settingsGhcOptions of
[] -> defaultGhcOptions
xs -> T.intercalate "\n" xs

defaultWarnings :: Text
defaultWarnings =
defaultGhcOptions :: Text
defaultGhcOptions =
[text|
-Wincomplete-uni-patterns
-Wincomplete-record-updates
-Wcompat
-Widentities
$versionWarnings
$versionGhcOptions
|]

versionWarnings :: Text
versionWarnings
versionGhcOptions :: Text
versionGhcOptions
= memptyIfFalse (settingsTestedVersions `hasLeast` Ghc801)
"-Wredundant-constraints\n"
<> memptyIfFalse (settingsTestedVersions `hasLeast` Ghc822)
Expand Down
5 changes: 2 additions & 3 deletions summoner-cli/summoner.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 2.0
name: summoner
version: 1.2.0
version: 1.3.0
synopsis: Tool for scaffolding completely configured production Haskell projects.
description: Tool for scaffolding completely configured production Haskell projects.
See [README.md](https://github.com/kowainik/summoner#-summoner) for details.
Expand All @@ -10,13 +10,12 @@ license: MPL-2.0
license-file: LICENSE
author: Kowainik
maintainer: xrom.xkov@gmail.com
copyright: 2018 Kowainik
copyright: 2018-2019 Kowainik
category: CLI, CLI Tool, Development
build-type: Simple
stability: stable
extra-doc-files: README.md
, CHANGELOG.md
data-dir: test/golden
tested-with: GHC == 8.2.2
, GHC == 8.4.4
, GHC == 8.6.3
Expand Down
4 changes: 2 additions & 2 deletions summoner-cli/test/Test/Golden.hs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fullProject = Settings
, settingsPrelude = Just $ CustomPrelude "relude" "Relude"
, settingsExtensions = ["ConstraintKinds", "LambdaCase", "OverloadedStrings"]
, settingsGitignore = [".secret"]
, settingsWarnings = ["-Wcompat", "-Widentities"]
, settingsGhcOptions = ["-Wcompat", "-Widentities"]
, settingsCabal = True
, settingsStack = True
, settingsStylish = Just "This is stylish-haskell.yaml\n"
Expand Down Expand Up @@ -126,7 +126,7 @@ smallProject = Settings
, settingsBaseType = "base"
, settingsPrelude = Nothing
, settingsExtensions = []
, settingsWarnings = []
, settingsGhcOptions = []
, settingsGitignore = []
, settingsCabal = True
, settingsStack = False
Expand Down
11 changes: 6 additions & 5 deletions summoner-cli/test/Test/TomlSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ genSource = do

genPartialConfig :: MonadGen m => m PartialConfig
genPartialConfig = do
cOwner <- Last . Just <$> genText
cFullName <- Last . Just <$> genText
cEmail <- Last . Just <$> genText
cLicense <- Last . Just <$> genLicense
cGhcVer <- Last . Just <$> genGhcVerArr
cOwner <- Last <$> Gen.maybe genText
cFullName <- Last <$> Gen.maybe genText
cEmail <- Last <$> Gen.maybe genText
cLicense <- Last <$> Gen.maybe genLicense
cGhcVer <- Last <$> Gen.maybe genGhcVerArr
cCabal <- genDecision
cStack <- genDecision
cGitHub <- genDecision
Expand All @@ -68,6 +68,7 @@ genPartialConfig = do
cPrelude <- Last <$> Gen.maybe genCustomPrelude
cExtensions <- genTextArr
cWarnings <- genTextArr
cGhcOptions <- genTextArr
cGitignore <- genTextArr
cStylish <- Last <$> Gen.maybe genSource
cContributing <- Last <$> Gen.maybe genSource
Expand Down
5 changes: 5 additions & 0 deletions summoner-tui/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
`summoner-tui` uses [PVP Versioning][1].
The changelog is available [on GitHub][2].

## Unreleased: 0.1.0

* [#285](https://github.com/kowainik/summoner/issues/285):
Implement `summon script` command.

## 0.0.0 — Nov 30, 2018

* [#208](https://github.com/kowainik/summoner/issues/208):
Expand Down
8 changes: 4 additions & 4 deletions summoner-tui/src/Summoner/Tui/Kit.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module Summoner.Tui.Kit
, projectMeta
, gitHub
, extensions
, warnings
, ghcOptions
, stylish
, contributing
, offline
Expand Down Expand Up @@ -90,7 +90,7 @@ data SummonKit = SummonKit
, summonKitProjectMeta :: !ProjectMeta
, summonKitGitHub :: !GitHub
, summonKitExtensions :: ![Text] -- ^ Can be recieved from the config file.
, summonKitWarnings :: ![Text] -- ^ Can be recieved from the config file.
, summonKitGhcOptions :: ![Text] -- ^ Can be recieved from the config file.
, summonKitGitignore :: ![Text] -- ^ Received from the config file.
, summonKitStylish :: !(Maybe Source) -- ^ Can be recieved from the config file.
, summonKitContributing :: !(Maybe Source) -- ^ Can be recieved from the config file.
Expand Down Expand Up @@ -176,7 +176,7 @@ summonKitToSettings sk = Settings
, settingsBaseType = baseT
, settingsPrelude = cP
, settingsExtensions = sk ^. extensions
, settingsWarnings = sk ^. warnings
, settingsGhcOptions = sk ^. ghcOptions
, settingsGitignore = sk ^. gitignore
, settingsCabal = sk ^. cabal
, settingsStack = sk ^. stack
Expand Down Expand Up @@ -259,7 +259,7 @@ configToSummonKit cRepo cNoUpload cOffline cConfigFile Config{..} = SummonKit
, gitHubAppVeyor = toBool cAppVey && kitStack
}
, summonKitExtensions = cExtensions
, summonKitWarnings = cWarnings
, summonKitGhcOptions = cWarnings ++ cGhcOptions
, summonKitGitignore = cGitignore
, summonKitStylish = getLast cStylish
, summonKitContributing = getLast cContributing
Expand Down
4 changes: 2 additions & 2 deletions summoner-tui/summoner-tui.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 2.0
name: summoner-tui
version: 0.0.0
version: 0.1.0
synopsis: Tool for scaffolding completely configured production Haskell projects using TUI.
description: : Tool for scaffolding completely configured production Haskell projects using TUI.
See [README.md](https://github.com/kowainik/summoner#-summoner) for details.
Expand Down Expand Up @@ -45,7 +45,7 @@ library
, microlens ^>= 0.4
, microlens-th ^>= 0.4
, relude ^>= 0.4.0
, summoner ^>= 1.2.0
, summoner ^>= 1.3.0
, text ^>= 1.2.3.0
, vty ^>= 5.25

Expand Down