I'm not sure what you're using to edit, but a good text editor with color-coding and highlighting can be really useful in avoiding this stuff and tracking it down when it happens.
I use Notepad++ and Vim (when I have to edit via an SSH terminal). I've heard good things about Visual Studio Code too