Skip to content

Commit 5cc0b50

Browse files
authored
fix: linting errors related to nullish coalescing (#2011)
* fix: linting errors related to nullish coalescing * Added: changelog
1 parent ead2423 commit 5cc0b50

File tree

11 files changed

+44
-120
lines changed

11 files changed

+44
-120
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
kind: BUG FIXES
2+
body: Fix for es lint error - nullish coalescing operator
3+
time: 2025-05-19T12:23:03.527053+05:30
4+
custom:
5+
Issue: "2011"
6+
Repository: vscode-terraform

src/commands/generateBugReport.ts

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ export class GenerateBugReportCommand implements vscode.Disposable {
4343
}
4444

4545
generateBody(extensions: VSCodeExtension[], problemText?: string): string {
46-
if (!problemText) {
47-
problemText = `Steps To Reproduce
46+
problemText ??= `Steps To Reproduce
4847
=====
4948
5049
Steps to reproduce the behavior:
@@ -85,7 +84,7 @@ Note whether you use any tools for managing Terraform version/execution (e.g. 't
8584
any credentials helpers, or whether you have any other Terraform extensions installed.
8685
-->
8786
`;
88-
}
87+
8988
const body = `Issue Description
9089
=====
9190
@@ -163,11 +162,7 @@ Outdated:\t${info.outdated}
163162
return 0;
164163
})
165164
.map((ext) => {
166-
return {
167-
name: ext.packageJSON.name,
168-
publisher: ext.packageJSON.publisher,
169-
version: ext.packageJSON.version,
170-
};
165+
return { name: ext.packageJSON.name, publisher: ext.packageJSON.publisher, version: ext.packageJSON.version };
171166
});
172167
return extensions;
173168
}
@@ -183,11 +178,7 @@ Outdated:\t${info.outdated}
183178
const response = resultJson.stdout.toString();
184179
const j = JSON.parse(response);
185180

186-
return {
187-
version: j.terraform_version,
188-
platform: j.platform,
189-
outdated: j.terraform_outdated,
190-
};
181+
return { version: j.terraform_version, platform: j.platform, outdated: j.terraform_outdated };
191182
} catch {
192183
// fall through
193184
}
@@ -204,20 +195,12 @@ Outdated:\t${info.outdated}
204195
const version = matches && matches.length > 1 ? matches[1] : 'Not found';
205196
const platform = response.split('\n')[1].replace('on ', '');
206197

207-
return {
208-
version: version,
209-
platform: platform,
210-
outdated: true,
211-
};
198+
return { version: version, platform: platform, outdated: true };
212199
} catch {
213200
// fall through
214201
}
215202
}
216203

217-
return {
218-
version: 'Not found',
219-
platform: 'Not found',
220-
outdated: false,
221-
};
204+
return { version: 'Not found', platform: 'Not found', outdated: false };
222205
}
223206
}

src/features/languageStatus.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,11 @@ export class LanguageStatusFeature implements StaticFeature {
2121
clear(): void {}
2222

2323
getState(): FeatureState {
24-
return {
25-
kind: 'static',
26-
};
24+
return { kind: 'static' };
2725
}
2826

2927
public fillClientCapabilities(capabilities: ClientCapabilities & ExperimentalClientCapabilities): void {
30-
if (!capabilities.experimental) {
31-
capabilities.experimental = {};
32-
}
28+
capabilities.experimental ??= {};
3329
}
3430

3531
public initialize(): void {

src/features/moduleCalls.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,11 @@ export class ModuleCallsFeature implements StaticFeature {
2727
clear(): void {}
2828

2929
getState(): FeatureState {
30-
return {
31-
kind: 'static',
32-
};
30+
return { kind: 'static' };
3331
}
3432

3533
public fillClientCapabilities(capabilities: ClientCapabilities & ExperimentalClientCapabilities): void {
36-
if (!capabilities.experimental) {
37-
capabilities.experimental = {};
38-
}
34+
capabilities.experimental ??= {};
3935
capabilities.experimental.refreshModuleCallsCommandId = CLIENT_MODULE_CALLS_CMD_ID;
4036
}
4137

src/features/moduleProviders.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,11 @@ export class ModuleProvidersFeature implements StaticFeature {
2727
clear(): void {}
2828

2929
getState(): FeatureState {
30-
return {
31-
kind: 'static',
32-
};
30+
return { kind: 'static' };
3331
}
3432

3533
public fillClientCapabilities(capabilities: ClientCapabilities & ExperimentalClientCapabilities): void {
36-
if (!capabilities.experimental) {
37-
capabilities.experimental = {};
38-
}
34+
capabilities.experimental ??= {};
3935
capabilities.experimental.refreshModuleProvidersCommandId = CLIENT_MODULE_PROVIDERS_CMD_ID;
4036
}
4137

src/features/showReferences.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,15 @@ export class ShowReferencesFeature implements StaticFeature {
3939
clear(): void {}
4040

4141
getState(): FeatureState {
42-
return {
43-
kind: 'static',
44-
};
42+
return { kind: 'static' };
4543
}
4644

4745
public fillClientCapabilities(capabilities: ClientCapabilities & ExperimentalClientCapabilities): void {
4846
if (!this.isEnabled) {
4947
return;
5048
}
51-
if (!capabilities.experimental) {
52-
capabilities.experimental = {};
53-
}
49+
50+
capabilities.experimental ??= {};
5451
capabilities.experimental.showReferencesCommandId = CLIENT_CMD_ID;
5552
}
5653

src/features/telemetry.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
* SPDX-License-Identifier: MPL-2.0
44
*/
55

6-
import * as vscode from 'vscode';
76
import TelemetryReporter from '@vscode/extension-telemetry';
7+
import * as vscode from 'vscode';
88
import { BaseLanguageClient, ClientCapabilities, FeatureState, StaticFeature } from 'vscode-languageclient';
99

1010
import { ExperimentalClientCapabilities } from './types';
@@ -28,15 +28,11 @@ export class TelemetryFeature implements StaticFeature {
2828
clear(): void {}
2929

3030
getState(): FeatureState {
31-
return {
32-
kind: 'static',
33-
};
31+
return { kind: 'static' };
3432
}
3533

3634
public fillClientCapabilities(capabilities: ClientCapabilities & ExperimentalClientCapabilities): void {
37-
if (!capabilities.experimental) {
38-
capabilities.experimental = {};
39-
}
35+
capabilities.experimental ??= {};
4036
capabilities.experimental.telemetryVersion = TELEMETRY_VERSION;
4137
}
4238

src/features/terraformVersion.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,11 @@ export class TerraformVersionFeature implements StaticFeature {
2929
clear(): void {}
3030

3131
getState(): FeatureState {
32-
return {
33-
kind: 'static',
34-
};
32+
return { kind: 'static' };
3533
}
3634

3735
public fillClientCapabilities(capabilities: ClientCapabilities & ExperimentalClientCapabilities): void {
38-
capabilities.experimental = capabilities.experimental || {};
36+
capabilities.experimental ??= {};
3937
capabilities.experimental.refreshTerraformVersionCommandId = this.clientTerraformVersionCommandId;
4038
}
4139

src/providers/terraform/moduleCalls.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class ModuleCallItem extends vscode.TreeItem {
2626
children.length >= 1 ? vscode.TreeItemCollapsibleState.Collapsed : vscode.TreeItemCollapsibleState.None,
2727
);
2828

29-
this.description = this.version ? this.version : '';
29+
this.description = this.version ?? '';
3030

3131
if (this.version === undefined) {
3232
this.tooltip = this.sourceAddr;
@@ -42,10 +42,7 @@ class ModuleCallItem extends vscode.TreeItem {
4242
getIcon(type: string | undefined) {
4343
switch (type) {
4444
case 'tfregistry':
45-
return {
46-
light: this.terraformIcon,
47-
dark: this.terraformIcon,
48-
};
45+
return { light: this.terraformIcon, dark: this.terraformIcon };
4946
case 'local':
5047
return new vscode.ThemeIcon('symbol-folder');
5148
case 'github':

src/providers/tfc/applyProvider.ts

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,8 @@ export class ApplyTreeDataProvider implements vscode.TreeDataProvider<vscode.Tre
8888
}
8989

9090
try {
91-
const result = await axios.get(apply.logReadUrl, {
92-
headers: { Accept: 'text/plain' },
93-
responseType: 'stream',
94-
});
95-
const lineStream = readline.createInterface({
96-
input: result.data,
97-
output: new Writable(),
98-
});
91+
const result = await axios.get(apply.logReadUrl, { headers: { Accept: 'text/plain' }, responseType: 'stream' });
92+
const lineStream = readline.createInterface({ input: result.data, output: new Writable() });
9993

10094
const applyLog: ApplyLog = {};
10195

@@ -104,9 +98,7 @@ export class ApplyTreeDataProvider implements vscode.TreeDataProvider<vscode.Tre
10498
const logLine: LogLine = JSON.parse(line);
10599

106100
if (logLine.type === 'apply_complete' && logLine.hook) {
107-
if (!applyLog.appliedChanges) {
108-
applyLog.appliedChanges = [];
109-
}
101+
applyLog.appliedChanges ??= [];
110102
applyLog.appliedChanges.push(logLine.hook);
111103
continue;
112104
}
@@ -119,15 +111,9 @@ export class ApplyTreeDataProvider implements vscode.TreeDataProvider<vscode.Tre
119111
continue;
120112
}
121113
if (logLine.type === 'diagnostic' && logLine.diagnostic) {
122-
if (!applyLog.diagnostics) {
123-
applyLog.diagnostics = [];
124-
}
125-
if (!applyLog.diagnosticSummary) {
126-
applyLog.diagnosticSummary = {
127-
errorCount: 0,
128-
warningCount: 0,
129-
};
130-
}
114+
applyLog.diagnostics ??= [];
115+
applyLog.diagnosticSummary ??= { errorCount: 0, warningCount: 0 };
116+
131117
applyLog.diagnostics.push(logLine.diagnostic);
132118
if (logLine.diagnostic.severity === 'warning') {
133119
applyLog.diagnosticSummary.warningCount += 1;
@@ -164,10 +150,7 @@ export class ApplyTreeDataProvider implements vscode.TreeDataProvider<vscode.Tre
164150
if (error instanceof Error) {
165151
message += error.message;
166152
vscode.window.showErrorMessage(message);
167-
this.reporter.sendTelemetryErrorEvent('applyLogError', {
168-
message: message,
169-
stack: error.stack,
170-
});
153+
this.reporter.sendTelemetryErrorEvent('applyLogError', { message: message, stack: error.stack });
171154
return;
172155
}
173156

0 commit comments

Comments
 (0)