summaryrefslogtreecommitdiffstatshomepage
path: root/py
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2020-02-14 11:42:44 +1100
committerDamien George <damien.p.george@gmail.com>2020-02-28 10:14:28 +1100
commit4b23e98fb0851eb74ec269022a1e86702e387b23 (patch)
tree3fa109f47b417fc177ff3b64bcb5d0b438e49dc9 /py
parentb169904254de8b206703c9c5166659d113255d53 (diff)
downloadmicropython-4b23e98fb0851eb74ec269022a1e86702e387b23.tar.gz
micropython-4b23e98fb0851eb74ec269022a1e86702e387b23.zip
tools/codeformat.py: Add formatter using uncrustify for C, black for Py.
This commit adds a tool, codeformat.py, which will reformat C and Python code to fit a certain style. By default the tool will reformat (almost) all the original (ie not 3rd-party) .c, .h and .py files in this repository. Passing filenames on the command-line to codeformat.py will reformat only those. Reformatting is done in-place. uncrustify is used for C reformatting, which is available for many platforms and can be easily built from source, see https://github.com/uncrustify/uncrustify. The configuration for uncrustify is also added in this commit and values are chosen to best match the existing code style. A small post-processing stage on .c and .h files is done by codeformat.py (after running uncrustify) to fix up some minor items: - space inserted after * when used as multiplication with sizeof - #if/ifdef/ifndef/elif/else/endif are dedented by one level when they are configuring if-blocks and case-blocks. For Python code, the formatter used is black, which can be pip-installed; see https://github.com/psf/black. The defaults are used, except for line- length which is set at 99 characters to match the "about 100" line-length limit used in C code. The formatting tools used and their configuration were chosen to strike a balance between keeping existing style and not changing too many lines of code, and enforcing a relatively strict style (especially for Python code). This should help to keep the code consistent across everything, and reduce cognitive load when writing new code to match the style.
Diffstat (limited to 'py')
0 files changed, 0 insertions, 0 deletions