eslint-plugin-mdx
Version:
ESLint Plugin for MDX
34 lines • 1.41 kB
JavaScript
import { getRuleConfig } from './helpers.js';
const pluralize = (count) => (count === 1 ? 'space' : 'spaces');
export const blockquoteIndentation = {
meta: {
type: 'layout',
docs: { description: 'Enforce blockquote indentation' },
schema: [{ type: ['number', 'string'] }],
},
create(context) {
const config = getRuleConfig(context, 'blockquote-indentation');
if (!config) {
return {};
}
let expected = typeof config.options === 'number' ? config.options : undefined;
return {
MDBlockquote(node) {
const [child] = node.children;
if (!child) {
return;
}
const actual = child.loc.start.column - node.loc.start.column;
expected ??= actual;
if (actual !== expected) {
const difference = expected - actual;
context.report({
loc: child.loc,
message: `Unexpected \`${actual}\` ${pluralize(actual)} between block quote marker and content, expected \`${expected}\` ${pluralize(expected)}, ${difference > 0 ? 'add' : 'remove'} \`${Math.abs(difference)}\` ${pluralize(Math.abs(difference))}`,
});
}
},
};
},
};
//# sourceMappingURL=blockquote-indentation.js.map