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
+29-15Lines changed: 29 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -51,9 +51,10 @@ 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
+
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.
57
58
58
59
### Examples
59
60
@@ -65,9 +66,11 @@ private int getNumberOfParameters() {
int numberOfParameters, int numberOfStatements, int numberOfExpressions,
70
-
int linesOfCode, int nestingDepth, int numberOfBranches) {
69
+
predicate methodStats(
70
+
string qualifiedName, string name, int numberOfParameters,
71
+
int numberOfStatements, int numberOfExpressions, int linesOfCode,
72
+
int nestingDepth, int numberOfBranches
73
+
) {
71
74
...
72
75
}
73
76
```
@@ -93,21 +96,24 @@ select main, "Main method has no parameters."
93
96
```
94
97
95
98
```ql
96
-
if x.isPublic() then
99
+
if
100
+
x.isPublic()
101
+
then
97
102
result = "public"
98
103
else
99
104
result = "private"
100
105
```
101
106
102
107
```ql
103
-
if
104
-
x.isPublic()
105
-
then
106
-
result = "public"
108
+
if x.isPublic()
109
+
then result = "public"
107
110
else
108
-
result = "private"
111
+
if x.isPrivate()
112
+
then result = "private"
113
+
else result = "protected"
109
114
```
110
115
116
+
111
117
## Braces
112
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.
113
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 `{`.
1. Write the `and` at the end of the line. This also applies in `where` clauses.
287
293
1.*Prefer* to write the `or` keyword on its own line.
288
-
1. The `or` keyword *may* be written at the end of a line, or within a line, provided that it has no unparenthesised `and` operands.
294
+
1. The `or` keyword *may* be written at the end of a line, or within a line, provided that it has no `and` operands.
289
295
1. Single-line formulas *may* be used in order to save space or add clarity, particularly in the *body* of a *quantifier/aggregation*.
290
296
1.*Always* use brackets to clarify the precedence of:
291
297
-`implies`
292
298
-`if`-`then`-`else`
299
+
1.*Avoid* using brackets to clarify the precedence of:
300
+
-`not`
301
+
-`and`
302
+
-`or`
293
303
1. Parenthesised formulas *can* be written:
294
304
- Within a single line. There *should not* be an additional space following the opening parenthesis or preceding the closing parenthesis.
295
305
- Spanning multiple lines. The opening parenthesis *should* be placed at the end of the preceding line, the body should be indented one level, and the closing bracket should be placed on a new line at the outer indentation.
296
306
1.*Quantifiers/aggregations**can* be written:
297
307
- Within a single line. In this case, there is no space to the inside of the parentheses, or after the quantifier keyword.
298
-
- Across multiple lines. In this case, type declarations are on the same line as the quantifier, the `|`*may* be at the end of the line, or *may* be on its own line, and the body of the quantifier *must* be indented one level. The closing `)` is written on a new line, at the outer indentation.
308
+
- Across multiple lines. In this case, type declarations are on the same line as the quantifier with the first `|` at the same line as the quantifier, the second `|`*must* be at the end of the same line as the quantifier or on its own line at the outer indentation, and the body of the quantifier *must* be indented one level. The closing `)` is written on a new line, at the outer indentation. If the type declarations need to be broken across multiple lines then there must *must* be a line break after the opening `(`, the type declarations indented one level, and the first `|` on its own line at the outer indentation.
299
309
1.`if`-`then`-`else`*can* be written:
300
310
- On a single line
301
311
- With the *body* after the `if`/`then`/`else` keyword
302
312
- With the *body* indented on the next line
303
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`.
304
315
1. The `and` and `else` keywords *may* be placed on the same line as the closing parenthesis.
305
316
1. The `and` and `else` keywords *may* be "cuddled": `) else (`
306
317
1.*Always* qualify *calls* to predicates of the same class with `this`.
0 commit comments