Skip to content

Commit

Permalink
Chore: Reproduce nested blocks failure (refs #181)
Browse files Browse the repository at this point in the history
The current implementation assumes the `blocks` module-level variable
will only be used once per physical file. If the file contains a nested
Markdown code block, the processor will be recursively run on the code
block's virtual file.
  • Loading branch information
btmills committed Mar 30, 2021
1 parent e0c8bce commit 12a6b18
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/lib/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,45 @@ describe("plugin", () => {
assert.strictEqual(report.results[0].messages[4].column, 2);
});

// https://github.com/eslint/eslint-plugin-markdown/issues/181
it("should work when called on nested code blocks in the same file", () => {

/*
* As of this writing, the nested code block, though it uses the same
* Markdown processor, must use a different extension or ESLint will not
* re-apply the processor on the nested code block. To work around that,
* a file named `test.md` contains a nested `markdown` code block in
* this test.
*
* https://github.com/eslint/eslint/pull/14227/files#r602802758
*/
const code = [
"<!-- test.md -->",
"",
"````markdown",
"<!-- test.md/0_0.markdown -->",
"",
"This test only repros if the MD files have a different number of lines before code blocks.",
"",
"```js",
"// test.md/0_0.markdown/0_0.js",
"console.log('single quotes')",
"```",
"````"
].join("\n");
const recursiveCli = initCLI("eslintrc.json", {
extensions: [".js", ".markdown", ".md"]
});
const report = recursiveCli.executeOnText(code, "test.md");

assert.strictEqual(report.results.length, 1);
assert.strictEqual(report.results[0].messages.length, 2);
assert.strictEqual(report.results[0].messages[0].message, "Unexpected console statement.");
assert.strictEqual(report.results[0].messages[0].line, 8);
assert.strictEqual(report.results[0].messages[1].message, "Strings must use doublequote.");
assert.strictEqual(report.results[0].messages[1].line, 8);
});

describe("configuration comments", () => {

it("apply only to the code block immediately following", () => {
Expand Down

0 comments on commit 12a6b18

Please sign in to comment.