Skip to content

Commit 31cfdab

Browse files
authored
chore: enable 'strict' type-checking in tsconfig (#796)
1 parent 2f356e6 commit 31cfdab

40 files changed

+309
-232
lines changed

package-lock.json

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

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,9 @@
387387
"lint": "eslint -c .eslintrc.js --ext .ts src/"
388388
},
389389
"devDependencies": {
390-
"@types/chai": "^5.2.2",
390+
"@types/babel__core": "^7.20.5",
391+
"@types/chai": "^4.3.10",
392+
"@types/chai-subset": "^1.3.6",
391393
"@types/json-to-ast": "^2.1.0",
392394
"@types/mocha": "^10.0.2",
393395
"@types/node": "^20.8.4",

src/caNotification.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import { applySettingNameMappings } from './utils';
77
* Interface representing the data structure for a Component Analysis (CA) Notification.
88
*/
99
interface CANotificationData {
10-
errorMessage: string;
11-
done: boolean;
12-
uri: Uri;
13-
diagCount: number;
14-
vulnCount: Map<string, number>;
10+
errorMessage: string | null;
11+
done: boolean | null;
12+
uri: Uri | null;
13+
diagCount: number | null;
14+
vulnCount: Map<string, number> | null;
1515
}
1616

1717
/**
@@ -40,10 +40,10 @@ class CANotification {
4040
constructor(respData: CANotificationData) {
4141
this.errorMessage = applySettingNameMappings(respData.errorMessage || '');
4242
this.done = respData.done === true;
43-
this.uri = respData.uri;
43+
this.uri = respData.uri || Uri.file('');
4444
this.diagCount = respData.diagCount || 0;
4545
this.vulnCount = respData.vulnCount || new Map<string, number>();
46-
this.totalVulnCount = Object.values(this.vulnCount).reduce((sum, cv) => sum + cv, 0);
46+
this.totalVulnCount = Array.from(this.vulnCount.values()).reduce((sum, cv) => sum + cv, 0);
4747
}
4848

4949
/**
@@ -139,7 +139,7 @@ class CANotification {
139139
* @returns The text content for the popup notification.
140140
*/
141141
public popupText(): string {
142-
const text: string = Object.entries(this.vulnCount)
142+
const text: string = Array.from(this.vulnCount.entries())
143143
.map(([provider, vulnCount]) => `Found ${vulnCount} direct ${this.singularOrPlural(vulnCount)} for ${this.capitalizeEachWord(provider)} Provider.`)
144144
.join(' ');
145145
return text || this.warningText().replace(/\$\((.*?)\)/g, '');

src/codeActionHandler.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ function clearCodeActionsMap(uri: Uri) {
3434
* @param codeAction - The code action to be registered.
3535
*/
3636
function registerCodeAction(uri: Uri, loc: string, codeAction: CodeAction) {
37-
codeActionsMap.set(uri.toString(), codeActionsMap.get(uri.toString()) || new Map<string, CodeAction[]>());
38-
39-
const innerMap = codeActionsMap.get(uri.toString());
40-
innerMap.set(loc, innerMap.get(loc) || []);
41-
innerMap.get(loc).push(codeAction);
37+
const innerMap = codeActionsMap.get(uri.toString()) || new Map<string, CodeAction[]>();
38+
const actionsAtLocation = innerMap.get(loc) || [];
39+
actionsAtLocation.push(codeAction);
40+
innerMap.set(loc, actionsAtLocation);
41+
codeActionsMap.set(uri.toString(), innerMap);
4242
}
4343

4444
/**
@@ -101,7 +101,7 @@ function generateSwitchToRecommendedVersionAction(title: string, dependency: str
101101
edit: new WorkspaceEdit()
102102
};
103103

104-
codeAction.edit.insert(uri, diagnostic.range.start, versionReplacementString);
104+
codeAction.edit!.insert(uri, diagnostic.range.start, versionReplacementString);
105105

106106
codeAction.command = {
107107
title: 'Track recommendation acceptance',

src/config.ts

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,39 @@ import { getTelemetryId } from './redhatTelemetry';
1010
* Represents the configuration settings for the extension.
1111
*/
1212
class Config {
13-
telemetryId: string;
14-
stackAnalysisCommand: string;
15-
trackRecommendationAcceptanceCommand: string;
16-
recommendationsEnabled: boolean;
17-
utmSource: string;
18-
exhortProxyUrl: string;
19-
matchManifestVersions: string;
20-
usePythonVirtualEnvironment: string;
21-
useGoMVS: string;
22-
enablePythonBestEffortsInstallation: string;
23-
usePipDepTree: string;
24-
vulnerabilityAlertSeverity: string;
25-
exhortMvnPath: string;
26-
exhortPreferMvnw: string;
27-
exhortGradlePath: string;
28-
exhortPreferGradlew: string;
29-
exhortNpmPath: string;
30-
exhortPnpmPath: string;
31-
exhortYarnPath: string;
32-
exhortGoPath: string;
33-
exhortPython3Path: string;
34-
exhortPip3Path: string;
35-
exhortPythonPath: string;
36-
exhortPipPath: string;
37-
rhdaReportFilePath: string;
38-
secrets: vscode.SecretStorage;
39-
exhortSyftPath: string;
40-
exhortSyftConfigPath: string;
41-
exhortSkopeoPath: string;
42-
exhortSkopeoConfigPath: string;
43-
exhortDockerPath: string;
44-
exhortPodmanPath: string;
45-
exhortImagePlatform: string;
13+
telemetryId: string | undefined;
14+
stackAnalysisCommand!: string;
15+
trackRecommendationAcceptanceCommand!: string;
16+
recommendationsEnabled!: boolean;
17+
utmSource!: string;
18+
exhortProxyUrl!: string;
19+
matchManifestVersions!: string;
20+
usePythonVirtualEnvironment!: string;
21+
useGoMVS!: string;
22+
enablePythonBestEffortsInstallation!: string;
23+
usePipDepTree!: string;
24+
vulnerabilityAlertSeverity!: string;
25+
exhortMvnPath!: string;
26+
exhortPreferMvnw!: string;
27+
exhortGradlePath!: string;
28+
exhortPreferGradlew!: string;
29+
exhortNpmPath!: string;
30+
exhortPnpmPath!: string;
31+
exhortYarnPath!: string;
32+
exhortGoPath!: string;
33+
exhortPython3Path!: string;
34+
exhortPip3Path!: string;
35+
exhortPythonPath!: string;
36+
exhortPipPath!: string;
37+
rhdaReportFilePath!: string;
38+
secrets!: vscode.SecretStorage;
39+
exhortSyftPath!: string;
40+
exhortSyftConfigPath!: string;
41+
exhortSkopeoPath!: string;
42+
exhortSkopeoConfigPath!: string;
43+
exhortDockerPath!: string;
44+
exhortPodmanPath!: string;
45+
exhortImagePlatform!: string;
4646

4747
private readonly DEFAULT_MVN_EXECUTABLE = 'mvn';
4848
private readonly DEFAULT_GRADLE_EXECUTABLE = 'gradle';
@@ -208,7 +208,7 @@ class Config {
208208
* Links the secret storage to the configuration object.
209209
* @param context The extension context.
210210
*/
211-
linkToSecretStorage(context) {
211+
linkToSecretStorage(context: { secrets: vscode.SecretStorage }) {
212212
this.secrets = context.secrets;
213213
}
214214

@@ -224,7 +224,7 @@ class Config {
224224
await this.secrets.store(SNYK_TOKEN_KEY, token);
225225
vscode.window.showInformationMessage('Snyk token has been saved successfully');
226226
} catch (error) {
227-
vscode.window.showErrorMessage(`Failed to save Snyk token to VSCode Secret Storage, Error: ${error.message}`);
227+
vscode.window.showErrorMessage(`Failed to save Snyk token to VSCode Secret Storage, Error: ${(error as Error).message}`);
228228
}
229229
}
230230

@@ -237,7 +237,7 @@ class Config {
237237
const token = await this.secrets.get(SNYK_TOKEN_KEY);
238238
return token || '';
239239
} catch (error) {
240-
vscode.window.showErrorMessage(`Failed to get Snyk token from VSCode Secret Storage, Error: ${error.message}`);
240+
vscode.window.showErrorMessage(`Failed to get Snyk token from VSCode Secret Storage, Error: ${(error as Error).message}`);
241241
await this.clearSnykToken(false);
242242
return '';
243243
}
@@ -254,7 +254,7 @@ class Config {
254254
vscode.window.showInformationMessage('Snyk token has been removed successfully');
255255
}
256256
} catch (error) {
257-
const errorMsg = `Failed to delete Snyk token from VSCode Secret Storage, Error: ${error.message}`;
257+
const errorMsg = `Failed to delete Snyk token from VSCode Secret Storage, Error: ${(error as Error).message}`;
258258
if (notify) {
259259
vscode.window.showErrorMessage(errorMsg);
260260
} else {

src/dependencyAnalysis/analysis.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ class AnalysisResponse implements IAnalysisResponse {
8787
: new DependencyData(source.id, issuesCount, this.getRecommendation(d), '', this.getHighestSeverity(d));
8888

8989
const resolvedRef = this.provider.resolveDependencyFromReference(d.ref);
90-
this.dependencies[resolvedRef] = this.dependencies[resolvedRef] || [];
91-
this.dependencies[resolvedRef].push(dd);
90+
const something = (this.dependencies.get(resolvedRef) || []);
91+
something.push(dd);
92+
this.dependencies.set(resolvedRef, something);
9293
}
9394
});
9495
});

src/dependencyAnalysis/collector.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,18 @@ import { Position, Range } from 'vscode';
1414
*/
1515
export interface IDependency {
1616
name: IPositionedString;
17-
version: IPositionedString;
18-
context: IPositionedContext;
17+
version: IPositionedString | undefined;
18+
context: IPositionedContext | undefined;
1919
}
2020

2121
/**
2222
* Represents a dependency and implements the IDependency interface.
2323
*/
2424
export class Dependency implements IDependency {
25-
public version: IPositionedString;
26-
public context: IPositionedContext;
25+
public version: IPositionedString | undefined;
26+
public context: IPositionedContext | undefined;
2727

28-
constructor(
29-
public name: IPositionedString
30-
) { }
28+
constructor(public name: IPositionedString) { }
3129
}
3230

3331
/**
@@ -47,7 +45,7 @@ export class DependencyMap {
4745
* @param key - The unique name key for the desired dependency.
4846
* @returns The dependency object linked to the specified unique name key.
4947
*/
50-
public get(key: string): IDependency {
48+
public get(key: string): IDependency | undefined {
5149
return this.mapper.get(key);
5250
}
5351
}
@@ -117,6 +115,6 @@ export function getRange(dep: IDependency): Range {
117115
const length = dep.version.value.length;
118116
return new Range(new Position(pos.line - 1, pos.column - 1), new Position(pos.line - 1, pos.column + length - 1));
119117
} else {
120-
return dep.context.range;
118+
return dep.context!.range;
121119
}
122120
}

src/dependencyAnalysis/diagnostics.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class DiagnosticsPipeline extends AbstractDiagnosticsPipeline<DependencyData> {
3737
* @param ecosystem - The name of the ecosystem in which dependencies are being analyzed.
3838
*/
3939
runDiagnostics(dependencies: Map<string, DependencyData[]>, ecosystem: string) {
40-
Object.entries(dependencies).map(([ref, dependencyData]: [string, DependencyData[]]) => {
40+
dependencies.forEach((dependencyData, ref) => {
4141
const dependencyRef = ecosystem === GRADLE ? ref : ref.split('@')[0];
4242
const dependency = this.dependencyMap.get(dependencyRef);
4343

@@ -62,7 +62,7 @@ class DiagnosticsPipeline extends AbstractDiagnosticsPipeline<DependencyData> {
6262

6363
const vulnProvider = dd.sourceId.split('(')[0];
6464
const issuesCount = dd.issuesCount;
65-
this.vulnCount[vulnProvider] = (this.vulnCount[vulnProvider] || 0) + issuesCount;
65+
this.vulnCount.set(vulnProvider, (this.vulnCount.get(vulnProvider) || 0) + issuesCount);
6666
});
6767
}
6868
DiagnosticsPipeline.diagnosticsCollection.set(this.diagnosticFilePath, this.diagnostics);
@@ -78,7 +78,7 @@ class DiagnosticsPipeline extends AbstractDiagnosticsPipeline<DependencyData> {
7878
* @param vulnerabilityDiagnostic - Vulnerability diagnostic object.
7979
* @private
8080
*/
81-
private createCodeAction(loc: string, ref: string, context: IPositionedContext, sourceId: string, vulnerabilityDiagnostic: Diagnostic) {
81+
private createCodeAction(loc: string, ref: string, context: IPositionedContext | undefined, sourceId: string, vulnerabilityDiagnostic: Diagnostic) {
8282
const dependency = ref;
8383
const switchToVersion = dependency.split('@')[1];
8484
const versionReplacementString = context ? context.value.replace(VERSION_PLACEHOLDER, switchToVersion) : switchToVersion;
@@ -112,9 +112,9 @@ async function performDiagnostics(diagnosticFilePath: Uri, contents: string, pro
112112

113113
diagnosticsPipeline.reportDiagnostics();
114114
} catch (error) {
115-
outputChannelDep.warn(`Component Analysis Error: ${buildErrorMessage(error)}\n${(error as Error).stack}`);
115+
outputChannelDep.warn(`component analysis error: ${buildErrorMessage(error as Error)}\n${(error as Error).stack}`);
116116
notifications.emit('caError', {
117-
errorMessage: error.message,
117+
errorMessage: (error as Error).message,
118118
uri: diagnosticFilePath,
119119
});
120120
}

src/dependencyReportPanel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class DependencyReportPanel {
1717
public static currentPanel: DependencyReportPanel | undefined;
1818

1919
public static readonly viewType = 'stackReport';
20-
public static data;
20+
public static data: any;
2121

2222
private readonly _panel: vscode.WebviewPanel;
2323
private _disposables: vscode.Disposable[] = [];
@@ -141,7 +141,7 @@ export class DependencyReportPanel {
141141
* @param column The column to reveal the panel in.
142142
* @private
143143
*/
144-
private _revealWebviewPanel(column: vscode.ViewColumn) {
144+
private _revealWebviewPanel(column: vscode.ViewColumn | undefined) {
145145
this._panel.reveal(column);
146146
}
147147

src/exhortServices.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ async function tokenValidationService(options: { [key: string]: string }, source
6868
return `Failed to validate token. Status: ${status}`;
6969
}
7070
} catch (error) {
71-
return `Failed to validate token, Error: ${error.message}`;
71+
return `Failed to validate token, Error: ${(error as Error).message}`;
7272
}
7373
}
7474

0 commit comments

Comments
 (0)