Skip to content

Commit

Permalink
Merge pull request #136 from kamadorueda/kamadorueda
Browse files Browse the repository at this point in the history
feat: inline beggining at
  • Loading branch information
kamadorueda authored Feb 18, 2022
2 parents 38c93ab + 8d10da6 commit 4a7a938
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/rules/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ pub fn rule(
};

// x @
let mut at = false;
let child = children.peek_next().unwrap();
if let rnix::SyntaxKind::NODE_PAT_BIND = child.element.kind() {
at = true;
match layout {
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::FormatWider(
Expand All @@ -47,25 +49,28 @@ pub fn rule(
steps.push_back(crate::builder::Step::Format(child.element));
}
}
if !has_comments && items_count <= 1 {
steps.push_back(crate::builder::Step::Whitespace);
} else {
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
}
children.move_next();
}

// /**/
let mut comment = false;
children.drain_comments_and_newlines(|element| match element {
crate::children::DrainCommentOrNewline::Comment(text) => {
steps.push_back(crate::builder::Step::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(_) => {}
});

if comment {
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
} else if at {
steps.push_back(crate::builder::Step::Whitespace);
}

// {
let child = children.get_next().unwrap();
steps.push_back(crate::builder::Step::Format(child.element));
Expand Down
5 changes: 5 additions & 0 deletions tests/cases/pattern/in
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
[
(a@{
self,
gomod2nix,
mach-nix,
}: _)
({
self,
gomod2nix,
Expand Down
6 changes: 6 additions & 0 deletions tests/cases/pattern/out
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
[
(a @ {
self,
gomod2nix,
mach-nix,
}:
_)
({
self,
gomod2nix,
Expand Down

0 comments on commit 4a7a938

Please sign in to comment.