Skip to content

Commit

Permalink
fixup! Rework bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
piegamesde committed May 7, 2023
1 parent 2e2797a commit dafec15
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 24 deletions.
26 changes: 14 additions & 12 deletions src/Nixfmt/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 3 additions & 6 deletions test/diff/idioms_pkgs_3/out.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
};
};

Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions test/diff/monsters_1/out.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions test/diff/monsters_3/out.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 ];
Expand Down
3 changes: 1 addition & 2 deletions test/diff/monsters_4/out.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dafec15

Please sign in to comment.