diff --git a/src/Nixfmt/Parser.hs b/src/Nixfmt/Parser.hs index ddfb558..a4c0c6f 100644 --- a/src/Nixfmt/Parser.hs +++ b/src/Nixfmt/Parser.hs @@ -292,6 +292,7 @@ stripIndentation parts = case commonIndentation $ mapMaybe lineHead parts of Nothing -> map (const []) parts Just indentation -> map (stripParts indentation) parts +-- Merge adjacent string parts which resulted as parsing artifacts normalizeLine :: [StringPart] -> [StringPart] normalizeLine [] = [] normalizeLine (TextPart "" : xs) = normalizeLine xs diff --git a/src/Nixfmt/Util.hs b/src/Nixfmt/Util.hs index 8bc5986..c2ae182 100644 --- a/src/Nixfmt/Util.hs +++ b/src/Nixfmt/Util.hs @@ -12,7 +12,7 @@ module Nixfmt.Util ( ) where -import Data.Char (isAlpha, isDigit, isSpace) +import Data.Char (isAlpha, isDigit) import Data.Text as Text ( Text, all, @@ -73,7 +73,7 @@ commonPrefix a b = -- prefix of zero texts is infinite, represented as Nothing. commonIndentation :: [Text] -> Maybe Text commonIndentation [] = Nothing -commonIndentation [x] = Just $ Text.takeWhile isSpace x +commonIndentation [x] = Just $ Text.takeWhile (== ' ') x commonIndentation (x : y : xs) = commonIndentation (commonPrefix x y : xs) isSpaces :: Text -> Bool