Skip to content

Commit

Permalink
Fix string parsing of tab indentation
Browse files Browse the repository at this point in the history
As much as everyone would wish for, tabs are not whitespace according to
Nix whitespace stripping.
Fixes NixOS#116, but my overall confidence level in Nixfmt's correctness in
parsing the mess which is the Nix syntax remains rather low.
  • Loading branch information
piegamesde committed Dec 2, 2024
1 parent 36d5d3d commit 4200d2e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/Nixfmt/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Nixfmt/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4200d2e

Please sign in to comment.