prettier / prettier/prettier

non-idempotent comment position before await statement inside try block

Open
#9,513 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area:comments area:idempotency lang:javascript
Dominant language
JavaScript
Stars
52.3k
Forks
5k
Avg merge
19h 2m
Merged PRs (30d)
117

Description

Prettier 2.1.2
Input Playground Link
Rerun on Output Playground Link

Note:

Using /* this type of comment */ works around the issue.

Input:


async function promptForSetUpSkeleton(): Promise<SkeletonAnswers> {
  let defaultAuthor
  try {
    defaultAuthor = ( // $FlowFixMe
      await spawn('git', ['config', 'user.name'], {
        maxBuffer: 1024,
      })
    ).stdout
      .toString('utf8')
      .trim()
  } catch (error) {
    // ignore
  }
}

Output:

async function promptForSetUpSkeleton(): Promise<SkeletonAnswers> {
  let defaultAuthor;
  try {
    defaultAuthor = // $FlowFixMe
    (
      await spawn("git", ["config", "user.name"], {
        maxBuffer: 1024,
      })
    ).stdout
      .toString("utf8")
      .trim();
  } catch (error) {
    // ignore
  }
}

Rerun on Output:

async function promptForSetUpSkeleton(): Promise<SkeletonAnswers> {
  let defaultAuthor;
  try {
    defaultAuthor = ( // $FlowFixMe
      await spawn("git", ["config", "user.name"], {
        maxBuffer: 1024,
      })
    ).stdout
      .toString("utf8")
      .trim();
  } catch (error) {
    // ignore
  }
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the example from the Input Playground Link and compare the first formatting result with the Rerun on Output Playground Link. Trace the formatter entry point for this JavaScript/TypeScript case; done means formatting is idempotent and preserves the comment position around the await statement.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.