Skip to content

Fix autofixable ESLint warnings #13613

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Aug 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ src/test/common/utils/regexp.unit.test.ts
src/test/common/utils/cacheUtils.unit.test.ts
src/test/common/utils/decorators.unit.test.ts
src/test/common/utils/localize.functional.test.ts
src/test/common/utils/workerPool.functional.test.ts
src/test/common/configSettings/configSettings.pythonPath.unit.test.ts
src/test/common/configSettings/configSettings.unit.test.ts
src/test/common/featureDeprecationManager.unit.test.ts
Expand Down Expand Up @@ -1053,6 +1054,7 @@ src/client/common/utils/version.ts
src/client/common/utils/misc.ts
src/client/common/utils/logging.ts
src/client/common/utils/cacheUtils.ts
src/client/common/utils/workerPool.ts
src/client/common/crypto.ts
src/client/common/extensions.ts
src/client/common/dotnet/compatibilityService.ts
Expand Down
5 changes: 3 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
"@typescript-eslint/no-useless-constructor": "error",
"@typescript-eslint/no-var-requires": "off",
// Other rules
"comma-dangle": "off",
"func-names": "off",
"import/extensions": "off",
"import/namespace": "off",
Expand All @@ -68,10 +67,12 @@
}
],
"max-len": [
"error",
"warn",
{
"code": 120,
"ignorePattern": "^import\\s.+\\sfrom\\s.+;$",
"ignoreStrings": true,
"ignoreTemplateLiterals": true,
"ignoreUrls": true
}
],
Expand Down
4 changes: 2 additions & 2 deletions src/client/pythonEnvironments/discovery/globalenv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function getPyenvTypeFinder(
pathJoin: (...parts: string[]) => string,
// </path>
getEnvVar: (name: string) => string | undefined,
exec: ExecFunc
exec: ExecFunc,
): TypeFinderFunc {
const find = getPyenvRootFinder(homedir, pathJoin, getEnvVar, exec);
return async (python) => {
Expand All @@ -49,7 +49,7 @@ export function getPyenvRootFinder(
homedir: string,
pathJoin: (...parts: string[]) => string,
getEnvVar: (name: string) => string | undefined,
exec: ExecFunc
exec: ExecFunc,
): RootFinderFunc {
return async () => {
const root = getEnvVar('PYENV_ROOT');
Expand Down
25 changes: 12 additions & 13 deletions src/client/pythonEnvironments/discovery/locators/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,12 @@ export async function lookForInterpretersInDirectory(pathToCheck: string, _: IFi
export class InterpreterLocatorHelper implements IInterpreterLocatorHelper {
constructor(
@inject(IFileSystem) private readonly fs: IFileSystem,
@inject(IPipEnvServiceHelper) private readonly pipEnvServiceHelper: IPipEnvServiceHelper
@inject(IPipEnvServiceHelper) private readonly pipEnvServiceHelper: IPipEnvServiceHelper,
) {}

public async mergeInterpreters(interpreters: PythonEnvironment[]): Promise<PythonEnvironment[]> {
const items = interpreters
.map((item) => {
return { ...item };
})
.map((item) => ({ ...item }))
.map((item) => {
item.path = path.normalize(item.path);
return item;
Expand All @@ -47,11 +46,11 @@ export class InterpreterLocatorHelper implements IInterpreterLocatorHelper {
// If same version and same base path, then ignore.
// Could be Python 3.6 with path = python.exe, and Python 3.6 and path = python3.exe.
if (
item.version &&
item.version.raw === currentVersion &&
item.path &&
current.path &&
this.fs.arePathsSame(path.dirname(item.path), path.dirname(current.path))
item.version
&& item.version.raw === currentVersion
&& item.path
&& current.path
&& this.fs.arePathsSame(path.dirname(item.path), path.dirname(current.path))
) {
return true;
}
Expand All @@ -63,8 +62,8 @@ export class InterpreterLocatorHelper implements IInterpreterLocatorHelper {
// Preserve type information.
// Possible we identified environment as unknown, but a later provider has identified env type.
if (
existingItem.envType === EnvironmentType.Unknown &&
current.envType !== EnvironmentType.Unknown
existingItem.envType === EnvironmentType.Unknown
&& current.envType !== EnvironmentType.Unknown
) {
existingItem.envType = current.envType;
}
Expand All @@ -75,7 +74,7 @@ export class InterpreterLocatorHelper implements IInterpreterLocatorHelper {
'sysPrefix',
'architecture',
'sysVersion',
'version'
'version',
];
for (const prop of props) {
if (!existingItem[prop] && current[prop]) {
Expand All @@ -95,7 +94,7 @@ export class InterpreterLocatorHelper implements IInterpreterLocatorHelper {
item.pipEnvWorkspaceFolder = info.workspaceFolder.fsPath;
item.envName = info.envName || item.envName;
}
})
}),
);
return items;
}
Expand Down
13 changes: 10 additions & 3 deletions src/client/pythonEnvironments/discovery/locators/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { inject, injectable } from 'inversify';
import { Disposable, Event, EventEmitter, Uri } from 'vscode';
import {
Disposable, Event, EventEmitter, Uri,
} from 'vscode';
import { traceDecorators } from '../../../common/logger';
import { IPlatformService } from '../../../common/platform/types';
import { IDisposableRegistry } from '../../../common/types';
Expand All @@ -15,7 +17,7 @@ import {
KNOWN_PATH_SERVICE,
PIPENV_SERVICE,
WINDOWS_REGISTRY_SERVICE,
WORKSPACE_VIRTUAL_ENV_SERVICE
WORKSPACE_VIRTUAL_ENV_SERVICE,
} from '../../../interpreter/contracts';
import { IServiceContainer } from '../../../ioc/types';
import { PythonEnvironment } from '../../info';
Expand All @@ -33,8 +35,11 @@ export class PythonInterpreterLocatorService implements IInterpreterLocatorServi
public didTriggerInterpreterSuggestions: boolean;

private readonly disposables: Disposable[] = [];

private readonly platform: IPlatformService;

private readonly interpreterLocatorHelper: IInterpreterLocatorHelper;

private readonly _hasInterpreters: Deferred<boolean>;

constructor(@inject(IServiceContainer) private serviceContainer: IServiceContainer) {
Expand All @@ -44,6 +49,7 @@ export class PythonInterpreterLocatorService implements IInterpreterLocatorServi
this.interpreterLocatorHelper = serviceContainer.get<IInterpreterLocatorHelper>(IInterpreterLocatorHelper);
this.didTriggerInterpreterSuggestions = false;
}

/**
* This class should never emit events when we're locating.
* The events will be fired by the indivitual locators retrieved in `getLocators`.
Expand All @@ -55,6 +61,7 @@ export class PythonInterpreterLocatorService implements IInterpreterLocatorServi
public get onLocating(): Event<Promise<PythonEnvironment[]>> {
return new EventEmitter<Promise<PythonEnvironment[]>>().event;
}

public get hasInterpreters(): Promise<boolean> {
return this._hasInterpreters.completed ? this._hasInterpreters.promise : Promise.resolve(false);
}
Expand Down Expand Up @@ -115,7 +122,7 @@ export class PythonInterpreterLocatorService implements IInterpreterLocatorServi
[GLOBAL_VIRTUAL_ENV_SERVICE, undefined],
[WORKSPACE_VIRTUAL_ENV_SERVICE, undefined],
[KNOWN_PATH_SERVICE, undefined],
[CURRENT_PATH_SERVICE, undefined]
[CURRENT_PATH_SERVICE, undefined],
];

const locators = keys
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,41 +16,51 @@ import { PythonEnvironment } from '../../info';
@injectable()
export class InterpreterLocatorProgressService implements IInterpreterLocatorProgressService {
private deferreds: Deferred<PythonEnvironment[]>[] = [];

private readonly refreshing = new EventEmitter<void>();

private readonly refreshed = new EventEmitter<void>();

private readonly locators: IInterpreterLocatorService[] = [];

constructor(
@inject(IServiceContainer) serviceContainer: IServiceContainer,
@inject(IDisposableRegistry) private readonly disposables: Disposable[]
@inject(IDisposableRegistry) private readonly disposables: Disposable[],
) {
this.locators = serviceContainer.getAll<IInterpreterLocatorService>(IInterpreterLocatorService);
}

public get onRefreshing(): Event<void> {
return this.refreshing.event;
}

public get onRefreshed(): Event<void> {
return this.refreshed.event;
}

public register(): void {
this.locators.forEach((locator) => {
locator.onLocating(this.handleProgress, this, this.disposables);
});
}

@traceDecorators.verbose('Detected refreshing of Interpreters')
private handleProgress(promise: Promise<PythonEnvironment[]>) {
this.deferreds.push(createDeferredFrom(promise));
this.notifyRefreshing();
this.checkProgress();
}

@traceDecorators.verbose('All locators have completed locating')
private notifyCompleted() {
this.refreshed.fire();
}

@traceDecorators.verbose('Notify locators are locating')
private notifyRefreshing() {
this.refreshing.fire();
}

private checkProgress() {
if (this.deferreds.length === 0) {
return;
Expand All @@ -63,6 +73,7 @@ export class InterpreterLocatorProgressService implements IInterpreterLocatorPro
.then(() => this.checkProgress())
.ignoreErrors();
}

@traceDecorators.verbose('Checking whether locactors have completed locating')
private areAllItemsComplete() {
this.deferreds = this.deferreds.filter((item) => !item.completed);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { IServiceContainer } from '../../../../ioc/types';
import { EnvironmentType, PythonEnvironment } from '../../../info';
import { lookForInterpretersInDirectory } from '../helpers';
import { CacheableLocatorService } from './cacheableLocatorService';

const flatten = require('lodash/flatten') as typeof import('lodash/flatten');

/**
Expand All @@ -19,7 +20,7 @@ export class KnownPathsService extends CacheableLocatorService {
public constructor(
@inject(IKnownSearchPathsForInterpreters) private knownSearchPaths: IKnownSearchPathsForInterpreters,
@inject(IInterpreterHelper) private helper: IInterpreterHelper,
@inject(IServiceContainer) serviceContainer: IServiceContainer
@inject(IServiceContainer) serviceContainer: IServiceContainer,
) {
super('KnownPathsService', serviceContainer);
}
Expand Down Expand Up @@ -48,13 +49,15 @@ export class KnownPathsService extends CacheableLocatorService {
const promises = this.knownSearchPaths.getSearchPaths().map((dir) => this.getInterpretersInDirectory(dir));
return Promise.all<string[]>(promises)
.then((listOfInterpreters) => flatten(listOfInterpreters))
.then((interpreters) => interpreters.filter((item) => item.length > 0))
.then((interpreters) =>
Promise.all(interpreters.map((interpreter) => this.getInterpreterDetails(interpreter)))
)
.then((interpreters) =>
interpreters.filter((interpreter) => !!interpreter).map((interpreter) => interpreter!)
);
.then((interpreters) => interpreters.filter(
(item) => item.length > 0,
))
.then((interpreters) => Promise.all(
interpreters.map((interpreter) => this.getInterpreterDetails(interpreter)),
))
.then((interpreters) => interpreters.filter(
(interpreter) => !!interpreter,
).map((interpreter) => interpreter!));
}

/**
Expand All @@ -69,7 +72,7 @@ export class KnownPathsService extends CacheableLocatorService {
return {
...(details as PythonEnvironment),
path: interpreter,
envType: EnvironmentType.Unknown
envType: EnvironmentType.Unknown,
};
}

Expand All @@ -87,6 +90,7 @@ export class KnownPathsService extends CacheableLocatorService {
@injectable()
export class KnownSearchPathsForInterpreters implements IKnownSearchPathsForInterpreters {
constructor(@inject(IServiceContainer) private readonly serviceContainer: IServiceContainer) {}

/**
* Return the paths where Python interpreters might be found.
*/
Expand Down
Loading