Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix: multiline-comment-style rule add extra space after * (fixes #12785
…) (#12823)

* Fix: multiline-comment-style rule missed an extra space after *  (fixes #12785)

* logic changed to handled only the edge case

* test case added for the edge case

* checks full offset and apply space after * only if there already isn't white space after it.

* addeed new test case
  • Loading branch information
karthikkp authored and kaicataldo committed Jan 27, 2020
1 parent 0460748 commit 533c114
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/rules/multiline-comment-style.js
Expand Up @@ -316,6 +316,10 @@ module.exports = {
const [, prefix = "", initialOffset = ""] = lineTextToAlignWith.match(/^(\s*(?:\/?\*)?(\s*))/u) || [];

offset = `${commentTextPrefix.slice(prefix.length)}${initialOffset}`;

if (/^\s*\//u.test(lineText) && offset.length === 0) {
offset += " ";
}
break;
}

Expand Down
94 changes: 94 additions & 0 deletions tests/lib/rules/multiline-comment-style.js
Expand Up @@ -328,6 +328,15 @@ ruleTester.run("multiline-comment-style", rule, {
*/
`,
options: ["separate-lines"]
},
{
code: `
/*
* // a line comment
*some.code();
*/
`,
options: ["starred-block"]
}
],

Expand Down Expand Up @@ -1379,6 +1388,91 @@ ${" "}
{ messageId: "missingStar", line: 4 },
{ messageId: "endNewline", line: 4 }
]
},
{
code: `
/*
// a line comment
some.code();
*/
`,
output: `
/*
* // a line comment
*some.code();
*/
`,
options: ["starred-block"],
errors: [
{ messageId: "missingStar", line: 3 },
{ messageId: "missingStar", line: 4 }
]
},
{
code: `
/*
// a line comment
* some.code();
*/
`,
output: `
/*
* // a line comment
* some.code();
*/
`,
options: ["starred-block"],
errors: [
{ messageId: "missingStar", line: 3 }
]
},
{
code: `
////This comment is in
//\`separate-lines\` format.
`,
output: null,
options: ["starred-block"],
errors: [
{ messageId: "expectedBlock", line: 2 }
]
},
{
code: `
// // This comment is in
// \`separate-lines\` format.
`,
output: null,
options: ["starred-block"],
errors: [
{ messageId: "expectedBlock", line: 2 }
]
},
{
code: `
/*
{
\t"foo": 1,
\t//"bar": 2
}
*/
`,
output: `
/*
*{
*\t"foo": 1,
*\t//"bar": 2
*}
*/
`,
options: ["starred-block"],
errors: [
{ messageId: "missingStar", line: 3 },
{ messageId: "missingStar", line: 4 },
{ messageId: "missingStar", line: 5 },
{ messageId: "missingStar", line: 6 },
{ messageId: "alignment", line: 7 }
]
}
]
});

0 comments on commit 533c114

Please sign in to comment.