Skip to content

Commit 9aba2eb

Browse files
authored
feat: allow for hidden code in Markdown examples (#275)
1 parent 57db428 commit 9aba2eb

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

.github/ISSUE_TEMPLATE/CODING-GUIDELINE.yml

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,23 @@ body:
154154
id: non-compliant-example-code
155155
attributes:
156156
label: Non-Compliant Example - Code
157-
description: Here we write a code example showcasing the unintended or consequential behavior. Non-normative.
158-
placeholder: fn non_compliant_example() { /* ... */ }
157+
description: |
158+
Code example showcasing the unintended or consequential behavior. Non-normative.
159+
160+
**Hidden lines:** If your code needs `use` statements, a `fn main()` wrapper, or other boilerplate to compile, but you don't want them shown in the documentation, prefix those lines with `# ` (hash + space). These lines will be compiled but hidden in the rendered docs.
161+
162+
Example with hidden lines:
163+
```
164+
# use std::mem::MaybeUninit;
165+
# fn main() {
166+
let x: u32 = unsafe { MaybeUninit::uninit().assume_init() }; // UB
167+
# }
168+
```
169+
placeholder: |
170+
# use std::collections::HashMap;
171+
# fn main() {
172+
let map = HashMap::new();
173+
# }
159174
validations:
160175
required: true
161176
- type: textarea
@@ -170,7 +185,22 @@ body:
170185
id: compliant-example-code
171186
attributes:
172187
label: Compliant Example - Code
173-
description: Here we write a code example showcasing we avoid unintended or consequential behavior by following the Coding Guideline.
174-
placeholder: fn compliant_example() { /* ... */ }
188+
description: |
189+
Code example showcasing we avoid unintended or consequential behavior by following the Coding Guideline.
190+
191+
**Hidden lines:** If your code needs `use` statements, a `fn main()` wrapper, or other boilerplate to compile, but you don't want them shown in the documentation, prefix those lines with `# ` (hash + space). These lines will be compiled but hidden in the rendered docs.
192+
193+
Example with hidden lines:
194+
```
195+
# use std::collections::HashMap;
196+
# fn main() {
197+
let mut map = HashMap::new();
198+
map.insert("key", "value"); // Compliant usage
199+
# }
200+
```
201+
placeholder: |
202+
# fn main() {
203+
let safe_value = 42u32; // Properly initialized
204+
# }
175205
validations:
176206
required: true

0 commit comments

Comments
 (0)