UNPKG

eslint-plugin-mdx

Version:
100 lines • 3.12 kB
import path from 'node:path'; import { DEFAULT_EXTENSIONS, MARKDOWN_EXTENSIONS, arrayify } from 'eslint-mdx'; export const ANY_OPTION_SCHEMA = {}; export const ENABLED_OPTION_SCHEMA = { additionalProperties: false, properties: { enabled: { const: true } }, required: ['enabled'], type: 'object', }; export const getParserOptions = (context) => { const options = { ...context.parserOptions, ...context.languageOptions?.parserOptions, }; return options; }; export const isMdxFile = (filename, extensions) => [...DEFAULT_EXTENSIONS, ...arrayify(extensions)].includes(path.extname(filename)); export const isMarkdownFile = (filename, markdownExtensions) => [...MARKDOWN_EXTENSIONS, ...arrayify(markdownExtensions)].includes(path.extname(filename)); export const NATIVE_REMARK_RULES = new Set([ 'emphasis-marker', 'final-newline', 'fenced-code-marker', 'heading-increment', 'heading-style', 'definition-case', 'definition-spacing', 'no-consecutive-blank-lines', 'no-duplicate-definitions', 'no-duplicate-headings', 'no-duplicate-headings-in-section', 'no-file-name-articles', 'no-file-name-consecutive-dashes', 'no-file-name-irregular-characters', 'no-file-name-mixed-case', 'no-file-name-outer-dashes', 'no-emphasis-as-heading', 'maximum-heading-length', 'no-heading-content-indent', 'link-title-style', 'no-heading-punctuation', 'ordered-list-marker-style', 'no-literal-urls', 'no-multiple-toplevel-headings', 'no-unused-definitions', 'rule-style', 'no-shell-dollars', 'no-table-indentation', 'no-shortcut-reference-image', 'no-shortcut-reference-link', 'strong-marker', 'unordered-list-marker-style', 'blockquote-indentation', 'checkbox-character-style', 'code-block-style', 'fenced-code-flag', 'final-definition', 'hard-break-spaces', 'list-item-bullet-indent', 'list-item-content-indent', 'list-item-indent', 'list-item-spacing', 'maximum-line-length', 'no-blockquote-without-marker', 'no-undefined-references', 'ordered-list-marker-value', 'table-cell-padding', 'table-pipe-alignment', 'table-pipes', ]); export const getRuleConfig = (context, name) => { const { remarkConfig, } = context.sourceCode.parserServices; if (!remarkConfig) { return null; } const { ruleOptions } = remarkConfig; const eslintOptions = context.options; const hasEslintOption = eslintOptions.length > 0; const hasRemarkOption = name in ruleOptions; if (!hasEslintOption && !hasRemarkOption) { return null; } return { options: (hasEslintOption ? eslintOptions[0] : ruleOptions[name]), }; }; export const getNodeText = (node) => { if (node.type === 'MDHtml') { return ''; } if (node.value != null) { return node.value; } if (node.alt) { return node.alt; } return (node.children ?? []).map(child => getNodeText(child)).join(''); }; //# sourceMappingURL=helpers.js.map