Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Remove extraneous linefeeds in one-var fixer (#10741) #10955

Merged
merged 1 commit into from Feb 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/rules/one-var.js
Expand Up @@ -334,7 +334,11 @@ module.exports = {
* y`
* ^ afterComma
*/
if (afterComma.loc.start.line > tokenAfterDeclarator.loc.end.line || afterComma.type === "Line" || afterComma.type === "Block") {
if (
afterComma.loc.start.line > tokenAfterDeclarator.loc.end.line ||
afterComma.type === "Line" ||
afterComma.type === "Block"
) {
let lastComment = afterComma;

while (lastComment.type === "Line" || lastComment.type === "Block") {
Expand All @@ -343,7 +347,7 @@ module.exports = {

return fixer.replaceTextRange(
[tokenAfterDeclarator.range[0], lastComment.range[0]],
`;\n${sourceCode.text.slice(tokenAfterDeclarator.range[1], lastComment.range[0])}\n${declaration.kind} `
`;${sourceCode.text.slice(tokenAfterDeclarator.range[1], lastComment.range[0])}${declaration.kind} `
);
}

Expand Down
8 changes: 4 additions & 4 deletions tests/lib/rules/one-var.js
Expand Up @@ -884,7 +884,7 @@ ruleTester.run("one-var", rule, {
},
{
code: "const foo = 1,\n bar = 2;",
output: "const foo = 1;\n\n \nconst bar = 2;",
output: "const foo = 1;\n const bar = 2;",
options: [{ initialized: "never" }],
parserOptions: { ecmaVersion: 6 },
errors: [{
Expand All @@ -896,7 +896,7 @@ ruleTester.run("one-var", rule, {
},
{
code: "var foo = 1,\n bar = 2;",
output: "var foo = 1;\n\n \nvar bar = 2;",
output: "var foo = 1;\n var bar = 2;",
options: [{ initialized: "never" }],
errors: [{
message: "Split initialized 'var' declarations into multiple statements.",
Expand All @@ -907,7 +907,7 @@ ruleTester.run("one-var", rule, {
},
{
code: "var foo = 1, // comment\n bar = 2;",
output: "var foo = 1;\n // comment\n \nvar bar = 2;",
output: "var foo = 1; // comment\n var bar = 2;",
options: [{ initialized: "never" }],
errors: [{
message: "Split initialized 'var' declarations into multiple statements.",
Expand All @@ -929,7 +929,7 @@ ruleTester.run("one-var", rule, {
},
{
code: "var f, /* test */ l;",
output: "var f;\n /* test */ \nvar l;",
output: "var f; /* test */ var l;",
options: ["never"],
errors: [{
message: "Split 'var' declarations into multiple statements.",
Expand Down