diff --git a/src/Nixfmt/Pretty.hs b/src/Nixfmt/Pretty.hs index 3a3d7b52..439d1887 100644 --- a/src/Nixfmt/Pretty.hs +++ b/src/Nixfmt/Pretty.hs @@ -84,19 +84,21 @@ instance Pretty Binder where -- `foo = bar` pretty (Assignment selectors assign expr semicolon) = base $ group $ hcat selectors <> hardspace - <> nest 2 (pretty assign <> absorbInner expr) + <> nest 2 (pretty assign <> inner) where - -- Function declaration / If statement / Let binding - -- If it is multi-line, force it into a new line with indentation, semicolon on separate line - absorbInner expr@(Abstraction _ _ _) = line <> pretty expr <> line' <> pretty semicolon - absorbInner expr@(If _ _ _ _ _ _) = line <> pretty expr <> line' <> pretty semicolon - absorbInner expr@(Let _ _ _ _) = line <> pretty expr <> line' <> pretty semicolon - -- Absorbable term (list/attrset) - -- force-absorb the term and then the semicolon - absorbInner expr@(Term t) | isAbsorbable t = hardspace <> group expr <> softline' <> pretty semicolon - -- `foo = bar`, otherwise - -- Try to absorb and keep the semicolon attached, spread otherwise - absorbInner expr = softline <> group (pretty expr <> softline' <> pretty semicolon) + inner = + case expr of + -- Function declaration / If statement / Let binding + -- If it is multi-line, force it into a new line with indentation, semicolon on separate line + (Abstraction _ _ _) -> line <> pretty expr <> line' <> pretty semicolon + (If _ _ _ _ _ _) -> line <> pretty expr <> line' <> pretty semicolon + (Let _ _ _ _) -> line <> pretty expr <> line' <> pretty semicolon + -- Term + -- Absorb and keep the semicolon attached if possible + (Term t) -> (if isAbsorbable t then hardspace else softline) <> group expr <> pretty semicolon + -- Everything else + -- Try to absorb and keep the semicolon attached, spread otherwise + _ -> softline <> group (pretty expr <> softline' <> pretty semicolon) -- | Pretty print a term without wrapping it in a group. diff --git a/test/diff/idioms_pkgs_3/out.nix b/test/diff/idioms_pkgs_3/out.nix index fea7c990..d48009d0 100644 --- a/test/diff/idioms_pkgs_3/out.nix +++ b/test/diff/idioms_pkgs_3/out.nix @@ -225,11 +225,9 @@ let defaultPrefs = { "geo.provider.network.url" = { value = - "https://location.services.mozilla.com/v1/geolocate?key=%MOZILLA_API_KEY%" - ; + "https://location.services.mozilla.com/v1/geolocate?key=%MOZILLA_API_KEY%"; reason = - "Use MLS by default for geolocation, since our Google API Keys are not working" - ; + "Use MLS by default for geolocation, since our Google API Keys are not working"; }; }; @@ -259,8 +257,7 @@ buildStdenv.mkDerivation ({ # https://bugzilla.mozilla.org/show_bug.cgi?id=1773259 name = "rust-cbindgen-0.24.2-compat.patch"; url = - "https://raw.githubusercontent.com/canonical/firefox-snap/5622734942524846fb0eb7108918c8cd8557fde3/patches/fix-ftbfs-newer-cbindgen.patch" - ; + "https://raw.githubusercontent.com/canonical/firefox-snap/5622734942524846fb0eb7108918c8cd8557fde3/patches/fix-ftbfs-newer-cbindgen.patch"; hash = "sha256-+wNZhkDB3HSknPRD4N6cQXY7zMT/DzNXx29jQH0Gb1o="; }) ] ++ lib.optional (lib.versionOlder version "111") ./env_var_for_system_dir-ff86.patch diff --git a/test/diff/monsters_1/out.nix b/test/diff/monsters_1/out.nix index e6895770..beea1434 100644 --- a/test/diff/monsters_1/out.nix +++ b/test/diff/monsters_1/out.nix @@ -232,8 +232,7 @@ rec # foo = # foo - "Checks whether the contrast between two colors meet the WCAG requirements" - ; + "Checks whether the contrast between two colors meet the WCAG requirements"; # foo homepage # foo diff --git a/test/diff/monsters_3/out.nix b/test/diff/monsters_3/out.nix index fac5cee4..0f66f531 100644 --- a/test/diff/monsters_3/out.nix +++ b/test/diff/monsters_3/out.nix @@ -60,8 +60,7 @@ stdenv.mkDerivation rec { ''; meta = with lib; { description = - "Checks whether the contrast between two colors meet the WCAG requirements" - ; + "Checks whether the contrast between two colors meet the WCAG requirements"; homepage = "https://gitlab.gnome.org/World/design/contrast"; license = licenses.gpl3Plus; maintainers = with maintainers; [ jtojnar ]; diff --git a/test/diff/monsters_4/out.nix b/test/diff/monsters_4/out.nix index 90d57edc..10c74252 100644 --- a/test/diff/monsters_4/out.nix +++ b/test/diff/monsters_4/out.nix @@ -118,8 +118,7 @@ rec # Foo { # Foo description # Foo = # Foo - "Checks whether the contrast between two colors meet the WCAG requirements" - ; # Foo + "Checks whether the contrast between two colors meet the WCAG requirements"; # Foo homepage # Foo = # Foo "https://gitlab.gnome.org/World/design/contrast"; # Foo