The Tidy button is adding spaces before and after any question mark that is part of an optional chaining operator (?.). This breaks optional chaining. It appears to be recognizing question marks as being part of a ternary operator instead:

test={ func(){} }


test = { func(){} }

// optional chaining operator ?. gets separated when using Tidy
test ? .func()

Tidy button:

Snippet editor with Tidy button circled

I am not sure if bug report or feature request, since optional chaining is a relatively recent ES.Next feature.

  • If anyone can make better judgment on if this counts as a bug report, feel free to re-tag it. Optional chaining is a stage-4 proposal already, but it's still relatively new, so I'd probably consider it a low-priority feature request.
    – user120242
    Commented May 21, 2020 at 22:28
  • What does "tidy" mean in this context? Commented May 22, 2020 at 0:30
  • 2
    @P.Mort.-forgotClayShirky_q The code beautifier button that uses Tidy to reformat the code in snippets. Use "Copy snippet to answer" and then "edit the above snippet", then press the "Tidy" button. You will see that it reformats ?. to ? ., breaking the first code segment (the second segment is already broken to show what Tidy does). If you can format my question so that it's easier to see/understand feel free to edit it for clarity.
    – user120242
    Commented May 22, 2020 at 0:32
  • 1
    @user120242 I updated your question a bit with more details. Hope it makes it more clear especially since non-programmers may be on this site. Feel free to roll back if you don't agree with them. Commented May 22, 2020 at 0:56
  • Nice edit. Maybe it would help if I there were separate snippets for working code vs broken code after using Tidy?
    – user120242
    Commented May 22, 2020 at 1:18
  • hmm in my opinion it's clear from your code comment what happens before and after so I think it's fine as is. You can do that if you feel it would be more clear though. Commented May 22, 2020 at 1:39
  • Ah okay, I'm also wondering if I put it in the wrong place? Maybe this should go on Meta Stack Overflow, since it's primarily for the coders? Stack Exchange also has snippets though, so maybe it belongs here?
    – user120242
    Commented May 22, 2020 at 1:54
  • 1
    That's my thought too, the stack snippets are available in other stack exchange sites (not just stack overflow) so I think it's fine here. Commented May 22, 2020 at 4:09
  • Cross site duplicate on MSO: "tidy button on SO code snippet tool breaks optional chaining in JS code" and related: "Update JS-Beautify Snippet formatter" (previously mentioned)
    – Makyen
    Commented Aug 21, 2022 at 1:00


You must log in to answer this question.

Browse other questions tagged .