Use a code formatter!
That’s it. That’s the whole post. If you’re writing code, you should probably assure that it’s formatted to some kind of standard. That’s what formatters do. They will style your code according to best practices so that you don’t have to worry about it.
While there are various opinions on what is best, I recommend black for Python and prettier for JavaScript, although of course there are other possibilities. Whatever language you are using will almost certainly have some options.
That is all. Thank you for your attention :)