Coding Style & Guidelines

The following sections contain TS coding guidelines for different types of file. They are continually evolving and should not be considered “set in stone”. Feel free to question them and provide feedback.

To help configuring text editors the project comes with “EditorConfig” file(s). (../../.editorconfig).

Common Rules

The following rules are common for all types of text file, except where noted otherwise:

  1. Files shall be UTF-8 encoded.

  2. Use Unix style line endings (LF character)

  3. The primary language of the project is English. All comments and documentation must be in this language.

  4. Trailing whitespace is not welcome, please trim these.

C Rules

C source code rules are base on the Linux Coding Style (See: LCS). The following deviations apply:

  1. TS follows ISO/IEC 9899:1999 standard with ACLE version Q3 2020 extensions.

  2. Line length shall not exceed 100 characters.

  3. Use snake_case for function, variable and file names.

  4. Each file shall be “self contained” and include header files with external dependencies. No file shall depend on headers included by other files.

  5. Include ordering: please include project specific headers first and then system includes. Please order the files alphabetically in the above two groups.

  6. All variables must be initialized.

C source files should include a copyright and license comment block at the head of each file. Here is an example:

/*
 * Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

Boring stuff is not for smart people and the project uses the Uncrustify code beautifier to easy formatting the source. (See ../../.uncrustify.cfg)

CMake Rules

Cmake files (e.g. CMakeLists.txt and .cmake) should conform to the following rules:

  1. CMake file names use CamelCase style.

  2. Indent with tabs and otherwise use spaces. Use 4 spaces for tab size.

  3. Use LF as line end in CMake files.

  4. Remove trailing whitespace.

  5. Maximum line length is 128 characters.

  6. When complicated functionality is needed prefer CMake scripting over other languages.

  7. Prefix local variables with _.

  8. Use functions to prevent global name-space pollution.

  9. Use snake_case for function and variable names.

  10. Use the include_guard() CMake function when creating new modules, to prevent multiple inclusion.

  11. Use self contained modules, i.e. include direct dependencies of the module.

  12. Use the Sphinx CMake domain for in-line documentation of CMake scripts. For details please refer to the CMake Documentation.

Each file should include a copyright and license comment block at the head of each file. Here is an example:

#-------------------------------------------------------------------------------
# Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
#-------------------------------------------------------------------------------

Restructured Text Rules

Please refer to Writing Documentation.


Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved.

SPDX-License-Identifier: BSD-3-Clause