You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/ql-style-guide.md
+15-9Lines changed: 15 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -51,7 +51,7 @@ select c, "This call to '$@' is deprecated because " + reason + ".",
51
51
1. There *should not* be additional blank lines within a predicate.
52
52
1. There *may* be a new line:
53
53
- 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.
55
55
1.*Avoid* other line breaks in declarations, other than to break long lines.
56
56
1. When operands of *binary operators* span two lines, the operator *should* be placed at the end of the first line.
57
57
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."
96
96
```
97
97
98
98
```ql
99
-
if x.isPublic() then
99
+
if
100
+
x.isPublic()
101
+
then
100
102
result = "public"
101
103
else
102
104
result = "private"
103
105
```
104
106
105
107
```ql
106
-
if
107
-
x.isPublic()
108
-
then
109
-
result = "public"
108
+
if x.isPublic()
109
+
then result = "public"
110
110
else
111
-
result = "private"
111
+
if x.isPrivate()
112
+
then result = "private"
113
+
else result = "protected"
112
114
```
113
115
116
+
114
117
## Braces
115
118
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.
116
119
1. The closing `}`*must* be placed on its own line, indented to the outer level, or be on the same line as the opening `{`.
- With the *body* after the `if`/`then`/`else` keyword
309
312
- With the *body* indented on the next line
310
313
-*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`.
311
315
1. The `and` and `else` keywords *may* be placed on the same line as the closing parenthesis.
312
316
1. The `and` and `else` keywords *may* be "cuddled": `) else (`
313
317
1.*Always* qualify *calls* to predicates of the same class with `this`.
0 commit comments