diff --git a/CHANGELOG.md b/CHANGELOG.md index d4e5c0f..75f848f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -72,6 +72,12 @@ Types of changes + value, + }: ``` +- `with` expressions now indent the new scope and follow the equal sign: + ```diff + - binPath = + - with pkgs; + + binPath = with pkgs; + ``` ## [0.2.0] - 2022-02-17 diff --git a/src/rules/assert_and_with.rs b/src/rules/assert_and_with.rs index cc37654..e6f73dd 100644 --- a/src/rules/assert_and_with.rs +++ b/src/rules/assert_and_with.rs @@ -68,11 +68,18 @@ pub fn rule( let child = children.get_next().unwrap(); match layout { crate::config::Layout::Tall => { - if comment - || matches!( + if { + matches!( child.element.kind(), rnix::SyntaxKind::NODE_ASSERT | rnix::SyntaxKind::NODE_WITH ) + } { + steps.push_back(crate::builder::Step::NewLine); + steps.push_back(crate::builder::Step::Pad); + steps.push_back(crate::builder::Step::FormatWider( + child.element, + )); + } else if comment || !matches!( child.element.kind(), rnix::SyntaxKind::NODE_ATTR_SET @@ -84,11 +91,13 @@ pub fn rule( | rnix::SyntaxKind::NODE_STRING ) { + steps.push_back(crate::builder::Step::Indent); steps.push_back(crate::builder::Step::NewLine); steps.push_back(crate::builder::Step::Pad); steps.push_back(crate::builder::Step::FormatWider( child.element, )); + steps.push_back(crate::builder::Step::Dedent); } else { steps.push_back(crate::builder::Step::Whitespace); steps.push_back(crate::builder::Step::FormatWider( diff --git a/src/rules/key_value.rs b/src/rules/key_value.rs index bbc6cf9..e8b06fb 100644 --- a/src/rules/key_value.rs +++ b/src/rules/key_value.rs @@ -86,18 +86,18 @@ pub fn rule( } else if false || matches!( child_expr.element.kind(), - rnix::SyntaxKind::NODE_ATTR_SET + rnix::SyntaxKind::NODE_ASSERT + | rnix::SyntaxKind::NODE_ATTR_SET | rnix::SyntaxKind::NODE_PAREN | rnix::SyntaxKind::NODE_LAMBDA | rnix::SyntaxKind::NODE_LET_IN | rnix::SyntaxKind::NODE_LIST | rnix::SyntaxKind::NODE_STRING + | rnix::SyntaxKind::NODE_WITH ) || (matches!( child_expr.element.kind(), - rnix::SyntaxKind::NODE_ASSERT - | rnix::SyntaxKind::NODE_APPLY - | rnix::SyntaxKind::NODE_WITH + rnix::SyntaxKind::NODE_APPLY ) && !newlines) { steps.push_back(crate::builder::Step::Whitespace); diff --git a/tests/cases/assert/out b/tests/cases/assert/out index d85afa1..ea3a02a 100644 --- a/tests/cases/assert/out +++ b/tests/cases/assert/out @@ -4,7 +4,7 @@ /* b */ - c) + c) (assert /* a @@ -18,7 +18,7 @@ /* b */ - c) + c) (assert b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc) (assert b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc) ] diff --git a/tests/cases/idioms/out b/tests/cases/idioms/out index 8b7aa32..78dd934 100644 --- a/tests/cases/idioms/out +++ b/tests/cases/idioms/out @@ -26,10 +26,10 @@ { meta = with lib; # comment - { - a = 1; - b = 2; - c = 3; - }; + { + a = 1; + b = 2; + c = 3; + }; } ] diff --git a/tests/cases/with/in b/tests/cases/with/in index 9a4f0a6..5c96714 100644 --- a/tests/cases/with/in +++ b/tests/cases/with/in @@ -24,7 +24,8 @@ { a = with b;with b;with b; 1; } - {binPath = + { + binPath = with pkgs; makeBinPath ( [ diff --git a/tests/cases/with/out b/tests/cases/with/out index 85521f9..e993618 100644 --- a/tests/cases/with/out +++ b/tests/cases/with/out @@ -4,7 +4,7 @@ /* b */ - c) + c) (with /* a @@ -18,7 +18,7 @@ /* b */ - c) + c) (with b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc) (with b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc) {a = with b; 1;} @@ -34,7 +34,7 @@ { a = with b; # comment - 1; + 1; } { a = with b; 1; @@ -60,8 +60,7 @@ a = with b; with b; with b; 1; } { - binPath = - with pkgs; + binPath = with pkgs; makeBinPath ( [ rsync