From dc2d2ec0a331a841905934e795cbf1568f9ee8f7 Mon Sep 17 00:00:00 2001 From: Brandon Mills Date: Sun, 14 Feb 2021 19:03:28 -0500 Subject: [PATCH] Update: Upgrade remark-parse to v7 (fixes #77, fixes #78) `remark-parse@7.0.0` includes https://github.com/remarkjs/remark/pull/423, which fixes handling of leading and trailing newlines in fenced code blocks. Tagging this as `Update` so it'll be semver-minor. Are we comfortable with a parser major version bump in a semver-minor release? --- package.json | 2 +- tests/lib/plugin.js | 32 ++++++++++++++++++++++++++++++++ tests/lib/processor.js | 16 +++++++++++++++- 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index ffdf6f45..8d016485 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "nyc": "^14.1.1" }, "dependencies": { - "remark-parse": "^5.0.0", + "remark-parse": "^7.0.0", "unified": "^6.1.2" }, "peerDependencies": { diff --git a/tests/lib/plugin.js b/tests/lib/plugin.js index 8f0d002a..d702b81b 100644 --- a/tests/lib/plugin.js +++ b/tests/lib/plugin.js @@ -145,6 +145,21 @@ describe("plugin", () => { assert.strictEqual(report.results[0].messages[1].endLine, 8); }); + // https://github.com/eslint/eslint-plugin-markdown/issues/77 + it("should emit correct line numbers with leading blank line", () => { + const code = [ + "### Heading", + "", + "```js", + "", + "console.log('a')", + "```" + ].join("\n"); + const report = cli.executeOnText(code, "test.md"); + + assert.strictEqual(report.results[0].messages[0].line, 5); + }); + it("doesn't add end locations to messages without them", () => { const code = [ "```js", @@ -277,6 +292,23 @@ describe("plugin", () => { assert.strictEqual(report.results[0].messages[3].line, 15); }); + // https://github.com/eslint/eslint-plugin-markdown/issues/78 + it("preserves leading empty lines", () => { + const code = [ + "", + "", + "```js", + "", + "\"use strict\";", + "```" + ].join("\n"); + const report = cli.executeOnText(code, "test.md"); + + assert.strictEqual(report.results.length, 1); + assert.strictEqual(report.results[0].messages.length, 1); + assert.strictEqual(report.results[0].messages[0].message, "Unexpected newline before \"use strict\" directive."); + assert.strictEqual(report.results[0].messages[0].line, 5); + }); }); describe("should fix code", () => { diff --git a/tests/lib/processor.js b/tests/lib/processor.js index b3b596b4..031f2c91 100644 --- a/tests/lib/processor.js +++ b/tests/lib/processor.js @@ -199,7 +199,21 @@ describe("processor", () => { assert.strictEqual(blocks.length, 1); assert.strictEqual(blocks[0].filename, "0.js"); - assert.strictEqual(blocks[0].text, "\n\n \n \n"); + assert.strictEqual(blocks[0].text, "\n\n\n \n \n"); + }); + + it("should preserve leading and trailing empty lines", () => { + const code = [ + "```js", + "", + "console.log(42);", + "", + "```" + ].join("\n"); + const blocks = processor.preprocess(code); + + assert.strictEqual(blocks[0].filename, "0.js"); + assert.strictEqual(blocks[0].text, "\nconsole.log(42);\n\n"); }); it("should ignore code fences with unspecified info string", () => {