Chapter 6. Contributions Guide
because MSYS2 uses Unix-style line endings, it is often easier to configure your text editor to use LF (Unix style)
endings when editing ESP-IDF source files.
If you accidentally have some commits in your branch that add LF endings, you can convert them to Unix by running
this command in an MSYS2 or Unix terminal (change directory to the IDF working directory and check the correct
branch is currently checked out, beforehand):
git rebase --exec 'git diff-tree --no-commit-id --name-only -r HEAD | xargs␣
,→dos2unix && git commit -a --amend --no-edit --allow-empty' master
(Note that this line rebases on master, change the branch name at the end to rebase on another branch.)
For updating a single commit, it’s possible to run dos2unix FILENAME and then run git commit --amend
Formatting Your Code You can use astyle program to format your code according to the above recommen-
dations.
If you are writing a file from scratch, or doing a complete rewrite, feel free to re-format the entire file. If you are
changing a small portion of file, don’t re-format the code you didn’t change. This will help others when they review
your changes.
To re-format a file, run:
tools/format.sh components/my_component/file.c
Type Definitions Should be snake_case, ending with _t suffix:
typedef int signed_32_bit_t;
Enum Enums should be defined through the typedef and be namespaced:
typedef enum
{
MODULE_FOO_ONE,
MODULE_FOO_TWO,
MODULE_FOO_THREE
} module_foo_t;
Assertions The standard C assert() function, defined in assert.h should be used to check conditions that
should be true in source code. In the default configuration, an assert condition that returns false or 0 will call
abort() and trigger a Fatal Error.
assert() should only be used to detect unrecoverable errors due to a serious internal logic bug or corruption,
where it’s not possible for the program to continue. For recoverable errors, including errors that are possible due
to invalid external input, an error value should be returned.
Note: When asserting a value of type esp_err_t``is equal to ``ESP_OK, use the ESP_ERROR_CHECK
macro instead of an assert().
It’s possible to configure ESP-IDF projects with assertions disabled (see CON-
FIG_COMPILER_OPTIMIZATION_ASSERTION_LEVEL). Therefore, functions called in an assert() statement
should not have side-effects.
It’s also necessary to use particular techniques to avoid “variable set but not used”warnings when assertions are
disabled, due to code patterns such as:
Espressif Systems 1571
Submit Document Feedback
Release v4.4