Sublime Forum

ST3 Default theme is has subtle syntax error

#1

FYI, the Default theme in ST3 (build 3009) contains a syntax error. I found this when I was trying to modify a copy of it and couldn’t figure out
why some changes weren’t getting applied. Down around line 308:

    {
        "class": "panel_close_button",
        "attributes": "hover"],
        "layer0.opacity": 0.0,
        "layer1.opacity": 1.0,
    },

The last line in the block (“layer1.opacity”) has a trailing comma, which is invalid JSON. Took me a helluva long time to find this!

0 Likes

#2

Trailing commas are allowed in Sublime Text 3.

The rationale being that we’ve already departed from the JSON spec in allowing comments, so there’s little harm in being friendly about trailing commas too.

0 Likes

#3

That would issue a challange to editing these JSON files plugin-wise. I made up the comments with some regexp that just strips them but trailing commas would be a pita. Well, I can just mark them as parse errors and let the user take care of them but this does not feel like a step to be taken even. Comments are a thing that JSON really is missing when used as a data structure where you want to comment things but trailing commas is just a hack, even though this is probably the most common error message when parsing key bindings fails.

0 Likes

#4

I could swear that the trailing comma was causing some kind of real problem with my theme, which removing it fixed. However adding it back isn’t having any visible effect (even after restarting ST3) so maybe I was hallucinating.

I have mixed feelings about ST3 supporting non-standard JSON extensions. On the one hand, I think the JSON spec is really, really boneheaded for not allowing both comments and superfluous trailing commas in the first place. It’s a major pain in the butt that it doesn’t. On the other hand it means that ST3 config files can’t be viewed or modified with tools that don’t also support the extensions. (I actually found this because I was frustrated by my theme not working and I wanted to compare it against the built-in theme element-by-element. I wrote a Python script to do so using the standard json module, which of course choked.) Comments aren’t too bad to deal with; a simple regex will strip them. Trailing commas are a bit more difficult to clean out before feeding the file to an external tool.

0 Likes