Sublime Forum

JSONComma: No need to care about them anymore!

#1

Hi!

I’ve been using this little plugin for a while now, and I think it’s worth sharing.

JSONComma is a plugin that removes trailing commas, and adds needed ones!

 {
     "hello": "world",
-    "not needed": "damn comma",
+    "not needed": "damn comma"
 }

Adds needed commas!

 {
-    "hello": "world"
-    "not needed": "damn comma"
+    "hello": "world",
+    "not needed": "damn comma",
     "aList": [
-        "hello" "world"
-        "this" "is" "a nasty ]{ example ] "
-        ["BUT" "IT" "STILL" "WORKS!!"]
+        "hello", "world",
+        "this", "is", "a nasty ]{ example ] ",
+        ["BUT", "IT", "STILL", "WORKS!!"]
     ]
 }

Matt

5 Likes

#2

Nice, I’ll probably use this. I hate forgetting commas :tired_face:

1 Like

#3

@math2001, may you add support all PackageDev syntaxes and Suricate syntax? It’s syntaxes for JSON format.

Thanks.

0 Likes

#4

@Sasha_Chernykh What do they add? Just know that JSONComma uses the scope to define it needs to add/remove a comma, so changing the syntax define could maybe mess up everything.

So, I’ll change how JSONComma defines if it’s available: it’s going to use the scope instead of the syntax definition file name. I tested for Suricate, it’s going to work.

For the the PackageDev ones, it should work too because there’s json in the scope name.

BTW, Happy new year!

1 Like

#5

@Sasha_Chernykh I pushed some commits. Could you try on your computer. It’s working on mine for the suricate syntax.

BTW, 0.1.0's out! :smile:

1 Like

#6

Thanks, JSONComma works for Suricate for me. We waiting PackageDev support. Happy New Year!

0 Likes

#7

So it’s now working with packageDev? I’ll download it and it should be easier to fix it :smile: Thanks for your time!

0 Likes

#8

Now JSONComma package successfully worked for me in Suricate, but not worked in PackageDev, for example, in Sublime Settings and Sublime Text Key Map syntaxes.

Thanks.

0 Likes

#9

:confounded: I forgot about it… I’ll do it soon (on my todo list)

0 Likes

#10

I had a look, and… there’s no “good” solution. JSONComma uses the scope (especially punctuation.definition.string.end.json) to determine whether it should remove or add a comma.

With package dev

With the normal JSON

So, there’s two solutions.

Edit package dev

It’s not hard, just push the normal JSON, and then add their edits (what are they?)

Use normal json for package dev

Open a JSON-tmLanguage and go to view -> Syntax -> Open all with current extensions as -> JavaScript -> JSON

I’ll look in the package dev to see if the first solution is possible.

Matt

0 Likes

#11

There are also other issues with PackageDev strings not containing the opening and closing quotes PackageDev#43 so creating a PR there may not be a bad idea.

1 Like

#12

Thanks for letting me know @r-stein

0 Likes

#13

I intend to rewrite all syntax definitions using .sublime-syntax, so small pull requests are unlikely to be released, because I would need to spend time on the package anyway. There are a multitude of issues with the current definitions that go beyond missing quotation punctuation scopes, although they generally “work”.

Won’t be taking too long until I find the time to do this, I hope.

1 Like

#14

@FichteFoll I’m not really good (at all) at building syntax definition, but can’t you push a syntax and add you modification “above” it?

0 Likes

#15

Technically, yes, you can push a syntax (any context, basically) and apply certain rules to each of the contexts that might be pushed as a consequence (using with_prototype). That isn’t applicable in this situation, however, since you’d end up rewriting basically the entire syntax definition anyway.

0 Likes