mvnmgrx / kiutils

Simple and SCM-friendly KiCad file parser based on Python dataclasses for KiCad 6.0 and up.
GNU General Public License v3.0
81 stars 27 forks source link

You may want to put your output through an s-expression formatter #121

Open mofosyne opened 1 month ago

mofosyne commented 1 month ago

While debugging a bug in kiutils. I've written up a https://gist.github.com/mofosyne/93ad8d64fb40ef80f6af3b09dc755414 s-expression formatter for it.

It mostly matches the current KiCADv8 s-expression styling but diverges from KiCADv8's output style in that the 'xy' element inside 'pts' is also indented on a new line. This is because KiCADv8's styling rule is not consistent specifically regarding the 'pts' element.

But aside from that, it matches close enough to be useful as a 'output' cleaner for your utility, so you may want to consider piping your output though this at least.


This also provides an additional opportunity for testing your function. If you get a valid KiCADv8 document and you then lint it and also formatter the output of your kiutils then you will be able to do an automated diff to make sure there is no regression introduced.

This is because if I do not make any changes to a document then opening/saving the document should emit the same output.

mofosyne commented 1 month ago

Made further cleanup of the script and placed it in this repo now https://github.com/mofosyne/sexp_formatter so reference this when you want to port it over.