Skip to content

Commit 6feb1d0

Browse files
committed
QL style guide: Clarify some outstanding issues.
1 parent 3e022ad commit 6feb1d0

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

docs/ql-style-guide.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ select c, "This call to '$@' is deprecated because " + reason + ".",
5454
- Immediately after `if`, `then`, or `else` keywords. The `then` and `else` parts *should* be consistent.
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.
57+
1. If the parameter list needs to be broken across multiple lines then there must *must* be a line break after the opening `(`, the parameter declarations indented one level, and the `) {` on its own line at the outer indentation.
5758

5859
### Examples
5960

@@ -65,9 +66,11 @@ private int getNumberOfParameters() {
6566
```
6667

6768
```ql
68-
predicate methodStats(string qualifiedName, string name,
69-
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+
) {
7174
...
7275
}
7376
```
@@ -285,17 +288,21 @@ deprecated Expr getInitializer()
285288
1. *Prefer* one *conjunct* per line.
286289
1. Write the `and` at the end of the line. This also applies in `where` clauses.
287290
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.
291+
1. The `or` keyword *may* be written at the end of a line, or within a line, provided that it has no `and` operands.
289292
1. Single-line formulas *may* be used in order to save space or add clarity, particularly in the *body* of a *quantifier/aggregation*.
290293
1. *Always* use brackets to clarify the precedence of:
291294
- `implies`
292295
- `if`-`then`-`else`
296+
1. *Avoid* using brackets to clarify the precedence of:
297+
- `not`
298+
- `and`
299+
- `or`
293300
1. Parenthesised formulas *can* be written:
294301
- Within a single line. There *should not* be an additional space following the opening parenthesis or preceding the closing parenthesis.
295302
- 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.
296303
1. *Quantifiers/aggregations* *can* be written:
297304
- 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.
305+
- Across multiple lines. In this case, type declarations are on the same line as the quantifier with the `|` at the end of 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.
299306
1. `if`-`then`-`else` *can* be written:
300307
- On a single line
301308
- With the *body* after the `if`/`then`/`else` keyword
@@ -360,7 +367,8 @@ deprecated Expr getInitializer()
360367

361368
```ql
362369
exists(Type qualifierType |
363-
this.hasNonExactQualifierType(qualifierType) |
370+
this.hasNonExactQualifierType(qualifierType)
371+
|
364372
result = getANonExactQualifierSubType(qualifierType)
365373
)
366374
```

0 commit comments

Comments
 (0)