Skip to content

Commit

Permalink
Update: Upgrade remark-parse to v7 (fixes #77, fixes #78)
Browse files Browse the repository at this point in the history
`remark-parse@7.0.0` includes
remarkjs/remark#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?
  • Loading branch information
btmills committed Feb 27, 2021
1 parent 610cffd commit dc2d2ec
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"nyc": "^14.1.1"
},
"dependencies": {
"remark-parse": "^5.0.0",
"remark-parse": "^7.0.0",
"unified": "^6.1.2"
},
"peerDependencies": {
Expand Down
32 changes: 32 additions & 0 deletions tests/lib/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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 = [
"<!-- eslint lines-around-directive: ['error', 'never'] -->",
"",
"```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", () => {
Expand Down
16 changes: 15 additions & 1 deletion tests/lib/processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down

0 comments on commit dc2d2ec

Please sign in to comment.