From ff247ad6f423fec093b440e7a25f976888b76841 Mon Sep 17 00:00:00 2001 From: Veronika Romashkina Date: Thu, 21 May 2020 10:41:40 +0100 Subject: [PATCH] [#460] Use relude-0.7.0.0 (#462) * [#460] Use relude-0.7.0.0 Resolves #460 * Fix stack, update HLint rules --- .travis.yml | 2 +- CHANGELOG.md | 4 ++++ stack.yaml | 1 + summoner-cli/src/Summoner/Project.hs | 8 +++++--- summoner-cli/src/Summoner/Question.hs | 16 ++++++++-------- summoner-cli/src/Summoner/Template.hs | 1 - summoner-cli/src/Summoner/Template/Cabal.hs | 1 - summoner-cli/src/Summoner/Template/GitHub.hs | 1 - summoner-cli/src/Summoner/Template/Mempty.hs | 18 ------------------ summoner-cli/summoner.cabal | 4 +--- summoner-tui/summoner-tui.cabal | 2 +- 11 files changed, 21 insertions(+), 37 deletions(-) delete mode 100644 summoner-cli/src/Summoner/Template/Mempty.hs diff --git a/.travis.yml b/.travis.yml index 980c971d..ec6f644e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,7 +15,7 @@ matrix: install: # HLint - - curl https://raw.githubusercontent.com/kowainik/relude/v0.6.0.0/.hlint.yaml -o .hlint-relude.yaml + - curl https://raw.githubusercontent.com/kowainik/relude/v0.7.0.0/.hlint.yaml -o .hlint-relude.yaml - curl -sSL https://raw.github.com/ndmitchell/neil/master/misc/travis.sh | sh -s -- hlint -h .hlint-relude.yaml summoner-cli/src/ summoner-cli/test/ summoner-cli/app/ summoner-tui/src/ summoner-tui/app/ # install stack and build project diff --git a/CHANGELOG.md b/CHANGELOG.md index 746bc502..a151d18f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ The changelog is available [on GitHub][2]. * [#459](https://github.com/kowainik/summoner/issues/459): Bump up `tomland` version to `1.3.0.0`. +* [#460](https://github.com/kowainik/summoner/issues/460): + Bump up `relude` version to `0.7.0.0`. + Remove `Summoner.Template.Mempty` as `memptyIfFalse` is imported from + `Relude`. * [#455](https://github.com/kowainik/summoner/issues/455): Allow `validation-selective` version `0.1.0.0`. * [#452](https://github.com/kowainik/summoner/issues/452): diff --git a/stack.yaml b/stack.yaml index 316ed413..1c5a605c 100644 --- a/stack.yaml +++ b/stack.yaml @@ -8,5 +8,6 @@ extra-deps: - colourista-0.1.0.0 - generic-data-0.8.0.0 - hspec-hedgehog-0.0.1.1 + - relude-0.7.0.0 - tomland-1.3.0.0 - validation-selective-0.1.0.0 diff --git a/summoner-cli/src/Summoner/Project.hs b/summoner-cli/src/Summoner/Project.hs index 855900c4..ad0326fc 100644 --- a/summoner-cli/src/Summoner/Project.hs +++ b/summoner-cli/src/Summoner/Project.hs @@ -19,8 +19,9 @@ module Summoner.Project import Colourista (bold, errorMessage, formattedMessage, green, infoMessage, skipMessage, successMessage, warningMessage) +import Data.List.NonEmpty ((<|)) import NeatInterpolation (text) -import Relude.Extra.Enum (universe) +import Relude.Extra.Enum (universe, universeNonEmpty) import Shellmet (($?)) import System.Directory (findExecutable, setCurrentDirectory) @@ -38,10 +39,11 @@ import Summoner.Question (YesNoPrompt (..), checkUniqueName, choose, doesExistPr import Summoner.Settings (Settings (..)) import Summoner.Source (fetchSources) import Summoner.Template (createProjectTemplate) -import Summoner.Template.Mempty (memptyIfFalse) import Summoner.Text (intercalateMap, moduleNameValid, packageNameValid, packageToModule) import Summoner.Tree (showBoldTree, traverseTree) +import qualified Data.List.NonEmpty as NE + -- | Generate the project. generateProject @@ -76,7 +78,7 @@ generateProjectInteractive connectMode projectName ConfigP{..} = do putText licenseText settingsLicenseName <- if isOffline connectMode then NONE <$ infoMessage "'NONE' license is used in offline mode" - else choose parseLicenseName "License: " $ ordNub (cLicense : universe) + else choose parseLicenseName "License: " $ NE.nub (cLicense <| universeNonEmpty) -- License creation settingsYear <- currentYear diff --git a/summoner-cli/src/Summoner/Question.hs b/summoner-cli/src/Summoner/Question.hs index f6dfc2ba..1d333634 100644 --- a/summoner-cli/src/Summoner/Question.hs +++ b/summoner-cli/src/Summoner/Question.hs @@ -45,7 +45,6 @@ import System.IO (hFlush) import Summoner.Text (headToUpper, intercalateMap) import qualified Data.Text as T -import qualified Relude.Unsafe as Unsafe {- HLINT ignore "Redundant multi-way if" -} @@ -130,22 +129,23 @@ printQuestion question (def:rest) = do choose :: Show a => (Text -> Maybe a) -- ^ Parse function -> Text -- ^ Question text. - -> [a] -- ^ List of available options. + -> NonEmpty a -- ^ List of available options. -> IO a -- ^ The chosen option. choose parser question choices = do - let showChoices = map show choices + let showChoices = map show $ toList choices printQuestion question showChoices answer <- prompt if T.null answer - then pure (Unsafe.head choices) + then pure (head choices) else whenNothing (parser answer) (errorMessage "This wasn't a valid choice." >> choose parser question choices) -- | Like 'choose' but the possible answer are 'Y' or 'N'. -chooseYesNo :: YesNoPrompt -- ^ Target and Prompt - -> IO a -- ^ action for 'Y' answer - -> IO a -- ^ action for 'N' answer - -> IO a +chooseYesNo + :: YesNoPrompt -- ^ Target and Prompt + -> IO a -- ^ action for 'Y' answer + -> IO a -- ^ action for 'N' answer + -> IO a chooseYesNo p@YesNoPrompt {..} yesDo noDo = do printQuestion yesNoPrompt ["y", "n"] answer <- yesOrNo <$> prompt diff --git a/summoner-cli/src/Summoner/Template.hs b/summoner-cli/src/Summoner/Template.hs index 24d1a4be..0301a07f 100644 --- a/summoner-cli/src/Summoner/Template.hs +++ b/summoner-cli/src/Summoner/Template.hs @@ -15,7 +15,6 @@ import Summoner.Template.Cabal (cabalFile) import Summoner.Template.Doc (docFiles) import Summoner.Template.GitHub (gitHubFiles) import Summoner.Template.Haskell (haskellFiles) -import Summoner.Template.Mempty (memptyIfFalse) import Summoner.Template.Stack (stackFiles) import Summoner.Tree (TreeFs (..), insertTree) diff --git a/summoner-cli/src/Summoner/Template/Cabal.hs b/summoner-cli/src/Summoner/Template/Cabal.hs index 6b9e140b..fa977cc0 100644 --- a/summoner-cli/src/Summoner/Template/Cabal.hs +++ b/summoner-cli/src/Summoner/Template/Cabal.hs @@ -19,7 +19,6 @@ import Summoner.Default (defaultCabal) import Summoner.GhcVer (cabalBaseVersions, showGhcVer) import Summoner.License (LicenseName (..)) import Summoner.Settings (Settings (..)) -import Summoner.Template.Mempty (memptyIfFalse) import Summoner.Text (endLine, intercalateMap, packageToModule) import Summoner.Tree (TreeFs (..)) diff --git a/summoner-cli/src/Summoner/Template/GitHub.hs b/summoner-cli/src/Summoner/Template/GitHub.hs index 2ef7cf02..3cff5966 100644 --- a/summoner-cli/src/Summoner/Template/GitHub.hs +++ b/summoner-cli/src/Summoner/Template/GitHub.hs @@ -30,7 +30,6 @@ import NeatInterpolation (text) import Summoner.Default (defaultCabal, defaultGHC) import Summoner.GhcVer (GhcVer (..), oldGhcs, showGhcVer) import Summoner.Settings (Settings (..)) -import Summoner.Template.Mempty (memptyIfFalse) import Summoner.Text (endLine, intercalateMap, tconcatMap) import Summoner.Tree (TreeFs (..)) diff --git a/summoner-cli/src/Summoner/Template/Mempty.hs b/summoner-cli/src/Summoner/Template/Mempty.hs deleted file mode 100644 index 7f7b3a59..00000000 --- a/summoner-cli/src/Summoner/Template/Mempty.hs +++ /dev/null @@ -1,18 +0,0 @@ -{- | -Copyright: (c) 2017-2019 Kowainik -SPDX-License-Identifier: MPL-2.0 -Maintainer: Kowainik - -'Monoid' utilities for templates. --} - -module Summoner.Template.Mempty - ( memptyIfFalse - ) where - - -{- | Returns the given value in case of the given 'Bool' is 'True'. -Otherwise, it returns 'mempty'. --} -memptyIfFalse :: Monoid m => Bool -> m -> m -memptyIfFalse p val = if p then val else mempty diff --git a/summoner-cli/summoner.cabal b/summoner-cli/summoner.cabal index 7422b59b..6731c786 100644 --- a/summoner-cli/summoner.cabal +++ b/summoner-cli/summoner.cabal @@ -72,12 +72,11 @@ source-repository head common common-options build-depends: base >= 4.11 && < 4.14 - , relude ^>= 0.6.0.0 + , relude ^>= 0.7.0.0 mixins: base hiding (Prelude) , relude (Relude as Prelude , Relude.Extra.Enum - , Relude.Unsafe ) ghc-options: -Wall @@ -129,7 +128,6 @@ library Summoner.Template.Doc Summoner.Template.GitHub Summoner.Template.Haskell - Summoner.Template.Mempty Summoner.Template.Script Summoner.Template.Stack Summoner.Text diff --git a/summoner-tui/summoner-tui.cabal b/summoner-tui/summoner-tui.cabal index 6ee69fb1..3adf220d 100644 --- a/summoner-tui/summoner-tui.cabal +++ b/summoner-tui/summoner-tui.cabal @@ -26,7 +26,7 @@ source-repository head common common-options build-depends: base >= 4.11 && < 4.14 - , relude ^>= 0.6.0.0 + , relude ^>= 0.7.0.0 mixins: base hiding (Prelude) , relude (Relude as Prelude