← index #10751PR #5700
Related · high · value 1.842
QUERY · ISSUE

codeformat.py bug

openby mbedNoobNinjaopened 2023-02-14updated 2024-09-01
bug

Description:

When codeformat.py formats *.h or *.c files (#10595) , it reduces file content by deleting not only formating symbols and whitespaces but also the code being formated!

before_codeformat.txt
after_codeformat.txt

and while working on before_codeformat.h codformat.py gives the folowing error:

Parsing: ..\ports\renesas-ra\boards\VK_RA4W1\ra_cfg\fsp_cfg\bsp\bsp_cfg.h as language C
Traceback (most recent call last):
   File "D:\micropython\tools\codeformat.py", line 218, in <module>
     main()
   File "D:\micropython\tools\codeformat.py", line 205, in main
     fixup_c(file)
   File "D:\micropython\tools\codeformat.py", line 136, in fixup_c
     if dedent_stack[-1] >= 0:
        ~~~~~~~~~~~~^^^^
IndexError: list index out of range

Environment:

OS Win 10 (22H2)
Uncrustify 0.72.0_f
Python 3.11.1
Package Version
black 22.12.0
click 8.1.3
colorama 0.4.6
mypy-extensions 0.4.3
pathspec 0.11.0
pip 23.0
platformdirs 2.6.2
pyserial 3.5
setuptools 65.5.0
CANDIDATE · PULL REQUEST

Reformat C and Python source code using uncrustify and black

mergedby dpgeorgeopened 2020-02-26updated 2020-03-01

This PR combines #5691 (uncrustify for C) and #5699 (black for Python) to reformat the majority of the code in this repository. See discussion in #4223 for further background.

The script tools/codeformat.py does the formatting, and run without args will format everything. Run with args it will format just the given files.

I'm pretty happy with this now, IMO it strikes a good balance between keeping existing style and not changing too many lines, and enforcing a relatively strict style (especially for Python code).

Thanks to @jimmo for helping with codeformat.py and fine tuning uncrustify options.


I intend to merge this very soon. If anyone has any comments then please make them ASAP so they can be addressed.

FYI @stinos @Jongy @tannewt @MrSurly @codefreax @dlech @dhalbert

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied