Skip to content

Commit a0a00ba

Browse files
authored
docs(code-stype-guide): Add comment rules (#668)
1 parent 4050ac5 commit a0a00ba

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

modules/contributor/pages/code-style-guide.adoc

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,88 @@ If any of the items are commented, all items should be.
275275
It should however also be noted that there is no requirement to comment fields or variants.
276276
Comments should only be added if they provide additional information not available from context.
277277

278+
== Comments
279+
280+
General rules apply for both doc comments and developer comments.
281+
The comments should not exceed a line-width of 100 characters with the exception of URLs.
282+
Long inline URLs should be avoided.
283+
Put links onto their own line or reference them with Markdown references instead.
284+
Comments should always form complete sentences with full stops at the end.
285+
286+
[TIP.code-rule,caption=Examples of correct code for this rule]
287+
====
288+
289+
[source]
290+
----
291+
100 characters v
292+
|
293+
/// This is my comment which exceeds
294+
/// the width of 100 characters and|
295+
/// thus needs to [wrap][1]. |
296+
/// |
297+
/// Another comment where the |
298+
/// final dot exceeds the |
299+
/// line-width. |
300+
/// |
301+
/// [1]: https::example.com/path/to/file.html
302+
----
303+
304+
'''
305+
306+
[source]
307+
----
308+
100 characters v
309+
|
310+
// This is a dev comment which links
311+
// to a bunch of PRs. See: |
312+
// |
313+
// - https://example.com/project/pull/123
314+
// - https://example.com/project/pull/321
315+
----
316+
317+
====
318+
319+
[WARNING.code-rule,caption=Examples of incorrect code for this rule]
320+
====
321+
322+
[source]
323+
----
324+
100 characters v
325+
|
326+
/// This is my comment which exceeds the
327+
/// width of 100 characters and thus needs
328+
/// to [wrap](https::example.com/path/to/file.html).
329+
/// |
330+
/// Another comment where the |
331+
/// final dot exceeds the line-width.
332+
----
333+
334+
'''
335+
336+
[source]
337+
----
338+
100 characters v
339+
|
340+
// This is a dev comment which links
341+
// to a bunch of PRs. See: https://example.com/project/pull/123
342+
// and https://example.com/project/pull/321
343+
----
344+
345+
====
346+
347+
Additionally, doc comments should follow the structure outlined by the Rust project, which is described https://doc.rust-lang.org/rustdoc/how-to-write-documentation.html#documenting-components[here]:
348+
349+
[source]
350+
----
351+
[short sentence explaining what it is]
352+
353+
[more detailed explanation]
354+
355+
[at least one code example that users can copy/paste to try it]
356+
357+
[even more advanced explanations if necessary]
358+
----
359+
278360
== Error handling
279361

280362
=== Choice of error crate and usage

0 commit comments

Comments
 (0)