Tl;Dr: Make use of the Ask question warnings to reduce the misuse of Stack Snippets. Automatically run it in the background when the user click the "Review your questions button", if there is an error then show a warning.
On google-apps-script I often find questions using stack-snippets with obvious mistakes
- Added JavaScript in the HTML section
- Added HTML in the JavaScript section
Based on posts from 2014 and probably other more recent, other tags that might commonly have questions using Stack Snippets with obvious mistakes that aren't the subject of what is being asked.
Another misuse that might appear nou so obviou but that might be easily caught by running the Stack Snippet, is using non standard methods without including the corresponding API or that belong to an unsupported platform, i.e. Google Apps Script methods like SpreadsheetApp.getActiveSpreadsheet()
.
I think that the frequency of mistakes like these could be reduced without having to invest too much on ux-research-time / design / user-experience by making use to the warning-message / tip-warnings / quality-filter features when a question is composed.
One "crazy idea" is to automatically trigger the Stack Snippet "run" button in the background and showing a warning if there was an error thrown.
While reviewing this feature request it might be worthy to consider consider the implications of showing warnings when
- javascript, html or css aren't included based just on the Stack Snippet code blocks used... i.e., it the HTML block has any content show a warning if the html is missing.
- the HTML section isn't empty but doesn't include HTML tags but include very typical JavaScript script estatements patterns like variable declarations, i.e. line starting with
var
,let
,const
followed by a word followed by a=
.class
followed by word followed by{
.function
followed by a word, followed by(
,)
,{
.
- the JavaScript section isn't empty but include very typical HTML patterns like
- a line starting
<
followed by a word, followed by one of more typical attributes,id
,href
,src
, and ending with>
.
- a line starting
Something "easier" to implement from a coding perspective but not from the overall solution development perspective as it will require to involve a larger team be is to make that the "Ask Question Wizard" asks the OP to run the Stack Snippet and fix any error before posting the question unless that the purpose of the code is to show the error. For first time askers, show a warning if there was an error.
Related feature-requests
- Warning if using jQuery in snippet and jQuery not tagged/used in question, from 2014, votes +26
- Replace code snippets by normal code block if JavaScript tag is absent, from 2014, votes +54
- Warning when snippet mark-up is used on posts not tagged with <...>, from 2015, votes +35
- Code snippets are a pest (make more obvious are only for JS/HTML/CSS and add a button to automatically remove stack snippets), from 2016, votes +99
- Should Guided Mode allow snippets?, from 2019, votes +20
Related