From fa8d747441b6fa4b2d467452fbb34a636866f663 Mon Sep 17 00:00:00 2001 From: Kevin Amado Date: Fri, 18 Feb 2022 12:14:03 -0500 Subject: [PATCH] feat: inline end at --- CHANGELOG.md | 13 +++++++++++++ src/rules/pattern.rs | 8 +++++--- tests/cases/pattern/out | 3 +-- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b9d34b..d217e3d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,19 @@ Types of changes ### Changed - Let-in expressions are now indented in the top-level of a file. +- Patterns avoid a new line after `@`: + + ```nix + - args @ + - { + + args @ { + ``` + + ```nix + - } + - @ inp: + + } @ inp: + ``` ## [0.2.0] - 2022-02-17 diff --git a/src/rules/pattern.rs b/src/rules/pattern.rs index c5c90c8..7e1f6f7 100644 --- a/src/rules/pattern.rs +++ b/src/rules/pattern.rs @@ -174,11 +174,13 @@ pub fn rule( steps.push_back(crate::builder::Step::Format(child.element)); // /**/ + let mut comment = false; children.drain_comments_and_newlines(|element| match element { crate::children::DrainCommentOrNewline::Comment(text) => { steps.push_back(crate::builder::Step::NewLine); steps.push_back(crate::builder::Step::Pad); steps.push_back(crate::builder::Step::Comment(text)); + comment = true; } crate::children::DrainCommentOrNewline::Newline(_) => {} }); @@ -186,11 +188,11 @@ pub fn rule( // @ x if let Some(child) = children.peek_next() { if let rnix::SyntaxKind::NODE_PAT_BIND = child.element.kind() { - if !has_comments && items_count <= 1 { - steps.push_back(crate::builder::Step::Whitespace); - } else { + if comment { steps.push_back(crate::builder::Step::NewLine); steps.push_back(crate::builder::Step::Pad); + } else { + steps.push_back(crate::builder::Step::Whitespace); } match layout { crate::config::Layout::Tall => { diff --git a/tests/cases/pattern/out b/tests/cases/pattern/out index 3e1eae6..0dca503 100644 --- a/tests/cases/pattern/out +++ b/tests/cases/pattern/out @@ -9,8 +9,7 @@ self, gomod2nix, mach-nix, - } - @ inp: + } @ inp: _) ({}: _) ({ a }: _)