From 7f6af6b4369134812316ca09422ab48adad83cf7 Mon Sep 17 00:00:00 2001 From: piegames Date: Wed, 2 Oct 2024 15:45:04 +0200 Subject: [PATCH 1/5] tests: Add function calls with list-heavy arguments --- test/diff/apply_with_lists/in.nix | 78 +++++++++++++ test/diff/apply_with_lists/out-pure.nix | 134 +++++++++++++++++++++++ test/diff/apply_with_lists/out.nix | 139 ++++++++++++++++++++++++ 3 files changed, 351 insertions(+) create mode 100644 test/diff/apply_with_lists/in.nix create mode 100644 test/diff/apply_with_lists/out-pure.nix create mode 100644 test/diff/apply_with_lists/out.nix diff --git a/test/diff/apply_with_lists/in.nix b/test/diff/apply_with_lists/in.nix new file mode 100644 index 0000000..86eebd2 --- /dev/null +++ b/test/diff/apply_with_lists/in.nix @@ -0,0 +1,78 @@ +# This file contains an assortment of test cases involving list-heavy function calls + +[ + (f [ ] [ rhs lhs ]) + (lib.mkMerge [ false false ]) + (replaceStrings + [ "\${" "''" ] + #force multiline + [ "''\${" "'''" ]) + (replaceStrings [ ''"'' "\\" ] [ ''\"'' "\\\\" ] name) + (replaceStrings + [ ''"'' "\\" ] + # force multiline + [ ''\"'' "\\\\" ] + name) + (replaceStrings + [ "@" ":" "\\" "[" "]" ] + [ "-" "-" "-" "" "" ]) + (lists.removePrefix [ 1 2 ] [ ]) + (lists.removePrefix aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa [ 1 2 ] [ ]) + (builtins.replaceStrings + [ "@NIX_STORE_VERITY@" ] + [partitionTypes.usr-verity] + (builtins.readFile ./assert_uki_repart_match.py)) + (replaceStrings [ "-" ] [ "_" ] (toUpper final.rust.cargoShortTarget)) + (lib.mkChangedOptionModule + [ "security" "acme" "validMin" ] + [ "security" "acme" "defaults" "validMinDays" ] + (config: config.security.acme.validMin / (24 * 3600))) + (lib.replaceStrings + [ "https://registry" ".io/providers" ] + [ "registry" ".io" ] + homepage) + (lib.mkRenamedOptionModule [ "boot" "extraTTYs" ] [ "console" "extraTTYs" ]) + # This line is engineered to exactly hit the line length limit + (lib.mkRenamedOptionModule [ "hardware" "package234" ] [ "hardware" "graphics" ]) + (mkRenamedOptionModule [ + "services" + "xserver" + "displayManager" + "sddm" + "enable" + ] [ "services" "displayManager" "sddm" "enable" ]) + (map (buildAllowCommand "allow" [ "snapshot" "mount" "destroy" ])) + (map (x: "${x} ${escapeShellArgs [ stateDir workDir logsDir ]}") [ + "+${unconfigureRunner}" # runs as root + configureRunner + setupWorkDir + ]) + (lib.checkListOfEnum "${pname}: theme accent" + [ + "Blue" + "Flamingo" + "Green" + ] + [ accent ] + lib.checkListOfEnum + "${pname}: color variant" + [ "Latte" "Frappe" "Macchiato" "Mocha" ] + [ variant ] + ) + (lib.switch [ coq.coq-version ssreflect.version ] [ + { + cases = [ + (lib.versions.range "8.15" "8.20") + lib.pred.true + ]; + out = "2.0.4"; + } + { + cases = [ + "8.5" + lib.pred.true + ]; + out = "20170512"; + } + ] null) +] diff --git a/test/diff/apply_with_lists/out-pure.nix b/test/diff/apply_with_lists/out-pure.nix new file mode 100644 index 0000000..1437bf1 --- /dev/null +++ b/test/diff/apply_with_lists/out-pure.nix @@ -0,0 +1,134 @@ +# This file contains an assortment of test cases involving list-heavy function calls + +[ + (f [ ] [ + rhs + lhs + ]) + (lib.mkMerge [ + false + false + ]) + (replaceStrings [ "\${" "''" ] + #force multiline + [ + "''\${" + "'''" + ] + ) + (replaceStrings [ ''"'' "\\" ] [ ''\"'' "\\\\" ] name) + (replaceStrings [ ''"'' "\\" ] + # force multiline + [ ''\"'' "\\\\" ] + name + ) + (replaceStrings + [ + "@" + ":" + "\\" + "[" + "]" + ] + [ + "-" + "-" + "-" + "" + "" + ] + ) + (lists.removePrefix [ + 1 + 2 + ] [ ]) + (lists.removePrefix aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa [ + 1 + 2 + ] [ ]) + (builtins.replaceStrings [ "@NIX_STORE_VERITY@" ] [ + partitionTypes.usr-verity + ] (builtins.readFile ./assert_uki_repart_match.py)) + (replaceStrings [ "-" ] [ "_" ] (toUpper final.rust.cargoShortTarget)) + (lib.mkChangedOptionModule [ "security" "acme" "validMin" ] [ + "security" + "acme" + "defaults" + "validMinDays" + ] (config: config.security.acme.validMin / (24 * 3600))) + (lib.replaceStrings [ "https://registry" ".io/providers" ] [ + "registry" + ".io" + ] homepage) + (lib.mkRenamedOptionModule [ "boot" "extraTTYs" ] [ + "console" + "extraTTYs" + ]) + # This line is engineered to exactly hit the line length limit + (lib.mkRenamedOptionModule [ "hardware" "package234" ] [ + "hardware" + "graphics" + ]) + (mkRenamedOptionModule + [ + "services" + "xserver" + "displayManager" + "sddm" + "enable" + ] + [ + "services" + "displayManager" + "sddm" + "enable" + ] + ) + (map ( + buildAllowCommand "allow" [ + "snapshot" + "mount" + "destroy" + ] + )) + (map + ( + x: + "${x} ${ + escapeShellArgs [ + stateDir + workDir + logsDir + ] + }" + ) + [ + "+${unconfigureRunner}" # runs as root + configureRunner + setupWorkDir + ] + ) + (lib.checkListOfEnum "${pname}: theme accent" [ "Blue" "Flamingo" "Green" ] + [ accent ] + lib.checkListOfEnum + "${pname}: color variant" + [ "Latte" "Frappe" "Macchiato" "Mocha" ] + [ variant ] + ) + (lib.switch [ coq.coq-version ssreflect.version ] [ + { + cases = [ + (lib.versions.range "8.15" "8.20") + lib.pred.true + ]; + out = "2.0.4"; + } + { + cases = [ + "8.5" + lib.pred.true + ]; + out = "20170512"; + } + ] null) +] diff --git a/test/diff/apply_with_lists/out.nix b/test/diff/apply_with_lists/out.nix new file mode 100644 index 0000000..3f4329f --- /dev/null +++ b/test/diff/apply_with_lists/out.nix @@ -0,0 +1,139 @@ +# This file contains an assortment of test cases involving list-heavy function calls + +[ + (f [ ] [ + rhs + lhs + ]) + (lib.mkMerge [ + false + false + ]) + (replaceStrings [ "\${" "''" ] + #force multiline + [ + "''\${" + "'''" + ] + ) + (replaceStrings [ ''"'' "\\" ] [ ''\"'' "\\\\" ] name) + (replaceStrings [ ''"'' "\\" ] + # force multiline + [ ''\"'' "\\\\" ] + name + ) + (replaceStrings + [ + "@" + ":" + "\\" + "[" + "]" + ] + [ + "-" + "-" + "-" + "" + "" + ] + ) + (lists.removePrefix [ + 1 + 2 + ] [ ]) + (lists.removePrefix aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa [ + 1 + 2 + ] [ ]) + (builtins.replaceStrings [ "@NIX_STORE_VERITY@" ] [ + partitionTypes.usr-verity + ] (builtins.readFile ./assert_uki_repart_match.py)) + (replaceStrings [ "-" ] [ "_" ] (toUpper final.rust.cargoShortTarget)) + (lib.mkChangedOptionModule [ "security" "acme" "validMin" ] [ + "security" + "acme" + "defaults" + "validMinDays" + ] (config: config.security.acme.validMin / (24 * 3600))) + (lib.replaceStrings [ "https://registry" ".io/providers" ] [ + "registry" + ".io" + ] homepage) + (lib.mkRenamedOptionModule [ "boot" "extraTTYs" ] [ + "console" + "extraTTYs" + ]) + # This line is engineered to exactly hit the line length limit + (lib.mkRenamedOptionModule [ "hardware" "package234" ] [ + "hardware" + "graphics" + ]) + (mkRenamedOptionModule + [ + "services" + "xserver" + "displayManager" + "sddm" + "enable" + ] + [ + "services" + "displayManager" + "sddm" + "enable" + ] + ) + (map ( + buildAllowCommand "allow" [ + "snapshot" + "mount" + "destroy" + ] + )) + (map + ( + x: + "${x} ${ + escapeShellArgs [ + stateDir + workDir + logsDir + ] + }" + ) + [ + "+${unconfigureRunner}" # runs as root + configureRunner + setupWorkDir + ] + ) + (lib.checkListOfEnum "${pname}: theme accent" + [ + "Blue" + "Flamingo" + "Green" + ] + [ accent ] + lib.checkListOfEnum + "${pname}: color variant" + [ "Latte" "Frappe" "Macchiato" "Mocha" ] + [ variant ] + ) + (lib.switch [ coq.coq-version ssreflect.version ] [ + { + cases = [ + (lib.versions.range "8.15" "8.20") + lib.pred.true + ]; + out = "2.0.4"; + } + { + cases = [ + "8.5" + lib.pred.true + ]; + out = "20170512"; + } + ] null) +] From 8dc9ddaca656880bc99d1b13cb491248bfe7e52c Mon Sep 17 00:00:00 2001 From: piegames Date: Thu, 3 Oct 2024 10:35:37 +0200 Subject: [PATCH 2/5] application: Special case list arguments 1/2 --- src/Nixfmt/Pretty.hs | 6 +++ test/diff/apply_with_lists/out-pure.nix | 66 +++++++++++++------------ test/diff/apply_with_lists/out.nix | 63 ++++++++++++----------- 3 files changed, 74 insertions(+), 61 deletions(-) diff --git a/src/Nixfmt/Pretty.hs b/src/Nixfmt/Pretty.hs index f03f7bc..c74e039 100644 --- a/src/Nixfmt/Pretty.hs +++ b/src/Nixfmt/Pretty.hs @@ -381,6 +381,12 @@ prettyApp indentFunction pre hasPost f a = -- because if they get expanded before anything else, -- only the `.`-and-after part gets to a new line, which looks very odd absorbApp (Application f' a'@(Term Selection{})) = group' Transparent (absorbApp f') <> line <> nest (group' RegularG $ absorbInner a') + -- If two consecutive arguments are lists, treat them specially: Don't priority expand, and also + -- if one does not fit onto the line then put both on a new line each. + -- Note that this does not handle the case where the two last arguments are lists, as the last argument + -- is handled elsewhere and cannot be pattern-matched here. + absorbApp (Application (Application f' l1@(Term List{})) l2@(Term List{})) = + group' Transparent (group' Transparent (absorbApp f') <> nest (group' RegularG $ line <> group (absorbInner l1) <> line <> group (absorbInner l2))) absorbApp (Application f' a') = group' Transparent (absorbApp f') <> line <> nest (group' Priority $ absorbInner a') -- First argument absorbApp expr diff --git a/test/diff/apply_with_lists/out-pure.nix b/test/diff/apply_with_lists/out-pure.nix index 1437bf1..176b458 100644 --- a/test/diff/apply_with_lists/out-pure.nix +++ b/test/diff/apply_with_lists/out-pure.nix @@ -17,7 +17,8 @@ ] ) (replaceStrings [ ''"'' "\\" ] [ ''\"'' "\\\\" ] name) - (replaceStrings [ ''"'' "\\" ] + (replaceStrings + [ ''"'' "\\" ] # force multiline [ ''\"'' "\\\\" ] name @@ -46,20 +47,18 @@ 1 2 ] [ ]) - (builtins.replaceStrings [ "@NIX_STORE_VERITY@" ] [ - partitionTypes.usr-verity - ] (builtins.readFile ./assert_uki_repart_match.py)) + (builtins.replaceStrings [ "@NIX_STORE_VERITY@" ] [ partitionTypes.usr-verity ] + (builtins.readFile ./assert_uki_repart_match.py) + ) (replaceStrings [ "-" ] [ "_" ] (toUpper final.rust.cargoShortTarget)) - (lib.mkChangedOptionModule [ "security" "acme" "validMin" ] [ - "security" - "acme" - "defaults" - "validMinDays" - ] (config: config.security.acme.validMin / (24 * 3600))) - (lib.replaceStrings [ "https://registry" ".io/providers" ] [ - "registry" - ".io" - ] homepage) + (lib.mkChangedOptionModule + [ "security" "acme" "validMin" ] + [ "security" "acme" "defaults" "validMinDays" ] + (config: config.security.acme.validMin / (24 * 3600)) + ) + (lib.replaceStrings [ "https://registry" ".io/providers" ] [ "registry" ".io" ] + homepage + ) (lib.mkRenamedOptionModule [ "boot" "extraTTYs" ] [ "console" "extraTTYs" @@ -108,27 +107,32 @@ setupWorkDir ] ) - (lib.checkListOfEnum "${pname}: theme accent" [ "Blue" "Flamingo" "Green" ] + (lib.checkListOfEnum "${pname}: theme accent" + [ "Blue" "Flamingo" "Green" ] [ accent ] lib.checkListOfEnum "${pname}: color variant" [ "Latte" "Frappe" "Macchiato" "Mocha" ] [ variant ] ) - (lib.switch [ coq.coq-version ssreflect.version ] [ - { - cases = [ - (lib.versions.range "8.15" "8.20") - lib.pred.true - ]; - out = "2.0.4"; - } - { - cases = [ - "8.5" - lib.pred.true - ]; - out = "20170512"; - } - ] null) + (lib.switch + [ coq.coq-version ssreflect.version ] + [ + { + cases = [ + (lib.versions.range "8.15" "8.20") + lib.pred.true + ]; + out = "2.0.4"; + } + { + cases = [ + "8.5" + lib.pred.true + ]; + out = "20170512"; + } + ] + null + ) ] diff --git a/test/diff/apply_with_lists/out.nix b/test/diff/apply_with_lists/out.nix index 3f4329f..851779e 100644 --- a/test/diff/apply_with_lists/out.nix +++ b/test/diff/apply_with_lists/out.nix @@ -17,7 +17,8 @@ ] ) (replaceStrings [ ''"'' "\\" ] [ ''\"'' "\\\\" ] name) - (replaceStrings [ ''"'' "\\" ] + (replaceStrings + [ ''"'' "\\" ] # force multiline [ ''\"'' "\\\\" ] name @@ -46,20 +47,18 @@ 1 2 ] [ ]) - (builtins.replaceStrings [ "@NIX_STORE_VERITY@" ] [ - partitionTypes.usr-verity - ] (builtins.readFile ./assert_uki_repart_match.py)) + (builtins.replaceStrings [ "@NIX_STORE_VERITY@" ] [ partitionTypes.usr-verity ] + (builtins.readFile ./assert_uki_repart_match.py) + ) (replaceStrings [ "-" ] [ "_" ] (toUpper final.rust.cargoShortTarget)) - (lib.mkChangedOptionModule [ "security" "acme" "validMin" ] [ - "security" - "acme" - "defaults" - "validMinDays" - ] (config: config.security.acme.validMin / (24 * 3600))) - (lib.replaceStrings [ "https://registry" ".io/providers" ] [ - "registry" - ".io" - ] homepage) + (lib.mkChangedOptionModule + [ "security" "acme" "validMin" ] + [ "security" "acme" "defaults" "validMinDays" ] + (config: config.security.acme.validMin / (24 * 3600)) + ) + (lib.replaceStrings [ "https://registry" ".io/providers" ] [ "registry" ".io" ] + homepage + ) (lib.mkRenamedOptionModule [ "boot" "extraTTYs" ] [ "console" "extraTTYs" @@ -120,20 +119,24 @@ [ "Latte" "Frappe" "Macchiato" "Mocha" ] [ variant ] ) - (lib.switch [ coq.coq-version ssreflect.version ] [ - { - cases = [ - (lib.versions.range "8.15" "8.20") - lib.pred.true - ]; - out = "2.0.4"; - } - { - cases = [ - "8.5" - lib.pred.true - ]; - out = "20170512"; - } - ] null) + (lib.switch + [ coq.coq-version ssreflect.version ] + [ + { + cases = [ + (lib.versions.range "8.15" "8.20") + lib.pred.true + ]; + out = "2.0.4"; + } + { + cases = [ + "8.5" + lib.pred.true + ]; + out = "20170512"; + } + ] + null + ) ] From 7c064a2f0c71a633b8b422fd6a560220f54cb858 Mon Sep 17 00:00:00 2001 From: piegames Date: Mon, 14 Oct 2024 11:48:54 +0200 Subject: [PATCH 3/5] cli: add --ir --- main/Main.hs | 10 ++++++++-- src/Nixfmt.hs | 9 ++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/main/Main.hs b/main/Main.hs index 99c592c..c8280d2 100644 --- a/main/Main.hs +++ b/main/Main.hs @@ -49,7 +49,8 @@ data Nixfmt = Nixfmt quiet :: Bool, strict :: Bool, verify :: Bool, - ast :: Bool + ast :: Bool, + ir :: Bool } deriving (Show, Data, Typeable) @@ -76,7 +77,11 @@ options = ast = False &= help - "Pretty print the internal AST, only for debugging" + "Pretty print the internal AST, only for debugging", + ir = + False + &= help + "Pretty print the internal intermediate representation, only for debugging" } &= summary ("nixfmt " ++ versionFromFile) &= help "Format Nix source code" @@ -157,6 +162,7 @@ type Formatter = FilePath -> Text -> Either String Text toFormatter :: Nixfmt -> Formatter toFormatter Nixfmt{ast = True} = Nixfmt.printAst +toFormatter Nixfmt{ir = True} = Nixfmt.printIR toFormatter Nixfmt{width, verify = True, strict} = Nixfmt.formatVerify (layout width strict) toFormatter Nixfmt{width, verify = False, strict} = Nixfmt.format (layout width strict) diff --git a/src/Nixfmt.hs b/src/Nixfmt.hs index fd432a6..716de3d 100644 --- a/src/Nixfmt.hs +++ b/src/Nixfmt.hs @@ -7,6 +7,7 @@ module Nixfmt ( format, formatVerify, printAst, + printIR, ) where @@ -15,7 +16,7 @@ import Data.Either (fromRight) import Data.Text (Text, unpack) import Data.Text.Lazy (toStrict) import qualified Nixfmt.Parser as Parser -import Nixfmt.Predoc (Pretty) +import Nixfmt.Predoc (Pretty, fixup, pretty) import Nixfmt.Pretty () import Nixfmt.Types (Expression, LanguageElement, ParseErrorBundle, Whole (..), walkSubprograms) import qualified Text.Megaparsec as Megaparsec (parse) @@ -41,6 +42,12 @@ printAst path unformatted = do Whole unformattedParsed' _ <- first errorBundlePretty . Megaparsec.parse Parser.file path $ unformatted Left (unpack $ toStrict $ pShow unformattedParsed') +-- | Pretty print the internal IR for debugging +printIR :: FilePath -> Text -> Either String Text +printIR filename = + bimap errorBundlePretty (toStrict . pShow . fixup . pretty) + . Megaparsec.parse Parser.file filename + -- Same functionality as `format`, but add sanity checks to guarantee the following properties of the formatter: -- - Correctness: The formatted output parses, and the parse tree is identical to the input's -- - Idempotency: Formatting the output again will not modify it From 1fde293459c37db8b7e5dc101436646f4721267d Mon Sep 17 00:00:00 2001 From: piegames Date: Thu, 3 Oct 2024 11:18:57 +0200 Subject: [PATCH 4/5] Refactor: renderSimple in prettyApp --- src/Nixfmt/Pretty.hs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Nixfmt/Pretty.hs b/src/Nixfmt/Pretty.hs index c74e039..f7cfc35 100644 --- a/src/Nixfmt/Pretty.hs +++ b/src/Nixfmt/Pretty.hs @@ -457,15 +457,22 @@ prettyApp indentFunction pre hasPost f a = ((\a'@Ann{preTrivia} -> (a'{preTrivia = []}, preTrivia)) . moveTrailingCommentUp) f - renderedF = pre <> group' Transparent (absorbApp fWithoutComment) - renderedFUnexpanded = unexpandSpacing' Nothing renderedF + -- renderSimple will take a document to render, and call one of two callbacks depending on whether + -- it can take a simplified layout (with removed line breaks) or not. + renderSimple :: Doc -> (Doc -> Doc) -> (Doc -> Doc) -> Doc + renderSimple toRender renderIfSimple renderOtherwise = + let renderedF = pre <> group' Transparent toRender + renderedFUnexpanded = unexpandSpacing' Nothing renderedF + in if isSimple (Application f a) && isJust renderedFUnexpanded + then renderIfSimple (fromJust renderedFUnexpanded) + else renderOtherwise renderedF post = if hasPost then line' else mempty in pretty comment' - <> ( if isSimple (Application f a) && isJust renderedFUnexpanded - then group' RegularG $ fromJust renderedFUnexpanded <> hardspace <> absorbLast a - else group' RegularG $ renderedF <> line <> absorbLast a <> post - ) + <> renderSimple + (absorbApp fWithoutComment) + (\fRendered -> group' RegularG $ fRendered <> hardspace <> absorbLast a) + (\fRendered -> group' RegularG $ fRendered <> line <> absorbLast a <> post) <> (if hasPost && not (null comment') then hardline else mempty) prettyWith :: Bool -> Expression -> Doc From ec04379990cc017a0e6e850bf617ab09d96c903a Mon Sep 17 00:00:00 2001 From: piegames Date: Thu, 3 Oct 2024 11:22:56 +0200 Subject: [PATCH 5/5] application: Special case list arguments 2/2 --- src/Nixfmt/Pretty.hs | 21 ++++++++-- test/diff/apply/out-pure.nix | 5 +-- test/diff/apply_with_lists/out-pure.nix | 55 +++++++++++-------------- test/diff/apply_with_lists/out.nix | 55 +++++++++++-------------- test/diff/idioms_lib_3/out-pure.nix | 5 +-- test/diff/idioms_lib_3/out.nix | 5 +-- 6 files changed, 68 insertions(+), 78 deletions(-) diff --git a/src/Nixfmt/Pretty.hs b/src/Nixfmt/Pretty.hs index f7cfc35..ae3e305 100644 --- a/src/Nixfmt/Pretty.hs +++ b/src/Nixfmt/Pretty.hs @@ -469,10 +469,23 @@ prettyApp indentFunction pre hasPost f a = post = if hasPost then line' else mempty in pretty comment' - <> renderSimple - (absorbApp fWithoutComment) - (\fRendered -> group' RegularG $ fRendered <> hardspace <> absorbLast a) - (\fRendered -> group' RegularG $ fRendered <> line <> absorbLast a <> post) + <> case (fWithoutComment, a) of + -- When the two last arguments are lists, render these specially (same as above) + -- Also no need to wrap in renderSimple here, because we know that these kinds of arguments + -- are never "simple" by definition. + (Application fWithoutCommandAndWithoutArg l1@(Term List{}), l2@(Term List{})) -> + group' RegularG $ + (pre <> group' Transparent (absorbApp fWithoutCommandAndWithoutArg)) + <> line + <> nest (group (absorbInner l1)) + <> line + <> nest (group (absorbInner l2)) + <> post + _ -> + renderSimple + (absorbApp fWithoutComment) + (\fRendered -> group' RegularG $ fRendered <> hardspace <> absorbLast a) + (\fRendered -> group' RegularG $ fRendered <> line <> absorbLast a <> post) <> (if hasPost && not (null comment') then hardline else mempty) prettyWith :: Bool -> Expression -> Doc diff --git a/test/diff/apply/out-pure.nix b/test/diff/apply/out-pure.nix index 9911461..9db9ebc 100644 --- a/test/diff/apply/out-pure.nix +++ b/test/diff/apply/out-pure.nix @@ -160,10 +160,7 @@ ''"'' "\${" ]; - escapeMultiline = libStr.replaceStrings [ "\${" "''" ] [ - "''\${" - "'''" - ]; + escapeMultiline = libStr.replaceStrings [ "\${" "''" ] [ "''\${" "'''" ]; test = foo [ diff --git a/test/diff/apply_with_lists/out-pure.nix b/test/diff/apply_with_lists/out-pure.nix index 176b458..edf22e6 100644 --- a/test/diff/apply_with_lists/out-pure.nix +++ b/test/diff/apply_with_lists/out-pure.nix @@ -1,20 +1,15 @@ # This file contains an assortment of test cases involving list-heavy function calls [ - (f [ ] [ - rhs - lhs - ]) + (f [ ] [ rhs lhs ]) (lib.mkMerge [ false false ]) - (replaceStrings [ "\${" "''" ] + (replaceStrings + [ "\${" "''" ] #force multiline - [ - "''\${" - "'''" - ] + [ "''\${" "'''" ] ) (replaceStrings [ ''"'' "\\" ] [ ''\"'' "\\\\" ] name) (replaceStrings @@ -39,14 +34,20 @@ "" ] ) - (lists.removePrefix [ - 1 - 2 - ] [ ]) - (lists.removePrefix aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa [ - 1 - 2 - ] [ ]) + (lists.removePrefix + [ + 1 + 2 + ] + [ ] + ) + (lists.removePrefix aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + [ + 1 + 2 + ] + [ ] + ) (builtins.replaceStrings [ "@NIX_STORE_VERITY@" ] [ partitionTypes.usr-verity ] (builtins.readFile ./assert_uki_repart_match.py) ) @@ -59,15 +60,12 @@ (lib.replaceStrings [ "https://registry" ".io/providers" ] [ "registry" ".io" ] homepage ) - (lib.mkRenamedOptionModule [ "boot" "extraTTYs" ] [ - "console" - "extraTTYs" - ]) + (lib.mkRenamedOptionModule [ "boot" "extraTTYs" ] [ "console" "extraTTYs" ]) # This line is engineered to exactly hit the line length limit - (lib.mkRenamedOptionModule [ "hardware" "package234" ] [ - "hardware" - "graphics" - ]) + (lib.mkRenamedOptionModule + [ "hardware" "package234" ] + [ "hardware" "graphics" ] + ) (mkRenamedOptionModule [ "services" @@ -76,12 +74,7 @@ "sddm" "enable" ] - [ - "services" - "displayManager" - "sddm" - "enable" - ] + [ "services" "displayManager" "sddm" "enable" ] ) (map ( buildAllowCommand "allow" [ diff --git a/test/diff/apply_with_lists/out.nix b/test/diff/apply_with_lists/out.nix index 851779e..580e2b6 100644 --- a/test/diff/apply_with_lists/out.nix +++ b/test/diff/apply_with_lists/out.nix @@ -1,20 +1,15 @@ # This file contains an assortment of test cases involving list-heavy function calls [ - (f [ ] [ - rhs - lhs - ]) + (f [ ] [ rhs lhs ]) (lib.mkMerge [ false false ]) - (replaceStrings [ "\${" "''" ] + (replaceStrings + [ "\${" "''" ] #force multiline - [ - "''\${" - "'''" - ] + [ "''\${" "'''" ] ) (replaceStrings [ ''"'' "\\" ] [ ''\"'' "\\\\" ] name) (replaceStrings @@ -39,14 +34,20 @@ "" ] ) - (lists.removePrefix [ - 1 - 2 - ] [ ]) - (lists.removePrefix aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa [ - 1 - 2 - ] [ ]) + (lists.removePrefix + [ + 1 + 2 + ] + [ ] + ) + (lists.removePrefix aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + [ + 1 + 2 + ] + [ ] + ) (builtins.replaceStrings [ "@NIX_STORE_VERITY@" ] [ partitionTypes.usr-verity ] (builtins.readFile ./assert_uki_repart_match.py) ) @@ -59,15 +60,12 @@ (lib.replaceStrings [ "https://registry" ".io/providers" ] [ "registry" ".io" ] homepage ) - (lib.mkRenamedOptionModule [ "boot" "extraTTYs" ] [ - "console" - "extraTTYs" - ]) + (lib.mkRenamedOptionModule [ "boot" "extraTTYs" ] [ "console" "extraTTYs" ]) # This line is engineered to exactly hit the line length limit - (lib.mkRenamedOptionModule [ "hardware" "package234" ] [ - "hardware" - "graphics" - ]) + (lib.mkRenamedOptionModule + [ "hardware" "package234" ] + [ "hardware" "graphics" ] + ) (mkRenamedOptionModule [ "services" @@ -76,12 +74,7 @@ "sddm" "enable" ] - [ - "services" - "displayManager" - "sddm" - "enable" - ] + [ "services" "displayManager" "sddm" "enable" ] ) (map ( buildAllowCommand "allow" [ diff --git a/test/diff/idioms_lib_3/out-pure.nix b/test/diff/idioms_lib_3/out-pure.nix index 387e9df..2c9c796 100644 --- a/test/diff/idioms_lib_3/out-pure.nix +++ b/test/diff/idioms_lib_3/out-pure.nix @@ -366,10 +366,7 @@ rec { ''"'' "\${" ]; - escapeMultiline = libStr.replaceStrings [ "\${" "''" ] [ - "''\${" - "'''" - ]; + escapeMultiline = libStr.replaceStrings [ "\${" "''" ] [ "''\${" "'''" ]; singlelineResult = ''"'' + concatStringsSep "\\n" (map escapeSingleline lines) + ''"''; multilineResult = diff --git a/test/diff/idioms_lib_3/out.nix b/test/diff/idioms_lib_3/out.nix index 469184e..53474a6 100644 --- a/test/diff/idioms_lib_3/out.nix +++ b/test/diff/idioms_lib_3/out.nix @@ -379,10 +379,7 @@ rec { ''"'' "\${" ]; - escapeMultiline = libStr.replaceStrings [ "\${" "''" ] [ - "''\${" - "'''" - ]; + escapeMultiline = libStr.replaceStrings [ "\${" "''" ] [ "''\${" "'''" ]; singlelineResult = ''"'' + concatStringsSep "\\n" (map escapeSingleline lines) + ''"''; multilineResult =