Skip to content

Inconsistent formatting logic of CallExpression and NewExpression #18171

@Dunqing

Description

@Dunqing

Prettier 3.6.2
Playground link

--parser babel-ts

Input:

// ConditionalExpression
fn(
  bifornCringerMoshedPerplexSawder,
  askTrovenaBeenaDependsRowans,
  glimseGlyphsHazardNoopsTieTie === averredBathersBoxroomBuggyNurl &&
    anodyneCondosMalateOverateRetinol
      ? annularCooeedSplicesWalksWayWay
      : kochabCooieGameOnOboleUnweave
);

new fn(
  bifornCringerMoshedPerplexSawder,
  askTrovenaBeenaDependsRowans,
  glimseGlyphsHazardNoopsTieTie === averredBathersBoxroomBuggyNurl &&
    anodyneCondosMalateOverateRetinol
      ? annularCooeedSplicesWalksWayWay
      : kochabCooieGameOnOboleUnweave
);

// MemberExpression
TelemetryTrustedValue(
  instance.capabilities.get(
    TerminalCapability?.PromptTypeDetection
  )?.promptType
)

new TelemetryTrustedValue(
  instance.capabilities.get(
    TerminalCapability?.PromptTypeDetection
  )?.promptType
)

Output:

// ConditionalExpression
fn(
  bifornCringerMoshedPerplexSawder,
  askTrovenaBeenaDependsRowans,
  glimseGlyphsHazardNoopsTieTie === averredBathersBoxroomBuggyNurl &&
    anodyneCondosMalateOverateRetinol
    ? annularCooeedSplicesWalksWayWay
    : kochabCooieGameOnOboleUnweave,
);

new fn(
  bifornCringerMoshedPerplexSawder,
  askTrovenaBeenaDependsRowans,
  glimseGlyphsHazardNoopsTieTie === averredBathersBoxroomBuggyNurl &&
  anodyneCondosMalateOverateRetinol
    ? annularCooeedSplicesWalksWayWay
    : kochabCooieGameOnOboleUnweave,
);

// MemberExpression
TelemetryTrustedValue(
  instance.capabilities.get(TerminalCapability?.PromptTypeDetection)
    ?.promptType,
);

new TelemetryTrustedValue(
  instance.capabilities.get(
    TerminalCapability?.PromptTypeDetection,
  )?.promptType,
);

Expected output:

// ConditionalExpression
fn(
  bifornCringerMoshedPerplexSawder,
  askTrovenaBeenaDependsRowans,
  glimseGlyphsHazardNoopsTieTie === averredBathersBoxroomBuggyNurl &&
    anodyneCondosMalateOverateRetinol
    ? annularCooeedSplicesWalksWayWay
    : kochabCooieGameOnOboleUnweave,
);

new fn(
  bifornCringerMoshedPerplexSawder,
  askTrovenaBeenaDependsRowans,
  glimseGlyphsHazardNoopsTieTie === averredBathersBoxroomBuggyNurl &&
    anodyneCondosMalateOverateRetinol
    ? annularCooeedSplicesWalksWayWay
    : kochabCooieGameOnOboleUnweave,
);

// MemberExpression
TelemetryTrustedValue(
  instance.capabilities.get(
    TerminalCapability?.PromptTypeDetection,
  )?.promptType,
);

new TelemetryTrustedValue(
  instance.capabilities.get(
    TerminalCapability?.PromptTypeDetection,
  )?.promptType,
);

Why?

There is no reason why we need the output to be different in CallExpression and NewExpression. Keep the same formatting, which also improves readability.

Metadata

Metadata

Assignees

Labels

good first issueGood fist issue!help wantedWe're a small group who can't get to every issue promptly. We’d appreciate help fixing this issue!lang:javascriptIssues affecting JS

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions