Skip to content

Commit

Permalink
Turn no-explicit-any into an eslint error (microsoft#15032)
Browse files Browse the repository at this point in the history
  • Loading branch information
brettcannon authored Dec 22, 2020
1 parent c1a8d94 commit 2bb9d27
Show file tree
Hide file tree
Showing 16 changed files with 46 additions and 7 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"no-empty-function": "off",
"@typescript-eslint/no-empty-function": ["error"],
"@typescript-eslint/no-empty-interface": "off",
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-non-null-assertion": "off",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "error",
Expand Down
10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,19 @@
"editor.formatOnSave": true
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
},
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
},
"[JSON]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
},
"[YAML]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
},
"typescript.tsdk": "./node_modules/typescript/lib", // we want to use the TS server from our node_modules folder to control its version
Expand Down
2 changes: 2 additions & 0 deletions src/client/jupyter/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface IJupyterServerUri {
baseUrl: string;
token: string;

// eslint-disable-next-line @typescript-eslint/no-explicit-any
authorizationHeader: any; // JSON object for authorization header.
expiration?: Date; // Date/time when header expires and should be refreshed.
displayName: string;
Expand Down Expand Up @@ -42,4 +43,5 @@ export enum ColumnType {
Bool = 'bool',
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type IRowsResponse = any[];
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ export abstract class CacheableLocatorService implements IInterpreterLocatorServ
const cacheKey = this.getCacheKey(resource);
const persistentFactory = this.serviceContainer.get<IPersistentStateFactory>(IPersistentStateFactory);
if (this.cachePerWorkspace) {
return persistentFactory.createWorkspacePersistentState<PythonEnvironment[]>(cacheKey, undefined as any);
return persistentFactory.createWorkspacePersistentState<PythonEnvironment[]>(cacheKey, undefined);
}
return persistentFactory.createGlobalPersistentState<PythonEnvironment[]>(cacheKey, undefined as any);
return persistentFactory.createGlobalPersistentState<PythonEnvironment[]>(cacheKey, undefined);
}

protected getCachedInterpreters(resource?: Uri): PythonEnvironment[] | undefined {
Expand Down
1 change: 1 addition & 0 deletions src/client/pythonEnvironments/info/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ export function updateEnvironment(environment: PartialPythonEnvironment, other:
];
props.forEach((prop) => {
if (!environment[prop] && other[prop]) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(environment as any)[prop] = other[prop];
}
});
Expand Down
1 change: 1 addition & 0 deletions src/test/languageServers/jedi/lspSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const settingsJsonPath = path.join(__dirname, '..', '..', '..', '..', 'src', 'te
const settingsJsonPromise = import('../../.vscode/settings.json');

settingsJsonPromise.then((settingsJson) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(<any>settingsJson)['python.experiments.optInto'] = [JediLSP.experiment];
return fs.writeFile(settingsJsonPath, JSON.stringify(settingsJson, undefined, ' '));
});
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ suite('Interpreters - Cacheable Locator Service', () => {
});

test('Interpreters must be retrieved once, then cached', async () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const expectedInterpreters = [1, 2] as any;
const mockedLocatorForVerification = mock(MockLocator);
const locator = new (class extends Locator {
Expand Down Expand Up @@ -113,9 +114,9 @@ suite('Interpreters - Cacheable Locator Service', () => {
class Watcher implements IInterpreterWatcher {
// eslint-disable-next-line class-methods-use-this
public onDidCreate(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
_listener: (e: Resource) => any,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
_thisArgs?: any,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_disposables?: Disposable[],
Expand All @@ -138,14 +139,17 @@ suite('Interpreters - Cacheable Locator Service', () => {
});

test('Ensure cache is cleared when watcher event fires', async () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const expectedInterpreters = [1, 2] as any;
const mockedLocatorForVerification = mock(MockLocator);
class Watcher implements IInterpreterWatcher {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
private listner?: (e: Resource) => any;

public onDidCreate(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
listener: (e: Resource) => any,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
_thisArgs?: any,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_disposables?: Disposable[],
Expand Down Expand Up @@ -213,6 +217,7 @@ suite('Interpreters - Cacheable Locator Service', () => {
locatingEventRaised = true;
});

// eslint-disable-next-line @typescript-eslint/no-explicit-any
when(mockedLocatorForVerification.getInterpretersImplementation()).thenResolve([1, 2] as any);
when(mockedLocatorForVerification.getCacheKey()).thenReturn('xyz');
when(mockedLocatorForVerification.getCachedInterpreters()).thenResolve();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ suite('Conda binary is located correctly', () => {
return Object.keys(getFile(filePath));
});

// eslint-disable-next-line @typescript-eslint/no-explicit-any
sinon.stub(fsapi, 'readFile' as any).callsFake(async (filePath: string | Buffer | number, encoding: string) => {
if (typeof filePath !== 'string') {
throw new Error(`expected filePath to be string, got ${typeof filePath}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ suite('Interpreters Conda Service', () => {
config = TypeMoq.Mock.ofType<IConfigurationService>();
settings = TypeMoq.Mock.ofType<IPythonSettings>();
procServiceFactory = TypeMoq.Mock.ofType<IProcessServiceFactory>();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
processService.setup((x: any) => x.then).returns(() => undefined);
procServiceFactory
.setup((p) => p.create(TypeMoq.It.isAny()))
Expand Down Expand Up @@ -133,6 +134,7 @@ suite('Interpreters Conda Service', () => {
);
});

// eslint-disable-next-line @typescript-eslint/no-explicit-any
function resetMockState(data: any) {
mockState = new MockState(data);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ suite('Interpretersx - Interpreter Hash Provider Factory', () => {
windowsStoreInterpreter = mock(WindowsStoreInterpreter);
standardHashProvider = mock(InterpreterHashProvider);
const windowsStoreInstance = instance(windowsStoreInterpreter);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(windowsStoreInstance as any).then = undefined;
factory = new InterpeterHashProviderFactory(
instance(configService),
Expand Down Expand Up @@ -55,6 +56,7 @@ suite('Interpretersx - Interpreter Hash Provider Factory', () => {
test('When provided resource resolves to a python path that is not a window store interpreter return standard hash provider', async () => {
const pythonPath = 'NonWindowsInterpreterPath';
const resource = Uri.file('1');
// eslint-disable-next-line @typescript-eslint/no-explicit-any
when(configService.getSettings(resource)).thenReturn({ pythonPath } as any);
when(windowsStoreInterpreter.isWindowsStoreInterpreter(pythonPath)).thenReturn(Promise.resolve(false));

Expand All @@ -66,6 +68,7 @@ suite('Interpretersx - Interpreter Hash Provider Factory', () => {
test('When provided resource resolves to a python path that is a windows store interpreter return windows store hash provider', async () => {
const pythonPath = 'NonWindowsInterpreterPath';
const resource = Uri.file('1');
// eslint-disable-next-line @typescript-eslint/no-explicit-any
when(configService.getSettings(resource)).thenReturn({ pythonPath } as any);
when(windowsStoreInterpreter.isWindowsStoreInterpreter(pythonPath)).thenReturn(Promise.resolve(true));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ suite('Interpreters - Watcher Builder', () => {

when(workspaceService.getWorkspaceFolder(anything())).thenReturn();
when(serviceContainer.get<IInterpreterWatcher>(IInterpreterWatcher, WORKSPACE_VIRTUAL_ENV_SERVICE)).thenReturn(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(watcher as any) as IInterpreterWatcher,
);

Expand All @@ -34,6 +35,7 @@ suite('Interpreters - Watcher Builder', () => {

when(workspaceService.getWorkspaceFolder(anything())).thenReturn();
when(serviceContainer.get<IInterpreterWatcher>(IInterpreterWatcher, WORKSPACE_VIRTUAL_ENV_SERVICE)).thenReturn(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(watcher as any) as IInterpreterWatcher,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,13 @@ suite('Interpreters - PipEnv', () => {
procServiceFactory = TypeMoq.Mock.ofType<IProcessServiceFactory>();
platformService = TypeMoq.Mock.ofType<IPlatformService>();
pipEnvServiceHelper = mock(PipEnvServiceHelper);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
processService.setup((x: any) => x.then).returns(() => undefined);
procServiceFactory
.setup((p) => p.create(TypeMoq.It.isAny()))
.returns(() => Promise.resolve(processService.object));

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const persistentState = TypeMoq.Mock.ofType<IPersistentState<any>>();
persistentStateFactory
.setup((p) => p.createGlobalPersistentState(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ suite('Interpreters from Windows Registry (unit)', () => {
interpreterHelper
.setup((h) => h.getInterpreterInformation(TypeMoq.It.isAny()))

// eslint-disable-next-line @typescript-eslint/no-explicit-any
.returns(() => Promise.resolve({} as any));
stateFactory
.setup((s) => s.createGlobalPersistentState(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
Expand Down Expand Up @@ -736,6 +737,7 @@ suite('Interpreters from Windows Registry (unit)', () => {
hive: RegistryHive.HKCU,
arch: Architecture.x86,

// eslint-disable-next-line @typescript-eslint/no-explicit-any
value: <any>undefined,
},

Expand Down Expand Up @@ -955,6 +957,7 @@ suite('Interpreters from Windows Registry (unit)', () => {
hive: RegistryHive.HKCU,
arch: Architecture.x86,

// eslint-disable-next-line @typescript-eslint/no-explicit-any
value: <any>undefined,
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ suite('Interpreters - Windows Store Interpreter', () => {
const key = `WINDOWS_STORE_INTERPRETER_HASH_${pythonPath}`;
const pythonService = mock<IPythonExecutionService>();
const pythonServiceInstance = instance(pythonService);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(pythonServiceInstance as any).then = undefined;
const oneHour = 60 * 60 * 1000;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ suite('Interpreters - Workspace VirtualEnv Service', () => {
public async getInterpreterWatchers(resource: Uri | undefined): Promise<IInterpreterWatcher[]> {
return super.getInterpreterWatchers(resource);
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
})(undefined as any, instance(serviceContainer), instance(builder));

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const watchers = 1 as any;
when(builder.getWorkspaceVirtualEnvInterpreterWatcher(anything())).thenResolve(watchers);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ suite('Interpreters - Workspace VirtualEnv Watcher Service', () => {
when(platformService.isMac).thenReturn(os === OSType.OSX);

class FSWatcher {
// eslint-disable-next-line class-methods-use-this, @typescript-eslint/no-unused-vars
// eslint-disable-next-line class-methods-use-this, @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
public onDidCreate(_listener: (e: Uri) => any, _thisArgs?: any, _disposables?: Disposable[]): Disposable {
return { dispose: noop };
}
Expand All @@ -68,6 +68,7 @@ suite('Interpreters - Workspace VirtualEnv Watcher Service', () => {

const fsWatcher = mock(FSWatcher);
when(workspaceService.createFileSystemWatcher(anything())).thenReturn(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
instance((fsWatcher as any) as FileSystemWatcher),
);

Expand Down Expand Up @@ -108,9 +109,10 @@ suite('Interpreters - Workspace VirtualEnv Watcher Service', () => {
when(platformService.isMac).thenReturn(os === OSType.OSX);

class FSWatcher {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
private listener?: (e: Uri) => any;

// eslint-disable-next-line @typescript-eslint/no-unused-vars
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
public onDidCreate(listener: (e: Uri) => any, _thisArgs?: any, _disposables?: Disposable[]): Disposable {
this.listener = listener;
return { dispose: noop };
Expand All @@ -122,6 +124,7 @@ suite('Interpreters - Workspace VirtualEnv Watcher Service', () => {
}
const fsWatcher = new FSWatcher();
when(workspaceService.getWorkspaceFolder(anything())).thenReturn(undefined);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
when(workspaceService.createFileSystemWatcher(anything())).thenReturn((fsWatcher as any) as FileSystemWatcher);
await watcher.register(undefined);
let invoked = false;
Expand Down

0 comments on commit 2bb9d27

Please sign in to comment.