dprint / dprint-plugin-json

JSON code formatting plugin for dprint.
https://dprint.dev/plugins/json
MIT License
19 stars 5 forks source link

🙏🏻[feat/req] add 'preferSingleLine' option #3

Closed rivy closed 3 years ago

rivy commented 3 years ago

Currently, for JSON elements which are split onto multiple lines, but fit into the line length, the multi-line format is always maintained. For example,

{
  "includes": ["**/*.{ts,tsx,js,jsx,cjs,mjs,json,md,rs}"],
  "excludes": [
    ".history",
    "**/node_modules"
  ]
}

won't shrink the excludes entry unless the first entry (".history") is on the initial line.

Ultimately, I'm trying to create repeatable final formatting for files which might be formatted in a different style (eg, deno or prettier). A 'preferSingleLine' option makes that an easier/possible task.

In fact, while thinking about this post, it occurs to me that a "global" version of 'preferSingleLine' indicating a default to capable plugins might be a useful option to help create the same output no matter the form (basically differing only in whitespace).

dsherret commented 3 years ago

Released in 0.11.0. Use "preferSingleLine": true or more specifically "array.preferSingleLine": true or "object.preferSingleLine": true.

In fact, while thinking about this post, it occurs to me that a "global" version of 'preferSingleLine' indicating a default to capable plugins might be a useful option to help create the same output no matter the form (basically differing only in whitespace).

It's a slippery slope to add config to the global area that might only be shared by a couple plugins, so I'm leaving that global config to be only config used by the underlying dprint-core printer which is used by many of the dprint plugins.

rivy commented 3 years ago

Thanks!