Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treat single-star comments as JSDoc #5206

Merged
merged 9 commits into from
Oct 23, 2018
Merged

Conversation

j-f1
Copy link
Member

@j-f1 j-f1 commented Oct 8, 2018

Fixes #5194. Are the other changes to the snapshots reasonable?

@j-f1
Copy link
Member Author

j-f1 commented Oct 8, 2018

Alternate heuristic: either a /** ... */ single-line comment, or every line except the first and last starts with a *, the first is either empty or *, and the last is empty.

@j-f1 j-f1 added the status:wip Pull requests that are a work in progress and should not be merged label Oct 8, 2018
Copy link
Member

@lydell lydell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you marked this as WIP, but I like it already :)

@lydell
Copy link
Member

lydell commented Oct 13, 2018

@j-f1 How do you feel about this one?

@j-f1
Copy link
Member Author

j-f1 commented Oct 13, 2018

Sorry, I haven’t had a chance to refactor the heuristic yet @lydell. I’ll take a look at that this afternoon/evening (EDT).

@lydell
Copy link
Member

lydell commented Oct 14, 2018

Is this an intended change?

Prettier 1.14.3
Playground link

--parser babylon

Input:

  /** one
   * two
   */

Output:

/** one
 * two
 */

Prettier pr-5206
Playground link

--parser babylon

Input:

  /** one
   * two
   */

Output:

/** one
   * two
   */

@j-f1
Copy link
Member Author

j-f1 commented Oct 14, 2018

Sort of. Should I allow arbitrary text on the first line in both /** and /* comments, or just /* ones?

@lydell
Copy link
Member

lydell commented Oct 14, 2018

First line: Anything goes, I’d say. I can’t see a reason to restrict the first line in any way?

@lydell
Copy link
Member

lydell commented Oct 14, 2018

Perhaps the function should be called something like isIndentableBlockComment rather than isJSDocComment

@j-f1 j-f1 removed the status:wip Pull requests that are a work in progress and should not be merged label Oct 14, 2018
@lydell
Copy link
Member

lydell commented Oct 14, 2018

Could you add these tests?

  /** first line
   * second line
   * third line */

  /* first line
   * second line
   * third line */

@lydell
Copy link
Member

lydell commented Oct 14, 2018

Btw, would this work?

function isIndentableBlockComment(comment) {
  // If the comment has multiple lines and every line starts with a star
  // we can fix the indentation of each line. The stars in the `/*` and
  // `*/` delimiters are not included in the comment value, so add them
  // back first.
  const lines = `*${comment.value}*`.split("\n");
  return lines.length > 1 && lines.every(line => line.trim()[0] === "*");
}

EDIT: Updated code.

@lydell
Copy link
Member

lydell commented Oct 21, 2018

@j-f1 I took the liberty to update your branch with my suggestions myself. What do you think?

@j-f1
Copy link
Member Author

j-f1 commented Oct 21, 2018

LGTM. Good to merge? (cc @duailibe too)

@lydell lydell merged commit 6a17465 into prettier:master Oct 23, 2018
@ikatyang ikatyang added this to the 1.15 milestone Oct 25, 2018
@j-f1 j-f1 deleted the single-star-jsdoc branch October 26, 2018 15:07
@lock lock bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Jan 24, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jan 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants