UNPKG

eslint-plugin-mdx

Version:
47 lines 1.66 kB
import { isJsxNode } from 'eslint-mdx'; export const noJsxHtmlComments = { meta: { type: 'problem', docs: { description: 'Forbid invalid html style comments in jsx block', category: 'SyntaxError', recommended: true, }, messages: { jsxHtmlComments: 'html style comments are invalid in jsx: {{ origin }}', }, fixable: 'code', }, create(context) { return { ExpressionStatement(node) { const { JSXElementsWithHTMLComments: invalidNodes, } = context.parserServices; if (!isJsxNode(node.expression) || node.parent.type !== 'Program' || !invalidNodes || invalidNodes.length === 0) { return; } const invalidNode = invalidNodes.shift(); if (invalidNode.data.inline) { return; } const comments = invalidNode.data.comments; for (const { fixed, loc, origin } of comments) { context.report({ messageId: 'jsxHtmlComments', data: { origin, }, loc, node, fix(fixer) { return fixer.replaceTextRange([loc.start.offset, loc.end.offset], fixed); }, }); } }, }; }, }; //# sourceMappingURL=no-jsx-html-comments.js.map