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
Updated QLDoc style guide with detailed requirements for documentation, including general, language, and specific item requirements. Added examples for predicates, classes, and modules.
Copy file name to clipboardExpand all lines: .github/copilot-instructions.md
+182-2Lines changed: 182 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -59,7 +59,7 @@ When reviewing tests, it is critical to:
59
59
- 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.
60
60
- 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.
61
61
62
-
###Validating Query style
62
+
## Validating Query style
63
63
64
64
The following list describes the required style guides for a query that **must** be validated during the code-review process.
65
65
@@ -76,4 +76,184 @@ A query **must** include:
76
76
- 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.
77
77
- Do not try to explain the solution in the message; instead that should be provided in the help for the query.
78
78
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`.
0 commit comments