eslint-plugin-mdx
Version:
ESLint Plugin for MDX
33 lines • 1.27 kB
JavaScript
import { ENABLED_OPTION_SCHEMA, getRuleConfig } from './helpers.js';
export const finalDefinition = {
meta: {
type: 'layout',
docs: { description: 'Require definitions at the end' },
schema: [ENABLED_OPTION_SCHEMA],
},
create(context) {
const config = getRuleConfig(context, 'final-definition');
if (!config) {
return {};
}
return {
Program() {
const body = context.sourceCode.ast.body;
const definition = body.find(node => node.type === 'MDDefinition' ||
node.type === 'MDFootnoteDefinition');
const index = definition ? body.indexOf(definition) : -1;
if (definition &&
body
.slice(index + 1)
.some(node => node.type !== 'MDDefinition' &&
node.type !== 'MDFootnoteDefinition')) {
context.report({
loc: definition.loc,
message: 'Unexpected definition before last content, expected definitions after last content',
});
}
},
};
},
};
//# sourceMappingURL=final-definition.js.map