Skip to content
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

Address ESLint errors from recommended plugins #2441

Merged
merged 1 commit into from
Nov 18, 2024
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: 1 addition & 1 deletion extensions/vscode/src/actions/showAssociateGUID.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Views } from "src/constants";
import { useApi } from "src/api";

export async function showAssociateGUID(state: PublisherState) {
let urlOrGuid = "";
const urlOrGuid = "";
const result = await window.showInputBox({
title: "Enter the URL of the Existing Content Item on the Server",
prompt: "Please provide the content's URL from Connect",
Expand Down
2 changes: 1 addition & 1 deletion extensions/vscode/src/api/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class PublishingClientApi {
this.entrypoints = new EntryPoints(this.client);
}

logDuration(response: AxiosResponse<any, any>) {
logDuration(response: AxiosResponse<unknown, unknown>) {
const timestamp = response.config.ts;
if (timestamp) {
const request = response.request;
Expand Down
1 change: 1 addition & 0 deletions extensions/vscode/src/api/types/error.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
// Copyright (C) 2023 by Posit Software, PBC.

import { ErrorCode } from "../../utils/errorTypes";
Expand Down
12 changes: 0 additions & 12 deletions extensions/vscode/src/api/types/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -622,10 +622,6 @@ export function isPublishCreateDeploymentStart(

export interface PublishCreateDeploymentLog extends EventStreamMessage {
type: "publish/createDeployment/log";
data: {
// structured data not guaranteed, use selective or generic queries
// from data map
};
}
export type OnPublishCreateDeploymentLogCallback = (
msg: PublishCreateDeploymentLog,
Expand Down Expand Up @@ -683,10 +679,6 @@ export function isPublishUploadBundleStart(

export interface PublishUploadBundleLog extends EventStreamMessage {
type: "publish/uploadBundle/log";
data: {
// structured data not guaranteed, use selective or generic queries
// from data map
};
}
export type OnPublishUploadBundleLogCallback = (
msg: PublishUploadBundleLog,
Expand Down Expand Up @@ -745,10 +737,6 @@ export function isPublishDeployBundleStart(

export interface PublishDeployBundleLog extends EventStreamMessage {
type: "publish/deployBundle/log";
data: {
// structured data not guaranteed, use selective or generic queries
// from data map
};
}
export type OnPublishDeployBundleLogCallback = (
msg: PublishDeployBundleLog,
Expand Down
1 change: 1 addition & 0 deletions extensions/vscode/src/eventErrors.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
// Copyright (C) 2024 by Posit Software, PBC.

import { describe, expect, test } from "vitest";
Expand Down
4 changes: 3 additions & 1 deletion extensions/vscode/src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ export class EventStream extends Readable implements Disposable {
* @param object - The object to convert.
* @returns The object with camel case keys.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const convertKeysToCamelCase = (object: any): any => {
if (typeof object !== "object" || object === null) {
return object;
Expand All @@ -297,9 +298,10 @@ const convertKeysToCamelCase = (object: any): any => {
return object.map((item) => convertKeysToCamelCase(item));
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const newObject: any = {};
for (const key in object) {
if (object.hasOwnProperty(key)) {
if (Object.prototype.hasOwnProperty.call(object, key)) {
// Convert the key to camel case
const newKey = key.charAt(0).toLowerCase() + key.slice(1);
// Recursively convert keys for nested objects
Expand Down
2 changes: 2 additions & 0 deletions extensions/vscode/src/multiStepInputs/multiStepHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ export class MultiStepInput {
if (item === QuickInputButtons.Back) {
reject(InputFlowAction.back);
} else {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
resolve(<any>item);
}
}),
Expand Down Expand Up @@ -260,6 +261,7 @@ export class MultiStepInput {
if (item === QuickInputButtons.Back) {
reject(InputFlowAction.back);
} else {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
resolve(<any>item);
}
}),
Expand Down
134 changes: 66 additions & 68 deletions extensions/vscode/src/multiStepInputs/newDeployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ export async function newDeployment(
let credentials: Credential[] = [];
let credentialListItems: QuickPickItem[] = [];

let entryPointListItems: QuickPickItem[] = [];
const entryPointListItems: QuickPickItem[] = [];
let inspectionResults: ConfigurationInspectionResult[] = [];
let contentRecordNames = new Map<string, string[]>();
const contentRecordNames = new Map<string, string[]>();

let newConfig: Configuration | undefined;
let newOrSelectedCredential: Credential | undefined;
Expand All @@ -95,7 +95,7 @@ export async function newDeployment(
newCredentials: NewCredentialAttrs;
};

let newDeploymentData: NewDeploymentData = {
const newDeploymentData: NewDeploymentData = {
entrypoint: {},
newCredentials: {},
};
Expand All @@ -114,62 +114,58 @@ export async function newDeployment(
return newCredentialForced() || newCredentialSelected();
};

const getConfigurationInspectionQuickPicks = (
const getConfigurationInspectionQuickPicks = async (
relEntryPoint: EntryPointPath,
) => {
return new Promise<QuickPickItemWithInspectionResult[]>(
async (resolve, reject) => {
const inspectionListItems: QuickPickItemWithInspectionResult[] = [];

try {
const python = await getPythonInterpreterPath();
const relEntryPointDir = path.dirname(relEntryPoint);
const relEntryPointFile = path.basename(relEntryPoint);

const inspectResponse = await api.configurations.inspect(
relEntryPointDir,
python,
{
entrypoint: relEntryPointFile,
},
);

inspectionResults = inspectResponse.data;
inspectionResults.forEach((result) => {
const config = result.configuration;
if (config.entrypoint) {
inspectionListItems.push({
iconPath: new ThemeIcon("gear"),
label: config.type.toString(),
description: `(${contentTypeStrings[config.type]})`,
inspectionResult: result,
});
}
): Promise<QuickPickItemWithInspectionResult[]> => {
const inspectionListItems: QuickPickItemWithInspectionResult[] = [];

try {
const python = await getPythonInterpreterPath();
const relEntryPointDir = path.dirname(relEntryPoint);
const relEntryPointFile = path.basename(relEntryPoint);

const inspectResponse = await api.configurations.inspect(
relEntryPointDir,
python,
{
entrypoint: relEntryPointFile,
},
);

inspectionResults = inspectResponse.data;
inspectionResults.forEach((result) => {
const config = result.configuration;
if (config.entrypoint) {
inspectionListItems.push({
iconPath: new ThemeIcon("gear"),
label: config.type.toString(),
description: `(${contentTypeStrings[config.type]})`,
inspectionResult: result,
});
} catch (error: unknown) {
if (isAxiosErrorWithJson(error)) {
return reject(error);
}
const summary = getSummaryStringFromError(
"newDeployment, configurations.inspect",
error,
);
window.showErrorMessage(
`Unable to continue with project inspection failure for ${entryPointFile}. ${summary}`,
);
return reject();
}
if (!inspectionListItems.length) {
const msg = `Unable to continue with no project entrypoints found during inspection for ${entryPointFile}.`;
window.showErrorMessage(msg);
return reject();
}
return resolve(inspectionListItems);
},
);
});
} catch (error: unknown) {
if (isAxiosErrorWithJson(error)) {
throw error;
}
const summary = getSummaryStringFromError(
"newDeployment, configurations.inspect",
error,
);
window.showErrorMessage(
`Unable to continue with project inspection failure for ${entryPointFile}. ${summary}`,
);
throw error;
}
if (!inspectionListItems.length) {
const msg = `Unable to continue with no project entrypoints found during inspection for ${entryPointFile}.`;
window.showErrorMessage(msg);
throw new Error(msg);
}
return inspectionListItems;
};

const getCredentials = new Promise<void>(async (resolve, reject) => {
const getCredentials = async (): Promise<void> => {
try {
const response = await api.credentials.list();
credentials = response.data;
Expand All @@ -190,12 +186,11 @@ export async function newDeployment(
window.showErrorMessage(
`Unable to continue with a failed API response. ${summary}`,
);
return reject(summary);
throw error;
}
return resolve();
});
};

const getEntrypoints = new Promise<void>((resolve) => {
const getEntrypoints = () => {
if (entryPointFile) {
// we were passed in a specific entrypoint file.
// while we don't need it, we'll still provide the results
Expand All @@ -205,7 +200,7 @@ export async function newDeployment(
iconPath: new ThemeIcon("file"),
label: entryPointPath,
});
return resolve();
return;
}

// build up a list of open files, relative to the opened workspace folder
Expand Down Expand Up @@ -237,10 +232,10 @@ export async function newDeployment(
label: browseForEntrypointLabel,
detail: "Select a file as your entrypoint.",
});
return resolve();
});
return;
};

const getContentRecords = new Promise<void>(async (resolve, reject) => {
const getContentRecords = async () => {
try {
const response = await api.contentRecords.getAll(
projectDir ? projectDir : ".",
Expand All @@ -266,10 +261,9 @@ export async function newDeployment(
window.showInformationMessage(
`Unable to continue due to deployment error. ${summary}`,
);
return reject();
throw error;
}
return resolve();
});
};

// ***************************************************************
// Order of all steps
Expand Down Expand Up @@ -763,7 +757,11 @@ export async function newDeployment(
"Initializing::newDeployment",
viewId,
async () =>
await Promise.all([getCredentials, getEntrypoints, getContentRecords]),
await Promise.all([
getCredentials(),
getEntrypoints(),
getContentRecords(),
]),
);
} catch {
// errors have already been displayed by the underlying promises..
Expand Down Expand Up @@ -874,7 +872,7 @@ export async function newDeployment(
FileAction.INCLUDE,
newDeploymentData.entrypoint.inspectionResult.projectDir,
);
} catch (error: unknown) {
} catch (_error: unknown) {
// continue on as it is not necessary to include .posit files for deployment
console.debug(
`Failed to add the configuration file '${configName}' to \`files\`.`,
Expand Down Expand Up @@ -923,7 +921,7 @@ export async function newDeployment(
FileAction.INCLUDE,
newDeploymentData.entrypoint.inspectionResult.projectDir,
);
} catch (error: unknown) {
} catch (_error: unknown) {
// continue on as it is not necessary to include .posit files for deployment
console.debug(
`Failed to add the content record file '${newContentRecord.deploymentName}' to \`files\`.`,
Expand Down
Loading