Help with json linter


#1

Alright, so, I recently submitted a PR and then had to edit it multiple times because I suck and don’t format things the right way (yeah, I use tabs, hate me).

Anyway, I saw a lot of talk about a linter on Github but I didn’t really know what such a thing was. Is there one in the source code? If there is, I have no idea how to make it work.

But right, so I googled around and found http://dev.narc.ro/cataclysm/format.html

Is that the current web linter? Because I punched in a couple of my json from a mod I’ve been working on and all it did was correct them, rather than pointing out the errors so I could learn what the issue was. It also appeared to be inconsistent.

Specifically, I asked it to correct this entry:

[
  {
    "type" : "overmap_special",
    "id" : "Prepper Cache",
    "overmaps" : [
      { "point":[0,0,0], "overmap": "cache_main_north"},
	  { "point":[0,0,-1], "overmap": "cache_under_north"}
    ],
    "locations" : [ "forest" ], 
    "city_distance" : [20, -1],
    "city_sizes" : [0, 12],
    "occurrences" : [0, 3],
    "rotate" : false, 
    "flags" : ["CLASSIC"]
  }
]

and it just mashed all of “overmaps” onto one line, which is not how the core game files look.

So I was just wondering if that was up to date, or if there’s a different web-based linter I’m unaware of. Or, even, if someone can point me at a downloadable version of the linter I’m supposed to be using.


#2

There’s a JSON formatter in tools/format/json_formatter.cgi if you compile from source. And when I ran that JSON through it, I got:

[
  {
    "type": "overmap_special",
    "id": "Prepper Cache",
    "overmaps": [ { "point": [ 0, 0, 0 ], "overmap": "cache_main_north" }, { "point": [ 0, 0, -1 ], "overmap": "cache_under_north" } ],
    "locations": [ "forest" ],
    "city_distance": [ 20, -1 ],
    "city_sizes": [ 0, 12 ],
    "occurrences": [ 0, 3 ],
    "rotate": false,
    "flags": [ "CLASSIC" ]
  }
]

General rules of CDDA formating are documented in doc/JSON_STYLE.md (https://github.com/CleverRaven/Cataclysm-DDA/blob/482191fe75f0e58e66e0d6045fc86028758c7d76/doc/JSON_STYLE.md). The tricky bit is that short lists and objects go on a single line:

"responses": [ { "talk_topic": "TALK_DONE", "text": "Bye." } ],

But long lists and objects get split:

"responses": [
   {
     "talk_topic": "TALK_DONE",
     "text": "Well, that was really helpful.  You're definitely a shining example of post<cataclysm> humanity, you <swear> <swear> <swear>.  I hope you <swear> die.  Bye."
  }
],

The line length is supposed to be 100 characters, but the linter is unpredictable.


#3

Well, I’m having a lot of problems compiling the game. I’ll just take your word for it and get around to working that out later because I’m frustrated.

But I read the JSON_STYLE.md and I understand why it put the overmaps on a single line. Thanks for the input and I’ll mark this as a solution.