diff --git a/lib/rules/multiline-comment-style.js b/lib/rules/multiline-comment-style.js index 68cd666532dc..fca426533acf 100644 --- a/lib/rules/multiline-comment-style.js +++ b/lib/rules/multiline-comment-style.js @@ -22,7 +22,21 @@ module.exports = { }, fixable: "whitespace", - schema: [{ enum: ["starred-block", "separate-lines", "bare-block"] }], + schema: [ + { + enum: ["starred-block", "separate-lines", "bare-block"] + }, + { + type: "object", + properties: { + allowJsDoc: { + type: "boolean", + default: true + } + }, + additionalProperties: false + } + ], messages: { expectedBlock: "Expected a block comment instead of consecutive line comments.", expectedBareBlock: "Expected a block comment without padding stars.", @@ -37,6 +51,8 @@ module.exports = { create(context) { const sourceCode = context.getSourceCode(); const option = context.options[0] || "starred-block"; + const params = context.options[1] || {}; + const allowJsDoc = "allowJsDoc" in params ? params.allowJsDoc : true; //---------------------------------------------------------------------- // Helpers @@ -333,11 +349,18 @@ module.exports = { "separate-lines"(commentGroup) { const [firstComment] = commentGroup; - if (firstComment.type !== "Block" || isJSDocComment(commentGroup)) { + const isJSDoc = isJSDocComment(commentGroup); + + if (firstComment.type !== "Block" || (allowJsDoc && isJSDoc)) { return; } - const commentLines = getCommentLines(commentGroup); + let commentLines = getCommentLines(commentGroup); + + if (!allowJsDoc && isJSDoc) { + commentLines = commentLines.slice(1, commentLines.length - 1); + } + const tokenAfter = sourceCode.getTokenAfter(firstComment, { includeComments: true }); if (tokenAfter && firstComment.loc.end.line === tokenAfter.loc.start.line) { diff --git a/tests/lib/rules/multiline-comment-style.js b/tests/lib/rules/multiline-comment-style.js index 1f2302f9a226..9dabe791b371 100644 --- a/tests/lib/rules/multiline-comment-style.js +++ b/tests/lib/rules/multiline-comment-style.js @@ -628,6 +628,20 @@ ruleTester.run("multiline-comment-style", rule, { options: ["separate-lines"], errors: [{ messageId: "expectedLines", line: 2 }] }, + { + code: ` + /** + * JSDoc + * Comment + */ + `, + output: ` + // JSDoc + // Comment + `, + options: ["separate-lines", { allowJsDoc: false }], + errors: [{ messageId: "expectedLines", line: 2 }] + }, { code: ` /* foo