diff --git a/package.yaml b/package.yaml index f8fcc01b..eeffdb0b 100644 --- a/package.yaml +++ b/package.yaml @@ -48,7 +48,6 @@ library: - bytestring - composition-extra - conduit - - errata - errors - exceptions - extra @@ -103,4 +102,3 @@ tests: - load-env - restyler - text - - yaml diff --git a/restyler.cabal b/restyler.cabal index a8480225..3a3c3a28 100644 --- a/restyler.cabal +++ b/restyler.cabal @@ -55,8 +55,6 @@ library Restyler.Restyler.Run Restyler.RestyleResult Restyler.RestylerResult - Restyler.Wiki - Restyler.Yaml.Errata other-modules: Paths_restyler hs-source-dirs: @@ -89,7 +87,6 @@ library , bytestring , composition-extra , conduit - , errata , errors , exceptions , extra @@ -155,8 +152,6 @@ test-suite test Restyler.Restyler.RunSpec Restyler.RestylerSpec Restyler.Test.FS - Restyler.WikiSpec - Restyler.Yaml.ErrataSpec SpecHelper Paths_restyler hs-source-dirs: @@ -194,5 +189,4 @@ test-suite test , load-env , restyler , text - , yaml default-language: GHC2021 diff --git a/src/Restyler/Restyler/Run.hs b/src/Restyler/Restyler/Run.hs index 13a100e2..ab42cee2 100644 --- a/src/Restyler/Restyler/Run.hs +++ b/src/Restyler/Restyler/Run.hs @@ -43,7 +43,6 @@ import Restyler.Monad.WriteFile import Restyler.Options import Restyler.Restyler import Restyler.RestylerResult -import Restyler.Wiki qualified as Wiki import System.FilePath (()) import System.FilePath qualified as FilePath @@ -77,8 +76,6 @@ instance Exception RestylerOutOfMemory where displayException (RestylerOutOfMemory Restyler {..}) = mconcat [ "Restyler " <> rName <> " used too much memory (exit code 137)" - , "\n" - , "\nSee " <> unpack (Wiki.commonError "Restyle Error 137") <> " for more details" ] newtype RestylerCommandNotFound = RestylerCommandNotFound Restyler @@ -90,8 +87,6 @@ instance Exception RestylerCommandNotFound where [ "Restyler " <> rName <> " has an invalid command (exit code 127)" , "\n" , "You may need to adjust restylers[" <> rName <> "].command" - , "\n" - , "\nSee " <> unpack (Wiki.commonError "Restyle Error 127") <> " for more details" ] -- | Runs the configured @'Restyler'@s for the files and reports results diff --git a/src/Restyler/Wiki.hs b/src/Restyler/Wiki.hs deleted file mode 100644 index b52b08ab..00000000 --- a/src/Restyler/Wiki.hs +++ /dev/null @@ -1,33 +0,0 @@ --- | --- --- Module : Restyler.Wiki --- Copyright : (c) 2024 Patrick Brisbin --- License : AGPL-3 --- Maintainer : pbrisbin@gmail.com --- Stability : experimental --- Portability : POSIX -module Restyler.Wiki - ( commonError - , page - ) where - -import Restyler.Prelude - -import Data.Text qualified as T - -commonError :: Text -> Text -commonError = page . ("Common Errors: " <>) - -page :: Text -> Text -page = (wikiPrefix <>) . autoSlashPrefix . autoHyphenate - -autoHyphenate :: Text -> Text -autoHyphenate = T.replace " " "-" - -autoSlashPrefix :: Text -> Text -autoSlashPrefix x - | "/" `T.isPrefixOf` x = x - | otherwise = "/" <> x - -wikiPrefix :: Text -wikiPrefix = "https://github.com/restyled-io/restyled.io/wiki" diff --git a/src/Restyler/Yaml/Errata.hs b/src/Restyler/Yaml/Errata.hs deleted file mode 100644 index de3caf18..00000000 --- a/src/Restyler/Yaml/Errata.hs +++ /dev/null @@ -1,74 +0,0 @@ --- | --- --- Module : Restyler.Yaml.Errata --- Copyright : (c) 2024 Patrick Brisbin --- License : AGPL-3 --- Maintainer : pbrisbin@gmail.com --- Stability : experimental --- Portability : POSIX -module Restyler.Yaml.Errata - ( formatInvalidYaml - ) where - -import Restyler.Prelude - -import Data.ByteString.Char8 qualified as BS8 -import Data.Text.Lazy qualified as TL -import Data.Yaml (YamlMark (..)) -import Errata -import Errata.Styles -import Errata.Types (Column, Line) - -formatInvalidYaml - :: FilePath -> ByteString -> String -> String -> YamlMark -> Text -formatInvalidYaml path src problem context mark = - TL.toStrict - $ prettyErrors (decodeUtf8 @Text src) - $ fromMaybe (yamlErrata path problem context mark) - $ do - guard $ problem == tabProblem && context == tabContext - c <- getCharAt (yamlLine nextMark) (yamlColumn nextMark) src - guard $ c == '\t' - pure - $ yamlErrata - path - "Tab found for indentation" - "YAML forbids tabs for indentation: https://yaml.org/faq.html" - nextMark - where - nextMark = - mark - { yamlLine = yamlLine mark + 1 - , yamlColumn = 1 - } - -yamlErrata :: FilePath -> String -> String -> YamlMark -> [Errata] -yamlErrata path problem context mark = - [ errataSimple - (Just "Yaml parse exception") - ( blockSimple - basicStyle - basicPointer - path - Nothing - ( yamlLine mark - , yamlColumn mark - , yamlColumn mark + 1 - , Just $ pack problem - ) - (Just $ pack context) - ) - Nothing - ] - -tabProblem :: String -tabProblem = "found character that cannot start any token" - -tabContext :: String -tabContext = "while scanning for the next token" - --- | Return 'Char' at (1-based) line/column of a 'ByteString' -getCharAt :: Line -> Column -> ByteString -> Maybe Char -getCharAt ln cn bs = do - l <- (!? (ln - 1)) $ BS8.lines bs - BS8.indexMaybe l (cn - 1) diff --git a/test/Restyler/WikiSpec.hs b/test/Restyler/WikiSpec.hs deleted file mode 100644 index db7391cf..00000000 --- a/test/Restyler/WikiSpec.hs +++ /dev/null @@ -1,36 +0,0 @@ --- | --- --- Module : Restyler.WikiSpec --- Copyright : (c) 2024 Patrick Brisbin --- License : AGPL-3 --- Maintainer : pbrisbin@gmail.com --- Stability : experimental --- Portability : POSIX -module Restyler.WikiSpec - ( spec - ) where - -import Restyler.Prelude - -import Restyler.Wiki qualified as Wiki -import Test.Hspec - -spec :: Spec -spec = do - describe "commonEror" $ do - it "builds a Common Errors page" $ do - Wiki.commonError "Plan Upgrade Required" - `shouldBe` "https://github.com/restyled-io/restyled.io/wiki/Common-Errors:-Plan-Upgrade-Required" - - describe "page" $ do - it "builds a page spelled out exactly" $ do - Wiki.page "/Disabling-Restyled" - `shouldBe` "https://github.com/restyled-io/restyled.io/wiki/Disabling-Restyled" - - it "auto-slash-prefixes" $ do - Wiki.page "Disabling-Restyled" - `shouldBe` "https://github.com/restyled-io/restyled.io/wiki/Disabling-Restyled" - - it "auto-hyphenates" $ do - Wiki.page "Disabling Restyled" - `shouldBe` "https://github.com/restyled-io/restyled.io/wiki/Disabling-Restyled" diff --git a/test/Restyler/Yaml/ErrataSpec.hs b/test/Restyler/Yaml/ErrataSpec.hs deleted file mode 100644 index 1aefd9d8..00000000 --- a/test/Restyler/Yaml/ErrataSpec.hs +++ /dev/null @@ -1,81 +0,0 @@ -{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-} - --- | --- --- Module : Restyler.Yaml.ErrataSpec --- Copyright : (c) 2024 Patrick Brisbin --- License : AGPL-3 --- Maintainer : pbrisbin@gmail.com --- Stability : experimental --- Portability : POSIX -module Restyler.Yaml.ErrataSpec - ( spec - ) where - -import SpecHelper - -import Data.Aeson -import Data.Text qualified as T -import Data.Yaml (ParseException (..), YamlException (..)) -import Data.Yaml qualified as Yaml -import Restyler.Yaml.Errata - -spec :: Spec -spec = do - describe "formatInvalidYaml" $ do - it "adds an annotation pointing out line/column" $ example $ do - let - invalidYaml :: ByteString - invalidYaml = - encodeUtf8 - $ unlines - [ "restylers:" - , " - brittany" - , " include:" - , " - '**/*.hs'" - , " - '!src/Graphula/Class.hs' # CPP" - , " - stylish-haskell" - , "" - , "comments: false" - , "" - , "labels:" - , " - restyled" - ] - - Left (InvalidYaml (Just (YamlParseException p c m))) = - Yaml.decodeEither' @Value invalidYaml - - formatInvalidYaml "" invalidYaml p c m - `shouldBeLines` [ "Yaml parse exception" - , "--> :2:13" - , " |" - , "2 | - brittany" - , " | ^ mapping values are not allowed in this context" - ] - - it "handles tabs nicely" $ example $ do - let - invalidYaml :: ByteString - invalidYaml = - encodeUtf8 - $ unlines - [ "statuses:" - , "\tdifferences: false" - ] - - Left (InvalidYaml (Just (YamlParseException p c m))) = - Yaml.decodeEither' @Value invalidYaml - - formatInvalidYaml "" invalidYaml p c m - `shouldBeLines` [ "Yaml parse exception" - , "--> :2:1" - , " |" - , "2 | differences: false" - , " | ^^^^ Tab found for indentation" - , "YAML forbids tabs for indentation: https://yaml.org/faq.html" - ] - -shouldBeLines :: MonadIO m => Text -> [Text] -> m () -shouldBeLines x = shouldBe (T.dropWhileEnd (== '\n') x <> "\n") . T.unlines - -infix 1 `shouldBeLines`