Skip to content

Commit 8b2d79a

Browse files
committed
Formatting fixes and code tidy-up
1 parent c4db8b6 commit 8b2d79a

3 files changed

Lines changed: 25 additions & 19 deletions

File tree

extensions/ql-vscode/src/remote-queries/remote-queries-markdown-generation.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ export function generateMarkdown(query: RemoteQuery, analysesResults: AnalysisRe
1919
}
2020

2121
// Append nwo and results count to the summary table
22-
summaryLines.push(
23-
`| ${analysisResult.nwo} | [${analysisResult.interpretedResults.length} result(s)](${createGistRelativeLink(analysisResult.nwo)}) |`
24-
);
22+
const nwo = analysisResult.nwo;
23+
const resultsCount = analysisResult.interpretedResults.length;
24+
const link = createGistRelativeLink(nwo);
25+
summaryLines.push(`| ${nwo} | [${resultsCount} result(s)](${link}) |`);
2526

2627
// Generate individual markdown file for each repository
2728
const lines = [
@@ -34,15 +35,16 @@ export function generateMarkdown(query: RemoteQuery, analysesResults: AnalysisRe
3435
}
3536
files.push(lines);
3637
}
37-
files.push(summaryLines);
38-
return files;
38+
return [summaryLines, ...files];
3939
}
4040

4141
export function generateMarkdownSummary(query: RemoteQuery): MarkdownFile {
4242
const lines: MarkdownFile = [];
4343
// Title
44-
lines.push(`## Results for "${query.queryName}"`);
45-
lines.push('');
44+
lines.push(
45+
`### Results for "${query.queryName}"`,
46+
''
47+
);
4648

4749
// Expandable section containing query text
4850
const queryCodeBlock = [
@@ -54,12 +56,16 @@ export function generateMarkdownSummary(query: RemoteQuery): MarkdownFile {
5456
...buildExpandableMarkdownSection('Query', queryCodeBlock)
5557
);
5658

57-
// Summary table
59+
// Padding between sections
5860
lines.push(
59-
'### Summary',
60-
''
61+
'<br />',
62+
'',
6163
);
64+
65+
// Summary table
6266
lines.push(
67+
'### Summary',
68+
'',
6369
'| Repository | Results |',
6470
'| --- | --- |',
6571
);
@@ -151,9 +157,7 @@ function buildExpandableMarkdownSection(title: string, contents: MarkdownFile):
151157
'<details>',
152158
`<summary>${title}</summary>`,
153159
'',
154-
);
155-
expandableLines.push(...contents);
156-
expandableLines.push(
160+
...contents,
157161
'',
158162
'</details>',
159163
''

extensions/ql-vscode/test/pure-tests/remote-queries/markdown-generation/interpreted-results/data/summary.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## Results for "Shell command built from environment values"
1+
### Results for "Shell command built from environment values"
22

33
<details>
44
<summary>Query</summary>
@@ -39,6 +39,8 @@ select highlight, source, sink, "This shell command depends on an uncontrolled $
3939

4040
</details>
4141

42+
<br />
43+
4244
### Summary
4345

4446
| Repository | Results |

extensions/ql-vscode/test/pure-tests/remote-queries/markdown-generation/interpreted-results/markdown-generation.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ describe('markdown generation', async function() {
1717
// Check that query has results for two repositories, plus a summary file
1818
expect(markdownFiles.length).to.equal(3);
1919

20-
const markdownFile1 = markdownFiles[0]; // results for github/codeql repo
21-
const markdownFile2 = markdownFiles[1]; // results for meteor/meteor repo
22-
const markdownFile3 = markdownFiles[2]; // summary file
20+
const markdownFile0 = markdownFiles[0]; // summary file
21+
const markdownFile1 = markdownFiles[1]; // results for github/codeql repo
22+
const markdownFile2 = markdownFiles[2]; // results for meteor/meteor repo
2323

24+
const expectedSummaryFile = await readTestOutputFile('data/summary.md');
2425
const expectedTestOutput1 = await readTestOutputFile('data/results-repo1.md');
2526
const expectedTestOutput2 = await readTestOutputFile('data/results-repo2.md');
26-
const expectedSummaryFile = await readTestOutputFile('data/summary.md');
2727

2828
// Check that markdown output is correct, after making line endings consistent
29+
expect(markdownFile0.join('\n')).to.equal(expectedSummaryFile);
2930
expect(markdownFile1.join('\n')).to.equal(expectedTestOutput1);
3031
expect(markdownFile2.join('\n')).to.equal(expectedTestOutput2);
31-
expect(markdownFile3.join('\n')).to.equal(expectedSummaryFile);
3232
});
3333
});
3434

0 commit comments

Comments
 (0)