Skip to content

Commit

Permalink
Add guidelines to format references to code elements
Browse files Browse the repository at this point in the history
  • Loading branch information
loic-joly-sonarsource authored Oct 15, 2024
1 parent 82b94b9 commit 733ac96
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
10 changes: 10 additions & 0 deletions docs/description.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,16 @@ tsql:: use `sql`

In case no language is appropriate for a code block (for example shared examples between multiple languages), you can use `text` as the language.

=== References within code blocks

When referencing a name within a comment in a code example, use double quotes to make it clear it refers to an existing element in the code.

[source,cpp]
----
int i = 0;
cout << noexcept(++i); // Noncompliant, "i" is not incremented
----

=== Diff view

Additionally, you can also use two attributes to let the products know your code examples should be highlighted with a diff view when possible
Expand Down
14 changes: 14 additions & 0 deletions docs/styling_guide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,17 @@ Use it when referencing variable names, file names, tokens, and all kinds of spe
Write:: Compiling source file `src/generic_file.py` breaks an `assert` call in pytest framework.
Avoid:: Compiling source file "src/generic_file.py" breaks an `assert` call in `pytest` framework.

== Referencing elements from the code

When referencing elements from the code within a normal sentence, use the `backticks` (```) to format it. This includes variable names, function names, class names, and so on.

When referencing the same elements within a comment in a code block, surrpond it with double quotes.
[source,cpp]
----
int i = 0;
// Write
cout << noexcept(++i); // Noncompliant, "i" is not incremented -> Double quotes
// Avoid
cout << noexcept(++i); // Noncompliant, i is not incremented -> No quotes
cout << noexcept(++i); // Noncompliant, `i` is not incremented -> Backticks
----

0 comments on commit 733ac96

Please sign in to comment.