Uploaded image for project: 'Moodle Community Sites'
  1. Moodle Community Sites
  2. MDLSITE-5873

Clarify coding style for trailing comma in multi-line array declaration

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Component/s: Coding style
    • Labels:
      None

      Description

      Policy: Trailing comma in multi-line array declaration

      Since 20th May 2020, this rule applies:

      1. The uses of a trailing comma on multi-line array declaration is required in PHP and JS.
      2. It's NOT required to change all current old-style occurrences in the codebase. We'll follow a progressive approach here (new code and modified code)

       

      For example for the expected format:

      $foo = [
          'a',
          'b',
          'c',
      ];

      I'd like to propose that we recommend or require the use of a trailing comma on multi-line array declarations, in PHP and JS.

      For example:

      $foo = [
        'a',
        'b',
        'c',
      ];
      

      Rationale:

      1. Adding additional keys to the array later leads to fewer lines of diff (1 addition, vs. 1 removal + 2 addition)
      2. Git blame and git history are clearer.

       

      So this is a proposal to require the use of a trailing comma on multi-line array declarations.

      Associated actions include:

      a) Modify codechecker in order to provide basic support to the proposal above.
      b) Document the change
      c) Explicitly, it's NOT required to change all current old-style occurrences in the codebase. We'll follow a progressive approach here (new code and modified code).

       

      And that's all. Options are:

      A) We accept the change to require the use of a trailing comma on multi-line array declarations.
      B) We continue as we are.
       

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              sarjona Sara Arjona (@sarjona)
              Reporter:
              dobedobedoh Andrew Nicols
              Participants:
              Component watchers:
              Marina Glancy, Eloy Lafuente (stronk7)
              Votes:
              3 Vote for this issue
              Watchers:
              10 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: