Skip to content

Commit 27ae404

Browse files
authored
test: add case for #470 (#566)
1 parent 2672044 commit 27ae404

File tree

11 files changed

+151
-656
lines changed

11 files changed

+151
-656
lines changed

.changeset/great-snakes-nail.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"eslint-mdx": minor
3+
"eslint-plugin-mdx": minor
4+
---
5+
6+
feat: check nested code blocks without blank lines

packages/eslint-plugin-mdx/src/processors/helpers.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ export const DEFAULT_LANGUAGE_MAPPER: Record<string, string> = {
55
typescript: 'ts',
66
typescriptreact: 'tsx',
77
markdown: 'md',
8+
markdownjsx: 'mdx',
9+
markdownreact: 'mdx',
810
mdown: 'md',
911
mkdn: 'md',
1012
}

test/__snapshots__/fixtures.test.ts.snap

Lines changed: 132 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`fixtures lint code blocks should work as expected: code-blocks.md 1`] = `
3+
exports[`fixtures lint code blocks should work as expected: code-blocks/278.md 1`] = `
44
[
55
{
66
"column": 1,
@@ -113,7 +113,7 @@ exports[`fixtures lint code blocks should work as expected: code-blocks.md 1`] =
113113
]
114114
`;
115115

116-
exports[`fixtures lint code blocks should work as expected: code-blocks.md 2`] = `
116+
exports[`fixtures lint code blocks should work as expected: code-blocks/278.md 2`] = `
117117
"# abc
118118
119119
# abc
@@ -168,7 +168,128 @@ import React from 'react'
168168
"
169169
`;
170170

171-
exports[`fixtures lint code blocks should work as expected: code-blocks.mdx 1`] = `
171+
exports[`fixtures lint code blocks should work as expected: code-blocks/455.mdx 1`] = `
172+
[
173+
{
174+
"column": 1,
175+
"endColumn": 6,
176+
"endLine": 2,
177+
"fix": {
178+
"range": [
179+
6,
180+
9,
181+
],
182+
"text": "let",
183+
},
184+
"line": 2,
185+
"message": "Unexpected var, use let or const instead.",
186+
"messageId": "unexpectedVar",
187+
"nodeType": "VariableDeclaration",
188+
"ruleId": "no-var",
189+
"severity": 2,
190+
},
191+
{
192+
"column": 5,
193+
"endColumn": 6,
194+
"endLine": 4,
195+
"fix": {
196+
"range": [
197+
13,
198+
30,
199+
],
200+
"text": "const b = [1, 2, 3]",
201+
},
202+
"line": 4,
203+
"message": "'b' is never reassigned. Use 'const' instead.",
204+
"messageId": "useConst",
205+
"nodeType": "Identifier",
206+
"ruleId": "prefer-const",
207+
"severity": 2,
208+
},
209+
{
210+
"column": 13,
211+
"endColumn": 25,
212+
"endLine": 6,
213+
"fix": {
214+
"range": [
215+
43,
216+
57,
217+
],
218+
"text": ".at(-1)",
219+
},
220+
"line": 6,
221+
"message": "Prefer \`.at(…)\` over \`[….length - index]\`.",
222+
"messageId": "negative-index",
223+
"nodeType": "BinaryExpression",
224+
"ruleId": "unicorn/prefer-at",
225+
"severity": 2,
226+
},
227+
]
228+
`;
229+
230+
exports[`fixtures lint code blocks should work as expected: code-blocks/455.mdx 2`] = `
231+
"\`\`\`js
232+
let a
233+
234+
const b = [1, 2, 3]
235+
236+
const c = b.at(-1)
237+
238+
export { c }
239+
\`\`\`
240+
"
241+
`;
242+
243+
exports[`fixtures lint code blocks should work as expected: code-blocks/470.mdx 1`] = `
244+
[
245+
{
246+
"column": 3,
247+
"endColumn": 23,
248+
"endLine": 3,
249+
"line": 3,
250+
"message": "Identifier 'im_not_camel_case_oops' is not in camel case.",
251+
"messageId": "notCamelCase",
252+
"nodeType": "Identifier",
253+
"ruleId": "camelcase",
254+
"severity": 2,
255+
},
256+
{
257+
"column": 3,
258+
"endColumn": 23,
259+
"endLine": 3,
260+
"line": 3,
261+
"message": "Expected an assignment or function call and instead saw an expression.",
262+
"messageId": "unusedExpression",
263+
"nodeType": "ExpressionStatement",
264+
"ruleId": "@typescript-eslint/no-unused-expressions",
265+
"severity": 2,
266+
},
267+
{
268+
"column": 1,
269+
"endColumn": 23,
270+
"endLine": 8,
271+
"line": 8,
272+
"message": "Identifier 'im_not_camel_case_oops' is not in camel case.",
273+
"messageId": "notCamelCase",
274+
"nodeType": "Identifier",
275+
"ruleId": "camelcase",
276+
"severity": 2,
277+
},
278+
{
279+
"column": 1,
280+
"endColumn": 23,
281+
"endLine": 8,
282+
"line": 8,
283+
"message": "Expected an assignment or function call and instead saw an expression.",
284+
"messageId": "unusedExpression",
285+
"nodeType": "ExpressionStatement",
286+
"ruleId": "@typescript-eslint/no-unused-expressions",
287+
"severity": 2,
288+
},
289+
]
290+
`;
291+
292+
exports[`fixtures lint code blocks should work as expected: code-blocks/534.mdx 1`] = `
172293
[
173294
{
174295
"column": 7,
@@ -251,7 +372,7 @@ Content {/* nothing special */}
251372
]
252373
`;
253374
254-
exports[`fixtures lint code blocks should work as expected: code-blocks.mdx 2`] = `
375+
exports[`fixtures lint code blocks should work as expected: code-blocks/534.mdx 2`] = `
255376
"\`\`\`ts
256377
import { CommandRegister } from "@foo";
257378
export function registerCommands(commandRegister: CommandRegister) {
@@ -288,78 +409,6 @@ Content {/* nothing special */}
288409
"
289410
`;
290411
291-
exports[`fixtures lint code blocks should work as expected: flat-config/code-blocks.mdx 1`] = `
292-
[
293-
{
294-
"column": 1,
295-
"endColumn": 6,
296-
"endLine": 2,
297-
"fix": {
298-
"range": [
299-
6,
300-
9,
301-
],
302-
"text": "let",
303-
},
304-
"line": 2,
305-
"message": "Unexpected var, use let or const instead.",
306-
"messageId": "unexpectedVar",
307-
"nodeType": "VariableDeclaration",
308-
"ruleId": "no-var",
309-
"severity": 2,
310-
},
311-
{
312-
"column": 5,
313-
"endColumn": 6,
314-
"endLine": 4,
315-
"fix": {
316-
"range": [
317-
13,
318-
30,
319-
],
320-
"text": "const b = [1, 2, 3]",
321-
},
322-
"line": 4,
323-
"message": "'b' is never reassigned. Use 'const' instead.",
324-
"messageId": "useConst",
325-
"nodeType": "Identifier",
326-
"ruleId": "prefer-const",
327-
"severity": 2,
328-
},
329-
{
330-
"column": 13,
331-
"endColumn": 25,
332-
"endLine": 6,
333-
"fix": {
334-
"range": [
335-
43,
336-
57,
337-
],
338-
"text": ".at(-1)",
339-
},
340-
"line": 6,
341-
"message": "Prefer \`.at(…)\` over \`[….length - index]\`.",
342-
"messageId": "negative-index",
343-
"nodeType": "BinaryExpression",
344-
"ruleId": "unicorn/prefer-at",
345-
"severity": 2,
346-
},
347-
]
348-
`;
349-
350-
exports[`fixtures lint code blocks should work as expected: flat-config/code-blocks.mdx 2`] = `
351-
"\`\`\`js
352-
let a
353-
354-
const b = [1, 2, 3]
355-
356-
const c = b.at(-1)
357-
358-
export { c }
359-
\`\`\`
360-
"
361-
`;
362-
363412
exports[`fixtures should match all snapshots: 287.mdx 1`] = `[]`;
364413
365414
exports[`fixtures should match all snapshots: 292.mdx 1`] = `
@@ -1471,7 +1520,7 @@ Here's a YouTube shortcode:
14711520
"
14721521
`;
14731522
1474-
exports[`fixtures should match all snapshots: code-blocks.md 1`] = `
1523+
exports[`fixtures should match all snapshots: code-blocks/278.md 1`] = `
14751524
[
14761525
{
14771526
"column": 1,
@@ -1506,7 +1555,11 @@ exports[`fixtures should match all snapshots: code-blocks.md 1`] = `
15061555
]
15071556
`;
15081557
1509-
exports[`fixtures should match all snapshots: code-blocks.mdx 1`] = `
1558+
exports[`fixtures should match all snapshots: code-blocks/455.mdx 1`] = `[]`;
1559+
1560+
exports[`fixtures should match all snapshots: code-blocks/470.mdx 1`] = `[]`;
1561+
1562+
exports[`fixtures should match all snapshots: code-blocks/534.mdx 1`] = `
15101563
[
15111564
{
15121565
"column": 1,
@@ -1571,7 +1624,7 @@ Content {/* nothing special */}
15711624
]
15721625
`;
15731626
1574-
exports[`fixtures should match all snapshots: code-blocks.mdx 2`] = `
1627+
exports[`fixtures should match all snapshots: code-blocks/534.mdx 2`] = `
15751628
"\`\`\`ts
15761629
import { CommandRegister } from "@foo";
15771630
export function registerCommands(commandRegister: CommandRegister) {
@@ -1651,8 +1704,6 @@ exports[`fixtures should match all snapshots: esm/test.md 1`] = `
16511704
]
16521705
`;
16531706
1654-
exports[`fixtures should match all snapshots: flat-config/code-blocks.mdx 1`] = `[]`;
1655-
16561707
exports[`fixtures should match all snapshots: jsx-in-list.mdx 1`] = `
16571708
[
16581709
{

test/__snapshots__/flat-config.test.ts.snap

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)