Julian Hall | e76ade8 | 2020-11-25 03:07:21 +0100 | [diff] [blame^] | 1 | Coding Style & Guidelines |
| 2 | ========================= |
| 3 | |
| 4 | The following sections contain |TS| coding guidelines. They are continually evolving and should not be considered "set |
| 5 | in stone". Feel free to question them and provide feedback. |
| 6 | |
| 7 | The |TS| project uses multiple "domains" (textual content types, like programming languages) and each defines its own |
| 8 | rules. |
| 9 | |
| 10 | To help configuring text editors the project comes with "`EditorConfig`_" file(s). (:download:`../../.editorconfig`). |
| 11 | |
| 12 | Shared rules |
| 13 | ------------ |
| 14 | |
| 15 | The following rules are common for all domains, except where noted otherwise: |
| 16 | |
| 17 | #. Files shall be **UTF-8** encoded. |
| 18 | #. Use **Unix** style line endings (``LF`` character) |
| 19 | #. The primary language of the project is English. All comments and documentation must be in this language. |
| 20 | #. Trailing whitespace is not welcome, please trim these. |
| 21 | |
| 22 | C Domain |
| 23 | -------- |
| 24 | |
| 25 | C source code rules are base on the *Linux Coding Style* (See: |LCS|). The following deviations apply: |
| 26 | |
| 27 | 5. |TS| follows *ISO/IEC 9899:1999* standard with |ACLE| version *Q3 2020* extensions. |
| 28 | #. Line length shall not exceed 100 characters. |
| 29 | #. Use `snake_case`_ for function, variable and file names. |
| 30 | #. Each file shall be "self contained" and include header files with external dependencies. No file shall depend on |
| 31 | headers included by other files. |
| 32 | #. Include ordering: please include project specific headers first and then system includes. Please order the files |
| 33 | alphabetically in the above two groups. |
| 34 | #. All variables must be initialized. |
| 35 | |
| 36 | Boring stuff is not for smart people and the project uses the `Uncrustify`_ code beautifier to easy formatting the |
| 37 | source. (See :download:`../../.uncrustify.cfg`) |
| 38 | |
| 39 | CMake domain |
| 40 | ------------ |
| 41 | |
| 42 | 11. CMake file names use `CamelCase`_ style. |
| 43 | #. Indent with tabs and otherwise use spaces. Use 4 spaces for tab size. |
| 44 | #. Use LF as line end in CMake files. |
| 45 | #. Remove trailing whitespace. |
| 46 | #. Maximum line length is 128 characters. |
| 47 | #. When complicated functionality is needed prefer CMake scripting over other languages. |
| 48 | #. Prefix local variables with `_`. |
| 49 | #. Use functions to prevent global name-space pollution. |
| 50 | #. Use `snake_case`_ for function and variable names. |
| 51 | #. Use the ``include_guard()`` CMake function when creating new modules, to prevent multiple inclusion. |
| 52 | #. Use self contained modules, i.e. include direct dependencies of the module. |
| 53 | #. Use the Sphinx CMake domain for in-line documentation of CMake scripts. For details please refer to the |
| 54 | `CMake Documentation`_. |
| 55 | |
| 56 | .. todo:: Explain CMake return values and parent scope concept in more detail. |
| 57 | |
| 58 | Restructured Text Domain |
| 59 | ------------------------ |
| 60 | |
| 61 | Please refer to :doc:`/developer/writing-documentation`. |
| 62 | |
| 63 | -------------- |
| 64 | |
| 65 | .. _`CamelCase`: https://hu.wikipedia.org/wiki/CamelCase |
| 66 | .. _`snake_case`: https://en.wikipedia.org/wiki/Snake_case |
| 67 | .. _`CMake Documentation`: https://github.com/Kitware/CMake/blob/master/Help/dev/documentation.rst |
| 68 | .. _`EditorConfig`: https://editorconfig.org/ |
| 69 | .. _`Uncrustify`: https://github.com/uncrustify/uncrustify |
| 70 | |
| 71 | *Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.* |
| 72 | |
| 73 | SPDX-License-Identifier: BSD-3-Clause |