Skip to content

Commit

Permalink
Allow tabs and spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
3timeslazy authored and kamadorueda committed Nov 24, 2024
1 parent 9953b11 commit e2c843c
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/alejandra/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub(crate) struct BuildCtx {
pub pos_old: crate::position::Position,
pub path: String,
pub vertical: bool,
pub indent: String,
}

pub(crate) fn build(
Expand Down Expand Up @@ -99,7 +100,7 @@ fn build_step(
add_token(
builder,
rnix::SyntaxKind::TOKEN_WHITESPACE,
&format!("{0:<1$}", "", 2 * build_ctx.indentation),
&build_ctx.indent.repeat(build_ctx.indentation),
);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/alejandra/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub fn in_memory(
path,
pos_old: crate::position::Position::default(),
vertical: true,
indent,
};

let after = crate::builder::build(&mut build_ctx, ast.node().into())
Expand Down
6 changes: 6 additions & 0 deletions src/alejandra/tests/indent/apply/in.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
foo =
bar:
baz:
fnbody;
}
4 changes: 4 additions & 0 deletions src/alejandra/tests/indent/apply/out.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
foo = bar: baz:
fnbody;
}
11 changes: 11 additions & 0 deletions src/alejandra/tests/indent/attr_set/in.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
a = rec {
a = {
a = rec {
a = {
a = rec {a = {a = rec {a = {a = rec {a = {};};};};};};
};
};
};
};
}
11 changes: 11 additions & 0 deletions src/alejandra/tests/indent/attr_set/out.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
a = rec {
a = {
a = rec {
a = {
a = rec {a = {a = rec {a = {a = rec {a = {};};};};};};
};
};
};
};
}
11 changes: 11 additions & 0 deletions src/alejandra/tests/indent/list/in.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[
# over indented
1
# under indented
2
# no indentation
[1 2]
[
1 2 3
]
]
13 changes: 13 additions & 0 deletions src/alejandra/tests/indent/list/out.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
# over indented
1
# under indented
2
# no indentation
[1 2]
[
1
2
3
]
]

0 comments on commit e2c843c

Please sign in to comment.