Skip to content

Commit

Permalink
Put semicolons on same line again
Browse files Browse the repository at this point in the history
  • Loading branch information
piegamesde committed Oct 11, 2023
1 parent 549541f commit 8d9b97f
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 156 deletions.
7 changes: 1 addition & 6 deletions src/Nixfmt/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -451,11 +451,6 @@ instance Pretty Expression where
group (pretty if_ <> line <> nest 2 (pretty cond) <> line <> pretty then_)
<> (surroundWith line $ nest 2 $ group expr0)
<> pretty else_ <> absorbElse expr1
-- This trailing line' is a bit of a hack. It makes sure that the semicolon in binders gets placed onto
-- a new line if the items ends with a (multiline) if.
-- Normally this should only be the case when in binders as this might interfere with other syntax constructs,
-- but because our style always puts a new line after multiline Ifs it turns out to work just fine ^^
<> line'

pretty (Abstraction (IDParameter param) colon body)
= pretty param <> pretty colon <> absorbAbs 1 body
Expand Down Expand Up @@ -503,7 +498,7 @@ instance Pretty Expression where
line <> pretty (moveTrailingCommentUp op') <> nest 2 (absorbOperation expr)
in
group' False $
((concat . map prettyOperation . (flatten Nothing)) operation) <> line'
(concat . map prettyOperation . (flatten Nothing)) operation

pretty (MemberCheck expr qmark sel)
= pretty expr <> softline
Expand Down
9 changes: 3 additions & 6 deletions test/diff/attr_set/out.nix
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@
++ (optionals condition [
more
items
])
;
]);
b = with pkgs; [
a
lot
Expand Down Expand Up @@ -195,8 +194,7 @@
secret-config.ssh-hosts
// {
foo = "bar";
}
;
};
programs.ssh.knownHosts3 =
lib.mapAttrs (
host_name: publicKey: {
Expand Down Expand Up @@ -225,8 +223,7 @@
)
// {
foo = "bar";
}
;
};
programs.ssh.knownHosts5 =
someStuff
// lib.mapAttrs (
Expand Down
24 changes: 8 additions & 16 deletions test/diff/idioms_lib_2/out.nix
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,7 @@ rec {
if pathExists suffixFile then
lib.strings.fileContents suffixFile
else
"pre-git"
;
"pre-git";

/* Attempts to return the the current revision of nixpkgs and
returns the supplied default value otherwise.
Expand All @@ -216,8 +215,7 @@ rec {
else if lib.pathExists revisionFile then
lib.fileContents revisionFile
else
default
;
default;

nixpkgsVersion =
builtins.trace "`lib.nixpkgsVersion` is deprecated, use `lib.version` instead!"
Expand Down Expand Up @@ -263,8 +261,7 @@ rec {
else if a > b then
1
else
0
;
0;

/* Split type into two subtypes by predicate `p`, take all elements
of the first subtype to be less than all the elements of the
Expand Down Expand Up @@ -300,8 +297,7 @@ rec {
else if p b then
1
else
no a b
;
no a b;

/* Reads a JSON file.
Expand Down Expand Up @@ -352,8 +348,7 @@ rec {
abort "NIX_ABORT_ON_WARN=true; warnings are treated as unrecoverable errors."
)
else
msg: builtins.trace "warning: ${msg}"
;
msg: builtins.trace "warning: ${msg}";

/* Like warn, but only warn when the first argument is `true`.
Expand Down Expand Up @@ -436,8 +431,7 @@ rec {
if f ? __functor then
f.__functionArgs or (lib.functionArgs (f.__functor f))
else
builtins.functionArgs f
;
builtins.functionArgs f;

/* Check whether something is a function or something
annotated with function args.
Expand Down Expand Up @@ -470,8 +464,7 @@ rec {
"14" = "E";
"15" = "F";
}
.${toString d}
;
.${toString d};
in
lib.concatMapStrings toHexDigit (toBaseDigits 16 i);

Expand All @@ -496,8 +489,7 @@ rec {
r = i - ((i / base) * base);
q = (i - r) / base;
in
[ r ] ++ go q
;
[ r ] ++ go q;
in
assert (base >= 2);
assert (i >= 0);
Expand Down
42 changes: 14 additions & 28 deletions test/diff/idioms_lib_3/out.nix
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ rec {
else if isFloat v then
libStr.floatToString v
else
err "this value is" (toString v)
;
err "this value is" (toString v);

# Generate a line of key k and value v, separated by
# character sep. If sep appears in k, it is escaped.
Expand Down Expand Up @@ -103,8 +102,7 @@ rec {
if listsAsDuplicateKeys then
k: v: map (mkLine k) (if lib.isList v then v else [ v ])
else
k: v: [ (mkLine k v) ]
;
k: v: [ (mkLine k v) ];
in
attrs:
libStr.concatStrings (lib.concatLists (libAttr.mapAttrsToList mkLines attrs));
Expand Down Expand Up @@ -156,8 +154,7 @@ rec {
''
[${mkSectionName sectName}]
''
+ toKeyValue { inherit mkKeyValue listsAsDuplicateKeys; } sectValues
;
+ toKeyValue { inherit mkKeyValue listsAsDuplicateKeys; } sectValues;
in
# map input to ini sections
mapAttrsToStringsSep "\n" mkSection attrsOfAttrs;
Expand Down Expand Up @@ -216,8 +213,7 @@ rec {
else
(toKeyValue { inherit mkKeyValue listsAsDuplicateKeys; } globalSection) + "\n"
)
+ (toINI { inherit mkSectionName mkKeyValue listsAsDuplicateKeys; } sections)
;
+ (toINI { inherit mkSectionName mkKeyValue listsAsDuplicateKeys; } sections);

# Generate a git-config file from an attrset.
#
Expand Down Expand Up @@ -252,8 +248,7 @@ rec {
if containsQuote || subsections == [ ] then
name
else
''${section} "${subsection}"''
;
''${section} "${subsection}"'';

# generation for multiple ini values
mkKeyValue =
Expand All @@ -273,8 +268,7 @@ rec {
else if length path > 1 then
{ ${concatStringsSep "." (lib.reverseList (tail path))}.${head path} = value; }
else
{ ${head path} = value; }
;
{ ${head path} = value; };
in
attrs:
lib.foldl lib.recursiveUpdate { } (lib.flatten (recurse [ ] attrs));
Expand Down Expand Up @@ -321,8 +315,7 @@ rec {
else
const "<unevaluated>"
else
id
;
id;
mapAny =
with builtins;
depth: v:
Expand All @@ -334,8 +327,7 @@ rec {
else if isList v then
map evalNext v
else
transform (depth + 1) v
;
transform (depth + 1) v;
in
mapAny 0;

Expand Down Expand Up @@ -368,16 +360,14 @@ rec {
${indent} ''
else
" "
;
" ";
outroSpace =
if multiline then
''
${indent}''
else
" "
;
" ";
in
if isInt v then
toString v
Expand Down Expand Up @@ -417,8 +407,7 @@ rec {
+ introSpace
+ concatStringsSep introSpace (lib.init escapedLines)
+ (if lastLine == "" then outroSpace else introSpace + lastLine)
+ "''"
;
+ "''";
in
if multiline && length lines > 1 then multilineResult else singlelineResult
else if true == v then
Expand Down Expand Up @@ -473,8 +462,7 @@ rec {
+ outroSpace
+ "}"
else
abort "generators.toPretty: should never happen (v = ${v})"
;
abort "generators.toPretty: should never happen (v = ${v})";
in
go indent;

Expand Down Expand Up @@ -502,8 +490,7 @@ rec {
else if isFloat x then
float ind x
else
abort "generators.toPlist: should never happen (v = ${v})"
;
abort "generators.toPlist: should never happen (v = ${v})";

literal = ind: x: ind + x;

Expand Down Expand Up @@ -586,6 +573,5 @@ rec {
else if v == null then
abort "generators.toDhall: cannot convert a null to Dhall"
else
builtins.toJSON v
;
builtins.toJSON v;
}
39 changes: 13 additions & 26 deletions test/diff/idioms_lib_4/out.nix
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ rec {
types.significantByte.check x.significantByte
else
!(x ? significantByte)
)
;
);
};

types.cpuType = enum (attrValues cpuTypes);
Expand Down Expand Up @@ -371,8 +370,7 @@ rec {
then
execFormats.aout
else
execFormats.elf
;
execFormats.elf;

# Determine when two CPUs are compatible with each other. That is,
# can code built for system B run on system A? For that to happen,
Expand Down Expand Up @@ -509,8 +507,7 @@ rec {
check =
x:
types.execFormat.check x.execFormat
&& all types.kernelFamily.check (attrValues x.families)
;
&& all types.kernelFamily.check (attrValues x.families);
};

types.kernel = enum (attrValues kernels);
Expand Down Expand Up @@ -609,8 +606,7 @@ rec {
watchos = kernels.ios;
tvos = kernels.ios;
win32 = kernels.windows;
}
;
};

################################################################################

Expand Down Expand Up @@ -732,8 +728,7 @@ rec {
types.cpuType.check cpu
&& types.vendor.check vendor
&& types.kernel.check kernel
&& types.abi.check abi
;
&& types.abi.check abi;
};

isSystem = isType "system";
Expand All @@ -754,8 +749,7 @@ rec {
abi = "unknown";
}
else
throw "Target specification with 1 components is ambiguous"
;
throw "Target specification with 1 components is ambiguous";
"2" = # We only do 2-part hacks for things Nix already supports
if elemAt l 1 == "cygwin" then
{
Expand Down Expand Up @@ -784,8 +778,7 @@ rec {
{
cpu = elemAt l 0;
kernel = elemAt l 1;
}
;
};
"3" =
# cpu-kernel-environment
if
Expand Down Expand Up @@ -824,12 +817,10 @@ rec {
if elemAt l 2 == "mingw32" then
"windows" # autotools breaks on -gnu for window
else
elemAt l 2
;
elemAt l 2;
}
else
throw "Target specification with 3 components is ambiguous"
;
throw "Target specification with 3 components is ambiguous";
"4" = {
cpu = elemAt l 0;
vendor = elemAt l 1;
Expand Down Expand Up @@ -868,16 +859,14 @@ rec {
else if isWindows parsed then
vendors.pc
else
vendors.unknown
;
vendors.unknown;
kernel =
if hasPrefix "darwin" args.kernel then
getKernel "darwin"
else if hasPrefix "netbsd" args.kernel then
getKernel "netbsd"
else
getKernel args.kernel
;
getKernel args.kernel;
abi =
if args ? abi then
getAbi args.abi
Expand All @@ -893,8 +882,7 @@ rec {
else
abis.gnu
else
abis.unknown
;
abis.unknown;
};
in
mkSystem parsed;
Expand All @@ -916,8 +904,7 @@ rec {
else if kernel.families ? darwin then
"${cpu.name}-darwin"
else
"${cpu.name}-${kernelName kernel}"
;
"${cpu.name}-${kernelName kernel}";

tripleFromSystem =
{
Expand Down
Loading

0 comments on commit 8d9b97f

Please sign in to comment.