Always add trailing commas, for arrays and annotations

Created on 16 April 2016, over 8 years ago
Updated 14 August 2023, over 1 year ago

Problem/Motivation

The current coding standards specify:

Note the comma at the end of the last array element; This is not a typo! It helps prevent parsing errors if another element is placed at the end of the list later.

This is not really explicit.

On top of that we also don't specify trailing commas for annotations yet.

Proposed resolution

1 Change the paragraph after the second example in the arrays coding standards

Note the comma at the end of the last array element; This is not a typo! It helps prevent parsing errors if another element is placed at the end of the list later.

Note that, as seen above, in multi-line arrays there MUST be a comma after the last array element. This helps prevent parsing errors if another element is placed at the end of the list later.

2. Change the example and notes afterwards for annotations .

/**
(rest of the documentation for this class)
 *
 * @Plugin(
 *   id = "aggregator",
 *   title = @Translation("Default fetcher"),
 *   description = @Translation("Downloads data from a URL using Drupal's HTTP request handler.")
 * )
 */
class DefaultFetcher implements FetcherInterface {

Drupal standards notes:

  • It is better to use a specific plugin type, like @EntityType, rather than the generic @Plugin.
  • Each key of a plugin annotation should be on its own line.
  • Annotations are functional code, so individual lines should not be wrapped.
  • For more information on how annotations are used for plugins, see the plugin documentation .
**
(rest of the documentation for this class)
 *
 * @Plugin(
 *   id = "aggregator",
 *   title = @Translation("Default fetcher"),
 *   description = @Translation("Downloads data from a URL using Drupal's HTTP request handler."),
 * )
 */
class DefaultFetcher implements FetcherInterface {

Drupal standards notes:

  • It is better to use a specific plugin type, like @EntityType, rather than the generic @Plugin.
  • Each key of a plugin annotation should be on its own line.
  • Annotations are functional code, so individual lines should not be wrapped.
  • Same as for arrays , you MUST also include a comma after the last element in the definition (and in the definitions of any nested annotations).
  • For more information on how annotations are used for plugins, see the plugin documentation .

Remaining tasks

  1. Agree on documentation changes
  2. After the consultation period (in upcoming announcement) discuss at the next CS meeting.
📌 Task
Status

Fixed

Component

Coding Standards

Created by

🇩🇪Germany dawehner

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.

Production build 0.71.5 2024