Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ module.exports = {
{
// 3. Optionally, customize the configuration ESLint uses for ```js
// fenced code blocks inside .md files.
files: ["**/*.md/*.js"],
files: ["**/*.md/*.js", "**/*.md/*.js:*"],
// ...
rules: {
// ...
Expand Down Expand Up @@ -87,12 +87,17 @@ module.exports = {
// ...
{
// 1. Target ```js code blocks in .md files.
files: ["**/*.md/*.js"],
files: ["**/*.md/*.js", "**/*.md/*.js:*"],
rules: {
// 2. Disable other rules.
"no-console": "off",
"import/no-unresolved": "off"
}
},
{
// 2. Target "```js esm" code blocks
files: ["**/*.md/*.js:esm"],
parserOptions: { type: "module" }
}
]
};
Expand Down Expand Up @@ -167,7 +172,7 @@ module.exports = {
// In v2, configuration for fenced code blocks is separate from the
// containing Markdown file. Each code block has a virtual filename
// appended to the Markdown file's path.
files: ["**/*.md/*.js"],
files: ["**/*.md/*.js", "**/*.md/*.js:*"],
// Configuration for fenced code blocks goes with the override for
// the code block's virtual filename, for example:
parserOptions: {
Expand Down Expand Up @@ -195,7 +200,10 @@ module.exports = {
processor: "markdown/markdown"
},
{
files: ["**/*.{md,mkdn,mdown,markdown}/*.{js,javascript,jsx,node}"]
files: [
"**/*.{md,mkdn,mdown,markdown}/*.{js,javascript,jsx,node}",
"**/*.{md,mkdn,mdown,markdown}/*.{js,javascript,jsx,node}:*"
]
// ...
}
]
Expand Down
4 changes: 2 additions & 2 deletions lib/processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ function preprocess(text) {
});

return blocks.map((block, index) => ({
filename: `${index}.${block.lang.trim().split(" ")[0]}`,
filename: `${index}.${block.lang}${block.meta ? `:${block.meta}` : ""}`,
text: [
...block.comments,
block.value,
Expand Down Expand Up @@ -286,7 +286,7 @@ function adjustBlock(block) {

const out = {
line: lineInCode + blockStart,
column: message.column + block.position.indent[lineInCode - 1] - 1
column: message.column + block.baseIndentText.length
};

if (Number.isInteger(message.endLine)) {
Expand Down
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": "^9.0.0",
"unified": "^6.1.2"
},
"peerDependencies": {
Expand Down
18 changes: 9 additions & 9 deletions tests/lib/processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ 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 ignore code fences with unspecified info string", () => {
Expand Down Expand Up @@ -273,16 +273,16 @@ describe("processor", () => {
assert.strictEqual(blocks[0].filename, "0.JavaScript");
});

it("should ignore anything after the first word of the info string", () => {
it("should should handle meta info", () => {
const code = [
"```js more words are ignored",
"var answer = 6 * 7;",
"```js esm",
"export {};",
"```"
].join("\n");
const blocks = processor.preprocess(code);

assert.strictEqual(blocks.length, 1);
assert.strictEqual(blocks[0].filename, "0.js");
assert.strictEqual(blocks[0].filename, "0.js:esm");
});

it("should ignore leading whitespace in the info string", () => {
Expand All @@ -294,7 +294,7 @@ describe("processor", () => {
const blocks = processor.preprocess(code);

assert.strictEqual(blocks.length, 1);
assert.strictEqual(blocks[0].filename, "0.js");
assert.strictEqual(blocks[0].filename, "0.js:ignores leading whitespace");
});

it("should ignore trailing whitespace in the info string", () => {
Expand Down Expand Up @@ -362,7 +362,7 @@ describe("processor", () => {
const blocks = processor.preprocess(code);

assert.strictEqual(blocks[0].filename, "0.js");
assert.strictEqual(blocks[0].text, "var answer = 6 * 7;\nconsole.log(answer);\n");
assert.strictEqual(blocks[0].text, "var answer = 6 * 7;\r\nconsole.log(answer);\n");
});

it("should unindent space-indented code fences", () => {
Expand Down Expand Up @@ -646,8 +646,8 @@ describe("processor", () => {
const result = processor.postprocess(messages);

assert.strictEqual(result[2].column, 9);
assert.strictEqual(result[3].column, 2);
assert.strictEqual(result[4].column, 2);
assert.strictEqual(result[3].column, 4);
assert.strictEqual(result[4].column, 4);
});

it("should adjust fix range properties", () => {
Expand Down