github.com/cilium/cilium@v1.16.2/Documentation/contributing/docs/docsstyle.rst (about) 1 .. only:: not (epub or latex or html) 2 3 WARNING: You are looking at unreleased Cilium documentation. 4 Please use the official rendered version released here: 5 https://docs.cilium.io 6 7 .. _docs_style_guide: 8 9 ******************* 10 Documentation style 11 ******************* 12 13 .. |RST| replace:: reStructuredText 14 15 Here are some guidelines and best practices for contributing to Cilium's 16 documentation. They have several objectives: 17 18 - Ensure that the documentation is rendered in the best possible way (in 19 particular for code blocks). 20 21 - Make the documentation easy to maintain and extend. 22 23 - Help keep a consistent style throughout the documentation. 24 25 - In the end, provide a better experience to users, and help them find the 26 information they need. 27 28 See also :ref:`the documentation for testing <testing-documentation>` for 29 instructions on how to preview documentation changes. 30 31 General considerations 32 ---------------------- 33 34 Write in US English. 35 For example, use "prioritize" instead of ":spelling:ignore:`prioritise`" and 36 "color" instead of ":spelling:ignore:`colour`". 37 38 Maintain a consistent style with the rest of the documentation when possible, 39 or at least with the rest of the updated page. 40 41 Omit hyphens when possible. For example, use "load balancing" instead of 42 "load-balancing". 43 44 Header 45 ------ 46 47 Use the following header when adding new files to the Documentation. 48 49 .. code-block:: rst 50 51 .. only:: not (epub or latex or html) 52 53 WARNING: You are looking at unreleased Cilium documentation. 54 Please use the official rendered version released here: 55 https://docs.cilium.io 56 57 One exception is |RST| fragments that are supposed to be sourced from other 58 documentation files. Those do not need this header. 59 60 Headings 61 -------- 62 63 Prefer sentence case (capital letter on first word) rather than 64 title case for all headings. 65 66 Body 67 ---- 68 69 Wrap the lines for long sentences or paragraphs. There is no fixed convention 70 on the length of lines, but targeting a width of about 80 characters should be 71 safe in most circumstances. 72 73 Capitalization 74 -------------- 75 76 Follow `the section on capitalization for API objects`_ from the Kubernetes 77 style guide for when to (not) capitalize API objects. In particular: 78 79 When you refer specifically to interacting with an API object, use 80 `UpperCamelCase`_, also known as Pascal case. 81 82 And: 83 84 When you are generally discussing an API object, use `sentence-style 85 capitalization`_ 86 87 For example, write "Gateway API", capitalized. Use "Gateway" when writing about 88 an API object as an entity, and "gateway" for a specific instance. 89 90 The following examples are correct:: 91 92 - Gateway API is a subproject of Kubernetes SIG Network. 93 - Cilium is conformant to the Gateway API spec at version X.Y.Z. 94 - In order to expose this service, create a Gateway to hold the listener configuration. 95 - Traffic from the Internet passes through the gateway to get to the backend service. 96 - Now that you have created the "foo" gateway, you need to create some Routes. 97 98 But the following examples are incorrect:: 99 100 - The implementation of gateway API 101 - To create a gateway object, ... 102 103 .. _the section on capitalization for API objects: https://kubernetes.io/docs/contribute/style/style-guide/#use-upper-camel-case-for-api-objects 104 .. _UpperCamelCase: https://en.wikipedia.org/wiki/Camel_case 105 .. _sentence-style capitalization: https://docs.microsoft.com/en-us/style-guide/text-formatting/using-type/use-sentence-style-capitalization 106 107 .. _docs_style_code_blocks: 108 109 Code blocks 110 ----------- 111 112 Code snippets and other literal blocks usually fall under one of those three 113 categories: 114 115 - They contain `substitution references`_ (for example: ``|SCM_WEB|``). In that 116 case, always use the ``.. parsed-literal`` directive, otherwise the token 117 will not be substituted. 118 119 Prefer: 120 121 .. code-block:: rst 122 123 .. parsed-literal:: 124 125 $ kubectl create -f \ |SCM_WEB|\/examples/minikube/http-sw-app.yaml 126 127 128 Avoid: 129 130 .. code-block:: rst 131 132 .. code-block:: shell-session 133 134 $ kubectl create -f \ |SCM_WEB|\/examples/minikube/http-sw-app.yaml 135 136 - If the text is not a code snippet, but just some fragment that should be 137 printed verbatim (for example, the unstructured output of a shell command), 138 use the marker for `literal blocks`_ (``::``). 139 140 Prefer: 141 142 .. code-block:: rst 143 144 See the output in ``dmesg``: 145 146 :: 147 148 [ 3389.935842] flen=6 proglen=70 pass=3 image=ffffffffa0069c8f from=tcpdump pid=20583 149 [ 3389.935847] JIT code: 00000000: 55 48 89 e5 48 83 ec 60 48 89 5d f8 44 8b 4f 68 150 151 See more output in ``dmesg``:: 152 153 [ 3389.935849] JIT code: 00000010: 44 2b 4f 6c 4c 8b 87 d8 00 00 00 be 0c 00 00 00 154 [ 3389.935850] JIT code: 00000020: e8 1d 94 ff e0 3d 00 08 00 00 75 16 be 17 00 00 155 156 Avoid: 157 158 .. code-block:: rst 159 160 See the output in ``dmesg``: 161 162 .. parsed-literal:: 163 164 [ 3389.935842] flen=6 proglen=70 pass=3 image=ffffffffa0069c8f from=tcpdump pid=20583 165 [ 3389.935847] JIT code: 00000000: 55 48 89 e5 48 83 ec 60 48 89 5d f8 44 8b 4f 68 166 167 The reason is that because these snippets contain no code, there is no need 168 to mark them as code or parsed literals. The former would tell Sphinx to 169 attempt to apply syntax highlight, the second would tell it to look for |RST| 170 markup to parse in the block. 171 172 - If the text contained code or structured output, use the ``.. code-block`` 173 directive. Do *not* use the ``.. code`` directive, which is slightly less 174 flexible. 175 176 Prefer: 177 178 .. code-block:: rst 179 180 .. code-block:: shell-session 181 182 $ ls 183 cilium 184 $ cd cilium/ 185 186 Avoid: 187 188 .. code-block:: rst 189 190 .. parsed-literal:: 191 192 $ ls 193 cilium 194 $ cd cilium/ 195 196 .. code-block:: bash 197 198 $ ls 199 cilium 200 $ cd cilium/ 201 202 .. code-block:: shell-session 203 204 ls 205 cilium 206 cd cilium/ 207 208 The ``.. code-block`` directive should always take a language name as 209 argument, for example: ``.. code-block:: yaml`` or ``.. code-block:: 210 shell-session``. The use of ``bash`` is possible but should be limited to 211 Bash scripts. For any listing of shell commands, and in particular if the 212 snippet mixes commands and their output, use ``shell-session``, which will 213 bring the best coloration and may trigger the generation of the ``Copy 214 commands`` button. 215 216 For snippets containing shell commands, in particular if they also contain the 217 output for those commands, use prompt symbols to prefix the commands. Use ``$`` 218 for commands to run as a normal user, and ``#`` for commands to run with 219 administrator privileges. You may use ``sudo`` as an alternative way to mark 220 commands to run with privileges. 221 222 .. _substitution references: https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#substitution-references 223 .. _literal blocks: https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#literal-blocks 224 225 Links 226 ----- 227 228 - Avoid using `embedded URIs`_ (```... <...>`__``), which make the document 229 harder to read when looking at the source code of the documentation. Prefer 230 to use `block-level hyperlink targets`_ (where the URI is not written 231 directly in the sentence in the |RST| file, below the paragraph). 232 233 Prefer: 234 235 .. code-block:: rst 236 237 See the `documentation for Cilium`_. 238 239 Here is another link to `the same documentation <cilium documentation>`_. 240 241 .. _documentation for Cilium: 242 .. _cilium documentation: https://docs.cilium.io/en/latest/ 243 244 Avoid: 245 246 .. code-block:: rst 247 248 See the `documentation for Cilium <https://docs.cilium.io/en/latest/>`__. 249 250 - If using embedded URIs, use anonymous hyperlinks (```... <...>`__`` with two 251 underscores, see the documentation for `embedded URIs`_) instead of named 252 references (```... <...>`_``, note the single underscore). 253 254 Prefer (but see previous item): 255 256 .. code-block:: rst 257 258 See the `documentation for Cilium <https://docs.cilium.io/en/latest/>`__. 259 260 Avoid: 261 262 .. code-block:: rst 263 264 See the `documentation for Cilium <https://docs.cilium.io/en/latest/>`_. 265 266 .. _embedded URIs: https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#embedded-uris-and-aliases 267 .. _block-level hyperlink targets: https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#hyperlink-targets 268 269 Lists 270 ----- 271 272 - Left-align the body of a list item with the text on the first line, after the 273 item symbol. 274 275 Prefer: 276 277 .. code-block:: rst 278 279 - The text in this item 280 wraps of several lines, 281 with consistent indentation. 282 283 Avoid: 284 285 .. code-block:: rst 286 287 - The text in this item 288 wraps on several lines 289 and the indent is not consistent 290 with the first line. 291 292 - For enumerated lists, prefer auto-numbering with the ``#.`` marker rather 293 than manually numbering the sections. 294 295 Prefer: 296 297 .. code-block:: rst 298 299 #. First item 300 #. Second item 301 302 Avoid: 303 304 .. code-block:: rst 305 306 1. First item 307 2. Second item 308 309 - Be consistent with periods at the end of list items. In general, omit periods 310 from bulleted list items unless the items are complete sentences. But if one 311 list item requires a period, use periods for all items. 312 313 Prefer: 314 315 .. code-block:: rst 316 317 - This is one list item 318 - This is another list item 319 320 Avoid: 321 322 .. code-block:: rst 323 324 - This is one list item, period. We use punctuation. 325 - This list item should have a period too, but doesn't 326 327 Callouts 328 -------- 329 330 Use callouts effectively. For example, use the ``.. note::`` directive to 331 highlight information that helps users in a specific context. Do not use it to 332 avoid refactoring a section or paragraph. 333 334 For example, when adding information about a new configuration flag that 335 completes a feature, there is no need to append it as a note, given that it 336 does not require particular attention from the reader. Avoid the following: 337 338 .. parsed-literal:: 339 340 Blinking pods are easier to spot in the dark. Use feature flag 341 \`\`--blinking-pods\`\` to make new pods blink twice when they launch. If 342 you create blinking pods often, sunglasses may help protect your eyes. 343 344 **\.. note:: 345 346 Use the flag \`\`--blinking-pods-blink-number\`\` to change the number 347 of times pods blink on start-up.** 348 349 Instead, merge the new content with the existing paragraph: 350 351 .. parsed-literal:: 352 353 Blinking pods are easier to spot in the dark. Use feature flag 354 \`\`--blinking-pods\`\` to make new pods blink when they launch. **By 355 default, blinking pods blink twice, but you can use the flag 356 \`\`--blinking-pods-blink-number\`\` to specify how many times they blink 357 on start-up.** If you create blinking pods often, sunglasses may help 358 protect your eyes. 359 360 Roles 361 ----- 362 363 - We have a dedicated role for referencing Cilium GitHub issues, to reference 364 them in a consistent fashion. Use it when relevant. 365 366 Prefer: 367 368 .. code-block:: rst 369 370 See :gh-issue:`1234`. 371 372 Avoid: 373 374 .. code-block:: rst 375 376 See `this GitHub issue <https://github.com/cilium/cilium/issues/1234>`__. 377 378 Common pitfalls 379 --------------- 380 381 There are best practices for writing documentation; follow them. In general, 382 default to the `Kubernetes style guide`_, especially for `content best 383 practices`_. The following subsections cover the most common feedback given for 384 Cilium documentation Pull Requests. 385 386 Use active voice 387 ~~~~~~~~~~~~~~~~ 388 389 Prefer:: 390 391 Enable the flag. 392 393 Avoid:: 394 395 Ensure the flag is enabled. 396 397 Use present tense 398 ~~~~~~~~~~~~~~~~~ 399 400 Prefer:: 401 402 The service returns a response code. 403 404 Avoid:: 405 406 The service will return a response code. 407 408 Address the user as "you", not "we" 409 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 410 411 Prefer:: 412 413 You can specify values to filter tags. 414 415 Avoid:: 416 417 We'll specify this value to filter tags. 418 419 Use plain, direct language 420 ~~~~~~~~~~~~~~~~~~~~~~~~~~ 421 422 Prefer:: 423 424 Always configure the bundle explicitly in production environments. 425 426 Avoid:: 427 428 It is recommended to always configure the bundle explicitly in production environments. 429 430 Write for good localization 431 ~~~~~~~~~~~~~~~~~~~~~~~~~~~ 432 433 Assume that what you write will be localized with machine translation. Figures 434 of speech often localize poorly, as do idioms like "above" and "below". 435 436 Prefer:: 437 438 The following example 439 To assist this process, 440 441 Avoid:: 442 443 The example below 444 To give this process a boost, 445 446 Define abbreviations 447 ~~~~~~~~~~~~~~~~~~~~ 448 449 Define abbreviations when you first use them on a page. 450 451 Prefer:: 452 453 Certificate authority (CA) 454 455 Avoid:: 456 457 CA 458 459 Don't use Latin abbreviations 460 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 461 462 Prefer:: 463 464 - For example, 465 - In other words, 466 - by following the ... 467 - and others 468 469 Avoid:: 470 471 - e.g. 472 - i.e. 473 - via 474 - etc. 475 476 Spell words fully 477 ~~~~~~~~~~~~~~~~~ 478 479 Prefer:: 480 481 and 482 483 Avoid:: 484 485 & 486 487 .. _Kubernetes style guide: https://kubernetes.io/docs/contribute/style/style-guide/ 488 .. _content best practices: https://kubernetes.io/docs/contribute/style/style-guide/#content-best-practices 489 490 Specific language 491 ----------------- 492 493 Use specific language. Avoid words like "this" (as a pronoun) and "it" when 494 referring to concepts, actions, or process states. Be as specific as possible, 495 even if specificity seems overly repetitive. This requirement exists for two 496 reasons: 497 498 1. Indirect language assumes too much clarity on the part of the writer and too 499 much understanding on the part of the reader. 500 501 2. Specific language is easier to review and easier to localize. 502 503 Words like "this" and "it" are indirect references. For example: 504 505 .. code-block:: rst 506 507 Feature A requires all pods to be painted blue. This means that the Agent 508 must apply its "paint" action to all pods. To achieve this, use the dedicated 509 CLI invocation. 510 511 In the preceding paragraph, the word "this" indirectly references both an 512 inferred consequence ("this means") and a desired goal state ("to achieve 513 this"). Instead, be as specific as possible: 514 515 .. code-block:: rst 516 517 Feature A requires all pods to be painted blue. Consequently, the Agent must 518 apply its "paint" action to all pods. To make the Agent paint all pods blue, 519 use the dedicated CLI invocation. 520 521 The following subsections contain more examples. 522 523 Use specific wording rather than vague wording 524 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 525 526 Prefer:: 527 528 For each core, the Ingester attempts to spawn a worker pool. 529 530 Avoid:: 531 532 For each core, it attempts to spawn a worker pool. 533 534 Use specific instructions rather than vague instructions 535 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 536 537 Prefer:: 538 539 Set the annotation value to remote. 540 541 Avoid:: 542 543 Set it to remote.