Postponed on #3252380: Coding standard for json

Problem/Motivation

The composer.json of our components does not follow the code-style. Indentation should be 4 spaces instead of 2.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#2 2983304-1.patch26.39 KBwebflo

Comments

webflo created an issue. See original summary.

webflo’s picture

Status: Active » Needs review
StatusFileSize
new26.39 KB
tstoeckler’s picture

Status: Needs review » Reviewed & tested by the community

Yup, scanned through the file and it all looks good to me. Thanks!

cilefen’s picture

Is there a way we could prevent code style drift in these files?

idebr’s picture

I suppose it would be enforced by adding a CodeSniffer rule. It is currently only added as a setting in .editorconfig

mile23’s picture

I'm not sure we should use PHPCS for JSON.

We have eslint etc but there are a few problems:

1) There's no build step for it.

2) There's no build step for it.

We also have this: #2708751: Run composer validate --strict if a composer.json exists It addresses malformed JSON but not CS stuff like indentation.

webflo’s picture

This could be a follow-up issue?

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 2: 2983304-1.patch, failed testing. View results

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

mpp’s picture

Isn't a .json file a type of javascript and doesn't Drupal expect those to be indented with 2 spaces?

I don't want to complicate the discussion but I couldn't find where composer states that it requires an indentation of 4 spaces. On the contrary there has been a discussion that they don't want to enforce it. See https://github.com/composer/composer/issues/5494

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Category: Bug report » Task
Issue summary: View changes
Status: Needs work » Postponed
Issue tags: +Bug Smash Initiative
Related issues: +#3252380: Coding standard for json

@webflo, thanks for the patch!

Coding standard issues are tasks not bugs, changing category.

I searched for json coding standards in the JavaScript coding standards and did not find any mention of json. Nor could I find it mentioned in any of the code standard documentation.

I asked in #coding-standards and #documentation and got somewhat different answers. In #bugsmash, longware wasn't aware or any and in #documentation bradjones1 assumed that json would be covered as 'an extension of the JS standards'. So, I don't know either.

I do know that, if this were to be done, it would be changed after there was some checking of the json files so that they stayed compliant with the Drupal Standard. Since that isn't available right now I am postponing this on #3252380: Coding standard for json.

webflo’s picture

Thanks for the follow-up issue.

I think composer.json files are somewhat special, because you can edit it with your editor and with composer cli. If you run composer require drupal/something, composer will insert the package into the composer.json file and uses 4 spaces for format the file.

This issue is about switching to 4 spaces for composer.json to minimize the diff in workflows where version control is used.

mile23’s picture

IIRC, Composer will figure out the indentation and use that when it adds things.

Also, there's an issue in that components live outside the places our tools are normally scanning. We have an issue about that but I can't seem to find it right now.

mile23’s picture

Related: #3272110: Drupal 9 and 10's Drupal\Component composer.json files are totally out of date

Moving forward all the components will at least be somewhat auto-generated, along with the project metapackages.

This means the path of least resistance is whatever json_encode()'s JSON_PRETTY_PRINT gives us.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

quietone’s picture

Component: base system » other
Status: Postponed » Closed (outdated)
Issue tags: -Composer

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.