Skip to content

Commit

Permalink
Define how to handle thins within conditionals
Browse files Browse the repository at this point in the history
  • Loading branch information
corvus-ch committed Sep 9, 2020
1 parent 7c9df81 commit 3a98203
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions docs/modules/ROOT/pages/references/style-guide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,62 @@ local baz =
};
----

* Objects within a conditional start on the same line as the condition.
+
[source,jsonnet]
----
// PREFERRED
local foo(x) =
if x == 42 then {
result: "The Answer",
}
else {
result: "Don't know",
};
// ACCEPTABLE
local bar(x) =
if x == 42 then
{
result: "The Answer",
}
else
{
result: "Don't know",
};
----

* Start `if` and `else` on new lines and prefer to keep `else if` together.
+
[sourece,jsonnet]
----
// PREFERRED
local foo(x) =
if x < 42 then {
result: "No enought",
}
else if > 42 then {
result: "Too much",
}
else {
result: "The Answer",
}
// ACCEPTABLE
local bar(x) =
if x < 42 then {
result: "No enought",
}
else
if > 42 then {
result: "Too much",
}
else {
result: "The Answer",
}
----

* Omit tailing `,` on single line arrays and objects.
Keep them when splitting over multiple lines.
+
Expand Down

0 comments on commit 3a98203

Please sign in to comment.