1
Fork 0
mirror of https://github.com/RGBCube/alejandra synced 2025-07-31 12:37:45 +00:00

Merge pull request #144 from kamadorueda/kamadorueda

feat: indent with
This commit is contained in:
Kevin Amado 2022-02-18 17:15:18 -05:00 committed by GitHub
commit 0644375c56
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 34 additions and 19 deletions

View file

@ -72,6 +72,12 @@ Types of changes
+ value, + 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 ## [0.2.0] - 2022-02-17

View file

@ -68,11 +68,18 @@ pub fn rule(
let child = children.get_next().unwrap(); let child = children.get_next().unwrap();
match layout { match layout {
crate::config::Layout::Tall => { crate::config::Layout::Tall => {
if comment if {
|| matches!( matches!(
child.element.kind(), child.element.kind(),
rnix::SyntaxKind::NODE_ASSERT | rnix::SyntaxKind::NODE_WITH 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!( || !matches!(
child.element.kind(), child.element.kind(),
rnix::SyntaxKind::NODE_ATTR_SET rnix::SyntaxKind::NODE_ATTR_SET
@ -84,11 +91,13 @@ pub fn rule(
| rnix::SyntaxKind::NODE_STRING | rnix::SyntaxKind::NODE_STRING
) )
{ {
steps.push_back(crate::builder::Step::Indent);
steps.push_back(crate::builder::Step::NewLine); steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad); steps.push_back(crate::builder::Step::Pad);
steps.push_back(crate::builder::Step::FormatWider( steps.push_back(crate::builder::Step::FormatWider(
child.element, child.element,
)); ));
steps.push_back(crate::builder::Step::Dedent);
} else { } else {
steps.push_back(crate::builder::Step::Whitespace); steps.push_back(crate::builder::Step::Whitespace);
steps.push_back(crate::builder::Step::FormatWider( steps.push_back(crate::builder::Step::FormatWider(

View file

@ -86,18 +86,18 @@ pub fn rule(
} else if false } else if false
|| matches!( || matches!(
child_expr.element.kind(), 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_PAREN
| rnix::SyntaxKind::NODE_LAMBDA | rnix::SyntaxKind::NODE_LAMBDA
| rnix::SyntaxKind::NODE_LET_IN | rnix::SyntaxKind::NODE_LET_IN
| rnix::SyntaxKind::NODE_LIST | rnix::SyntaxKind::NODE_LIST
| rnix::SyntaxKind::NODE_STRING | rnix::SyntaxKind::NODE_STRING
| rnix::SyntaxKind::NODE_WITH
) )
|| (matches!( || (matches!(
child_expr.element.kind(), child_expr.element.kind(),
rnix::SyntaxKind::NODE_ASSERT rnix::SyntaxKind::NODE_APPLY
| rnix::SyntaxKind::NODE_APPLY
| rnix::SyntaxKind::NODE_WITH
) && !newlines) ) && !newlines)
{ {
steps.push_back(crate::builder::Step::Whitespace); steps.push_back(crate::builder::Step::Whitespace);

View file

@ -4,7 +4,7 @@
/* /*
b b
*/ */
c) c)
(assert (assert
/* /*
a a
@ -18,7 +18,7 @@
/* /*
b b
*/ */
c) c)
(assert b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc) (assert b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc)
(assert b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc) (assert b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc)
] ]

View file

@ -26,10 +26,10 @@
{ {
meta = with lib; meta = with lib;
# comment # comment
{ {
a = 1; a = 1;
b = 2; b = 2;
c = 3; c = 3;
}; };
} }
] ]

View file

@ -24,7 +24,8 @@
{ a = with b;with b;with b; { a = with b;with b;with b;
1; 1;
} }
{binPath = {
binPath =
with pkgs; with pkgs;
makeBinPath ( makeBinPath (
[ [

View file

@ -4,7 +4,7 @@
/* /*
b b
*/ */
c) c)
(with (with
/* /*
a a
@ -18,7 +18,7 @@
/* /*
b b
*/ */
c) c)
(with b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc) (with b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc)
(with b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc) (with b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc)
{a = with b; 1;} {a = with b; 1;}
@ -34,7 +34,7 @@
{ {
a = with b; a = with b;
# comment # comment
1; 1;
} }
{ {
a = with b; 1; a = with b; 1;
@ -60,8 +60,7 @@
a = with b; with b; with b; 1; a = with b; with b; with b; 1;
} }
{ {
binPath = binPath = with pkgs;
with pkgs;
makeBinPath ( makeBinPath (
[ [
rsync rsync