4b23e98fb0
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. |
||
---|---|---|
.. | ||
.gitattributes | ||
.gitignore | ||
bootstrap_upip.sh | ||
build-stm-latest.sh | ||
cc1 | ||
check_code_size.sh | ||
codeformat.py | ||
codestats.sh | ||
dfu.py | ||
file2h.py | ||
gen-changelog.sh | ||
gen-cpydiff.py | ||
gendoc.py | ||
insert-usb-ids.py | ||
make-frozen.py | ||
makemanifest.py | ||
metrics.py | ||
mpy_bin2res.py | ||
mpy_cross_all.py | ||
mpy_ld.py | ||
mpy-tool.py | ||
pyboard.py | ||
pydfu.py | ||
tinytest-codegen.py | ||
uf2conv.py | ||
uncrustify.cfg | ||
upip_utarfile.py | ||
upip.py |