UNPKG

eslint-plugin-mdx

Version:
38 lines • 1.39 kB
import { ENABLED_OPTION_SCHEMA, getRuleConfig } from './helpers.js'; const isParagraph = (node) => node?.type === 'MDParagraph'; export const noEmphasisAsHeading = { meta: { type: 'problem', docs: { description: 'Disallow emphasis used as a heading', }, schema: [ENABLED_OPTION_SCHEMA], }, create(context) { const config = getRuleConfig(context, 'no-emphasis-as-heading'); if (!config) { return {}; } return { MDParagraph(node) { const parent = node.parent; const children = parent?.children ?? parent?.body; const index = children.indexOf(node); const next = children[index + 1]; if (!isParagraph(next)) { return; } const [head] = node.children; if (node.children.length !== 1 || (head?.type !== 'MDEmphasis' && head?.type !== 'MDStrong')) { return; } context.report({ loc: node.loc, message: `Unexpected ${head.type === 'MDStrong' ? 'strong' : 'emphasis'} introducing a section, expected a heading instead`, }); }, }; }, }; //# sourceMappingURL=no-emphasis-as-heading.js.map