Skip to content

Commit 2a66585

Browse files
committed
Address some review comments, apart from the bullet format.
1 parent 68d8b66 commit 2a66585

File tree

1 file changed

+56
-70
lines changed

1 file changed

+56
-70
lines changed

docs/ql-style-guide.md

Lines changed: 56 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22

33
## Introduction
44

5-
This document describes how to format the QL code in this repository, covering aspects such as layout, white-space, naming and documentation. Adhering to consistent standards makes code easier to read and maintain. Of course, these are only guidelines, and can be overridden as the need arises on a case-by-case basis. Where existing code deviates from these guidelines, prefer consistency with the surrounding code.
5+
This document describes how to format the QL code you contribute to this repository. It covers aspects such as layout, white-space, naming and documentation. Adhering to consistent standards makes code easier to read and maintain. Of course, these are only guidelines, and can be overridden as the need arises on a case-by-case basis. Where existing code deviates from these guidelines, prefer consistency with the surrounding code.
66

77
Words in *italic* are defined in the [Glossary](#glossary).
88

99
## Indentation
1010
1. *Always* use 2 spaces for indentation.
1111
1. *Always* indent:
1212
- the *body* of a module, newtype, class or predicate,
13-
- the second and subsequent lines after a line break used to split a long line,
13+
- the second and subsequent lines after you use a line break to split a long line,
1414
- the *body* of a `from`, `where` or `select` clause where it spans multiple lines,
1515
- the *body* of a *quantifier* that spans multiple lines.
1616

1717

18-
Examples:
18+
### Examples
1919

2020
```ql
2121
module Helpers {
@@ -47,15 +47,15 @@ select c, "This call to '$@' is deprecated because " + reason + ".",
4747
- before each declaration, except for the first declaration in a *body*,
4848
- before the `from`-`where`-`select` section in a query file.
4949
1. *Avoid* two or more adjacent blank lines.
50-
1. There *must* be a new line after the *annotations* `cached`, `deprecated`, `pragma`, `language` and `bindingset`.
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.
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,
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.
5757

58-
Examples:
58+
### Examples
5959

6060
```ql
6161
cached
@@ -78,12 +78,6 @@ where main.getName() = "Main"
7878
select main, "This is the program entry point."
7979
```
8080

81-
```ql
82-
from Method main
83-
where main.getName() = "Main"
84-
select main, "This is the program entry point."
85-
```
86-
8781
```ql
8882
from Method main
8983
where
@@ -98,6 +92,13 @@ select main, "Main method has no parameters."
9892
else result = "private"
9993
```
10094

95+
```ql
96+
if x.isPublic() then
97+
result = "public"
98+
else
99+
result = "private"
100+
```
101+
101102
```ql
102103
if
103104
x.isPublic()
@@ -113,8 +114,7 @@ select main, "Main method has no parameters."
113114
1. Braces of empty blocks *may* be placed on a single line, with a single space separating the braces.
114115
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.
115116

116-
117-
For example,
117+
### Examples
118118

119119
```ql
120120
class ThrowException extends ThrowExpr {
@@ -146,7 +146,7 @@ class ThrowException extends ThrowExpr {
146146
1. *Do not* use tabs.
147147

148148

149-
For example,
149+
### Examples
150150

151151
```ql
152152
cached
@@ -174,8 +174,9 @@ private predicate foo(Expr e, Expr p) {
174174
1. *Avoid* short or single-letter names for classes, predicates and fields.
175175
1. Short or single letter names for parameters and *quantifiers* *may* be used provided that they are sufficiently clear.
176176
1. Use names as they are used in the target-language specification.
177+
1. Use American English.
177178

178-
Examples:
179+
### Examples
179180

180181
```ql
181182
/** ... */
@@ -205,16 +206,25 @@ class Type extends ... {
205206
```
206207

207208
## Documentation
209+
210+
General requirements:
211+
208212
1. Documentation *must* adhere to the [QLDoc specification](https://help.semmle.com/QL/QLDocSpecification.html).
209-
1. Public declarations *must* be documented.
210-
1. Non-public declarations *should* be documented.
211-
1. Declarations in query files *should* be documented.
212213
1. Use `/** ... */` for documentation, even for single line comments.
213214
1. For single-line documentation, the `/**` and `*/` are written on the same line as the comment.
214215
1. For multi-line documentation, the `/**` and `*/` are written on separate lines. There is a `*` preceding each comment line, aligned on the first `*`.
215-
1. Library files (`.qll` files) *should* be documented with QLDoc.
216-
1. Query files, except for tests, *must* have a QLDoc query documentation comment.
217-
1. Documentation *should* be appropriate for users of the library. Put documentation for maintainers in normal comments.
216+
1. Use full sentences, with capital letters and full stops.
217+
1. Use American English.
218+
1. Documentation comments *should* be appropriate for users of the code.
219+
1. Documentation for maintainers of the code *must* use normal comments.
220+
221+
Documenting specific items:
222+
223+
1. Public declarations *must* be documented.
224+
1. Non-public declarations *should* be documented.
225+
1. Declarations in query files *should* be documented.
226+
1. Library files (`.qll` files) *should* be have a documentation comment at the top of the file.
227+
1. Query files, except for tests, *must* have a QLDoc query documentation comment at the top of the file.
218228
1. Predicates that do not have a result *should* be documented `/** Holds if ... */`
219229
1. Predicates that have a result *should* be documented `/** Gets ... */`
220230
1. All predicate parameters *should* be referred to in the predicate documentation.
@@ -224,10 +234,8 @@ class Type extends ... {
224234
1. Where a class denotes a generic concept with subclasses, list those subclasses.
225235
1. Declarations that are deprecated *should* be documented as `DEPRECATED: ...`
226236
1. Declarations that are for internal use *should* be documented as `INTERNAL: Do not use`.
227-
1. Use full sentences, with capital letters and full stops.
228237

229-
230-
Examples:
238+
### Examples
231239

232240
```ql
233241
/** Provides logic for determining constant expressions. */
@@ -278,10 +286,10 @@ deprecated Expr getInitializer()
278286
1. Write the `and` at the end of the line. This also applies in `where` clauses.
279287
1. *Prefer* to write the `or` keyword on its own line.
280288
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.
281-
1. Single-line formulas *may* be used in order to save space or add clarity, particularly in the *body* of a *quantifier/aggregation*.
282-
1. *Avoid* additional brackets to clarify the precedence of `not`, `and` and `or`.
283-
1. *Always* clarify the precedence of `implies` with brackets.
284-
1. *Always* clarify the precedence of `if`-`then`-`else` with brackets.
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+
1. *Always* use brackets to clarify the precedence of:
291+
- `implies`,
292+
- `if`-`then`-`else`.
285293
1. Parenthesised formulas *can* be written:
286294
- within a single line. There *should not* be an additional space following the opening parenthesis or preceding the closing parenthesis.
287295
- 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.
@@ -293,12 +301,12 @@ deprecated Expr getInitializer()
293301
- with the *body* after the `if`/`then`/`else` keyword,
294302
- with the *body* indented on the next line.
295303
- *Always* parenthesise the `else` part if it is a compound formula.
296-
1. The `and` and `else` keywords *may* be placed on the same line as the a closing parenthesis.
304+
1. The `and` and `else` keywords *may* be placed on the same line as the closing parenthesis.
297305
1. The `and` and `else` keywords *may* be "cuddled": `) else (`
298306
1. *Always* qualify *calls* to predicates of the same class with `this`.
299307
2. *Prefer* postfix casts `a.(Expr)` to prefix casts `(Expr)a`.
300308

301-
Examples:
309+
### Examples
302310

303311
```ql
304312
argumentType.isImplicitlyConvertibleTo(parameterType)
@@ -391,44 +399,22 @@ Examples:
391399
```
392400

393401
## Glossary
394-
*[annotation](https://help.semmle.com/QL/QLLanguageSpecification.html#annotations)*:
395-
An additional specifier used to modify a declaration, such as `private`, `override`, `deprecated`, `pragma`, `bindingset`, or `cached`.
396-
397-
*body*:
398-
The text inside `{ }`, `( )`, or each section of an `if`-`then`-`else` or `from`-`where`-`select`.
399-
400-
*binary operator*:
401-
An operator with two operands, such as comparison operators, `and`, `or`, `implies`, or arithmetic operators.
402-
403-
*call*:
404-
A *formula* that invokes a predicate, e.g. `this.isStatic()` or `calls(a,b)`.
405-
406-
407-
*[conjunct](https://help.semmle.com/QL/QLLanguageSpecification.html#conjunctions)*:
408-
A formula that is an operand to an `and`.
409-
410-
411-
*declaration*:
412-
A class, module, predicate, field or newtype.
413-
414-
415-
*[disjunct](https://help.semmle.com/QL/QLLanguageSpecification.html#disjunctions)*:
416-
A formula that is an operand to an `or`.
417-
418-
*[formula](https://help.semmle.com/QL/QLLanguageSpecification.html#formulas)*:
419-
A logical expression, such as `A = B`, a *call*, a *quantifier*, `and`, `or`, `not`, 'in` or `instanceof`.
420-
421-
*should/should not/avoid/prefer*:
422-
Adhere to this rule wherever possible, where it makes sense.
423-
424-
*may/can*:
425-
This is a reasonable alternative, to be used with discretion.
426-
427-
*must/always/do not*:
428-
Always adhere to this rule.
429-
430-
*[quantifier/aggregation](https://help.semmle.com/QL/QLLanguageSpecification.html#aggregations)*:
431-
`exists`, `count`, `strictcount`, `any`, `forall`, `forex` and so on.
432402

433-
*variable*:
434-
A parameter to a predicate, a field, a from variable, or a variable introduced by a *quantifier* or *aggregation*.
403+
|-------------|----------|
404+
| Phrase | Meaning |
405+
|-------------|----------|
406+
| *[annotation](https://help.semmle.com/QL/QLLanguageSpecification.html#annotations)* |
407+
An additional specifier used to modify a declaration, such as `private`, `override`, `deprecated`, `pragma`, `bindingset`, or `cached`. |
408+
| *body* | The text inside `{ }`, `( )`, or each section of an `if`-`then`-`else` or `from`-`where`-`select`. |
409+
| *binary operator* | An operator with two operands, such as comparison operators, `and`, `or`, `implies`, or arithmetic operators. |
410+
| *call* | A *formula* that invokes a predicate, e.g. `this.isStatic()` or `calls(a,b)`. |
411+
| *[conjunct](https://help.semmle.com/QL/QLLanguageSpecification.html#conjunctions)* | A formula that is an operand to an `and`. |
412+
| *declaration* | A class, module, predicate, field or newtype. |
413+
| *[disjunct](https://help.semmle.com/QL/QLLanguageSpecification.html#disjunctions)* | A formula that is an operand to an `or`. |
414+
| *[formula](https://help.semmle.com/QL/QLLanguageSpecification.html#formulas)* | A logical expression, such as `A = B`, a *call*, a *quantifier*, `and`, `or`, `not`, 'in` or `instanceof`. |
415+
| *should/should not/avoid/prefer* | Adhere to this rule wherever possible, where it makes sense. |
416+
| *may/can* | This is a reasonable alternative, to be used with discretion. |
417+
| *must/always/do not* | Always adhere to this rule. |
418+
| *[quantifier/aggregation](https://help.semmle.com/QL/QLLanguageSpecification.html#aggregations)* | `exists`, `count`, `strictcount`, `any`, `forall`, `forex` and so on. |
419+
| *variable* | A parameter to a predicate, a field, a from variable, or a variable introduced by a *quantifier* or *aggregation*. |
420+
|-------------|----------|

0 commit comments

Comments
 (0)