Skip to content

Commit ffffb6d

Browse files
committed
Clean up eslint errors
1 parent b21b2e1 commit ffffb6d

File tree

7 files changed

+149
-119
lines changed

7 files changed

+149
-119
lines changed

src/client/pythonEnvironments/discovery/locators/helpers.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { EnvironmentType, PythonEnvironment } from '../../info';
1010

1111
const CheckPythonInterpreterRegEx = IS_WINDOWS ? /^python(\d+(.\d+)?)?\.exe$/ : /^python(\d+(.\d+)?)?$/;
1212

13-
export async function lookForInterpretersInDirectory(pathToCheck: string, _: IFileSystem): Promise<string[]> {
13+
export async function lookForInterpretersInDirectory(pathToCheck: string): Promise<string[]> {
1414
// Technically, we should be able to use fs.getFiles(). However,
1515
// that breaks some tests. So we stick with the broader behavior.
1616
try {
@@ -40,9 +40,9 @@ export class InterpreterLocatorHelper implements IInterpreterLocatorHelper {
4040
item.path = path.normalize(item.path);
4141
return item;
4242
})
43-
.reduce<PythonEnvironment[]>((accumulator, current) => {
43+
.reduce<PythonEnvironment[]>((accumulator, current:PythonEnvironment) => {
4444
const currentVersion = current && current.version ? current.version.raw : undefined;
45-
const existingItem = accumulator.find((item) => {
45+
let existingItem = accumulator.find((item) => {
4646
// If same version and same base path, then ignore.
4747
// Could be Python 3.6 with path = python.exe, and Python 3.6 and path = python3.exe.
4848
if (
@@ -76,12 +76,11 @@ export class InterpreterLocatorHelper implements IInterpreterLocatorHelper {
7676
'sysVersion',
7777
'version',
7878
];
79-
for (const prop of props) {
80-
if (!existingItem[prop] && current[prop]) {
81-
// tslint:disable-next-line: no-any
82-
(existingItem as any)[prop] = current[prop];
79+
props.forEach((prop) => {
80+
if (existingItem && !existingItem[prop] && current[prop]) {
81+
existingItem = { ...existingItem, [prop]: current[prop] };
8382
}
84-
}
83+
});
8584
}
8685
return accumulator;
8786
}, []);

src/client/pythonEnvironments/discovery/locators/index.ts

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
/* eslint-disable max-classes-per-file */
12
import { inject, injectable } from 'inversify';
3+
import { flatten } from 'lodash';
24
import {
35
Disposable, Event, EventEmitter, Uri,
46
} from 'vscode';
@@ -21,15 +23,14 @@ import {
2123
} from '../../../interpreter/contracts';
2224
import { IServiceContainer } from '../../../ioc/types';
2325
import { PythonEnvInfo } from '../../base/info';
24-
import { ILocator, Locator, NOOP_ITERATOR, PythonEnvsIterator, PythonLocatorQuery } from '../../base/locator';
26+
import {
27+
ILocator, Locator, NOOP_ITERATOR, PythonEnvsIterator, PythonLocatorQuery,
28+
} from '../../base/locator';
2529
import { DisableableLocator, Locators } from '../../base/locators';
2630
import { PythonEnvironment } from '../../info';
2731
import { isHiddenInterpreter } from './services/interpreterFilter';
2832
import { GetInterpreterLocatorOptions } from './types';
2933

30-
// tslint:disable-next-line:no-require-imports no-var-requires
31-
const flatten = require('lodash/flatten') as typeof import('lodash/flatten');
32-
3334
/**
3435
* A wrapper around all locators used by the extension.
3536
*/
@@ -39,7 +40,7 @@ export class ExtensionLocators extends Locators {
3940
nonWorkspace: ILocator[],
4041
// This is expected to be a locator wrapping any found in
4142
// the workspace (i.e. WorkspaceLocators).
42-
workspace: ILocator
43+
workspace: ILocator,
4344
) {
4445
super([...nonWorkspace, workspace]);
4546
}
@@ -62,10 +63,12 @@ type RootURI = string;
6263
*/
6364
export class WorkspaceLocators extends Locator {
6465
private readonly locators: Record<RootURI, DisableableLocator> = {};
66+
6567
private readonly roots: Record<RootURI, Uri> = {};
68+
6669
constructor(
6770
// used to produce the per-root locators:
68-
private readonly factories: WorkspaceLocatorFactory[]
71+
private readonly factories: WorkspaceLocatorFactory[],
6972
) {
7073
super();
7174
}
@@ -75,10 +78,10 @@ export class WorkspaceLocators extends Locator {
7578
*
7679
* @param folders - the info used to keep track of the workspace folders
7780
*/
78-
public activate(folders: IWorkspaceFolders) {
79-
for (const root of folders.roots) {
81+
public activate(folders: IWorkspaceFolders):void {
82+
folders.roots.forEach((root) => {
8083
this.addRoot(root);
81-
}
84+
});
8285
folders.onAdded((root: Uri) => this.addRoot(root));
8386
folders.onRemoved((root: Uri) => this.removeRoot(root));
8487
}
@@ -106,7 +109,11 @@ export class WorkspaceLocators extends Locator {
106109
}
107110
}
108111
// Fall back to checking all the roots.
112+
// The eslint disable below should be removed after we have a
113+
// better solution for these. We need asyncFind for this.
114+
// eslint-disable-next-line no-restricted-syntax
109115
for (const key of Object.keys(this.locators)) {
116+
// eslint-disable-next-line no-await-in-loop
110117
const resolved = await this.locators[key].resolveEnv(env);
111118
if (resolved !== undefined) {
112119
return resolved;
@@ -120,9 +127,9 @@ export class WorkspaceLocators extends Locator {
120127
this.removeRoot(root);
121128
// Create the root's locator, wrapping each factory-generated locator.
122129
const locators: ILocator[] = [];
123-
for (const create of this.factories) {
130+
this.factories.forEach((create) => {
124131
locators.push(...create(root));
125-
}
132+
});
126133
const locator = new DisableableLocator(new Locators(locators));
127134
// Cache it.
128135
const key = root.toString();
@@ -158,17 +165,18 @@ export class WorkspaceLocators extends Locator {
158165
* or the URI must be a parent of one of the candidates.
159166
*/
160167
function matchURI(uri: Uri, ...candidates: Uri[]): boolean {
161-
const uriPath = uri.path.endsWith('/') ? uri.path : `{uri.path}/`;
162-
for (const candidate of candidates) {
168+
const uriPath = uri.path.endsWith('/') ? uri.path : '{uri.path}/';
169+
const matchedUri = candidates.find((candidate) => {
163170
if (candidate.scheme === uri.scheme) {
164171
if (candidate.path === uri.path) {
165172
return true;
166-
} else if (candidate.path.startsWith(uriPath)) {
173+
} if (candidate.path.startsWith(uriPath)) {
167174
return true;
168175
}
169176
}
170-
}
171-
return false;
177+
return false;
178+
});
179+
return matchedUri !== undefined;
172180
}
173181

174182
/**
@@ -186,6 +194,9 @@ export class PythonInterpreterLocatorService implements IInterpreterLocatorServi
186194

187195
private readonly _hasInterpreters: Deferred<boolean>;
188196

197+
private readonly onLocatingEmitter:EventEmitter<Promise<PythonEnvironment[]>> =
198+
new EventEmitter<Promise<PythonEnvironment[]>>();
199+
189200
constructor(@inject(IServiceContainer) private serviceContainer: IServiceContainer) {
190201
this._hasInterpreters = createDeferred<boolean>();
191202
serviceContainer.get<Disposable[]>(IDisposableRegistry).push(this);
@@ -196,14 +207,14 @@ export class PythonInterpreterLocatorService implements IInterpreterLocatorServi
196207

197208
/**
198209
* This class should never emit events when we're locating.
199-
* The events will be fired by the indivitual locators retrieved in `getLocators`.
210+
* The events will be fired by the individual locators retrieved in `getLocators`.
200211
*
201212
* @readonly
202213
* @type {Event<Promise<PythonEnvironment[]>>}
203214
* @memberof PythonInterpreterLocatorService
204215
*/
205216
public get onLocating(): Event<Promise<PythonEnvironment[]>> {
206-
return new EventEmitter<Promise<PythonEnvironment[]>>().event;
217+
return this.onLocatingEmitter.event;
207218
}
208219

209220
public get hasInterpreters(): Promise<boolean> {
@@ -215,7 +226,7 @@ export class PythonInterpreterLocatorService implements IInterpreterLocatorServi
215226
*
216227
* Called by VS Code to indicate it is done with the resource.
217228
*/
218-
public dispose() {
229+
public dispose():void {
219230
this.disposables.forEach((disposable) => disposable.dispose());
220231
}
221232

@@ -276,7 +287,9 @@ export class PythonInterpreterLocatorService implements IInterpreterLocatorServi
276287
// Set it to true the first time the user selects an interpreter
277288
if (!this.didTriggerInterpreterSuggestions && options?.onSuggestion === true) {
278289
this.didTriggerInterpreterSuggestions = true;
279-
locators.forEach((locator) => (locator.didTriggerInterpreterSuggestions = true));
290+
locators.forEach((locator) => {
291+
locator.didTriggerInterpreterSuggestions = true;
292+
});
280293
}
281294

282295
return locators;

src/client/pythonEnvironments/discovery/locators/progressService.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,13 @@ export class InterpreterLocatorProgressService implements IInterpreterLocatorPro
6161
this.refreshing.fire();
6262
}
6363

64-
private checkProgress() {
64+
private checkProgress(): void {
6565
if (this.deferreds.length === 0) {
6666
return;
6767
}
6868
if (this.areAllItemsComplete()) {
69-
return this.notifyCompleted();
69+
this.notifyCompleted();
70+
return;
7071
}
7172
Promise.all(this.deferreds.map((item) => item.promise))
7273
.catch(noop)

src/client/pythonEnvironments/discovery/locators/services/KnownPathsService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export class KnownPathsService extends CacheableLocatorService {
8383
const fs = this.serviceContainer.get<IFileSystem>(IFileSystem);
8484
return fs
8585
.directoryExists(dir)
86-
.then((exists) => (exists ? lookForInterpretersInDirectory(dir, fs) : Promise.resolve<string[]>([])));
86+
.then((exists) => (exists ? lookForInterpretersInDirectory(dir) : Promise.resolve<string[]>([])));
8787
}
8888
}
8989

src/client/pythonEnvironments/discovery/locators/services/baseVirtualEnvService.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// tslint:disable:no-unnecessary-callback-wrapper no-require-imports no-var-requires
22

33
import { injectable, unmanaged } from 'inversify';
4+
import { flatten, noop } from 'lodash';
45
import * as path from 'path';
56
import { Uri } from 'vscode';
67
import { traceError } from '../../../../common/logger';
@@ -12,8 +13,6 @@ import { EnvironmentType, PythonEnvironment } from '../../../info';
1213
import { lookForInterpretersInDirectory } from '../helpers';
1314
import { CacheableLocatorService } from './cacheableLocatorService';
1415

15-
const flatten = require('lodash/flatten') as typeof import('lodash/flatten');
16-
1716
@injectable()
1817
export class BaseVirtualEnvService extends CacheableLocatorService {
1918
private readonly virtualEnvMgr: IVirtualEnvironmentManager;
@@ -34,8 +33,10 @@ export class BaseVirtualEnvService extends CacheableLocatorService {
3433
this.fileSystem = serviceContainer.get<IFileSystem>(IFileSystem);
3534
}
3635

37-
// tslint:disable-next-line:no-empty
38-
public dispose() {}
36+
// eslint-disable-next-line class-methods-use-this
37+
public dispose(): void {
38+
noop();
39+
}
3940

4041
protected getInterpretersImplementation(resource?: Uri): Promise<PythonEnvironment[]> {
4142
return this.suggestionsFromKnownVenvs(resource);
@@ -53,7 +54,7 @@ export class BaseVirtualEnvService extends CacheableLocatorService {
5354
.getSubDirectories(pathToCheck)
5455
.then((subDirs) => Promise.all(this.getProspectiveDirectoriesForLookup(subDirs)))
5556
.then((dirs) => dirs.filter((dir) => dir.length > 0))
56-
.then((dirs) => Promise.all(dirs.map((d) => lookForInterpretersInDirectory(d, this.fileSystem))))
57+
.then((dirs) => Promise.all(dirs.map((d) => lookForInterpretersInDirectory(d))))
5758
.then((pathsWithInterpreters) => flatten(pathsWithInterpreters))
5859
.then((interpreters) => Promise.all(
5960
interpreters.map((interpreter) => this.getVirtualEnvDetails(interpreter, resource)),
@@ -92,16 +93,16 @@ export class BaseVirtualEnvService extends CacheableLocatorService {
9293
this.helper.getInterpreterInformation(interpreter),
9394
this.virtualEnvMgr.getEnvironmentName(interpreter, resource),
9495
this.virtualEnvMgr.getEnvironmentType(interpreter, resource),
95-
]).then(([details, virtualEnvName, type]) => {
96+
]).then(([details, virtualEnvName, type]):Promise<PythonEnvironment | undefined> => {
9697
if (!details) {
97-
return;
98+
return Promise.resolve(undefined);
9899
}
99100
this._hasInterpreters.resolve(true);
100-
return {
101+
return Promise.resolve({
101102
...(details as PythonEnvironment),
102103
envName: virtualEnvName,
103104
type: type! as EnvironmentType,
104-
};
105+
});
105106
});
106107
}
107108
}

0 commit comments

Comments
 (0)