eslint-plugin-mdx
Version:
ESLint Plugin for MDX
37 lines • 1.28 kB
JavaScript
import { getRuleConfig } from './helpers.js';
export const hardBreakSpaces = {
meta: {
type: 'layout',
docs: { description: 'Enforce hard break spaces' },
schema: [
{
additionalProperties: false,
properties: { allowSpaces: { type: 'boolean' } },
type: 'object',
},
],
},
create(context) {
const config = getRuleConfig(context, 'hard-break-spaces');
if (!config) {
return {};
}
const allowSpaces = config.options?.allowSpaces !== false;
return {
MDBreak(node) {
const raw = node.raw;
const size = raw.length - 1;
if ((raw.startsWith(' ') && !allowSpaces) ||
(raw.startsWith(' ') && size !== 2)) {
context.report({
loc: node.loc,
message: allowSpaces
? `Unexpected \`${size}\` spaces for hard break, expected \`2\` spaces`
: `Unexpected \`${size}\` spaces for hard break, expected escape`,
});
}
},
};
},
};
//# sourceMappingURL=hard-break-spaces.js.map