📄 markdown¶
📊 Analysis Summary¶
| Metric | Count |
|---|---|
| 🔧 Functions | 5 |
| 📦 Imports | 2 |
📚 Table of Contents¶
🛠️ File Location:¶
📂 packages/website/src/components/lib/markdown.ts
📦 Imports¶
| Name | Source |
|---|---|
ConfigModel |
../types |
parseESLintRC |
./parseConfig |
Functions¶
createMarkdown(state: ConfigModel): string¶
Create a markdown string that user can copy and paste into an issue
Calls:
[Playground, createSummary(state.code, 'Code', 'ts', 30), createSummaryJson(state.eslintrc, 'rules', 'Eslint config'), createSummaryJson(state.tsconfig, 'compilerOptions', 'TypeScript config'), generateVersionsTable(state.ts), ] .filter(Boolean) .join
Code
export function createMarkdown(state: ConfigModel): string {
return [
`[Playground](${document.location.toString()})`,
createSummary(state.code, 'Code', 'ts', 30),
createSummaryJson(state.eslintrc, 'rules', 'Eslint config'),
createSummaryJson(state.tsconfig, 'compilerOptions', 'TypeScript config'),
generateVersionsTable(state.ts),
]
.filter(Boolean)
.join('\n\n');
}
createMarkdownParams(state: ConfigModel): string¶
Create a URLSearchParams string for the issue template
Calls:
parseESLintRC (from ./parseConfig)Object.keysruleKeys[0].replacedocument.location.toStringgenerateVersionsTablenew URLSearchParams(params).toString
Code
export function createMarkdownParams(state: ConfigModel): string {
const { rules } = parseESLintRC(state.eslintrc);
const ruleKeys = Object.keys(rules);
const onlyRuleName =
ruleKeys.length === 1
? ruleKeys[0].replace('@typescript-eslint/', '')
: 'rule name here';
const params = {
'eslint-config': `module.exports = ${state.eslintrc}`,
labels: 'bug,package: eslint-plugin,triage',
'playground-link': document.location.toString(),
'repro-code': state.code,
template: '01-bug-report-plugin.yaml',
title: `Bug: [${onlyRuleName}] <short description of the issue>`,
'typescript-config': state.tsconfig,
versions: generateVersionsTable(state.ts),
};
return new URLSearchParams(params).toString();
}
createSummary(value: string, title: string, type: 'json' | 'ts', length: number): string¶
Parameters:
valuestringtitlestringtype'json' | 'ts'lengthnumber
Returns: string
Calls:
code.match
Code
function createSummary(
value: string,
title: string,
type: 'json' | 'ts',
length: number,
): string {
const code = `### ${title}\n\n\`\`\`${type}\n${value}\n\`\`\``;
if ((code.match(/\n/g) ?? []).length > length) {
return `<details>\n<summary>Expand</summary>\n\n${code}\n\n</details>`;
}
return code;
}
createSummaryJson(obj: string, field: string, title: string): string¶
Parameters:
objstringfieldstringtitlestring
Returns: string
Calls:
createSummary
Code
generateVersionsTable(tsVersion: string): string¶
Parameters:
tsVersionstring
Returns: string
Calls:
[ '| package | version |', '| -- | -- |',| `@typescript-eslint/eslint-plugin` | `${process.env.TS_ESLINT_VERSION}` |,| `@typescript-eslint/parser` | `${process.env.TS_ESLINT_VERSION}` |,| `TypeScript` | `${tsVersion}` |,| `ESLint` | `${process.env.ESLINT_VERSION}` |,| `node` | `web` |, ].join
Code
function generateVersionsTable(tsVersion: string): string {
return [
'| package | version |',
'| -- | -- |',
`| \`@typescript-eslint/eslint-plugin\` | \`${process.env.TS_ESLINT_VERSION}\` |`,
`| \`@typescript-eslint/parser\` | \`${process.env.TS_ESLINT_VERSION}\` |`,
`| \`TypeScript\` | \`${tsVersion}\` |`,
`| \`ESLint\` | \`${process.env.ESLINT_VERSION}\` |`,
`| \`node\` | \`web\` |`,
].join('\n');
}
Generated by Syntax Scribe