Skip to content

Commit

Permalink
feat: rebase Vladimir's pr
Browse files Browse the repository at this point in the history
  • Loading branch information
kamadorueda committed Nov 23, 2024
1 parent 74dfc7a commit dafc500
Show file tree
Hide file tree
Showing 42 changed files with 6,420 additions and 11 deletions.
5 changes: 2 additions & 3 deletions src/alejandra/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ pub(crate) enum Step {

#[derive(Clone)]
pub(crate) struct BuildCtx {
pub _config: Config,
pub config: Config,
pub force_wide: bool,
pub force_wide_success: bool,
pub indentation: usize,
pub pos_old: crate::position::Position,
pub path: String,
pub vertical: bool,
pub indent: String,
}

pub(crate) fn build(
Expand Down Expand Up @@ -100,7 +99,7 @@ fn build_step(
add_token(
builder,
rnix::SyntaxKind::TOKEN_WHITESPACE,
&build_ctx.indent.repeat(build_ctx.indentation),
&build_ctx.config.indentation.repeat(build_ctx.indentation),
);
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/alejandra/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
/// Configuration used by the formatter
#[derive(Clone)]
pub struct Config {}
pub struct Config {
/// Indentation to use, e.g. `" "` (two spaces).
pub indentation: String,
}

use std::default::Default;

impl Default for Config {
fn default() -> Self {
Self {}
Self { indentation: String::from(" ") }
}
}
3 changes: 1 addition & 2 deletions src/alejandra/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,13 @@ pub fn in_memory(
}

let mut build_ctx = crate::builder::BuildCtx {
_config: config,
config,
force_wide: false,
force_wide_success: true,
indentation: 0,
path,
pos_old: crate::position::Position::default(),
vertical: true,
indent,
};

let after = crate::builder::build(&mut build_ctx, ast.node().into())
Expand Down
114 changes: 114 additions & 0 deletions src/alejandra/tests/cases/apply/out-tabs.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
[
(a
b)
(
(a b)
(a b)
(a
/*
b
*/
c)
(
/*
a
*/
b
/*
c
*/
d
/*
e
*/
)
)
''
otherModules=${
pkgs.writeText "other-modules.json"
(l.toJSON
(l.mapAttrs
(pname: subOutputs: let
pkg =
subOutputs.packages."${pname}".overrideAttrs (old: {
buildScript = "true";
installMethod = "copy";
});
in "${pkg}/lib/node_modules/${pname}/node_modules")
outputs.subPackages))
}
''
{
name1 =
function
arg
{asdf = 1;};

name2 =
function
arg
{asdf = 1;}
argument;

name3 =
function
arg
{asdf = 1;}
{qwer = 12345;}
argument;
}
{
name1 =
function arg {
asdf = 1;
};

name2 =
function arg {
asdf = 1;
}
argument;

name3 =
function arg {
asdf = 1;
} {
qwer = 12345;
}
argument;
}
{
name4 =
function
arg
{asdf = 1;}
{
qwer = 12345;
qwer2 = 54321;
}
argument;
}
{
option1 =
function arg {asdf = 1;} {
qwer = 12345;
qwer2 = 54321;
}
lastArg;

option2 =
function arg {asdf = 1;} {
qwer = 12345;
qwer2 = 54321;
}
lastArg;

option3 =
function arg {asdf = 1;}
{
qwer = 12345;
qwer2 = 54321;
}
lastArg;
}
]
44 changes: 44 additions & 0 deletions src/alejandra/tests/cases/assert/out-tabs.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[
(assert b; e)
(assert b;
/*
d
*/
e)
(assert b; e)
(assert b;
/*
d
*/
e)
(assert
/*
a
*/
b; e)
(assert
/*
a
*/
b;
/*
d
*/
e)
(assert
/*
a
*/
b; e)
(assert
/*
a
*/
b;
/*
d
*/
e)
(assert b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc)
(assert b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc)
]
138 changes: 138 additions & 0 deletions src/alejandra/tests/cases/attr_set/out-tabs.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
[
{}
{
/*
a
*/
}
{a = 1;}
{
a = 1;
}

{b = 1;}
{
b = 1;
/*
c
*/
}
{
/*
a
*/
b = 1;
}
{
/*
a
*/
b = 1;
/*
c
*/
}

rec {c = 1;}
rec {
c = 1;
/*
d
*/
}
rec {
/*
b
*/
c = 1;
}
rec {
/*
b
*/
c = 1;
/*
d
*/
}
rec
/*
a
*/
{
c = 1;
}
rec
/*
a
*/
{
c = 1;
/*
d
*/
}
rec
/*
a
*/
{
/*
b
*/
c = 1;
}
rec
/*
a
*/
{
/*
b
*/
c = 1;
/*
d
*/
}

{
a = rec {
a = {
a = rec {
a = {
a = rec {a = {a = rec {a = {a = rec {a = {};};};};};};
};
};
};
};
}

rec {
c = 1;

e = 1;
}

rec
/*
a
*/
{
/*
b
*/

c = 1;

/*
d
*/

e = 1;

/*
f
*/
}
]
Loading

0 comments on commit dafc500

Please sign in to comment.