File tree 2 files changed +79
-5
lines changed
2 files changed +79
-5
lines changed Original file line number Diff line number Diff line change 77
77
78
78
Beauty is subjective, right?
79
79
80
- We started from the wisdom of the crowd,
81
- which comes in big part
82
- from the 2.3 million lines of code of [ Nixpkgs ] ( https://github.com/NixOS/nixpkgs ) .
83
- Then we applied the feedback of developers
84
- who have used [ Nix ] ( https://nixos.org ) on a day to day basis for several years.
80
+ We started from the original style of
81
+ [ Nixpkgs ] ( https://github.com/NixOS/nixpkgs ) ,
82
+ and then we applied the feedback of developers
83
+ who have used [ Nix ] ( https://nixos.org ) at scale
84
+ for several years.
85
85
86
86
- ✔️ ** Transparent**
87
87
Original file line number Diff line number Diff line change
1
+ # Alejandra's Style Guide
2
+
3
+ Alejandra's mission is to produce a ** consistent style**
4
+ that is ** easy to read**
5
+ and produces ** clean diffs** .
6
+ This means trading aggressively compact code
7
+ for regularity and ease of modification.
8
+
9
+ ## If-Then-Else
10
+
11
+ ✅ Good:
12
+
13
+ ``` nix
14
+ if predicate
15
+ then foo
16
+ else bar
17
+ ```
18
+
19
+ - The keyword at the beginning of the line
20
+ states clearly the meaning of the content that follows.
21
+ - Produces a clean diff when you add more code.
22
+ For example: adding content to the ` else `
23
+ only produces a diff in the ` else ` .
24
+
25
+ ❌ Bad:
26
+
27
+ <!-- nixfmt -->
28
+
29
+ ``` nix
30
+ if predicate then foo else bar
31
+ ```
32
+
33
+ - One-liners are hard to understand,
34
+ specially when nested,
35
+ or when logic gets long.
36
+ - Adding content produces a diff in the entire ` if-then-else ` .
37
+
38
+ ✅ Good:
39
+
40
+ ``` nix
41
+ if something <= 2.0
42
+ then
43
+ if somethingElse
44
+ then foo
45
+ else bar
46
+ else if something <= 4.0
47
+ then baz
48
+ else if something <= 6.0
49
+ then foo
50
+ else bar
51
+ ```
52
+
53
+ - It's easy to follow that there are many conditionals.
54
+ - The indentation makes it easy to read
55
+ which expression is associated to each conditional.
56
+ - Adding or modifying the branches produces a clean diff.
57
+
58
+ ❌ Bad:
59
+
60
+ <!-- nixpkgs-fmt -->
61
+
62
+ ``` nix
63
+ if cond
64
+ then if
65
+ looooooooooooooooooooooooooooooooooooooooooooooooooooong
66
+ then foo
67
+ else bar
68
+ else if cond
69
+ then foo
70
+ else bar
71
+ ```
72
+
73
+ - It's complex to distinct the parent ` if-then-else `
74
+ from the child ` if-then-else `
You can’t perform that action at this time.
0 commit comments