Skip to content

Commit

Permalink
Fix setting the dropdown of git config view (trailofbits#59)
Browse files Browse the repository at this point in the history
* Fix git config bug when updating through codemarker

* Linter suddenly complains about function return types
  • Loading branch information
jvdprng authored Oct 8, 2024
1 parent 81cc983 commit 71c4267
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 25 deletions.
24 changes: 21 additions & 3 deletions src/codeMarker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,13 @@ class WARoot {
* Saves the client's remote repository to the current user's file
*/
persistClientRemote(): void {
vscode.commands.executeCommand("weAudit.setGitConfigView", [this.rootPath, this.rootLabel], this.clientRemote, this.gitRemote, this.gitSha);
vscode.commands.executeCommand(
"weAudit.setGitConfigView",
{ rootPath: this.rootPath, rootLabel: this.rootLabel } as RootPathAndLabel,
this.clientRemote,
this.gitRemote,
this.gitSha,
);
const vscodeFolder = path.join(this.rootPath, ".vscode");
// create .vscode folder if it doesn't exist
if (!fs.existsSync(vscodeFolder)) {
Expand Down Expand Up @@ -281,7 +287,13 @@ class WARoot {
* Saves the audit remote repository to the current user's file
*/
persistAuditRemote(): void {
vscode.commands.executeCommand("weAudit.setGitConfigView", [this.rootPath, this.rootLabel], this.clientRemote, this.gitRemote, this.gitSha);
vscode.commands.executeCommand(
"weAudit.setGitConfigView",
{ rootPath: this.rootPath, rootLabel: this.rootLabel } as RootPathAndLabel,
this.clientRemote,
this.gitRemote,
this.gitSha,
);
const vscodeFolder = path.join(this.rootPath, ".vscode");
// create .vscode folder if it doesn't exist
if (!fs.existsSync(vscodeFolder)) {
Expand Down Expand Up @@ -313,7 +325,13 @@ class WARoot {
* Saves the relevant git hash to the current user's file
*/
persistGitHash(): void {
vscode.commands.executeCommand("weAudit.setGitConfigView", [this.rootPath, this.rootLabel], this.clientRemote, this.gitRemote, this.gitSha);
vscode.commands.executeCommand(
"weAudit.setGitConfigView",
{ rootPath: this.rootPath, rootLabel: this.rootLabel } as RootPathAndLabel,
this.clientRemote,
this.gitRemote,
this.gitSha,
);
const vscodeFolder = path.join(this.rootPath, ".vscode");
// create .vscode folder if it doesn't exist
if (!fs.existsSync(vscodeFolder)) {
Expand Down
14 changes: 7 additions & 7 deletions src/decorationManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class DecorationManager {
this.auditedFileDecorationType = this.loadAuditedDecorationConfiguration();
}

private createDecorationTypeWithString(color: string) {
private createDecorationTypeWithString(color: string): vscode.TextEditorDecorationType {
return vscode.window.createTextEditorDecorationType({
isWholeLine: true,
backgroundColor: color,
Expand All @@ -37,31 +37,31 @@ export class DecorationManager {
});
}

private loadOwnDecorationConfiguration() {
private loadOwnDecorationConfiguration(): vscode.TextEditorDecorationType {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const color: string = vscode.workspace.getConfiguration("weAudit").get("ownFindingColor")!;
return this.createDecorationTypeWithString(color);
}

private loadOtherDecorationConfiguration() {
private loadOtherDecorationConfiguration(): vscode.TextEditorDecorationType {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const color: string = vscode.workspace.getConfiguration("weAudit").get("otherFindingColor")!;
return this.createDecorationTypeWithString(color);
}

private loadOwnNoteDecorationConfiguration() {
private loadOwnNoteDecorationConfiguration(): vscode.TextEditorDecorationType {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const color: string = vscode.workspace.getConfiguration("weAudit").get("ownNoteColor")!;
return this.createDecorationTypeWithString(color);
}

private loadOtherNoteDecorationConfiguration() {
private loadOtherNoteDecorationConfiguration(): vscode.TextEditorDecorationType {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const color: string = vscode.workspace.getConfiguration("weAudit").get("otherNoteColor")!;
return this.createDecorationTypeWithString(color);
}

private loadAuditedDecorationConfiguration() {
private loadAuditedDecorationConfiguration(): vscode.TextEditorDecorationType {
return vscode.window.createTextEditorDecorationType({
isWholeLine: true,
backgroundColor: vscode.workspace.getConfiguration("weAudit").get("auditedColor"),
Expand All @@ -72,7 +72,7 @@ export class DecorationManager {
* Reload all decoration configurations.
* TODO: make it possible to reload only one decoration type
*/
public reloadAllDecorationConfigurations() {
public reloadAllDecorationConfigurations(): void {
// dispose old decoration types. This is necessary to clean up old decoration types,
// otherwise they would be left over and we wouldn't be able to remove them.
this.ownFindingDecorationType.dispose();
Expand Down
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { MultipleSavedFindings } from "./multiConfigs";
import { activateFindingDetailsWebview } from "./panels/findingDetailsPanel";
import { activateGitConfigWebview } from "./panels/gitConfigPanel";

export function activate(context: vscode.ExtensionContext) {
export function activate(context: vscode.ExtensionContext): void {
// if there are no open folders, return
// the extension will be reactivated when a folder is opened
if (vscode.workspace.workspaceFolders === undefined) {
Expand Down
2 changes: 1 addition & 1 deletion src/multiConfigs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class MultipleSavedFindingsTree implements vscode.TreeDataProvider<Config
});
}

findAndLoadConfigurationFiles() {
findAndLoadConfigurationFiles(): void {
this.configurationEntries = [];
this.rootEntries = [];
for (const rootPathAndLabel of this.rootPathsAndLabels) {
Expand Down
10 changes: 5 additions & 5 deletions src/panels/findingDetailsPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getUri } from "../utilities/getUri";
import { EntryDetails } from "../types";
import { WebviewMessage } from "../webview/webviewMessageTypes";

export function activateFindingDetailsWebview(context: vscode.ExtensionContext) {
export function activateFindingDetailsWebview(context: vscode.ExtensionContext): void {
const provider = new FindingDetailsProvider(context.extensionUri);

context.subscriptions.push(vscode.window.registerWebviewViewProvider(FindingDetailsProvider.viewType, provider));
Expand All @@ -19,7 +19,7 @@ class FindingDetailsProvider implements vscode.WebviewViewProvider {

constructor(private readonly _extensionUri: vscode.Uri) {}

public resolveWebviewView(webviewView: vscode.WebviewView, _context: vscode.WebviewViewResolveContext, _token: vscode.CancellationToken) {
public resolveWebviewView(webviewView: vscode.WebviewView, _context: vscode.WebviewViewResolveContext, _token: vscode.CancellationToken): void {
this._view = webviewView;

webviewView.webview.options = {
Expand Down Expand Up @@ -57,7 +57,7 @@ class FindingDetailsProvider implements vscode.WebviewViewProvider {
});
}

private _getHtmlForWebview(webview: vscode.Webview) {
private _getHtmlForWebview(webview: vscode.Webview): string {
// Get the local path to main script run in the webview, then convert it to a uri we can use in the webview.
const styleUri = getUri(webview, this._extensionUri, ["media", "style.css"]);
const webviewUri = getUri(webview, this._extensionUri, ["out", "findingDetailsWebview.js"]);
Expand Down Expand Up @@ -88,7 +88,7 @@ class FindingDetailsProvider implements vscode.WebviewViewProvider {
`;
}

private _setWebviewMessageListener(webview: vscode.Webview) {
private _setWebviewMessageListener(webview: vscode.Webview): void {
webview.onDidReceiveMessage(
(message: WebviewMessage) => {
const command = message.command;
Expand All @@ -105,6 +105,6 @@ class FindingDetailsProvider implements vscode.WebviewViewProvider {
}
}

function getNonce() {
function getNonce(): string {
return crypto.randomBytes(16).toString("base64");
}
10 changes: 5 additions & 5 deletions src/panels/gitConfigPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getUri } from "../utilities/getUri";
import { WebviewMessage, UpdateRepositoryMessage, SetWorkspaceRootsMessage } from "../webview/webviewMessageTypes";
import { RootPathAndLabel } from "../types";

export function activateGitConfigWebview(context: vscode.ExtensionContext) {
export function activateGitConfigWebview(context: vscode.ExtensionContext): void {
const provider = new GitConfigProvider(context.extensionUri);

context.subscriptions.push(vscode.window.registerWebviewViewProvider(GitConfigProvider.viewType, provider));
Expand Down Expand Up @@ -77,7 +77,7 @@ class GitConfigProvider implements vscode.WebviewViewProvider {
});
}

public resolveWebviewView(webviewView: vscode.WebviewView, _context: vscode.WebviewViewResolveContext, _token: vscode.CancellationToken) {
public resolveWebviewView(webviewView: vscode.WebviewView, _context: vscode.WebviewViewResolveContext, _token: vscode.CancellationToken): void {
this._view = webviewView;

webviewView.webview.options = {
Expand All @@ -99,7 +99,7 @@ class GitConfigProvider implements vscode.WebviewViewProvider {
});
}

private _getHtmlForWebview(webview: vscode.Webview) {
private _getHtmlForWebview(webview: vscode.Webview): string {
// Get the local path to main script run in the webview, then convert it to a uri we can use in the webview.
const styleUri = getUri(webview, this._extensionUri, ["media", "style.css"]);
const webviewUri = getUri(webview, this._extensionUri, ["out", "gitConfigWebview.js"]);
Expand Down Expand Up @@ -130,7 +130,7 @@ class GitConfigProvider implements vscode.WebviewViewProvider {
`;
}

private _setWebviewMessageListener(webview: vscode.Webview) {
private _setWebviewMessageListener(webview: vscode.Webview): void {
webview.onDidReceiveMessage(
(message: WebviewMessage) => {
const command = message.command;
Expand Down Expand Up @@ -169,6 +169,6 @@ class GitConfigProvider implements vscode.WebviewViewProvider {
}
}

function getNonce() {
function getNonce(): string {
return crypto.randomBytes(16).toString("base64");
}
2 changes: 1 addition & 1 deletion src/utilities/getUri.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ import { Uri, Webview } from "vscode";
* @param pathList An array of strings representing the path to a file/resource
* @returns A URI pointing to the file/resource
*/
export function getUri(webview: Webview, extensionUri: Uri, pathList: string[]) {
export function getUri(webview: Webview, extensionUri: Uri, pathList: string[]): Uri {
return webview.asWebviewUri(Uri.joinPath(extensionUri, ...pathList));
}
2 changes: 1 addition & 1 deletion src/webview/findingDetailsMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const vscode = acquireVsCodeApi();
// or toolkit components
window.addEventListener("load", main);

function main() {
function main(): void {
const titleField = document.getElementById("label-area") as TextField;
titleField?.addEventListener("change", handlePersistentFieldChange);

Expand Down
2 changes: 1 addition & 1 deletion src/webview/gitConfigMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const vscode = acquireVsCodeApi();
// or toolkit components
window.addEventListener("load", main);

function main() {
function main(): void {
const rootDropdown = document.getElementById("workspace-root-list-dropdown") as Dropdown;
rootDropdown?.addEventListener("change", handleDropdownChange);

Expand Down

0 comments on commit 71c4267

Please sign in to comment.