Skip to content

Commit

Permalink
Fix: multiline-comment-style autofixer added trailing space (#9454)
Browse files Browse the repository at this point in the history
This updates the multiline-comment-style autofixer to avoid adding a space after the `starred-block` asterisk for blank lines.
  • Loading branch information
not-an-aardvark committed Oct 18, 2017
1 parent e830aa1 commit 8768b2d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/rules/multiline-comment-style.js
Expand Up @@ -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);
}
Expand Down
34 changes: 34 additions & 0 deletions tests/lib/rules/multiline-comment-style.js
Expand Up @@ -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: `
/*
Expand Down

0 comments on commit 8768b2d

Please sign in to comment.