[meta] Fix Drupal.Array.Array.LongLineDeclaration coding standard

Created on 29 February 2020, about 5 years ago
Updated 24 February 2025, 2 months ago

Problem/Motivation

The Drupal.Array.Array.LongLineDeclaration coding standard should be applied to Drupal core.

Proposed resolution

@xjm suggests in #15:

This cleanup is large enough that I think we should split it into a few logical chunks (by concept, not by module). I'd suggest:

One patch for fixing the $modules test property.
One patch for fixing calls to drupalCreateUser().
One patch for fixing calls to drupalCreateNode().
Evaluating whatever's left after that and seeing if it should be split up further.

Remaining tasks

Create child issues and fix those first

User interface changes

API changes

Data model changes

Release notes snippet

🌱 Plan
Status

Active

Version

11.0 🔥

Component

other

Created by

🇮🇳India swatichouhan012

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇳🇿New Zealand quietone

    In #15, it was suggested to scope issues by drupalCreateUser and drupalCreateNode. The first issue was completed but new violations have come back into the code base. Because of the I'd rather this is done by directory so the sniff can be enabled as fixes are made.

    And for some facts, I enabled the sniff and phpcs reported 1,135 violations in 604 files. The longest line reported is 640, in var/www/html/core/lib/Drupal/Component/Utility/Xss.php.

  • 🇬🇧United Kingdom alexpott 🇪🇺🌍

    This has just made me change:

        $this->assertEquals(['entity_test.entity_test_mul_bundle.test', 'language.content_settings.entity_test_mul_with_bundle.test'], $permissions['translate test entity_test_mul_with_bundle']['dependencies']['config']);
    

    to

        $this->assertEquals([
          'entity_test.entity_test_mul_bundle.test',
          'language.content_settings.entity_test_mul_with_bundle.test',
        ], $permissions['translate test entity_test_mul_with_bundle']['dependencies']['config']);
    

    It's not an improvement. I think we should have reviewed all the lines that the updated rule with 120 length was suggesting we change. I'm not convinced that these line length rules result in good code and are appropriate for standards. I opened Drupal.Arrays.Array.LongLineDeclaration make me write less readable code Fixed to try to get us to consider this particular standard and that resulted in changing a limit from 80 to 120 which while better does not get to the real problem which is that writing standards on line length is hard and Drupal's current standards are out-of-date and need revisiting so that they make sense with the current state of code rather than enforcing them on our code. Our standards were written my Drupal was largely procedural. See https://lkml.org/lkml/2020/5/29/1038 for a longer discussion of why arbitrary line length limits are bad.

  • 🇳🇿New Zealand quietone

    @alexpott, I too don't like the resulting style in #45. Was that automatically formatted somehow?

    It would be better as this, with the array line limit of 120.

    $this->assertEquals(
          [
            'entity_test.entity_test_mul_bundle.test',
            'language.content_settings.entity_test_mul_with_bundle.test',
          ],
          $permissions['translate test entity_test_mul_with_bundle']['dependencies']['config']);
    
  • 🇬🇧United Kingdom alexpott 🇪🇺🌍

    No it is not auto-formatted but it passes out CS checks.

    The point is that applying this rule to core has resulted in changes like

    -      ['entity.user.collection', [['entity.user.collection', 'user.admin_permissions', 'entity.user_role.collection', 'user.role.settings']]],
    -      ['user.admin_permissions', [['entity.user.collection', 'user.admin_permissions', 'entity.user_role.collection', 'user.role.settings']]],
    -      ['entity.user_role.collection', [['entity.user.collection', 'user.admin_permissions', 'entity.user_role.collection', 'user.role.settings']]],
    

    to

    +      [
    +        'entity.user.collection',
    +        [
    +          [
    +            'entity.user.collection',
    +            'user.admin_permissions',
    +            'entity.user_role.collection',
    +            'user.role.settings',
    +          ],
    +        ],
    +      ],
    +      [
    +        'user.admin_permissions',
    +        [
    +          [
    +            'entity.user.collection',
    +            'user.admin_permissions',
    +            'entity.user_role.collection',
    +            'user.role.settings',
    +          ],
    +        ],
    +      ],
    +      [
    +        'entity.user_role.collection',
    +        [
    +          [
    +            'entity.user.collection',
    +            'user.admin_permissions',
    +            'entity.user_role.collection',
    +            'user.role.settings',
    +          ],
    +        ],
    +      ],
    

    This is not an improvement. It was easier in the original formatting to see that we had three test cases expecting the same tasks on the three different routes. With the current formatting that is much much harder to discern.

  • 🇳🇿New Zealand quietone

    @alexpott, thanks.

    I can think of two options to proceed;

    A) Continue implementing, despite the concerns.
    B) Postpone work on implementing the standard on a new issue in the Coding Standards project to decide on the array line limit.

    Is there one I missed?

  • 🇬🇧United Kingdom alexpott 🇪🇺🌍

    I think that another part of this issue is that we only implementing a line length limit when it has an array. I think we need to revisit all of our line length limits and compare them with the PSR standards (which are more modern but still getting on now). The current PSR-12 guidelines on line length are:

    There MUST NOT be a hard limit on line length.
    
    The soft limit on line length MUST be 120 characters.
    
    Lines SHOULD NOT be longer than 80 characters; lines longer than that SHOULD be split into multiple subsequent lines of no more than 80 characters each.
    

    See https://www.php-fig.org/psr/psr-12/

    I have no idea why we have a particular rule of arrays... it's a bit odd.

  • 🇬🇧United Kingdom alexpott 🇪🇺🌍

    Here's a discussion of what the PSR stuff means... https://stackoverflow.com/questions/14962667/what-is-a-line-length-soft-...

Production build 0.71.5 2024