There has been a fair bit of discussion about how "bad" code in answers can be dealt with - particularly as, once it is published it can be hard to remove. However "best answers" seem to have a degree of subjectivity surrounding them, so moderating for the avoidance of "bad" answers is not as obvious as it seems. What is not subjective though, is the long term effect of answers in the repository which contain potentially harmful code.
There are many systems for testing scripts and I wonder whether there might be any usefulness in adding an automated filter to all published code - to check that it is runnable and "safe" - rather like https://runnable.io/ though not, perhaps as comprehensive.
It could be assessed for potential attack vectors:
and compared to a database of known bad practices (for example the misuse of a function like
$.eval). Such a system could flag "bad" code in answers before it ever saw the light of day and reduce the frustration of OPs who get offered code snippets which will not run and cause even more confusion.
I don't think anyone deliberately posts "bad" code but perhaps such a tool might increase consciousness and help where perhaps there is no method available to test code at the time of posting in the hope that it will be OK.
The race to answer new questions and, accordingly, gain reputation has been discussed, and benefits of "quick and dirty" answers do exist, it seems: Fastest Gun in the West Problem but possibly a tool like this might help all of us improve even the code we produce in a hurry to give that quick answer.
Clearly, with two-and-a-half million users, manual moderation by the community itself seems a problematic expectation going forward and automation could, perhaps, be a part of a solution to that. Should we peer review questions before publishing them? and Add Peer-Reviewed Answer
Would it be feasible or desirable in the interest of safe coding?