UNPKG

eslint-plugin-mdx

Version:
41 lines • 1.75 kB
import { ENABLED_OPTION_SCHEMA, getRuleConfig } from './helpers.js'; const pluralize = (count) => (count === 1 ? 'space' : 'spaces'); export const listItemContentIndent = { meta: { type: 'layout', docs: { description: 'Enforce list item content indentation' }, schema: [ENABLED_OPTION_SCHEMA], }, create(context) { const config = getRuleConfig(context, 'list-item-content-indent'); if (!config) { return {}; } const sourceText = context.sourceCode.getText(); return { MDListItem(node) { const children = node.children.filter(child => child.loc); const [first] = children; if (!first) { return; } let expected = first.loc.start.column; if (typeof node.checked === 'boolean') { const checkboxStart = sourceText.lastIndexOf('[', first.range[0] - 1); expected -= first.range[0] - checkboxStart; } for (const child of children.slice(1)) { const actual = child.loc.start.column; if (actual !== expected) { const difference = expected - actual; context.report({ loc: child.loc, message: `Unexpected unaligned list item child, expected to align with first child, ${difference > 0 ? 'add' : 'remove'} \`${Math.abs(difference)}\` ${pluralize(Math.abs(difference))}`, }); } } }, }; }, }; //# sourceMappingURL=list-item-content-indent.js.map