9

Let's say that there is existing issue with the web code and OP is trying to describe the problem. He enters code for JS/HTML/CSS file as 3 separate code blocks (sometimes more).

Examples:

  • show image, which is based on his local resources (N/A on SO page)
  • there is typo (missing bracket, pair-tag not ended) and result not renders properly
  • (edit more if there are ideas please)

Should we spend the time to move the code into the snippet? Should these edits be approved?

1
  • 1
    Also if the question explicitly states that the code isn't meant to work and is just an illustration, don't be surprised if you convert it and find that it doesn't work...
    – BoltClock
    Commented May 12, 2018 at 0:58

1 Answer 1

16

The rule is:

Don't change the behavior of his code

If his code is missing a { or , don't add it as this may be the cause of the issue, thus the asked question. But if there is some local images and the issue is not related to these images you may update the links to use placeholder one.

We need also to pay attention to the order, if the OP shared different blocks of code including JS, don't add a snippet unless you are sure about the order of his code. Maybe he's having an issue because he's including the JS before the HTML.


For me adding a snippet should be done if and only if these conditions are present:

  • The OP shared his full code including all the relevant HTML/CSS/JS.
  • The converted snippet should reflect the behavior described by the OP even if it's an error.

Some of the edits I usually do when converting to snippet:

  • Remove html, body,head tags and doctype declaration
  • Remove useless comments
  • Remove unused CSS declaration
  • Add missing libraries only when am sure about them
  • In some rare cases, I add minor styles like border or background to better highlight some behaviors (overflow, width, etc).


UPDATE

For users with reputation <2K better avoid some of the above edits as they may get rejected because we may have significant difference between the initial code and the final code even if at the end the output is still the same.

1
  • 4
    While the question wasn't about making any changes to the code - but simply taking it and converting it into a Stack Snippet, this is relevant advice regardless, since I can imagine some editors naïvely clicking tidy on the code or fixing errors not remembering they're not supposed to.
    – BoltClock
    Commented May 12, 2018 at 0:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .