Skip to content

Commit 45fd975

Browse files
author
Carolyn Zech
authored
Fix formatting check in CI (#146)
The `.prettierignore` was ignoring some Typescript files that we'd actually want to check. Rather than have CI check against everything (`prettier .`) with a list of what to exclude, remove the exclusion list and just check all the Typescript files in `src`. See carolynzech#2 for evidence that it works. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.
1 parent 25489e8 commit 45fd975

File tree

5 files changed

+96
-98
lines changed

5 files changed

+96
-98
lines changed

.prettierignore

Lines changed: 0 additions & 15 deletions
This file was deleted.

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
"pretest": "npm run compile && npm run lint",
9191
"lint": "eslint src --ext ts",
9292
"pretty": "prettier --write \"src/**/*.ts\"",
93-
"prettier:check:ci": "./node_modules/.bin/prettier --check .",
93+
"prettier:check:ci": "npx prettier --check \"src/**/*.{ts,tsx}\"",
9494
"test": "node ./out/test/runTest.js"
9595
},
9696
"devDependencies": {
@@ -114,7 +114,7 @@
114114
"eslint-plugin-tsdoc": "^0.2.17",
115115
"glob": "^8.0.3",
116116
"mocha": "^10.0.0",
117-
"prettier": "2.8.0",
117+
"prettier": "3.4.2",
118118
"typescript": "^4.7.4"
119119
},
120120
"dependencies": {

src/ui/coverage/config.ts

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,48 @@
11
// Copyright Kani Contributors
22
// SPDX-License-Identifier: Apache-2.0 OR MIT
33

4-
import { DecorationRenderOptions, ExtensionContext, TextEditorDecorationType, window } from "vscode";
4+
import {
5+
DecorationRenderOptions,
6+
ExtensionContext,
7+
TextEditorDecorationType,
8+
window,
9+
} from 'vscode';
510

611
// Takes the extension context and stores the specified decoration (VS Code highliging API) values for that context
712
// By storing the decoration values per context, we allow users to de-highlight the same contexts.
813
// Without caching these values as a global cache, VS Code does not de-highlight.
914
class CoverageConfig {
10-
public covered!: TextEditorDecorationType;
11-
public partialcovered!: TextEditorDecorationType;
12-
public uncovered!: TextEditorDecorationType;
13-
14-
private context: ExtensionContext;
15-
16-
constructor(context: ExtensionContext) {
17-
this.context = context;
18-
this.setup();
19-
}
20-
21-
private setup(): void {
22-
const fullDecoration: DecorationRenderOptions = {
23-
backgroundColor: 'rgba(0, 255, 0, 0.2)', // Green background
24-
isWholeLine: false
25-
};
26-
27-
const partialDecoration: DecorationRenderOptions = {
28-
backgroundColor: 'rgba(255, 255, 0, 0.2)', // Yellow background
29-
isWholeLine: false
30-
};
31-
32-
const noDecoration: DecorationRenderOptions = {
33-
backgroundColor: 'rgba(255, 0, 0, 0.2)', // Red background
34-
isWholeLine: false
35-
};
36-
37-
this.covered = window.createTextEditorDecorationType(fullDecoration);
38-
this.partialcovered = window.createTextEditorDecorationType(partialDecoration);
39-
this.uncovered = window.createTextEditorDecorationType(noDecoration);
40-
}
15+
public covered!: TextEditorDecorationType;
16+
public partialcovered!: TextEditorDecorationType;
17+
public uncovered!: TextEditorDecorationType;
18+
19+
private context: ExtensionContext;
20+
21+
constructor(context: ExtensionContext) {
22+
this.context = context;
23+
this.setup();
24+
}
25+
26+
private setup(): void {
27+
const fullDecoration: DecorationRenderOptions = {
28+
backgroundColor: 'rgba(0, 255, 0, 0.2)', // Green background
29+
isWholeLine: false,
30+
};
31+
32+
const partialDecoration: DecorationRenderOptions = {
33+
backgroundColor: 'rgba(255, 255, 0, 0.2)', // Yellow background
34+
isWholeLine: false,
35+
};
36+
37+
const noDecoration: DecorationRenderOptions = {
38+
backgroundColor: 'rgba(255, 0, 0, 0.2)', // Red background
39+
isWholeLine: false,
40+
};
41+
42+
this.covered = window.createTextEditorDecorationType(fullDecoration);
43+
this.partialcovered = window.createTextEditorDecorationType(partialDecoration);
44+
this.uncovered = window.createTextEditorDecorationType(noDecoration);
45+
}
4146
}
4247

4348
export default CoverageConfig;

src/ui/coverage/coverageInfo.ts

Lines changed: 51 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,24 @@ interface CoverageEntry {
2020

2121
// Interface for storing the coverage status for each line of a document.
2222
export interface CoverageLines {
23-
full: vscode.Range[];
24-
partial: vscode.Range[];
25-
none: vscode.Range[];
23+
full: vscode.Range[];
24+
partial: vscode.Range[];
25+
none: vscode.Range[];
2626
}
2727

2828
enum CoverageStatus {
29-
Full = "FULL",
30-
Partial = "PARTIAL",
31-
None = "NONE"
29+
Full = 'FULL',
30+
Partial = 'PARTIAL',
31+
None = 'NONE',
3232
}
3333

3434
const warningMessage = `Line coverage is an unstable feature.`;
3535

3636
// Callback function for the coverage code lens action
37-
export async function runCodeCoverageAction(renderer: CoverageRenderer, functionName: string): Promise<void> {
37+
export async function runCodeCoverageAction(
38+
renderer: CoverageRenderer,
39+
functionName: string,
40+
): Promise<void> {
3841
const globalConfig = GlobalConfig.getInstance();
3942
const kaniBinaryPath = globalConfig.getFilePath();
4043

@@ -46,8 +49,7 @@ export async function runCodeCoverageAction(renderer: CoverageRenderer, function
4649
const playbackCommand: string = `${kaniBinaryPath} --coverage -Z line-coverage --harness ${functionName}`;
4750
const processOutput = await runCoverageCommand(playbackCommand, functionName);
4851

49-
50-
if(processOutput.statusCode == 0) {
52+
if (processOutput.statusCode == 0) {
5153
const coverageOutputArray = processOutput.result;
5254

5355
// Convert the array of (file, line, status) objects into Map<file <line, status>>
@@ -107,7 +109,7 @@ async function parseKaniCoverageOutput(stdout: string): Promise<any | undefined>
107109

108110
const coverageResults = kaniOutputArray.at(1);
109111

110-
if(coverageResults === undefined) {
112+
if (coverageResults === undefined) {
111113
return '';
112114
}
113115

@@ -161,21 +163,21 @@ function parseCoverageData(data: string[]): CoverageEntry[] {
161163
const coverageEntries: CoverageEntry[] = [];
162164

163165
for (const entry of data) {
164-
const parts = entry.split(', ');
166+
const parts = entry.split(', ');
165167

166-
if (parts.length === 3) {
167-
const [filePath, lineNumberStr, coverageStatus] = parts;
168-
if(filePath.includes('Complete - ')) {
169-
return coverageEntries;
170-
}
171-
const lineNumber = parseInt(lineNumberStr.trim(), 10);
168+
if (parts.length === 3) {
169+
const [filePath, lineNumberStr, coverageStatus] = parts;
170+
if (filePath.includes('Complete - ')) {
171+
return coverageEntries;
172+
}
173+
const lineNumber = parseInt(lineNumberStr.trim(), 10);
172174

173-
coverageEntries.push({
174-
filePath,
175-
lineNumber,
176-
coverageStatus,
177-
});
178-
}
175+
coverageEntries.push({
176+
filePath,
177+
lineNumber,
178+
coverageStatus,
179+
});
180+
}
179181
}
180182

181183
return coverageEntries;
@@ -184,21 +186,22 @@ function parseCoverageData(data: string[]): CoverageEntry[] {
184186
// Class representing the Renderer that handles rendering coverage highlights in the editor.
185187
export class CoverageRenderer {
186188
private configStore: Config;
187-
constructor(
188-
configStore: Config,
189-
) {
190-
this.configStore = configStore;
191-
}
189+
constructor(configStore: Config) {
190+
this.configStore = configStore;
191+
}
192192

193193
/**
194194
* Renders coverage highlights for multiple files.
195195
* @param editors - An array of text editor files to render coverage highlights for.
196196
* @param coverageMap - A map containing coverage data for each file.
197197
*/
198-
public renderInterface(editors: readonly vscode.TextEditor[], coverageMap: Map<string, Map<number, string>>): void {
198+
public renderInterface(
199+
editors: readonly vscode.TextEditor[],
200+
coverageMap: Map<string, Map<number, string>>,
201+
): void {
199202
editors.forEach((editor) => {
200203
// If coverageMap is empty, de-highlight the files
201-
if(coverageMap.size == 0) {
204+
if (coverageMap.size == 0) {
202205
const coverageLines: CoverageLines = {
203206
full: [],
204207
none: [],
@@ -222,8 +225,11 @@ export class CoverageRenderer {
222225
* @param editor - The text editor to render coverage highlights for.
223226
* @param coverageMap - A map containing coverage data for each file.
224227
*/
225-
public renderInterfaceForFile(editor: vscode.TextEditor, coverageMap: Map<string, Map<number, string>>): void {
226-
if(coverageMap.size == 0) {
228+
public renderInterfaceForFile(
229+
editor: vscode.TextEditor,
230+
coverageMap: Map<string, Map<number, string>>,
231+
): void {
232+
if (coverageMap.size == 0) {
227233
const coverageLines: CoverageLines = {
228234
full: [],
229235
none: [],
@@ -233,44 +239,46 @@ export class CoverageRenderer {
233239
this.renderHighlight(editor, coverageLines);
234240
}
235241
const fileMap = coverageMap.get(editor.document.fileName);
236-
if(fileMap === undefined){
242+
if (fileMap === undefined) {
237243
return;
238244
}
239245
const coverageLines = this.createCoverage(editor.document, fileMap);
240246
this.renderHighlight(editor, coverageLines);
241247
}
242248

243-
244249
/**
245250
* Creates coverage highlights for a given text document based on the coverageFileMap.
246251
* @param doc - The text document for which coverage highlights are to be created.
247252
* @param coverageFileMap - A map containing coverage status for each line number.
248253
* @returns An object containing coverage highlights categorized as 'full', 'partial', and 'none'.
249254
*/
250-
public createCoverage(doc: vscode.TextDocument, coverageFileMap: Map<number, string>): CoverageLines {
255+
public createCoverage(
256+
doc: vscode.TextDocument,
257+
coverageFileMap: Map<number, string>,
258+
): CoverageLines {
251259
const coverageLines: CoverageLines = {
252-
full: [],
253-
none: [],
254-
partial: [],
255-
};
260+
full: [],
261+
none: [],
262+
partial: [],
263+
};
256264

257265
for (let lineNum = 1; lineNum <= doc.lineCount; lineNum++) {
258266
const line = doc.lineAt(lineNum - 1);
259267
const status = coverageFileMap.get(lineNum);
260268

261-
if(status === undefined) {
269+
if (status === undefined) {
262270
continue;
263271
}
264272

265273
const range = new vscode.Range(line.range.start, line.range.end);
266274
switch (status) {
267-
case "FULL":
275+
case 'FULL':
268276
coverageLines.full.push(range);
269277
break;
270-
case "PARTIAL":
278+
case 'PARTIAL':
271279
coverageLines.partial.push(range);
272280
break;
273-
case "NONE":
281+
case 'NONE':
274282
coverageLines.none.push(range);
275283
break;
276284
default:

0 commit comments

Comments
 (0)