codeforgermany / click_that_hood

A game where users must identify a city's neighborhoods as fast as possible
http://click-that-hood.com
MIT License
450 stars 639 forks source link

Use Prettier instead of JSHint and format all files accordingly #318

Closed fnogatz closed 3 years ago

fnogatz commented 3 years ago

Following the comment in #308, I would suggest to use Prettier to consistently format all files, in particular our JavaScript as well as the JSON metadata files. I don't think we should stick to JSHint for static code analysis, so I completely removed it.

specious commented 3 years ago

It looks like prettier is configurable. I'd recommend keeping the configuration consistent with what jq outputs by default. A lot of people use jq.

fnogatz commented 3 years ago

I like the idea to be compatible with the output of jq. I ran all metadata JSON files through it, which effectively removed all empty lines. It seems that the output of jq and Prettier is only slightly different when it comes to arrays: "neighborhoodNoun": ["district", "districts"] is printed in a single line via Prettier and on multiple lines using jq. This behaviour can't be changed with Prettier's configuration settings. Thus I would stick to its defaults.

specious commented 3 years ago

I just checked it out and I think I see what's going on. jq breaks arrays up invariably, which in the case of point coordinates with two elements is a bit unnecessary:

      },
      "geometry": {
        "type": "MultiPolygon",
        "coordinates": [
          [
            [
              [
                7.578687,
                51.635618
              ],
              [
                7.575789,
                51.633743
              ],
              [
                7.574241,
                51.633811
              ],

Technically, jq isn't really meant to be so much of a pretty printer as it is a json parsing and processing tool. Formatting JSON by default is just one of its features.

Taking this into account, prettier definitely has an edge over jq in this case.