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
+39-39Lines changed: 39 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,10 +9,10 @@ Words in *italic* are defined in the [Glossary](#glossary).
9
9
## Indentation
10
10
1.*Always* use 2 spaces for indentation.
11
11
1.*Always* indent:
12
-
-the*body* of a module, newtype, class or predicate,
13
-
-the second and subsequent lines after you use a line break to split a long line,
14
-
-the*body* of a `from`, `where` or `select` clause where it spans multiple lines,
15
-
-the*body* of a *quantifier* that spans multiple lines.
12
+
-The*body* of a module, newtype, class or predicate
13
+
-The second and subsequent lines after you use a line break to split a long line
14
+
-The*body* of a `from`, `where` or `select` clause where it spans multiple lines
15
+
-The*body* of a *quantifier* that spans multiple lines
16
16
17
17
18
18
### Examples
@@ -43,15 +43,15 @@ select c, "This call to '$@' is deprecated because " + reason + ".",
43
43
1. Lines *must not* exceed 100 characters.
44
44
1. Long lines *should* be split with a line break, and the following lines *must* be indented one level until the next "regular" line break.
45
45
1. There *should* be a single blank line:
46
-
-between the file documentation and the first `import`,
47
-
-before each declaration, except for the first declaration in a *body*,
48
-
-before the `from`-`where`-`select` section in a query file.
46
+
-Between the file documentation and the first `import`
47
+
-Before each declaration, except for the first declaration in a *body*
48
+
-Before the `from`-`where`-`select` section in a query file
49
49
1.*Avoid* two or more adjacent blank lines.
50
50
1. There *must* be a new line after the *annotations*`cached`, `deprecated`, `pragma`, `language` and `bindingset`. Other *annotations* do not have a new line.
51
51
1. There *should not* be additional blank lines within a predicate.
52
52
1. There *may* be a new line:
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.
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.
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
@@ -109,7 +109,7 @@ select main, "Main method has no parameters."
109
109
```
110
110
111
111
## Braces
112
-
1. Braces follow "Stroustrup" style: The opening `{`*must* be placed at the end of the preceding line.
112
+
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
113
1. The closing `}`*must* be placed on its own line, indented to the outer level, or be on the same line as the opening `{`.
114
114
1. Braces of empty blocks *may* be placed on a single line, with a single space separating the braces.
115
115
1. Short predicates, not exceeding the maximum line width, *may* be placed on a single line, with a space following the opening brace and preceding the closing brace.
@@ -128,19 +128,19 @@ class ThrowException extends ThrowExpr {
128
128
129
129
## Spaces
130
130
1. There *must* be a space or line break:
131
-
-surrounding each `=` and `|`,
132
-
-after each comma.
131
+
-Surrounding each `=` and `|`
132
+
-After each `,`
133
133
1. There *should* be a space or line break:
134
-
-surrounding each *binary operator*, which *must* be balanced,
135
-
-surrounding`..` in a range.
136
-
- Exceptions to this are to save space or to improve readability.
134
+
-Surrounding each *binary operator*, which *must* be balanced
135
+
-Surrounding`..` in a range
136
+
- Exceptions to this may be made to save space or to improve readability.
137
137
1.*Avoid* other spaces, for example:
138
-
-after a *quantifier/aggregation* keyword,
139
-
-after the predicate name in a *call*,
140
-
-inside brackets used for *calls*, single-line quantifiers, and parenthesised formulas,
141
-
-surrounding a `.`,
142
-
-inside the opening or closing `[ ]`In a range expression,
143
-
-inside casts `a.(X)`.
138
+
-After a *quantifier/aggregation* keyword
139
+
-After the predicate name in a *call*
140
+
-Inside brackets used for *calls*, single-line quantifiers, and parenthesised formulas
141
+
-Surrounding a `.`
142
+
-Inside the opening or closing `[ ]`in a range expression
143
+
-Inside casts `a.(X)`
144
144
1.*Avoid* multiple spaces, except for indentation, and *avoid* additional indentation to align formulas, parameters or arguments.
145
145
1.*Do not* put whitespace on blank lines, or trailing on the end of a line.
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.
289
289
1. Single-line formulas *may* be used in order to save space or add clarity, particularly in the *body* of a *quantifier/aggregation*.
290
290
1.*Always* use brackets to clarify the precedence of:
291
-
-`implies`,
292
-
-`if`-`then`-`else`.
291
+
-`implies`
292
+
-`if`-`then`-`else`
293
293
1. Parenthesised formulas *can* be written:
294
-
-within a single line. There *should not* be an additional space following the opening parenthesis or preceding the closing parenthesis.
295
-
-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.
294
+
-Within a single line. There *should not* be an additional space following the opening parenthesis or preceding the closing parenthesis.
295
+
-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
296
1.*Quantifiers/aggregations**can* be written:
297
-
-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.
297
+
-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.
299
299
1.`if`-`then`-`else`*can* be written:
300
-
-on a single line,
301
-
-with the *body* after the `if`/`then`/`else` keyword,
302
-
-with the *body* indented on the next line.
300
+
-On a single line
301
+
-With the *body* after the `if`/`then`/`else` keyword
302
+
-With the *body* indented on the next line
303
303
-*Always* parenthesise the `else` part if it is a compound formula.
304
304
1. The `and` and `else` keywords *may* be placed on the same line as the closing parenthesis.
305
305
1. The `and` and `else` keywords *may* be "cuddled": `) else (`
0 commit comments