Problem/Motivation
The daily bug bingo in #bugsmash brought up #2983304: Apply code style to all component composer.json which lead to a search for Drupal coding standards for json file. I could not find any. There are coding standards for javaScript but it does not explicitly say if they apply to json as well.
Should there be standards for json? Whether that is agreed to or not, it would be helpful to have the documentation explain the current situation.
Steps to reproduce
Core commit code checks does not check json files.
Proposed resolution
Update coding standards documentation to explicitly state there are no Drupal coding standards for json files.
Remaining tasks
Make sure that there really are no coding standards for json.
Comments
Comment #2
froboy#2654894: Use an indent of 4 spaces for composer.json changed core's
composer.jsonto 4 space indents instead of two to follow composer's.I'd suggest that, for consistency, we encourage contrib modules to follow core's lead on this.
Comment #3
drunken monkeyI’d also be in favor of specifying standards. Does anyone know of some existing JSON style guide from which we could copy? (I couldn’t find anything. But I also can’t think of much we’d want to specify, tbh, except how to indent.)
If Core specifically changed their
composer.jsonto indent with four spaces, then that should be specified as a standard somewhere, because the reasoning is probably similar for contrib code as well (even though I guess it’s much rarer that someone wants to add a dependency on a module/theme, and not just to their site). Also, it seems this only applies tocomposer.jsonspecifically, so it might be prudent to also note in the standards that other JSON files should use two spaces, like the rest of Drupal code.Comment #4
mile23Most use-cases for JSON within Drupal are related to Composer, so tagging.
This is what Composer does:
So by default we're using 4 spaces for indent, and whatever else JSON_PRETTY_PRINT gives us.
The encode() method itself just goes to json_encode(), which, again, is the path of least resistance for generating human-readable (pretty) JSON.
We're also using a number of scripted tools to generate JSON for use by Composer, which all use json_encode() in this path-of-least-resistance way.
Given this, if we're adopting a coding standard for JSON, then this should be our standard. That way automatic tools are always in compliance without having to deal with a lot of edge cases.