diff --git a/CHANGELOG.md b/CHANGELOG.md index 94bd49b..fbf029c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +Unreleased / YYYY-MM-DD +======================= + +### Formatting changes + +* Empty sets: `{ }` + and lists: `[ ]` + are now formatted as: `{}` + and: `[]` respectively (#264) 1.2.0 / 2021-03-29 ================== diff --git a/src/rules.rs b/src/rules.rs index 51bb96d..bb3a9fa 100644 --- a/src/rules.rs +++ b/src/rules.rs @@ -54,10 +54,10 @@ pub(crate) fn spacing() -> SpacingDsl { .test("[1 2 3]", "[ 1 2 3 ]") .inside(NODE_LIST).after(T!["["]).single_space_or_newline() .inside(NODE_LIST).before(T!["]"]).single_space_or_newline() + .test("[]", "[]") + .inside(NODE_LIST).between(T!["["], T!["]"]).no_space() .inside(NODE_LIST).after(T!["["]).when(inline_with_attr_set).no_space() .inside(NODE_LIST).before(T!["]"]).when(inline_with_attr_set).no_space() - .test("[]", "[ ]") - .inside(NODE_LIST).between(T!["["], T!["]"]).single_space_or_optional_newline() .inside(NODE_LIST).between(VALUES, VALUES).single_space_or_newline() .inside(NODE_LIST).between(VALUES, TOKEN_COMMENT).single_space_or_optional_newline() .inside(NODE_LIST).between(TOKEN_COMMENT, VALUES).single_space_or_newline() @@ -72,8 +72,8 @@ pub(crate) fn spacing() -> SpacingDsl { .test("{foo = 92;}", "{ foo = 92; }") .inside(NODE_ATTR_SET).after(T!["{"]).single_space_or_newline() .inside(NODE_ATTR_SET).before(T!["}"]).single_space_or_newline() - .test("{}", "{ }") - .inside(NODE_ATTR_SET).between(T!["{"], T!["}"]).single_space() + .test("{}", "{}") + .inside(NODE_ATTR_SET).between(T!["{"], T!["}"]).no_space() .inside(NODE_ATTR_SET).before(NODE_KEY_VALUE).single_space_or_optional_newline() .inside(NODE_ATTR_SET).between(NODE_KEY_VALUE, NODE_KEY_VALUE).single_space_or_newline() .inside(NODE_ATTR_SET).between(NODE_INHERIT, [NODE_INHERIT, TOKEN_COMMENT]).single_space_or_optional_newline() @@ -120,7 +120,7 @@ pub(crate) fn spacing() -> SpacingDsl { .inside(NODE_IF_ELSE).around([T![else],T![then]]).single_space_or_optional_newline() .inside(NODE_IF_ELSE).after(T![then]).when(has_expression_node).single_space_or_newline() .inside(NODE_IF_ELSE).after(T![else]).when(has_expression_node).single_space_or_newline() - + // special-case to force a linebreak before `=` in // // ```nix @@ -434,7 +434,7 @@ pub(crate) fn indentation() -> IndentDsl { 92 ) "#) - + .rule("Indent attribute set content") .inside(NODE_ATTR_SET) .not_matching([T!["{"], T!["}"]]) diff --git a/test_data/indent_or_default.good.nix b/test_data/indent_or_default.good.nix index b9e2857..f989986 100644 --- a/test_data/indent_or_default.good.nix +++ b/test_data/indent_or_default.good.nix @@ -1,4 +1,4 @@ { catAttrs = builtins.catAttrs or - (attr: l: concatLists (map (s: if s ? ${attr} then [ s.${attr} ] else [ ]) l)); + (attr: l: concatLists (map (s: if s ? ${attr} then [ s.${attr} ] else []) l)); } diff --git a/test_data/indent_paren.good.nix b/test_data/indent_paren.good.nix index 8b99d96..8df65b5 100644 --- a/test_data/indent_paren.good.nix +++ b/test_data/indent_paren.good.nix @@ -19,7 +19,7 @@ a (attrNames n) ) - { } + {} list_of_attrs; bar = fun "arg" (callPackage ./. { inherit foo; diff --git a/test_data/indented_lambda.bad.nix b/test_data/indented_lambda.bad.nix index ef7790c..31ce591 100644 --- a/test_data/indented_lambda.bad.nix +++ b/test_data/indented_lambda.bad.nix @@ -8,8 +8,8 @@ else "--${k}" , mkOption ? k: v: if v == null - then [ ] - else [ (mkOptionName k) (lib.generators.mkValueStringDefault { } v) ] + then [] + else [ (mkOptionName k) (lib.generators.mkValueStringDefault {} v) ] }: { toINI = { # parameter comment diff --git a/test_data/indented_lambda.good.nix b/test_data/indented_lambda.good.nix index be1ed36..9d59e70 100644 --- a/test_data/indented_lambda.good.nix +++ b/test_data/indented_lambda.good.nix @@ -8,15 +8,15 @@ else "--${k}" , mkOption ? k: v: if v == null - then [ ] - else [ (mkOptionName k) (lib.generators.mkValueStringDefault { } v) ] + then [] + else [ (mkOptionName k) (lib.generators.mkValueStringDefault {} v) ] }: { toINI = { # parameter comment mkSectionName ? (name: libStr.escape [ "[" "]" ] name) - , mkKeyValue ? mkKeyValueDefault { } "=" + , mkKeyValue ? mkKeyValueDefault {} "=" }: attrsOfAttrs: mapAttrsToStringsSep "\n" mkSection attrsOfAttrs; } diff --git a/test_data/issue-132.good.nix b/test_data/issue-132.good.nix index b182b8e..b7f8611 100644 --- a/test_data/issue-132.good.nix +++ b/test_data/issue-132.good.nix @@ -1,6 +1,5 @@ { - buildInputs = [ - ] ++ stdenv.lib.optionals enableGui (with qt5; [ qtbase qtwebkit ]) - ++ stdenv.lib.optionals enableJupyter [ boost jsoncpp openssl zmqpp ] + buildInputs = [] ++ stdenv.lib.optionals enableGui (with qt5; [ qtbase qtwebkit ]) + ++ stdenv.lib.optionals enableJupyter [ boost jsoncpp openssl zmqpp ] ; } diff --git a/test_data/issue-185.bad.nix b/test_data/issue-185.bad.nix index 9131bdc..23d7a44 100644 --- a/test_data/issue-185.bad.nix +++ b/test_data/issue-185.bad.nix @@ -1,4 +1,4 @@ { attrs = {}; -lists = [ ]; +lists = []; } diff --git a/test_data/issue-185.good.nix b/test_data/issue-185.good.nix index 0748cec..5c3cac4 100644 --- a/test_data/issue-185.good.nix +++ b/test_data/issue-185.good.nix @@ -1,4 +1,4 @@ { - attrs = { }; - lists = [ ]; + attrs = {}; + lists = []; } diff --git a/test_data/issue-199.good.nix b/test_data/issue-199.good.nix index 8ea7119..306cada 100644 --- a/test_data/issue-199.good.nix +++ b/test_data/issue-199.good.nix @@ -29,4 +29,4 @@ let in -{ } +{} diff --git a/test_data/issue-205.bad.nix b/test_data/issue-205.bad.nix index cb47b51..8178fc0 100644 --- a/test_data/issue-205.bad.nix +++ b/test_data/issue-205.bad.nix @@ -9,4 +9,4 @@ let inherit foo;bar = baz; }; in -{ } +{} diff --git a/test_data/issue-205.good.nix b/test_data/issue-205.good.nix index 998ff3b..2613d9e 100644 --- a/test_data/issue-205.good.nix +++ b/test_data/issue-205.good.nix @@ -9,4 +9,4 @@ let inherit foo; bar = baz; }; in -{ } +{} diff --git a/test_data/list_elements.good.nix b/test_data/list_elements.good.nix index 5b0ad69..c8231e1 100644 --- a/test_data/list_elements.good.nix +++ b/test_data/list_elements.good.nix @@ -1,6 +1,6 @@ [ 1 - [ ] + [] { a = 92; } "hello" foo.bar diff --git a/test_data/nested_indent.bad.nix b/test_data/nested_indent.bad.nix index 4802951..c75ee23 100644 --- a/test_data/nested_indent.bad.nix +++ b/test_data/nested_indent.bad.nix @@ -1,5 +1,5 @@ { - pkgs ? import ./nix/nixpkgs.nix { }, + pkgs ? import ./nix/nixpkgs.nix {}, src ? builtins.fetchGit { url = ./.; ref = "HEAD"; diff --git a/test_data/nested_indent.good.nix b/test_data/nested_indent.good.nix index 8e85068..5431600 100644 --- a/test_data/nested_indent.good.nix +++ b/test_data/nested_indent.good.nix @@ -1,7 +1,7 @@ -{ pkgs ? import ./nix/nixpkgs.nix { } +{ pkgs ? import ./nix/nixpkgs.nix {} , src ? builtins.fetchGit { url = ./.; ref = "HEAD"; } }: -pkgs.example rec { } +pkgs.example rec {} diff --git a/test_data/nixpkgs_repository/doc_shellnix.good.nix b/test_data/nixpkgs_repository/doc_shellnix.good.nix index 542b6d5..8ac2019 100644 --- a/test_data/nixpkgs_repository/doc_shellnix.good.nix +++ b/test_data/nixpkgs_repository/doc_shellnix.good.nix @@ -1,5 +1,5 @@ -{ pkgs ? import ../. { } }: -(import ./default.nix { }).overrideAttrs (x: { +{ pkgs ? import ../. {} }: +(import ./default.nix {}).overrideAttrs (x: { buildInputs = x.buildInputs ++ [ pkgs.xmloscopy pkgs.ruby ]; }) diff --git a/test_data/nixpkgs_repository/lib_customisation.bad.nix b/test_data/nixpkgs_repository/lib_customisation.bad.nix index 9d4dd8d..3749b6a 100644 --- a/test_data/nixpkgs_repository/lib_customisation.bad.nix +++ b/test_data/nixpkgs_repository/lib_customisation.bad.nix @@ -4,16 +4,16 @@ newDrv = derivation (drv.drvAttrs // (f drv)); in lib.flip (extendDerivation true) newDrv ( { - meta = drv.meta or { }; - passthru = if drv ? passthru then drv.passthru else { }; + meta = drv.meta or {}; + passthru = if drv ? passthru then drv.passthru else {}; } // - (drv.passthru or { }) + (drv.passthru or {}) // (if (drv ? crossDrv && drv ? nativeDrv) then { crossDrv = overrideDerivation drv.crossDrv f; nativeDrv = overrideDerivation drv.nativeDrv f; } - else { })); + else {})); } diff --git a/test_data/nixpkgs_repository/lib_customisation.good.nix b/test_data/nixpkgs_repository/lib_customisation.good.nix index 23ce6fc..b807f3c 100644 --- a/test_data/nixpkgs_repository/lib_customisation.good.nix +++ b/test_data/nixpkgs_repository/lib_customisation.good.nix @@ -5,17 +5,17 @@ in lib.flip (extendDerivation true) newDrv ( { - meta = drv.meta or { }; - passthru = if drv ? passthru then drv.passthru else { }; + meta = drv.meta or {}; + passthru = if drv ? passthru then drv.passthru else {}; } // - (drv.passthru or { }) + (drv.passthru or {}) // (if (drv ? crossDrv && drv ? nativeDrv) then { crossDrv = overrideDerivation drv.crossDrv f; nativeDrv = overrideDerivation drv.nativeDrv f; } - else { }) + else {}) ); } diff --git a/test_data/nixpkgs_repository/lib_deprecated.good.nix b/test_data/nixpkgs_repository/lib_deprecated.good.nix index 92a8de4..4442b07 100644 --- a/test_data/nixpkgs_repository/lib_deprecated.good.nix +++ b/test_data/nixpkgs_repository/lib_deprecated.good.nix @@ -1,6 +1,6 @@ { innerClosePropagation = acc: xs: - if xs == [ ] + if xs == [] then acc else let @@ -14,8 +14,8 @@ in innerClosePropagation acc' (uniqList { - inputList = (maybeAttrNullable "propagatedBuildInputs" [ ] y) - ++ (maybeAttrNullable "propagatedNativeBuildInputs" [ ] y) + inputList = (maybeAttrNullable "propagatedBuildInputs" [] y) + ++ (maybeAttrNullable "propagatedNativeBuildInputs" [] y) ++ ys; acc = acc'; }); diff --git a/test_data/nixpkgs_repository/nixpkgs_idempotent.good.nix b/test_data/nixpkgs_repository/nixpkgs_idempotent.good.nix index 1cee320..5119844 100644 --- a/test_data/nixpkgs_repository/nixpkgs_idempotent.good.nix +++ b/test_data/nixpkgs_repository/nixpkgs_idempotent.good.nix @@ -2,7 +2,7 @@ # Operations on attribute sets. rec { filterAttrs = pred: set: - listToAttrs (concatMap (name: let v = set.${name}; in if pred name v then [ (nameValuePair name v) ] else [ ]) (attrNames set)); + listToAttrs (concatMap (name: let v = set.${name}; in if pred name v then [ (nameValuePair name v) ] else []) (attrNames set)); inherit (self.trivial) id const pipe concat or and bitAnd bitOr bitXor; } diff --git a/test_data/syntax_errors/issue-93.good.nix b/test_data/syntax_errors/issue-93.good.nix index 226fd02..104a61c 100644 --- a/test_data/syntax_errors/issue-93.good.nix +++ b/test_data/syntax_errors/issue-93.good.nix @@ -1 +1 @@ -{ } = +{} = diff --git a/test_data/top_level_with2.good.nix b/test_data/top_level_with2.good.nix index 033541b..2b41f38 100644 --- a/test_data/top_level_with2.good.nix +++ b/test_data/top_level_with2.good.nix @@ -1,4 +1,4 @@ -with import { }; +with import {}; stdenv.mkDerivation { name = "rnix"; buildInputs = [ cargo ];