Just wondering how other open-source developers deal with valid by badly-written pull requests.
I usually work closely with the PR author, giving them multiple rounds of suggestions until it's up to our project's coding standards. Sometimes the PR author "drops out" of the process in frustration, as they were just trying to give us a quick fix, and didn't necessarily want to do a lot of work. In those cases, I usually thank them, and rewrite the PR (or heavily modify it). But I'm hesitant to do this in all cases, because often the PR author is excited to see their name as part of the contributors list, and/or to see their own code used in the project.
How so you deal with this kind of thing?
It's up to the PR's author to decide if they care enough to do better next time. By accepting their work and landing the change you've demonstrated an appreciation for their effort with open arms, and I feel this makes it more likely they will contribute in the future and care about doing better.
Maybe make a comment to that effect before merging as-is, creating the opportunity to clean it up themselves first.
If it's coming from a regular contributor I'm far less charitable, this approach I mostly reserve for first-time/infrequent contributors.