Is there such a thing as a LaTeX code formatter
Take a look at TeXpretty. I have used it a couple of times for cleaning up messy code and it does a decent job.
I created a website that formats the latex code to make indents look correct.
The general idea of the website is to make sure you can read the code. It also provides table indentations. I am still looking to see if adding an empty comment block for formulas is possible.
https://c.albert-thompson.com/latex-pretty/