Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kaicataldo committed Nov 7, 2019
1 parent 2ff0cae commit cab04fd
Show file tree
Hide file tree
Showing 2 changed files with 206 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/rules/multiline-comment-style.js
Expand Up @@ -286,15 +286,15 @@ module.exports = {
fix(fixer) {
const lineStartIndex = sourceCode.getIndexFromLoc({ line: lineNumber, column: 0 });
const [linePrefix, whitespaceBefore, whitespaceAfter] = lineText.match(/^(\s*)\*?(\s*)/u);
const commentStartIndex = lineStartIndex + linePrefix.length;
const leadingWhitespace = whitespaceAfter || ` ${
const leadingWhitespace = whitespaceAfter.length && whitespaceAfter || ` ${
whitespaceBefore.startsWith(expectedLeadingWhitespace)
? whitespaceBefore.replace(expectedLeadingWhitespace, "")
: ""
}`;
const replacementText = lineNumber === firstComment.loc.end.line || lineText.length === linePrefix.length
? expectedLinePrefix
: `${expectedLinePrefix}${leadingWhitespace}`;
const commentStartIndex = lineStartIndex + linePrefix.length;

return fixer.replaceTextRange([lineStartIndex, commentStartIndex], replacementText);
}
Expand Down
204 changes: 204 additions & 0 deletions tests/lib/rules/multiline-comment-style.js
Expand Up @@ -1160,6 +1160,210 @@ ruleTester.run("multiline-comment-style", rule, {
`,
options: ["separate-lines"],
errors: [{ messageId: "expectedLines", line: 2 }]
},
{
code: `
/*
* foo
*
* bar
*/
`,
output: `
/* foo
${" "}
bar */
`,
options: ["bare-block"],
errors: [{ messageId: "expectedBareBlock", line: 2 }]
},
{
code: `
/*
* foo
*${" "}
* bar
*/
`,
output: `
/* foo
${" "}
bar */
`,
options: ["bare-block"],
errors: [{ messageId: "expectedBareBlock", line: 2 }]
},
{
code: `
// foo
//
// bar
`,
output: `
/*
* foo
*${" "}
* bar
*/
`,
options: ["starred-block"],
errors: [{ messageId: "expectedBlock", line: 2 }]
},
{
code: `
// foo
//${" "}
// bar
`,
output: `
/*
* foo
*${" "}
* bar
*/
`,
options: ["starred-block"],
errors: [{ messageId: "expectedBlock", line: 2 }]
},
{
code: `
// foo
//
// bar
`,
output: `
/* foo
${" "}
bar */
`,
options: ["bare-block"],
errors: [{ messageId: "expectedBlock", line: 2 }]
},
{
code: `
// foo
//${" "}
// bar
`,
output: `
/* foo
${" "}
bar */
`,
options: ["bare-block"],
errors: [{ messageId: "expectedBlock", line: 2 }]
},
{
code: `
/* foo
bar */
`,
output: `
// foo
//${" "}
// bar${" "}
`,
options: ["separate-lines"],
errors: [{ messageid: "expectedlines", line: 2 }]
},
{
code: `
/* foo
${" "}
bar */
`,
output: `
// foo
//${" "}
// bar${" "}
`,
options: ["separate-lines"],
errors: [{ messageid: "expectedlines", line: 2 }]
},
{
code: `
/* foo
bar */
`,
output: `
/*
* foo
*
* bar
*/
`,
options: ["starred-block"],
errors: [
{ messageId: "startNewline", line: 2 },
{ messageId: "missingStar", line: 3 },
{ messageId: "missingStar", line: 4 },
{ messageId: "endNewline", line: 4 }
]
},
{
code: `
/* foo
${" "}
bar */
`,
output: `
/*
* foo
*
* bar
*/
`,
options: ["starred-block"],
errors: [
{ messageId: "startNewline", line: 2 },
{ messageId: "missingStar", line: 3 },
{ messageId: "missingStar", line: 4 },
{ messageId: "endNewline", line: 4 }
]
},
{
code: `
/*foo
bar */
`,
output: `
/*
*foo
*
*bar${" "}
*/
`,
options: ["starred-block"],
errors: [
{ messageId: "startNewline", line: 2 },
{ messageId: "missingStar", line: 3 },
{ messageId: "missingStar", line: 4 },
{ messageId: "endNewline", line: 4 }
]
},
{
code: `
/*foo
${" "}
bar */
`,
output: `
/*
*foo
*
*bar${" "}
*/
`,
options: ["starred-block"],
errors: [
{ messageId: "startNewline", line: 2 },
{ messageId: "missingStar", line: 3 },
{ messageId: "missingStar", line: 4 },
{ messageId: "endNewline", line: 4 }
]
}
]
});

0 comments on commit cab04fd

Please sign in to comment.