Skip to content

Make objectFieldSeparatorTrailingPunctuation more smart for multi-line object notations #1636

@alexander-akait

Description

@alexander-akait

Motivation

Our code style is:

For single-line object notation:

/**
 * @typedef {{ a: boolean, b: string, c: number }} Example
 */

For multi-line object notation:

/**
 * @typedef {{
 * a: boolean,
 * b: string,
 * c: number,
 * }} Example
 */

We use:

{
  // ...
  rules: {
  "jsdoc/type-formatting": [
      "error",
      {
        objectTypeBracketSpacing: " ",
        objectFieldSeparator: "comma-and-linebreak",
      },
    ],
  },
}

We don't want a trailing comma for single-line object notation, but want it for multi-line.

Set the objectFieldSeparatorTrailingPunctuation to true will always add , (comma) to single-line and multi-line object notations, separatorForSingleObjectField is not fit for our purpose, because some object notations can be written in single-line with multiple properties.

We align our jsdocs like prettier formats objects.

Why some objects are using single-line and other are using multi-line? It all depends on how many properties are in the object and how much line length they occupy. If the object is longer than 80 characters, we write it in several lines.

Idea - objectFieldSeparatorTrailingPunctuation: boolean | "multi-line-only"

Current behavior

No ability to configure

Desired behavior

Ability to configure

Alternatives considered

No alternatives

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions