From 8768b2d5199e953e61311cdee764af5e74f3d61a Mon Sep 17 00:00:00 2001 From: Teddy Katz Date: Wed, 18 Oct 2017 12:55:54 -0400 Subject: [PATCH] Fix: multiline-comment-style autofixer added trailing space (#9454) This updates the multiline-comment-style autofixer to avoid adding a space after the `starred-block` asterisk for blank lines. --- lib/rules/multiline-comment-style.js | 8 +++-- tests/lib/rules/multiline-comment-style.js | 34 ++++++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/lib/rules/multiline-comment-style.js b/lib/rules/multiline-comment-style.js index cde28fd88d6..0972b7cc783 100644 --- a/lib/rules/multiline-comment-style.js +++ b/lib/rules/multiline-comment-style.js @@ -174,8 +174,12 @@ module.exports = { : MISSING_STAR_ERROR, fix(fixer) { const lineStartIndex = sourceCode.getIndexFromLoc({ line: lineNumber, column: 0 }); - const commentStartIndex = lineStartIndex + lineText.match(/^\s*\*? ?/)[0].length; - const replacementText = lineNumber === block.loc.end.line ? expectedLinePrefix : `${expectedLinePrefix} `; + const linePrefixLength = lineText.match(/^\s*\*? ?/)[0].length; + const commentStartIndex = lineStartIndex + linePrefixLength; + + const replacementText = lineNumber === block.loc.end.line || lineText.length === linePrefixLength + ? expectedLinePrefix + : `${expectedLinePrefix} `; return fixer.replaceTextRange([lineStartIndex, commentStartIndex], replacementText); } diff --git a/tests/lib/rules/multiline-comment-style.js b/tests/lib/rules/multiline-comment-style.js index 37739a4c9ba..9da55a99575 100644 --- a/tests/lib/rules/multiline-comment-style.js +++ b/tests/lib/rules/multiline-comment-style.js @@ -332,6 +332,40 @@ ruleTester.run("multiline-comment-style", rule, { `, errors: [{ message: ALIGNMENT_ERROR, line: 5 }] }, + { + code: ` + /* + * the following line + * + * is blank + */ + `, + output: ` + /* + * the following line + * + * is blank + */ + `, + errors: [{ message: ALIGNMENT_ERROR, line: 4 }] + }, + { + code: ` + /* + * the following line + * + * is blank + */ + `, + output: ` + /* + * the following line + * + * is blank + */ + `, + errors: [{ message: ALIGNMENT_ERROR, line: 4 }] + }, { code: ` /*