UNPKG

eslint-plugin-mdx

Version:
39 lines • 1.38 kB
import { ENABLED_OPTION_SCHEMA, getRuleConfig } from './helpers.js'; export const noDuplicateHeadingsInSection = { meta: { type: 'problem', docs: { description: 'Disallow duplicate headings within a section', }, schema: [ENABLED_OPTION_SCHEMA], }, create(context) { const config = getRuleConfig(context, 'no-duplicate-headings-in-section'); if (!config) { return {}; } const sourceText = context.sourceCode.getText(); const stack = []; return { MDHeading(node) { const rank = node.depth; const value = sourceText .slice(node.range[0], node.range[1]) .replace(/^\s*#{1,6}\s*/u, '') .trim() .toLowerCase(); const map = stack[rank - 1] ?? new Map(); stack[rank - 1] = map; if (map.has(value)) { context.report({ loc: node.loc, message: 'Unexpected heading with equivalent text in section, expected unique headings', }); } map.set(value, node); stack.length = rank; }, }; }, }; //# sourceMappingURL=no-duplicate-headings-in-section.js.map