Fix trailing JSDoc comments with trailing regular comments (#4414)

master
Lucas Duailibe 2018-05-04 10:15:30 -03:00 committed by GitHub
parent bafa76f613
commit 8e1b60e943
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 91 additions and 1 deletions

View File

@ -5508,7 +5508,21 @@ function printComment(commentPath, options) {
case "CommentBlock":
case "Block": {
if (isJsDocComment(comment)) {
return printJsDocComment(comment);
const printed = printJsDocComment(comment);
// We need to prevent an edge case of a previous trailing comment
// printed as a `lineSuffix` which causes the comments to be
// interleaved. See https://github.com/prettier/prettier/issues/4412
if (
comment.trailing &&
!privateUtil.hasNewline(
options.originalText,
options.locStart(comment),
{ backwards: true }
)
) {
return concat([hardline, printed]);
}
return printed;
}
const isInsideFlowComment =

View File

@ -1637,6 +1637,60 @@ exports[`trailing_space.js 1`] = `
`;
exports[`trailing-jsdocs.js 1`] = `
const CONNECTION_STATUS = exports.CONNECTION_STATUS = {
CLOSED: Object.freeze({ kind: 'CLOSED' }),
CONNECTED: Object.freeze({ kind: 'CONNECTED' }),
CONNECTING: Object.freeze({ kind: 'CONNECTING' }),
NOT_CONNECTED: Object.freeze({ kind: 'NOT_CONNECTED' }) };
/* A comment */ /**
* A type that can be written to a buffer.
*/ /**
* Describes the connection status of a ReactiveSocket/DuplexConnection.
* - NOT_CONNECTED: no connection established or pending.
* - CONNECTING: when \`connect()\` has been called but a connection is not yet
* established.
* - CONNECTED: when a connection is established.
* - CLOSED: when the connection has been explicitly closed via \`close()\`.
* - ERROR: when the connection has been closed for any other reason.
*/ /**
* A contract providing different interaction models per the [ReactiveSocket protocol]
* (https://github.com/ReactiveSocket/reactivesocket/blob/master/Protocol.md).
*/ /**
* A single unit of data exchanged between the peers of a \`ReactiveSocket\`.
*/
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
const CONNECTION_STATUS = (exports.CONNECTION_STATUS = {
CLOSED: Object.freeze({ kind: "CLOSED" }),
CONNECTED: Object.freeze({ kind: "CONNECTED" }),
CONNECTING: Object.freeze({ kind: "CONNECTING" }),
NOT_CONNECTED: Object.freeze({ kind: "NOT_CONNECTED" })
});
/* A comment */
/**
* A type that can be written to a buffer.
*/
/**
* Describes the connection status of a ReactiveSocket/DuplexConnection.
* - NOT_CONNECTED: no connection established or pending.
* - CONNECTING: when \`connect()\` has been called but a connection is not yet
* established.
* - CONNECTED: when a connection is established.
* - CLOSED: when the connection has been explicitly closed via \`close()\`.
* - ERROR: when the connection has been closed for any other reason.
*/
/**
* A contract providing different interaction models per the [ReactiveSocket protocol]
* (https://github.com/ReactiveSocket/reactivesocket/blob/master/Protocol.md).
*/
/**
* A single unit of data exchanged between the peers of a \`ReactiveSocket\`.
*/
`;
exports[`try.js 1`] = `
// comment 1
try {

View File

@ -0,0 +1,22 @@
const CONNECTION_STATUS = exports.CONNECTION_STATUS = {
CLOSED: Object.freeze({ kind: 'CLOSED' }),
CONNECTED: Object.freeze({ kind: 'CONNECTED' }),
CONNECTING: Object.freeze({ kind: 'CONNECTING' }),
NOT_CONNECTED: Object.freeze({ kind: 'NOT_CONNECTED' }) };
/* A comment */ /**
* A type that can be written to a buffer.
*/ /**
* Describes the connection status of a ReactiveSocket/DuplexConnection.
* - NOT_CONNECTED: no connection established or pending.
* - CONNECTING: when `connect()` has been called but a connection is not yet
* established.
* - CONNECTED: when a connection is established.
* - CLOSED: when the connection has been explicitly closed via `close()`.
* - ERROR: when the connection has been closed for any other reason.
*/ /**
* A contract providing different interaction models per the [ReactiveSocket protocol]
* (https://github.com/ReactiveSocket/reactivesocket/blob/master/Protocol.md).
*/ /**
* A single unit of data exchanged between the peers of a `ReactiveSocket`.
*/