Skip to content

Commit

Permalink
Fix: Allowing eslint-plugin-prettier to work (fixes #101) (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
simlu authored and btmills committed Nov 6, 2018
1 parent f9258b7 commit a2f4492
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
2 changes: 1 addition & 1 deletion lib/processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ function preprocess(text) {
});

return blocks.map(function(block) {
return block.comments.concat(block.value).join("\n");
return block.comments.concat(block.value).concat("").join("\n");
});
}

Expand Down
50 changes: 27 additions & 23 deletions tests/lib/processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe("processor", function() {
var blocks = processor.preprocess(code);

assert.equal(blocks.length, 1);
assert.equal(blocks[0], "var answer = 6 * 7;\n ```\nGoodbye");
assert.equal(blocks[0], "var answer = 6 * 7;\n ```\nGoodbye\n");
});

it("should ignore tab-indented code blocks", function() {
Expand All @@ -98,7 +98,7 @@ describe("processor", function() {
var blocks = processor.preprocess(code);

assert.equal(blocks.length, 1);
assert.equal(blocks[0], "var answer = 6 * 7;");
assert.equal(blocks[0], "var answer = 6 * 7;\n");
});

it("should allow backticks or tildes", function() {
Expand All @@ -113,8 +113,8 @@ describe("processor", function() {
var blocks = processor.preprocess(code);

assert.equal(blocks.length, 2);
assert.equal(blocks[0], "backticks");
assert.equal(blocks[1], "tildes");
assert.equal(blocks[0], "backticks\n");
assert.equal(blocks[1], "tildes\n");
});

it("should allow more than three fence characters", function() {
Expand All @@ -126,7 +126,7 @@ describe("processor", function() {
var blocks = processor.preprocess(code);

assert.equal(blocks.length, 1);
assert.equal(blocks[0], "four");
assert.equal(blocks[0], "four\n");
});

it("should require end fences at least as long as the starting fence", function() {
Expand All @@ -145,9 +145,9 @@ describe("processor", function() {
var blocks = processor.preprocess(code);

assert.equal(blocks.length, 3);
assert.equal(blocks[0], "four\n```");
assert.equal(blocks[1], "five");
assert.equal(blocks[2], "six");
assert.equal(blocks[0], "four\n```\n");
assert.equal(blocks[1], "five\n");
assert.equal(blocks[2], "six\n");
});

it("should not allow other content on ending fence line", function() {
Expand All @@ -160,7 +160,7 @@ describe("processor", function() {
var blocks = processor.preprocess(code);

assert.equal(blocks.length, 1);
assert.equal(blocks[0], "test();\n``` end");
assert.equal(blocks[0], "test();\n``` end\n");
});

it("should allow empty blocks", function() {
Expand All @@ -172,7 +172,7 @@ describe("processor", function() {
var blocks = processor.preprocess(code);

assert.equal(blocks.length, 1);
assert.equal(blocks[0], "");
assert.equal(blocks[0], "\n");
});

it("should allow whitespace-only blocks", function() {
Expand All @@ -188,7 +188,7 @@ describe("processor", function() {
var blocks = processor.preprocess(code);

assert.equal(blocks.length, 1);
assert.equal(blocks[0], "\n\n \n ");
assert.equal(blocks[0], "\n\n \n \n");
});

it("should ignore code fences with unspecified info string", function() {
Expand Down Expand Up @@ -292,7 +292,7 @@ describe("processor", function() {
].join("\n");
var blocks = processor.preprocess(code);

assert.equal(blocks[0], "var answer = 6 * 7;");
assert.equal(blocks[0], "var answer = 6 * 7;\n");
});

it("should allow multi-line source code", function() {
Expand All @@ -304,7 +304,7 @@ describe("processor", function() {
].join("\n");
var blocks = processor.preprocess(code);

assert.equal(blocks[0], "var answer = 6 * 7;\nconsole.log(answer);");
assert.equal(blocks[0], "var answer = 6 * 7;\nconsole.log(answer);\n");
});

it("should preserve original line endings", function() {
Expand All @@ -316,7 +316,7 @@ describe("processor", function() {
].join("\r\n");
var blocks = processor.preprocess(code);

assert.equal(blocks[0], "var answer = 6 * 7;\nconsole.log(answer);");
assert.equal(blocks[0], "var answer = 6 * 7;\nconsole.log(answer);\n");
});

it("should unindent space-indented code fences", function() {
Expand All @@ -329,7 +329,7 @@ describe("processor", function() {
].join("\n");
var blocks = processor.preprocess(code);

assert.equal(blocks[0], "var answer = 6 * 7;\n console.log(answer);\n// Fin.");
assert.equal(blocks[0], "var answer = 6 * 7;\n console.log(answer);\n// Fin.\n");
});

it("should find multiple code fences", function() {
Expand All @@ -349,8 +349,8 @@ describe("processor", function() {
var blocks = processor.preprocess(code);

assert.equal(blocks.length, 2);
assert.equal(blocks[0], "var answer = 6 * 7;");
assert.equal(blocks[1], "console.log(answer);");
assert.equal(blocks[0], "var answer = 6 * 7;\n");
assert.equal(blocks[1], "console.log(answer);\n");
});

it("should insert leading configuration comments", function() {
Expand Down Expand Up @@ -378,7 +378,8 @@ describe("processor", function() {
" \"single\"",
" ]",
"*/",
"alert('Hello, world!');"
"alert('Hello, world!');",
""
].join("\n"));
});

Expand All @@ -397,7 +398,8 @@ describe("processor", function() {
assert.equal(blocks[0], [
"/* global foo */",
"/* global bar:false, baz:true */",
"alert(foo, bar, baz);"
"alert(foo, bar, baz);",
""
].join("\n"));
});

Expand All @@ -414,7 +416,8 @@ describe("processor", function() {

assert.equal(blocks.length, 1);
assert.equal(blocks[0], [
"alert('Hello, world!');"
"alert('Hello, world!');",
""
].join("\n"));
});

Expand All @@ -431,7 +434,8 @@ describe("processor", function() {

assert.equal(blocks.length, 1);
assert.equal(blocks[0], [
"alert('Hello, world!');"
"alert('Hello, world!');",
""
].join("\n"));
});

Expand Down Expand Up @@ -465,7 +469,7 @@ describe("processor", function() {
var blocks = processor.preprocess(code);

assert.equal(blocks.length, 1);
assert.equal(blocks[0], "var answer = 6 * 7;");
assert.equal(blocks[0], "var answer = 6 * 7;\n");
});

it("should still work surrounded by other comments", function() {
Expand All @@ -485,7 +489,7 @@ describe("processor", function() {
var blocks = processor.preprocess(code);

assert.equal(blocks.length, 1);
assert.equal(blocks[0], "var answer = 6 * 7;");
assert.equal(blocks[0], "var answer = 6 * 7;\n");
});

});
Expand Down

0 comments on commit a2f4492

Please sign in to comment.