Skip to content

Commit

Permalink
Don't force-expand attrsets that contain a single inherit
Browse files Browse the repository at this point in the history
  • Loading branch information
piegamesde committed Sep 6, 2024
1 parent 331e0aa commit d8caa4c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 43 deletions.
6 changes: 5 additions & 1 deletion src/Nixfmt/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,11 @@ absorbExpr _ expr = pretty expr
-- Render the RHS value of an assignment or function parameter default value
absorbRHS :: Expression -> Doc
absorbRHS expr = case expr of
-- Absorbable expression. Always start on the same line
-- Exception to the case below: Don't force-expand attrsets if they only contain a single inherit statement
(Term (Set _ _ binders _))
| case unItems binders of [Item (Inherit{})] -> True; _ -> False ->
hardspace <> group (absorbExpr False expr)
-- Absorbable expression. Always start on the same line, and force-expand attrsets
_ | isAbsorbableExpr expr -> hardspace <> group (absorbExpr True expr)
-- Parenthesized expression. Same thing as the special case for parenthesized last argument in function calls.
(Term (Parenthesized open expr' close)) -> hardspace <> absorbParen open expr' close
Expand Down
24 changes: 6 additions & 18 deletions test/diff/idioms_lib_4/out-pure.nix
Original file line number Diff line number Diff line change
Expand Up @@ -521,33 +521,25 @@ rec {
# the normalized name for macOS.
macos = {
execFormat = macho;
families = {
inherit darwin;
};
families = { inherit darwin; };
name = "darwin";
};
ios = {
execFormat = macho;
families = {
inherit darwin;
};
families = { inherit darwin; };
};
# A tricky thing about FreeBSD is that there is no stable ABI across
# versions. That means that putting in the version as part of the
# config string is paramount.
freebsd12 = {
execFormat = elf;
families = {
inherit bsd;
};
families = { inherit bsd; };
name = "freebsd";
version = 12;
};
freebsd13 = {
execFormat = elf;
families = {
inherit bsd;
};
families = { inherit bsd; };
name = "freebsd";
version = 13;
};
Expand All @@ -557,19 +549,15 @@ rec {
};
netbsd = {
execFormat = elf;
families = {
inherit bsd;
};
families = { inherit bsd; };
};
none = {
execFormat = unknown;
families = { };
};
openbsd = {
execFormat = elf;
families = {
inherit bsd;
};
families = { inherit bsd; };
};
solaris = {
execFormat = elf;
Expand Down
24 changes: 6 additions & 18 deletions test/diff/idioms_lib_4/out.nix
Original file line number Diff line number Diff line change
Expand Up @@ -521,33 +521,25 @@ rec {
# the normalized name for macOS.
macos = {
execFormat = macho;
families = {
inherit darwin;
};
families = { inherit darwin; };
name = "darwin";
};
ios = {
execFormat = macho;
families = {
inherit darwin;
};
families = { inherit darwin; };
};
# A tricky thing about FreeBSD is that there is no stable ABI across
# versions. That means that putting in the version as part of the
# config string is paramount.
freebsd12 = {
execFormat = elf;
families = {
inherit bsd;
};
families = { inherit bsd; };
name = "freebsd";
version = 12;
};
freebsd13 = {
execFormat = elf;
families = {
inherit bsd;
};
families = { inherit bsd; };
name = "freebsd";
version = 13;
};
Expand All @@ -557,19 +549,15 @@ rec {
};
netbsd = {
execFormat = elf;
families = {
inherit bsd;
};
families = { inherit bsd; };
};
none = {
execFormat = unknown;
families = { };
};
openbsd = {
execFormat = elf;
families = {
inherit bsd;
};
families = { inherit bsd; };
};
solaris = {
execFormat = elf;
Expand Down
4 changes: 1 addition & 3 deletions test/diff/idioms_nixos_1/out-pure.nix
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,7 @@ in
})

(mkIf (!config.boot.isContainer) {
system.build = {
inherit kernel;
};
system.build = { inherit kernel; };

system.modulesTree = [ kernel ] ++ config.boot.extraModulePackages;

Expand Down
4 changes: 1 addition & 3 deletions test/diff/idioms_nixos_1/out.nix
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,7 @@ in
})

(mkIf (!config.boot.isContainer) {
system.build = {
inherit kernel;
};
system.build = { inherit kernel; };

system.modulesTree = [ kernel ] ++ config.boot.extraModulePackages;

Expand Down

0 comments on commit d8caa4c

Please sign in to comment.