Skip to content

Commit 4c815a9

Browse files
committed
feat: rebase Vladimir's pr
1 parent e2c843c commit 4c815a9

File tree

84 files changed

+6431
-65
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+6431
-65
lines changed

src/alejandra/src/builder.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::config::Config;
2+
use crate::config::Indentation;
23

34
#[derive(PartialEq)]
45
pub(crate) enum Step {
@@ -15,14 +16,13 @@ pub(crate) enum Step {
1516

1617
#[derive(Clone)]
1718
pub(crate) struct BuildCtx {
18-
pub _config: Config,
19+
pub config: Config,
1920
pub force_wide: bool,
2021
pub force_wide_success: bool,
2122
pub indentation: usize,
2223
pub pos_old: crate::position::Position,
2324
pub path: String,
2425
pub vertical: bool,
25-
pub indent: String,
2626
}
2727

2828
pub(crate) fn build(
@@ -100,7 +100,12 @@ fn build_step(
100100
add_token(
101101
builder,
102102
rnix::SyntaxKind::TOKEN_WHITESPACE,
103-
&build_ctx.indent.repeat(build_ctx.indentation),
103+
&match build_ctx.config.indentation {
104+
Indentation::FourSpaces => " ",
105+
Indentation::Tabs => "\t",
106+
Indentation::TwoSpaces => " ",
107+
}
108+
.repeat(build_ctx.indentation),
104109
);
105110
}
106111
}

src/alejandra/src/config.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,19 @@ use serde::Deserialize;
22

33
/// Configuration used by the formatter
44
#[derive(Clone, Copy, Default, Deserialize)]
5-
pub struct Config {}
5+
pub struct Config {
6+
/// Indentation to use
7+
pub indentation: Indentation,
8+
}
9+
10+
#[derive(Clone, Copy, Default, Deserialize)]
11+
/// Indentation options
12+
pub enum Indentation {
13+
/// Four spaces
14+
FourSpaces,
15+
/// Tabs
16+
Tabs,
17+
#[default]
18+
/// Two spaces
19+
TwoSpaces,
20+
}

src/alejandra/src/format.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,13 @@ pub fn in_memory(
3232
}
3333

3434
let mut build_ctx = crate::builder::BuildCtx {
35-
_config: config,
35+
config,
3636
force_wide: false,
3737
force_wide_success: true,
3838
indentation: 0,
3939
path,
4040
pos_old: crate::position::Position::default(),
4141
vertical: true,
42-
indent,
4342
};
4443

4544
let after = crate::builder::build(&mut build_ctx, ast.node().into())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
[
2+
(a
3+
b)
4+
(
5+
(a b)
6+
(a b)
7+
(a
8+
/*
9+
b
10+
*/
11+
c)
12+
(
13+
/*
14+
a
15+
*/
16+
b
17+
/*
18+
c
19+
*/
20+
d
21+
/*
22+
e
23+
*/
24+
)
25+
)
26+
''
27+
otherModules=${
28+
pkgs.writeText "other-modules.json"
29+
(l.toJSON
30+
(l.mapAttrs
31+
(pname: subOutputs: let
32+
pkg =
33+
subOutputs.packages."${pname}".overrideAttrs (old: {
34+
buildScript = "true";
35+
installMethod = "copy";
36+
});
37+
in "${pkg}/lib/node_modules/${pname}/node_modules")
38+
outputs.subPackages))
39+
}
40+
''
41+
{
42+
name1 =
43+
function
44+
arg
45+
{asdf = 1;};
46+
47+
name2 =
48+
function
49+
arg
50+
{asdf = 1;}
51+
argument;
52+
53+
name3 =
54+
function
55+
arg
56+
{asdf = 1;}
57+
{qwer = 12345;}
58+
argument;
59+
}
60+
{
61+
name1 =
62+
function arg {
63+
asdf = 1;
64+
};
65+
66+
name2 =
67+
function arg {
68+
asdf = 1;
69+
}
70+
argument;
71+
72+
name3 =
73+
function arg {
74+
asdf = 1;
75+
} {
76+
qwer = 12345;
77+
}
78+
argument;
79+
}
80+
{
81+
name4 =
82+
function
83+
arg
84+
{asdf = 1;}
85+
{
86+
qwer = 12345;
87+
qwer2 = 54321;
88+
}
89+
argument;
90+
}
91+
{
92+
option1 =
93+
function arg {asdf = 1;} {
94+
qwer = 12345;
95+
qwer2 = 54321;
96+
}
97+
lastArg;
98+
99+
option2 =
100+
function arg {asdf = 1;} {
101+
qwer = 12345;
102+
qwer2 = 54321;
103+
}
104+
lastArg;
105+
106+
option3 =
107+
function arg {asdf = 1;}
108+
{
109+
qwer = 12345;
110+
qwer2 = 54321;
111+
}
112+
lastArg;
113+
}
114+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
[
2+
(assert b; e)
3+
(assert b;
4+
/*
5+
d
6+
*/
7+
e)
8+
(assert b; e)
9+
(assert b;
10+
/*
11+
d
12+
*/
13+
e)
14+
(assert
15+
/*
16+
a
17+
*/
18+
b; e)
19+
(assert
20+
/*
21+
a
22+
*/
23+
b;
24+
/*
25+
d
26+
*/
27+
e)
28+
(assert
29+
/*
30+
a
31+
*/
32+
b; e)
33+
(assert
34+
/*
35+
a
36+
*/
37+
b;
38+
/*
39+
d
40+
*/
41+
e)
42+
(assert b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc)
43+
(assert b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc)
44+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
[
2+
{}
3+
{
4+
/*
5+
a
6+
*/
7+
}
8+
{a = 1;}
9+
{
10+
a = 1;
11+
}
12+
13+
{b = 1;}
14+
{
15+
b = 1;
16+
/*
17+
c
18+
*/
19+
}
20+
{
21+
/*
22+
a
23+
*/
24+
b = 1;
25+
}
26+
{
27+
/*
28+
a
29+
*/
30+
b = 1;
31+
/*
32+
c
33+
*/
34+
}
35+
36+
rec {c = 1;}
37+
rec {
38+
c = 1;
39+
/*
40+
d
41+
*/
42+
}
43+
rec {
44+
/*
45+
b
46+
*/
47+
c = 1;
48+
}
49+
rec {
50+
/*
51+
b
52+
*/
53+
c = 1;
54+
/*
55+
d
56+
*/
57+
}
58+
rec
59+
/*
60+
a
61+
*/
62+
{
63+
c = 1;
64+
}
65+
rec
66+
/*
67+
a
68+
*/
69+
{
70+
c = 1;
71+
/*
72+
d
73+
*/
74+
}
75+
rec
76+
/*
77+
a
78+
*/
79+
{
80+
/*
81+
b
82+
*/
83+
c = 1;
84+
}
85+
rec
86+
/*
87+
a
88+
*/
89+
{
90+
/*
91+
b
92+
*/
93+
c = 1;
94+
/*
95+
d
96+
*/
97+
}
98+
99+
{
100+
a = rec {
101+
a = {
102+
a = rec {
103+
a = {
104+
a = rec {a = {a = rec {a = {a = rec {a = {};};};};};};
105+
};
106+
};
107+
};
108+
};
109+
}
110+
111+
rec {
112+
c = 1;
113+
114+
e = 1;
115+
}
116+
117+
rec
118+
/*
119+
a
120+
*/
121+
{
122+
/*
123+
b
124+
*/
125+
126+
c = 1;
127+
128+
/*
129+
d
130+
*/
131+
132+
e = 1;
133+
134+
/*
135+
f
136+
*/
137+
}
138+
]

0 commit comments

Comments
 (0)