-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
markdown.ts
64 lines (58 loc) · 1.94 KB
/
markdown.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import type { ConfigModel } from '../types';
export function createSummary(
value: string,
title: string,
type: 'ts' | 'json',
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;
}
function createSummaryJson(
obj: ConfigModel['tsconfig'] | ConfigModel['eslintrc'],
field: string,
title: string,
): string {
if (obj && Object.keys(obj).length > 0) {
return createSummary(obj, title, 'json', 10);
}
return '';
}
export function genVersions(state: ConfigModel): string {
return [
'| package | version |',
'| -- | -- |',
`| \`@typescript-eslint/eslint-plugin\` | \`${process.env.TS_ESLINT_VERSION}\` |`,
`| \`@typescript-eslint/parser\` | \`${process.env.TS_ESLINT_VERSION}\` |`,
`| \`TypeScript\` | \`${state.ts}\` |`,
`| \`ESLint\` | \`${process.env.ESLINT_VERSION}\` |`,
`| \`node\` | \`web\` |`,
].join('\n');
}
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'),
genVersions(state),
]
.filter(Boolean)
.join('\n\n');
}
export function createMarkdownParams(state: ConfigModel): string {
const params = {
labels: 'bug,package: eslint-plugin,triage',
template: '1-bug-report-plugin.yaml',
title: 'Bug: [rule name here] <short description of the issue>',
'playground-link': document.location.toString(),
'repro-code': state.code,
'eslint-config': `module.exports = ${state.eslintrc ?? '{}'}`,
'typescript-config': state.tsconfig ?? '{}',
versions: genVersions(state),
};
return new URLSearchParams(params).toString();
}