Skip to content

Commit 9984647

Browse files
committed
QL style guide: Adjust style rules for if-then-else.
1 parent 31e1706 commit 9984647

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

docs/ql-style-guide.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ select c, "This call to '$@' is deprecated because " + reason + ".",
5151
1. There *should not* be additional blank lines within a predicate.
5252
1. There *may* be a new line:
5353
- Immediately after the `from`, `where` or `select` keywords in a query.
54-
- Immediately after `if`, `then`, or `else` keywords. The `then` and `else` parts *should* be consistent.
54+
- Immediately after `if`, `then`, or `else` keywords.
5555
1. *Avoid* other line breaks in declarations, other than to break long lines.
5656
1. When operands of *binary operators* span two lines, the operator *should* be placed at the end of the first line.
5757
1. If the parameter list needs to be broken across multiple lines then there *must* be a line break after the opening `(`, the parameter declarations indented one level, and the `) {` *must* be on its own line at the outer indentation.
@@ -96,21 +96,24 @@ select main, "Main method has no parameters."
9696
```
9797

9898
```ql
99-
if x.isPublic() then
99+
if
100+
x.isPublic()
101+
then
100102
result = "public"
101103
else
102104
result = "private"
103105
```
104106

105107
```ql
106-
if
107-
x.isPublic()
108-
then
109-
result = "public"
108+
if x.isPublic()
109+
then result = "public"
110110
else
111-
result = "private"
111+
if x.isPrivate()
112+
then result = "private"
113+
else result = "protected"
112114
```
113115

116+
114117
## Braces
115118
1. Braces follow [Stroustrup](https://en.wikipedia.org/wiki/Indentation_style#Variant:_Stroustrup) style. The opening `{` *must* be placed at the end of the preceding line.
116119
1. The closing `}` *must* be placed on its own line, indented to the outer level, or be on the same line as the opening `{`.
@@ -308,6 +311,7 @@ deprecated Expr getInitializer()
308311
- With the *body* after the `if`/`then`/`else` keyword
309312
- With the *body* indented on the next line
310313
- *Always* parenthesise the `else` part if it is a compound formula.
314+
1. If an `if`-`then`-`else` is broken across multiple lines then the `then` and `else` keywords *should* be at the start of lines aligned with the `if`.
311315
1. The `and` and `else` keywords *may* be placed on the same line as the closing parenthesis.
312316
1. The `and` and `else` keywords *may* be "cuddled": `) else (`
313317
1. *Always* qualify *calls* to predicates of the same class with `this`.
@@ -342,7 +346,8 @@ deprecated Expr getInitializer()
342346
```
343347

344348
```ql
345-
if e1 instanceof BitwiseOrExpr or e1 instanceof LogicalOrExpr then (
349+
if e1 instanceof BitwiseOrExpr or e1 instanceof LogicalOrExpr
350+
then (
346351
impliesSub(e1.(BinaryOperation).getAnOperand(), e2, b1, b2) and
347352
b1 = false
348353
) else (
@@ -397,7 +402,8 @@ deprecated Expr getInitializer()
397402
```
398403

399404
```ql
400-
if exists(this.getContainingType()) then (
405+
if exists(this.getContainingType())
406+
then (
401407
result = "A nested class" and
402408
parentName = this.getContainingType().getFullyQualifiedName()
403409
) else (

0 commit comments

Comments
 (0)