eslint-plugin-mdx
Version:
ESLint Plugin for MDX
35 lines • 1.16 kB
JavaScript
import { ENABLED_OPTION_SCHEMA, getRuleConfig } from './helpers.js';
export const noDuplicateHeadings = {
meta: {
type: 'problem',
docs: {
description: 'Disallow duplicate headings',
},
schema: [ENABLED_OPTION_SCHEMA],
},
create(context) {
const config = getRuleConfig(context, 'no-duplicate-headings');
if (!config) {
return {};
}
const sourceText = context.sourceCode.getText();
const headings = new Set();
return {
MDHeading(node) {
const text = sourceText
.slice(node.range[0], node.range[1])
.replace(/^\s*#{1,6}\s*/u, '')
.trim()
.toLowerCase();
if (headings.has(text)) {
context.report({
loc: node.loc,
message: 'Unexpected heading with equivalent text, expected unique headings',
});
}
headings.add(text);
},
};
},
};
//# sourceMappingURL=no-duplicate-headings.js.map