Skip to content

Commit c3b90f5

Browse files
committed
chore: replace any types with proper types and enforce no-explicit-any
Replace all explicit any annotations with types imported from existing packages (vscode, sinon, child_process) or TypeScript built-ins (unknown, inline object types, typeof console.log). Enable @typescript-eslint/no-explicit-any as an error in ESLint to prevent regressions.
1 parent b3b55ca commit c3b90f5

7 files changed

Lines changed: 36 additions & 20 deletions

File tree

src/extension.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
import { getConfiguration } from "./lib/ggshield-configuration-utils";
1010
import {
1111
ExtensionContext,
12+
OutputChannel,
1213
Uri,
1314
commands,
1415
languages,
@@ -39,7 +40,7 @@ import {
3940

4041
function registerOpenViewsCommands(
4142
context: ExtensionContext,
42-
outputChannel: any,
43+
outputChannel: OutputChannel,
4344
) {
4445
const showOutputCommand = commands.registerCommand(
4546
"gitguardian.showOutput",

src/gitguardian-interface/gitguardian-hover-provider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function extractInfosFromMessage(message: string): {
6565

6666
export function generateSecretName(
6767
currentFile: string,
68-
uriDiagnostic: any,
68+
uriDiagnostic: { detector: string; startLine: number },
6969
): string {
7070
return `${uriDiagnostic.detector} - ${vscode.workspace.asRelativePath(
7171
currentFile,

src/lib/authentication.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import { runGGShieldCommand } from "./run-ggshield";
22
import { GGShieldConfiguration } from "./ggshield-configuration";
3-
import { commands, ExtensionContext, WebviewView, workspace } from "vscode";
3+
import {
4+
commands,
5+
ExtensionContext,
6+
OutputChannel,
7+
WebviewView,
8+
workspace,
9+
} from "vscode";
410
import { spawn, SpawnOptionsWithoutStdio } from "child_process";
511
import * as os from "os";
612
import {
@@ -104,7 +110,7 @@ export async function updateAuthenticationStatus(
104110

105111
export async function loginGGShield(
106112
configuration: GGShieldConfiguration,
107-
outputChannel: any,
113+
outputChannel: OutputChannel,
108114
webviewView: WebviewView,
109115
context: ExtensionContext,
110116
): Promise<void> {

src/test/suite/ggshield-webview/gitguardian-quota-webview.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ suite("GitGuardianQuotaWebviewProvider", () => {
2020
setup(() => {
2121
mockWorkspaceState = {
2222
get: (_key: string) => undefined,
23-
update: (_key: string, _value: any) => Promise.resolve(),
23+
update: (_key: string, _value: unknown) => Promise.resolve(),
2424
keys: () => [],
2525
setKeysForSync: (_keys: readonly string[]) => {},
2626
};
@@ -41,7 +41,7 @@ suite("GitGuardianQuotaWebviewProvider", () => {
4141
onDidReceiveMessage: () => ({ dispose: () => {} }),
4242
cspSource: "",
4343
options: {} as WebviewOptions,
44-
postMessage: (_message: any) => Promise.resolve(true),
44+
postMessage: (_message: unknown) => Promise.resolve(true),
4545
asWebviewUri: (uri: Uri) => uri,
4646
},
4747
onDidChangeVisibility: () => ({ dispose: () => {} }),

src/test/suite/lib/authentication.test.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,17 @@ import { GGShieldConfiguration } from "../../../lib/ggshield-configuration";
22
import * as sinon from "sinon";
33
import * as runGGShield from "../../../lib/run-ggshield";
44
import * as childProcess from "child_process";
5+
import { ChildProcessWithoutNullStreams } from "child_process";
56
import * as statusBar from "../../../gitguardian-interface/gitguardian-status-bar";
67
import assert from "assert";
78
import { EventEmitter } from "events";
8-
import { commands, ExtensionContext, Memento } from "vscode";
9+
import {
10+
commands,
11+
ExtensionContext,
12+
Memento,
13+
OutputChannel,
14+
WebviewView,
15+
} from "vscode";
916
import {
1017
AuthenticationStatus,
1118
ConfigSource,
@@ -30,9 +37,9 @@ suite("updateAuthenticationStatus", () => {
3037
mockWorkspaceState = {
3138
get: (key: string) =>
3239
key === "authenticationStatus" ? authenticationStatus : undefined,
33-
update: (key: string, value: any) => {
40+
update: (key: string, value: unknown) => {
3441
if (key === "authenticationStatus") {
35-
authenticationStatus = value;
42+
authenticationStatus = value as AuthenticationStatus | undefined;
3643
}
3744
return Promise.resolve();
3845
},
@@ -169,7 +176,9 @@ suite("loginGGShield", () => {
169176
stdout: new EventEmitter(),
170177
stderr: new EventEmitter(),
171178
});
172-
spawnMock = sinon.stub(childProcess, "spawn").returns(fakeProc as any);
179+
spawnMock = sinon
180+
.stub(childProcess, "spawn")
181+
.returns(fakeProc as unknown as ChildProcessWithoutNullStreams);
173182
});
174183

175184
teardown(function () {
@@ -196,8 +205,8 @@ suite("loginGGShield", () => {
196205
apiUrl: "",
197206
insecure: insecure,
198207
} as GGShieldConfiguration,
199-
{ appendLine: () => {} } as any,
200-
{ webview: { postMessage: () => {} } } as any,
208+
{ appendLine: () => {} } as unknown as OutputChannel,
209+
{ webview: { postMessage: () => {} } } as unknown as WebviewView,
201210
{} as ExtensionContext,
202211
);
203212

src/test/suite/lib/ggshield-configuration-utils.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ suite("getConfiguration", () => {
2323
* Helper class to fake different configurations of the extension
2424
*/
2525
class FakeConfiguration {
26-
records: Record<string, any>;
26+
records: Record<string, unknown>;
2727

28-
constructor(records: Record<string, any>) {
28+
constructor(records: Record<string, unknown>) {
2929
this.records = records;
3030
}
3131

32-
public get(section: string, defaultValue: any): any {
32+
public get(section: string, defaultValue: unknown): unknown {
3333
if (this.records.hasOwnProperty(section)) {
3434
return this.records[section];
3535
}
@@ -40,13 +40,13 @@ suite("getConfiguration", () => {
4040
test("Vscode settings are correctly read", async () => {
4141
const context = {} as ExtensionContext;
4242
const outputChannel = window.createOutputChannel("GitGuardian");
43-
context.asAbsolutePath = sinon.stub().returns("") as any;
43+
context.asAbsolutePath = sinon.stub<[string], string>().returns("");
4444

4545
getConfigurationMock.returns(
4646
new FakeConfiguration({
4747
apiUrl: "https://custom-url.com",
4848
insecure: true,
49-
} as Record<string, any>),
49+
} as Record<string, unknown>),
5050
);
5151
const configuration = await getConfiguration(context, outputChannel);
5252

@@ -63,12 +63,12 @@ suite("getConfiguration", () => {
6363
test("insecure falls back on allowSelfSigned", async () => {
6464
const context = {} as ExtensionContext;
6565
const outputChannel = window.createOutputChannel("GitGuardian");
66-
context.asAbsolutePath = sinon.stub().returns("") as any;
66+
context.asAbsolutePath = sinon.stub<[string], string>().returns("");
6767

6868
getConfigurationMock.returns(
6969
new FakeConfiguration({
7070
allowSelfSigned: true,
71-
} as Record<string, any>),
71+
} as Record<string, unknown>),
7272
);
7373
const configuration = await getConfiguration(context, outputChannel);
7474

src/test/suite/lib/ggshield-resolver-utils.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ suite("getGGShield integration tests", () => {
1515
window.createOutputChannel("GitGuardian");
1616
const platform = process.platform;
1717
const arch = process.arch;
18-
let originalLog: (message?: any, ...optionalParams: any[]) => void;
18+
let originalLog: typeof console.log;
1919
let output: string;
2020

2121
setup(() => {

0 commit comments

Comments
 (0)