Skip to content

Commit 83cf49c

Browse files
authored
Revise QLDoc style guide and add examples
Updated QLDoc style guide with detailed requirements for documentation, including general, language, and specific item requirements. Added examples for predicates, classes, and modules.
1 parent 664a54a commit 83cf49c

File tree

1 file changed

+182
-2
lines changed

1 file changed

+182
-2
lines changed

.github/copilot-instructions.md

Lines changed: 182 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ When reviewing tests, it is critical to:
5959
- Consider the "test coverage" of the query, are each of its logical statements effectively exercised individually, collectively? The test should neither be overly bloated nor under specified.
6060
- Consider the edge cases of the language itself, will the analysis work in non-trivial cases, are all relevant language concepts tested here? This doesn't need to be exhaustive, but it should be thoughfully thorough.
6161

62-
### Validating Query style
62+
## Validating Query style
6363

6464
The following list describes the required style guides for a query that **must** be validated during the code-review process.
6565

@@ -76,4 +76,184 @@ A query **must** include:
7676
- Instead of `Return value from call is unused.` prefer `Return value from call to function [x] is unused.`, where `[x]` is a link to the function itself.
7777
- Do not try to explain the solution in the message; instead that should be provided in the help for the query.
7878

79-
All public predicates, classes, modules and files should be documented with QLDoc. All QLDoc should follow the [QLDoc style guide](https://github.com/github/codeql/blob/main/docs/qldoc-style-guide.md).
79+
All public predicates, classes, modules and files should be documented with QLDoc. All QLDoc should follow the following QLDoc style guide:
80+
81+
### General QLDoc requirements
82+
83+
1. Documentation must adhere to the [QLDoc specification](https://codeql.github.com/docs/ql-language-reference/ql-language-specification/#qldoc).
84+
1. Documentation comments should be appropriate for users of the code.
85+
1. Documentation for maintainers of the code must use normal comments.
86+
1. Use `/** ... */` for documentation, even for single line comments.
87+
- For single-line documentation, the `/**` and `*/` are written on the same line as the comment.
88+
- For multi-line documentation, the `/**` and `*/` are written on separate lines. There is a `*` preceding each comment line, aligned on the first `*`.
89+
1. Use code formatting (backticks) within comments for code from the source language, and also for QL code (for example, names of classes, predicates, and variables).
90+
1. Give explanatory examples of code in the target language, enclosed in ```` ```<target language> ```` or `` ` ``.
91+
92+
93+
### Language requirements
94+
95+
1. Use American English.
96+
1. Use full sentences, with capital letters and periods, except for the initial sentence of the comment, which may be fragmentary as described below.
97+
1. Use simple sentence structures and avoid complex or academic language.
98+
1. Avoid colloquialisms and contractions.
99+
1. Use words that are in common usage.
100+
101+
102+
### Requirements for specific items
103+
104+
1. Public declarations must be documented.
105+
1. Non-public declarations should be documented.
106+
1. Declarations in query files should be documented.
107+
1. Library files (`.qll` files) should have a documentation comment at the top of the file.
108+
1. Query files, except for tests, must have a QLDoc query documentation comment at the top of the file.
109+
110+
### QLDoc for predicates
111+
112+
1. Refer to all predicate parameters in the predicate documentation.
113+
1. Reference names, such as types and parameters, using backticks `` ` ``.
114+
1. Give examples of code in the target language, enclosed in ```` ```<target language> ```` or `` ` ``.
115+
1. Predicates that override a single predicate don't need QLDoc, as they will inherit it.
116+
117+
#### Predicates without result
118+
119+
1. Use a third-person verb phrase of the form ``Holds if `arg` has <property>.``
120+
1. Avoid:
121+
- `/** Whether ... */`
122+
- `/**" Relates ... */`
123+
- Question forms:
124+
- ``/** Is `x` a foo? */``
125+
- ``/** Does `x` have a bar? */``
126+
127+
##### Example
128+
129+
```ql
130+
/**
131+
* Holds if the qualifier of this call has type `qualifierType`.
132+
* `isExactType` indicates whether the type is exact, that is, whether
133+
* the qualifier is guaranteed not to be a subtype of `qualifierType`.
134+
*/
135+
```
136+
137+
#### Predicates with result
138+
139+
1. Use a third-person verb phrase of the form `Gets (a|the) <thing>.`
140+
1. Use "if any" if the item is usually unique but might be missing. For example
141+
`Gets the body of this method, if any.`
142+
1. If the predicate has more complex behaviour, for example multiple arguments are conceptually "outputs", it can be described like a predicate without a result. For example
143+
``Holds if `result` is a child of this expression.``
144+
1. Avoid:
145+
- `Get a ...`
146+
- `The ...`
147+
- `Results in ...`
148+
- Any use of `return`
149+
150+
##### Example
151+
```ql
152+
/**
153+
* Gets the expression denoting the super class of this class,
154+
* or nothing if this is an interface or a class without an `extends` clause.
155+
*/
156+
```
157+
158+
#### Deprecated predicates
159+
160+
The documentation for deprecated predicates should be updated to emphasize the deprecation and specify what predicate to use as an alternative.
161+
Insert a sentence of the form `DEPRECATED: Use <other predicate> instead.` at the start of the QLDoc comment.
162+
163+
##### Example
164+
165+
```ql
166+
/** DEPRECATED: Use `getAnExpr()` instead. */
167+
deprecated Expr getInitializer()
168+
```
169+
170+
#### Internal predicates
171+
172+
Some predicates are internal-only declarations that cannot be made private. The documentation for internal predicates should begin with `INTERNAL: Do not use.`
173+
174+
##### Example
175+
176+
```ql
177+
/**
178+
* INTERNAL: Do not use.
179+
*/
180+
```
181+
182+
#### Special predicates
183+
184+
Certain special predicates should be documented consistently.
185+
186+
- Always document `toString` as
187+
188+
```ql
189+
/** Gets a textual representation of this element. */
190+
string toString() { ... }
191+
```
192+
193+
- Always document `hasLocationInfo` as
194+
195+
```ql
196+
/**
197+
* Holds if this element is at the specified location.
198+
* The location spans column `startcolumn` of line `startline` to
199+
* column `endcolumn` of line `endline` in file `filepath`.
200+
* For more information, see
201+
* [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
202+
*/
203+
204+
predicate hasLocationInfo(string filepath, int startline, int startcolumn, int endline, int endcolumn) { ... }
205+
```
206+
207+
### QLDoc for classes
208+
209+
1. Document classes using a noun phrase of the form `A <domain element> that <has property>.`
210+
1. Use "that", not "which".
211+
1. Refer to member elements in the singular.
212+
1. Where a class denotes a generic concept with subclasses, list those subclasses.
213+
214+
##### Example
215+
216+
```ql
217+
/**
218+
* A delegate declaration, for example
219+
* ```
220+
* delegate void Logger(string text);
221+
* ```
222+
*/
223+
class Delegate extends ...
224+
```
225+
226+
```ql
227+
/**
228+
* An element that can be called.
229+
*
230+
* Either a method (`Method`), a constructor (`Constructor`), a destructor
231+
* (`Destructor`), an operator (`Operator`), an accessor (`Accessor`),
232+
* an anonymous function (`AnonymousFunctionExpr`), or a local function
233+
* (`LocalFunction`).
234+
*/
235+
class Callable extends ...
236+
```
237+
238+
### QLDoc for modules
239+
240+
Modules should be documented using a third-person verb phrase of the form `Provides <classes and predicates to do something>.`
241+
242+
##### Example
243+
244+
```ql
245+
/** Provides logic for determining constant expressions. */
246+
```
247+
```ql
248+
/** Provides classes representing the control flow graph within functions. */
249+
```
250+
251+
### Special variables
252+
253+
When referring to `this`, you may either refer to it as `` `this` `` or `this <type>`. For example:
254+
- ``Holds if `this` is static.``
255+
- `Holds if this method is static.`
256+
257+
When referring to `result`, you may either refer to it as `` `result` `` or as `the result`. For example:
258+
- ``Holds if `result` is a child of this expression.``
259+
- `Holds if the result is a child of this expression.`

0 commit comments

Comments
 (0)