Skip to content

Lines with a JSdoc typecast do not respect line length #8045

@sk-

Description

@sk-

Prettier 2.0.4
Playground link

--parser babel

Input:

// Prettier does not automatically wrap.
const myLongVariableName = /** @type {ThisIsAVeryLongTypeThatShouldTriggerLineWrapping} */ (fooBarBaz);

function jsdocCastInReturn() {
  return /** @type {ThisIsAVeryLongTypeThatShouldTriggerLineWrapping} */ (fooBarBaz);
}

// Prettier wraps but add a newline, just because there's a trailing whitespace.
const myLongVariableName = /** @type {ThisIsAVeryLongTypeThatShouldTriggerLineWrapping} */ 
      (fooBarBaz);

function jsdocCastInReturn() {
  return (/** @type {ThisIsAVeryLongTypeThatShouldTriggerLineWrapping} */ 
    (fooBarBaz));
}

// Prettier correctly formats and wraps the lines.
const myLongVariableName = /** @type {ThisIsAVeryLongTypeThatShouldTriggerLineWrapping} */
      (fooBarBaz);

function jsdocCastInReturn() {
  return (/** @type {ThisIsAVeryLongTypeThatShouldTriggerLineWrapping} */
    (fooBarBaz));
}

Output:

// Prettier does not automatically wrap.
const myLongVariableName = /** @type {ThisIsAVeryLongTypeThatShouldTriggerLineWrapping} */ (fooBarBaz);

function jsdocCastInReturn() {
  return /** @type {ThisIsAVeryLongTypeThatShouldTriggerLineWrapping} */ (fooBarBaz);
}

// Prettier wraps but add a newline, just because there's a trailing whitespace.
const myLongVariableName =
  /** @type {ThisIsAVeryLongTypeThatShouldTriggerLineWrapping} */

  (fooBarBaz);

function jsdocCastInReturn() {
  return (
    /** @type {ThisIsAVeryLongTypeThatShouldTriggerLineWrapping} */

    (fooBarBaz)
  );
}

// Prettier correctly formats and wraps the lines.
const myLongVariableName =
  /** @type {ThisIsAVeryLongTypeThatShouldTriggerLineWrapping} */
  (fooBarBaz);

function jsdocCastInReturn() {
  return (
    /** @type {ThisIsAVeryLongTypeThatShouldTriggerLineWrapping} */
    (fooBarBaz)
  );
}

Expected behavior:
prettier should automatically add new lines to wrap long constructs when using JSdoc casts, rather than having to manually add a line break. Also note that if you keep a trailing whitespace, prettier adds an extra new line.

Metadata

Metadata

Assignees

No one assigned

    Labels

    lang:javascriptIssues affecting JSlocked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions