Yes.
However, and it's a big however, you need to make sure that you don't alter the code in any other way. It's probably not quite as important here as it is on Stack Overflow, but editing code carries the risk that you might edit away the very problem that the OP is asking about.
Also, the poor formatting won't be the only thing that's wrong with the question so address and other issues like spelling, grammar and formatting of the explanatory text too.
And be prepared for your edit to be rejected if the reviewers think you've changed the code too much.