Skip to content

Commit

Permalink
Fix: nix-community#185 - Change rules for empty brackets
Browse files Browse the repository at this point in the history
  • Loading branch information
Rizary committed Mar 17, 2020
1 parent e4551ea commit e2dc3e6
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 15 deletions.
11 changes: 5 additions & 6 deletions src/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ 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()
.test("[]", "[ ]")
.inside(NODE_LIST).between(T!["["], T!["]"]).single_space()
.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()
Expand All @@ -79,9 +79,9 @@ pub(crate) fn spacing() -> SpacingDsl {
.inside(NODE_ATTR_SET).after(T!["{"]).single_space_or_newline()
.inside(NODE_ATTR_SET).before(T!["{"]).when(next_parent_has_update).newline()
.inside(NODE_ATTR_SET).before(T!["}"]).single_space_or_newline()
.inside(NODE_ATTR_SET).before(T!["}"]).when(next_parent_has_update).newline()
.test("{ }", "{}")
.inside(NODE_ATTR_SET).between(T!["{"], T!["}"]).no_space()
.inside(NODE_ATTR_SET).before(T!["}"]).when(next_parent_has_update).newline()
.test("{}", "{ }")
.inside(NODE_ATTR_SET).between(T!["{"], T!["}"]).single_space()
.inside(NODE_ATTR_SET).between(NODE_KEY_VALUE, NODE_KEY_VALUE).single_space_or_newline()
.inside(NODE_ATTR_SET).between(NODE_KEY_VALUE, TOKEN_COMMENT).single_space_or_optional_newline()

Expand Down Expand Up @@ -397,7 +397,6 @@ pub(crate) fn indentation() -> IndentDsl {
92
]
"#)

.rule("Indent parenthesized expressions")
.inside(NODE_PAREN)
.not_matching([T!["("],T![")"]])
Expand Down
2 changes: 1 addition & 1 deletion test_data/indent_or_default.good.nix
Original file line number Diff line number Diff line change
@@ -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));
}
2 changes: 1 addition & 1 deletion test_data/indented_lambda.good.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
# parameter comment
mkSectionName ? (name: libStr.escape [ "[" "]" ] name)
, mkKeyValue ? mkKeyValueDefault {} "="
, mkKeyValue ? mkKeyValueDefault { } "="
}: attrsOfAttrs:
mapAttrsToStringsSep "\n" mkSection attrsOfAttrs;
}
2 changes: 1 addition & 1 deletion test_data/issue-132.good.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
buildInputs = [] ++ stdenv.lib.optionals enableGui (with qt5; [ qtbase qtwebkit ])
buildInputs = [ ] ++ stdenv.lib.optionals enableGui (with qt5; [ qtbase qtwebkit ])
++ stdenv.lib.optionals enableJupyter [ boost jsoncpp openssl zmqpp ]
;
}
4 changes: 4 additions & 0 deletions test_data/issue-185.bad.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
attrs = {};
lists = [ ];
}
4 changes: 4 additions & 0 deletions test_data/issue-185.good.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
attrs = { };
lists = [ ];
}
2 changes: 1 addition & 1 deletion test_data/list_elements.good.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
1
[]
[ ]
{ a = 92; }
"hello"
foo.bar
Expand Down
4 changes: 2 additions & 2 deletions test_data/nested_indent.good.nix
Original file line number Diff line number Diff line change
@@ -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 { }
2 changes: 1 addition & 1 deletion test_data/syntax_errors/issue-93.bad.nix
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ } =
{} =
2 changes: 1 addition & 1 deletion test_data/syntax_errors/issue-93.good.nix
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{} =
{ } =
2 changes: 1 addition & 1 deletion test_data/top_level_with2.good.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
with import <nixpkgs> {};
with import <nixpkgs> { };
stdenv.mkDerivation {
name = "rnix";
buildInputs = [ cargo ];
Expand Down

0 comments on commit e2dc3e6

Please sign in to comment.