UNPKG

eslint-plugin-mdx

Version:
44 lines • 1.43 kB
import { getRuleConfig } from './helpers.js'; const markerText = (marker) => (marker === '`' ? '`` ` ``' : '`~`'); export const fencedCodeMarker = { meta: { type: 'layout', docs: { description: 'Enforce a consistent fenced code marker', }, schema: [{ enum: ['`', '~', 'consistent'], type: 'string' }], }, create(context) { const config = getRuleConfig(context, 'fenced-code-marker'); if (!config) { return {}; } let expected = config.options === '`' || config.options === '~' ? config.options : undefined; return { MDCode(node) { const raw = node.raw; let actual; if (raw.startsWith('```')) { actual = '`'; } else if (raw.startsWith('~~~')) { actual = '~'; } if (!actual) { return; } expected ??= actual; if (actual === expected) { return; } context.report({ loc: node.loc, message: `Unexpected fenced code marker ${markerText(actual)}, expected ${markerText(expected)}`, }); }, }; }, }; //# sourceMappingURL=fenced-code-marker.js.map