Chapter 6. Contributions Guide
6.4 Legal Part
Before a contribution can be accepted, you will need to sign our Contributor Agreement. You will be prompted for
this automatically as part of the Pull Request process.
6.5 Related Documents
6.5.1 Espressif IoT Development Framework Style Guide
About This Guide
Purpose of this style guide is to encourage use of common coding practices within the ESP-IDF.
Style guide is a set of rules which are aimed to help create readable, maintainable, and robust code. By writing
code which looks the same way across the code base we help others read and comprehend the code. By using same
conventions for spaces and newlines we reduce chances that future changes will produce huge unreadable diffs. By
following common patterns for module structure and by using language features consistently we help others understand
code behavior.
We try to keep rules simple enough, which means that they can not cover all potential cases. In some cases one has
to bend these simple rules to achieve readability, maintainability, or robustness.
When doing modifications to third-party code used in ESP-IDF, follow the way that particular project is written. That
will help propose useful changes for merging into upstream project.
C Code Formatting
Naming
• Any variable or function which is only used in a single source file should be declared static.
• Public names (non-static variables and functions) should be namespaced with a per-component or per-unit
prefix, to avoid naming collisions. ie esp_vfs_register() or esp_console_run(). Starting the
prefix with esp_ for Espressif-specific names is optional, but should be consistent with any other names in the
same component.
• Static variables should be prefixed with s_ for easy identification. For example, static bool s_invert.
• Avoid unnecessary abbreviations (ie shortening data to dat), unless the resulting name would otherwise be
very long.
Indentation Use 4 spaces for each indentation level. Don’t use tabs for indentation. Configure the editor to emit
4 spaces each time you press tab key.
Vertical Space Place one empty line between functions. Don’t begin or end a function with an empty line.
void function1()
{
do_one_thing();
do_another_thing();
// INCORRECT, don't place empty line here
}
// place empty line here
void function2()
{
// INCORRECT, don't use an empty line here
int var = 0;
while (var < SOME_CONSTANT) {
do_stuff(&var);
(continues on next page)
Espressif Systems 1568
Submit Document Feedback
Release v4.4