blob: 3090aa4899eeb87ca645be670efdee3de6018b5f [file] [log] [blame]
Julian Halle76ade82020-11-25 03:07:21 +01001Coding Style & Guidelines
2=========================
3
4The following sections contain |TS| coding guidelines. They are continually evolving and should not be considered "set
5in stone". Feel free to question them and provide feedback.
6
7The |TS| project uses multiple "domains" (textual content types, like programming languages) and each defines its own
8rules.
9
10To help configuring text editors the project comes with "`EditorConfig`_" file(s). (:download:`../../.editorconfig`).
11
12Shared rules
13------------
14
15The 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
22C Domain
23--------
24
25C source code rules are base on the *Linux Coding Style* (See: |LCS|). The following deviations apply:
26
275. |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
36Boring stuff is not for smart people and the project uses the `Uncrustify`_ code beautifier to easy formatting the
37source. (See :download:`../../.uncrustify.cfg`)
38
39CMake domain
40------------
41
4211. 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
58Restructured Text Domain
59------------------------
60
61Please 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
73SPDX-License-Identifier: BSD-3-Clause