UNPKG

eslint-plugin-mdx

Version:
38 lines • 1.33 kB
import { getRuleConfig } from './helpers.js'; export const noHeadingPunctuation = { meta: { type: 'problem', docs: { description: 'Disallow punctuation at the end of headings', }, schema: [{ type: ['string', 'object', 'null'] }], }, create(context) { const config = getRuleConfig(context, 'no-heading-punctuation'); if (!config) { return {}; } const sourceText = context.sourceCode.getText(); const expected = config.options == null ? /[!,.:;?]/u : typeof config.options === 'string' ? new RegExp(`[${config.options}]`, 'u') : config.options; return { MDHeading(node) { const text = sourceText .slice(node.range[0], node.range[1]) .replace(/^\s*#{1,6}\s*/u, '') .trim(); const tail = [...text].at(-1); if (tail && expected.test(tail)) { context.report({ loc: node.loc, message: `Unexpected character \`${tail}\` at end of heading, remove it`, }); } }, }; }, }; //# sourceMappingURL=no-heading-punctuation.js.map