Skip to content

Commit 3c8bbf9

Browse files
author
Kartik Raj
authored
Fix ESLint errors for environment variable provider (#15383)
1 parent 6267d38 commit 3c8bbf9

File tree

4 files changed

+57
-26
lines changed

4 files changed

+57
-26
lines changed

.eslintignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,6 @@ src/test/common/featureDeprecationManager.unit.test.ts
209209
src/test/common/serviceRegistry.unit.test.ts
210210
src/test/common/extensions.unit.test.ts
211211
src/test/common/variables/envVarsService.unit.test.ts
212-
src/test/common/variables/environmentVariablesProvider.unit.test.ts
213-
src/test/common/variables/envVarsProvider.multiroot.test.ts
214212
src/test/common/nuget/azureBobStoreRepository.unit.test.ts
215213
src/test/common/helpers.test.ts
216214
src/test/common/application/commands/reloadCommand.unit.test.ts
@@ -575,7 +573,6 @@ src/client/common/constants.ts
575573
src/client/common/variables/serviceRegistry.ts
576574
src/client/common/variables/environment.ts
577575
src/client/common/variables/types.ts
578-
src/client/common/variables/environmentVariablesProvider.ts
579576
src/client/common/variables/sysTypes.ts
580577
src/client/common/variables/systemVariables.ts
581578
src/client/common/nuget/azureBlobStoreNugetRepository.ts

src/client/common/variables/environmentVariablesProvider.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@ const CACHE_DURATION = 60 * 60 * 1000;
1717
@injectable()
1818
export class EnvironmentVariablesProvider implements IEnvironmentVariablesProvider, Disposable {
1919
public trackedWorkspaceFolders = new Set<string>();
20+
2021
private fileWatchers = new Map<string, FileSystemWatcher>();
22+
2123
private disposables: Disposable[] = [];
24+
2225
private changeEventEmitter: EventEmitter<Uri | undefined>;
26+
2327
private readonly envVarCaches = new Map<string, InMemoryCache<EnvironmentVariables>>();
2428

2529
constructor(
@@ -40,7 +44,7 @@ export class EnvironmentVariablesProvider implements IEnvironmentVariablesProvid
4044
return this.changeEventEmitter.event;
4145
}
4246

43-
public dispose() {
47+
public dispose(): void {
4448
this.changeEventEmitter.dispose();
4549
this.fileWatchers.forEach((watcher) => {
4650
if (watcher) {
@@ -70,6 +74,7 @@ export class EnvironmentVariablesProvider implements IEnvironmentVariablesProvid
7074
cache.data = { ...vars };
7175
return vars;
7276
}
77+
7378
public async _getEnvironmentVariables(resource?: Uri): Promise<EnvironmentVariables> {
7479
let mergedVars = await this.getCustomEnvironmentVariables(resource);
7580
if (!mergedVars) {
@@ -86,6 +91,7 @@ export class EnvironmentVariablesProvider implements IEnvironmentVariablesProvid
8691
}
8792
return mergedVars;
8893
}
94+
8995
public async getCustomEnvironmentVariables(resource?: Uri): Promise<EnvironmentVariables | undefined> {
9096
const systemVariables: SystemVariables = new SystemVariables(
9197
undefined,
@@ -99,15 +105,17 @@ export class EnvironmentVariablesProvider implements IEnvironmentVariablesProvid
99105
this.createFileWatcher(envFile, workspaceFolderUri);
100106
return this.envVarsService.parseFile(envFile, this.process.env);
101107
}
102-
public configurationChanged(e: ConfigurationChangeEvent) {
108+
109+
public configurationChanged(e: ConfigurationChangeEvent): void {
103110
this.trackedWorkspaceFolders.forEach((item) => {
104111
const uri = item && item.length > 0 ? Uri.file(item) : undefined;
105112
if (e.affectsConfiguration('python.envFile', uri)) {
106113
this.onEnvironmentFileChanged(uri);
107114
}
108115
});
109116
}
110-
public createFileWatcher(envFile: string, workspaceFolderUri?: Uri) {
117+
118+
public createFileWatcher(envFile: string, workspaceFolderUri?: Uri): void {
111119
if (this.fileWatchers.has(envFile)) {
112120
return;
113121
}
@@ -119,9 +127,10 @@ export class EnvironmentVariablesProvider implements IEnvironmentVariablesProvid
119127
this.disposables.push(envFileWatcher.onDidDelete(() => this.onEnvironmentFileChanged(workspaceFolderUri)));
120128
}
121129
}
130+
122131
private getWorkspaceFolderUri(resource?: Uri): Uri | undefined {
123132
if (!resource) {
124-
return;
133+
return undefined;
125134
}
126135
const workspaceFolder = this.workspaceService.getWorkspaceFolder(resource!);
127136
return workspaceFolder ? workspaceFolder.uri : undefined;

src/test/common/variables/envVarsProvider.multiroot.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ suite('Multiroot Environment Variables Provider', () => {
3434
const pathVariableName = getSearchPathEnvVarNames()[0];
3535
suiteSetup(async function () {
3636
if (!IS_MULTI_ROOT_TEST) {
37-
return this.skip();
37+
this.skip();
3838
}
3939
await clearPythonPathInWorkspaceFolder(workspace4Path);
4040
await updateSetting('envFile', undefined, workspace4PyFile, ConfigurationTarget.WorkspaceFolder);
@@ -178,7 +178,7 @@ suite('Multiroot Environment Variables Provider', () => {
178178
// this test is flaky on windows (likely the value of the path property
179179
// has incorrect path separator chars). Tracked by GH #4756
180180
if (isOs(OSType.Windows)) {
181-
return this.skip();
181+
this.skip();
182182
}
183183

184184
await updateSetting('envFile', '${workspaceRoot}/.env', workspace4PyFile, ConfigurationTarget.WorkspaceFolder);

src/test/common/variables/environmentVariablesProvider.unit.test.ts

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
12
// Copyright (c) Microsoft Corporation. All rights reserved.
23
// Licensed under the MIT License.
34

@@ -65,7 +66,9 @@ suite('Multiroot Environment Variables Provider', () => {
6566

6667
provider.trackedWorkspaceFolders.add(workspaceFolder1Uri.fsPath);
6768
provider.trackedWorkspaceFolders.add(workspaceFolder2Uri.fsPath);
68-
provider.onDidEnvironmentVariablesChange((uri) => (affectedWorkspace = uri));
69+
provider.onDidEnvironmentVariablesChange((uri) => {
70+
affectedWorkspace = uri;
71+
});
6972
const changedEvent: ConfigurationChangeEvent = {
7073
affectsConfiguration(setting: string, uri?: Uri) {
7174
return setting === 'python.envFile' && uri!.fsPath === workspaceFolder1Uri.fsPath;
@@ -82,9 +85,11 @@ suite('Multiroot Environment Variables Provider', () => {
8285
const workspaceFolderUri = Uri.file('workspace1');
8386

8487
provider.trackedWorkspaceFolders.add(workspaceFolderUri.fsPath);
85-
provider.onDidEnvironmentVariablesChange((uri) => (affectedWorkspace = uri));
88+
provider.onDidEnvironmentVariablesChange((uri) => {
89+
affectedWorkspace = uri;
90+
});
8691
const changedEvent: ConfigurationChangeEvent = {
87-
affectsConfiguration(_setting: string, _uri?: Uri) {
92+
affectsConfiguration() {
8893
return false;
8994
},
9095
};
@@ -95,9 +100,11 @@ suite('Multiroot Environment Variables Provider', () => {
95100
});
96101
test('Event is not fired when workspace is not tracked', () => {
97102
let affectedWorkspace: Uri | undefined;
98-
provider.onDidEnvironmentVariablesChange((uri) => (affectedWorkspace = uri));
103+
provider.onDidEnvironmentVariablesChange((uri) => {
104+
affectedWorkspace = uri;
105+
});
99106
const changedEvent: ConfigurationChangeEvent = {
100-
affectsConfiguration(_setting: string, _uri?: Uri) {
107+
affectsConfiguration() {
101108
return true;
102109
},
103110
};
@@ -110,17 +117,22 @@ suite('Multiroot Environment Variables Provider', () => {
110117
const workspaceTitle = workspaceUri ? '(with a workspace)' : '(without a workspace)';
111118
test(`Event is fired when the environment file is modified ${workspaceTitle}`, () => {
112119
let affectedWorkspace: Uri | undefined = Uri.file('dummy value');
113-
const envFile = path.join('a', 'b', 'env.file');
120+
envFile = path.join('a', 'b', 'env.file');
114121
const fileSystemWatcher = typemoq.Mock.ofType<FileSystemWatcher>();
115122

123+
// eslint-disable-next-line @typescript-eslint/ban-types
116124
let onChangeHandler: undefined | ((resource?: Uri) => Function);
117125

118126
fileSystemWatcher
119127
.setup((fs) => fs.onDidChange(typemoq.It.isAny()))
120-
.callback((cb) => (onChangeHandler = cb))
128+
.callback((cb) => {
129+
onChangeHandler = cb;
130+
})
121131
.verifiable(typemoq.Times.once());
122132
when(workspace.createFileSystemWatcher(envFile)).thenReturn(fileSystemWatcher.object);
123-
provider.onDidEnvironmentVariablesChange((uri) => (affectedWorkspace = uri));
133+
provider.onDidEnvironmentVariablesChange((uri) => {
134+
affectedWorkspace = uri;
135+
});
124136

125137
provider.createFileWatcher(envFile, workspaceUri);
126138

@@ -133,17 +145,22 @@ suite('Multiroot Environment Variables Provider', () => {
133145
});
134146
test(`Event is fired when the environment file is deleted ${workspaceTitle}`, () => {
135147
let affectedWorkspace: Uri | undefined = Uri.file('dummy value');
136-
const envFile = path.join('a', 'b', 'env.file');
148+
envFile = path.join('a', 'b', 'env.file');
137149
const fileSystemWatcher = typemoq.Mock.ofType<FileSystemWatcher>();
138150

151+
// eslint-disable-next-line @typescript-eslint/ban-types
139152
let onDeleted: undefined | ((resource?: Uri) => Function);
140153

141154
fileSystemWatcher
142155
.setup((fs) => fs.onDidDelete(typemoq.It.isAny()))
143-
.callback((cb) => (onDeleted = cb))
156+
.callback((cb) => {
157+
onDeleted = cb;
158+
})
144159
.verifiable(typemoq.Times.once());
145160
when(workspace.createFileSystemWatcher(envFile)).thenReturn(fileSystemWatcher.object);
146-
provider.onDidEnvironmentVariablesChange((uri) => (affectedWorkspace = uri));
161+
provider.onDidEnvironmentVariablesChange((uri) => {
162+
affectedWorkspace = uri;
163+
});
147164

148165
provider.createFileWatcher(envFile, workspaceUri);
149166

@@ -156,17 +173,22 @@ suite('Multiroot Environment Variables Provider', () => {
156173
});
157174
test(`Event is fired when the environment file is created ${workspaceTitle}`, () => {
158175
let affectedWorkspace: Uri | undefined = Uri.file('dummy value');
159-
const envFile = path.join('a', 'b', 'env.file');
176+
envFile = path.join('a', 'b', 'env.file');
160177
const fileSystemWatcher = typemoq.Mock.ofType<FileSystemWatcher>();
161178

179+
// eslint-disable-next-line @typescript-eslint/ban-types
162180
let onCreated: undefined | ((resource?: Uri) => Function);
163181

164182
fileSystemWatcher
165183
.setup((fs) => fs.onDidCreate(typemoq.It.isAny()))
166-
.callback((cb) => (onCreated = cb))
184+
.callback((cb) => {
185+
onCreated = cb;
186+
})
167187
.verifiable(typemoq.Times.once());
168188
when(workspace.createFileSystemWatcher(envFile)).thenReturn(fileSystemWatcher.object);
169-
provider.onDidEnvironmentVariablesChange((uri) => (affectedWorkspace = uri));
189+
provider.onDidEnvironmentVariablesChange((uri) => {
190+
affectedWorkspace = uri;
191+
});
170192

171193
provider.createFileWatcher(envFile, workspaceUri);
172194

@@ -178,7 +200,7 @@ suite('Multiroot Environment Variables Provider', () => {
178200
assert.equal(affectedWorkspace, workspaceUri);
179201
});
180202
test(`File system watcher event handlers are added once ${workspaceTitle}`, () => {
181-
const envFile = path.join('a', 'b', 'env.file');
203+
envFile = path.join('a', 'b', 'env.file');
182204
const fileSystemWatcher = typemoq.Mock.ofType<FileSystemWatcher>();
183205

184206
fileSystemWatcher.setup((fs) => fs.onDidChange(typemoq.It.isAny())).verifiable(typemoq.Times.once());
@@ -277,7 +299,7 @@ suite('Multiroot Environment Variables Provider', () => {
277299
});
278300

279301
test(`Cache result must be cleared when cache expires ${workspaceTitle}`, async () => {
280-
const envFile = path.join('a', 'b', 'env.file');
302+
envFile = path.join('a', 'b', 'env.file');
281303
const workspaceFolder = workspaceUri ? { name: '', index: 0, uri: workspaceUri } : undefined;
282304
const currentProcEnv = { SOMETHING: 'wow' };
283305

@@ -319,12 +341,15 @@ suite('Multiroot Environment Variables Provider', () => {
319341
};
320342
const envFileVars = { MY_FILE: '1234', PYTHONPATH: `./foo${path.delimiter}./bar` };
321343

344+
// eslint-disable-next-line @typescript-eslint/ban-types
322345
let onChangeHandler: undefined | ((resource?: Uri) => Function);
323346
const fileSystemWatcher = typemoq.Mock.ofType<FileSystemWatcher>();
324347

325348
fileSystemWatcher
326349
.setup((fs) => fs.onDidChange(typemoq.It.isAny()))
327-
.callback((cb) => (onChangeHandler = cb))
350+
.callback((cb) => {
351+
onChangeHandler = cb;
352+
})
328353
.verifiable(typemoq.Times.once());
329354
when(workspace.createFileSystemWatcher(envFile)).thenReturn(fileSystemWatcher.object);
330355

0 commit comments

Comments
 (0)