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

eslint: no-unsafe-member-access (partial) #1238

Merged
merged 2 commits into from
Apr 16, 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
8 changes: 4 additions & 4 deletions docs/usage-data.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Data collection

vscode-ansible has opt-in telemetry collection, provided by
`vscode-ansible` has opt-in telemetry collection, provided by
[vscode-redhat-telemetry](https://github.com/redhat-developer/vscode-redhat-telemetry).

## What's included in the vscode-ansible telemetry data

- ansible-language-server start
- errors during ansible-language-server start
- errors during `ansible-language-server` start
- any errors from LSP requests
- Ansible core version
- ansible-lint version if installed and enabled
- ansible-playbook command runs successfully or fails.
- ansible-navigator run command runs successfully or fails.
- `ansible-playbook` command runs successfully or fails.
- `ansible-navigator` run command runs successfully or fails.
- Ansible vault (ansible-vault) command run in case it fails.
- Resync Ansible inventory (ansible-inventory) command run in case it fails.
- Execution environment enabled or disabled
Expand Down
13 changes: 11 additions & 2 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ const __dirname = path.dirname(__filename); // get the name of the directory

export default tseslint.config(
{
ignores: ["**/out/", ".yarn/*", "media/*"],
ignores: ["**/out/", ".yarn/*", "media/*", "site/*"],
},
{
extends: [
eslint.configs.recommended,
...tseslint.configs.recommended,
...tseslint.configs.recommended, // TODO: switch to strictTypeChecked
prettierRecommendedConfig,
],
files: [
Expand Down Expand Up @@ -52,6 +52,15 @@ export default tseslint.config(
"@typescript-eslint/no-namespace": "error",
"@typescript-eslint/no-non-null-assertion": "error",
"@typescript-eslint/no-unused-vars": "error",
// Needed for tseslint.configs.strictTypeChecked
// "@typescript-eslint/require-await": "error",
// "@typescript-eslint/await-thenable": "error",
// "@typescript-eslint/unbound-method": "error",
// "@typescript-eslint/no-unsafe-member-access": "error",
// "@typescript-eslint/no-floating-promises": "error",
// "@typescript-eslint/restrict-template-expressions": "error",
// "@typescript-eslint/no-unsafe-argument": "error",
// "@typescript-eslint/no-unsafe-return": "error",
// Fix temporary off/warn made during eslint v9 upgrade:
"no-empty-function": "warn",
"no-case-declarations": "off",
Expand Down
11 changes: 8 additions & 3 deletions src/features/ansibleTox/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,14 @@
getTerminal(cwd, getRootParentLabelDesc(test)),
);
run.passed(test, Date.now() - start);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (e: any) {
run.failed(test, new vscode.TestMessage(e.message), Date.now() - start);
} catch (e: unknown) {
let msg;
if (e instanceof Error) {
msg = e.message;

Check warning on line 212 in src/features/ansibleTox/controller.ts

View check run for this annotation

Codecov / codecov/patch

src/features/ansibleTox/controller.ts#L212

Added line #L212 was not covered by tests
} else {
msg = `${e}`;

Check warning on line 214 in src/features/ansibleTox/controller.ts

View check run for this annotation

Codecov / codecov/patch

src/features/ansibleTox/controller.ts#L214

Added line #L214 was not covered by tests
}
run.failed(test, new vscode.TestMessage(msg), Date.now() - start);

Check warning on line 216 in src/features/ansibleTox/controller.ts

View check run for this annotation

Codecov / codecov/patch

src/features/ansibleTox/controller.ts#L216

Added line #L216 was not covered by tests
}
}

Expand Down
14 changes: 10 additions & 4 deletions src/features/contentCreator/scaffoldCollectionPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import * as os from "os";
import { getUri } from "../utils/getUri";
import { getNonce } from "../utils/getNonce";
import { AnsibleCreatorInitInterface } from "./types";
import { AnsibleCreatorInitInterface, PostMessageEvent } from "./types";
import { withInterpreter } from "../utils/commandRunner";
import { SettingsManager } from "../../settings";

Expand Down Expand Up @@ -306,11 +306,17 @@
const ADEVersion = await this.getBinDetail("ade", "--version");
if (ADEVersion === "failed") {
// send the system details to the webview
webView.postMessage({ command: "ADEPresence", arguments: false });
webView.postMessage({

Check warning on line 309 in src/features/contentCreator/scaffoldCollectionPage.ts

View check run for this annotation

Codecov / codecov/patch

src/features/contentCreator/scaffoldCollectionPage.ts#L309

Added line #L309 was not covered by tests
command: "ADEPresence",
arguments: false,
} as PostMessageEvent);
return;
}
// send the system details to the webview
webView.postMessage({ command: "ADEPresence", arguments: true });
webView.postMessage({

Check warning on line 316 in src/features/contentCreator/scaffoldCollectionPage.ts

View check run for this annotation

Codecov / codecov/patch

src/features/contentCreator/scaffoldCollectionPage.ts#L316

Added line #L316 was not covered by tests
command: "ADEPresence",
arguments: true,
} as PostMessageEvent);
return;
}

Expand Down Expand Up @@ -440,7 +446,7 @@
collectionUrl: collectionUrl,
status: ansibleCreatorCommandPassed,
},
});
} as PostMessageEvent);
}

public async openLogFile(fileUrl: string) {
Expand Down
16 changes: 16 additions & 0 deletions src/features/contentCreator/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,19 @@ export type AnsibleCreatorInitInterface = {
isForced: boolean;
isEditableModeInstall: boolean;
};

export type PostMessageEvent =
| {
command: "ADEPresence";
arguments: boolean;
}
| {
command: "execution-log";
arguments: {
commandOutput: string;
logFileUrl: string;
collectionUrl: string;
status: string;
};
data?: string;
};
24 changes: 14 additions & 10 deletions src/features/utils/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,22 @@
/** Get python interpreter details */
export async function getInterpreterDetails(): Promise<IInterpreterDetails> {
const pythonExtension = await activatePythonExtension();
const exports = await pythonExtension?.exports;
if (pythonExtension !== undefined) {
const exports = await pythonExtension.exports;

Check warning on line 26 in src/features/utils/python.ts

View check run for this annotation

Codecov / codecov/patch

src/features/utils/python.ts#L26

Added line #L26 was not covered by tests

const environment = await exports?.environments.resolveEnvironment(
exports?.environments.getActiveEnvironmentPath(),
);
if (exports !== undefined) {
const environment = await exports?.environments.resolveEnvironment(

Check warning on line 29 in src/features/utils/python.ts

View check run for this annotation

Codecov / codecov/patch

src/features/utils/python.ts#L29

Added line #L29 was not covered by tests
exports?.environments.getActiveEnvironmentPath(),
);

if (environment?.executable.uri) {
return {
path: environment?.executable.uri.fsPath,
environment: environment.environment?.name,
version: `${environment.version.major}.${environment.version.minor}.${environment.version.micro}`,
};
if (environment?.executable.uri) {
return {

Check warning on line 34 in src/features/utils/python.ts

View check run for this annotation

Codecov / codecov/patch

src/features/utils/python.ts#L34

Added line #L34 was not covered by tests
path: environment?.executable.uri.fsPath,
environment: environment.environment?.name,
version: `${environment.version.major}.${environment.version.minor}.${environment.version.micro}`,
};
}
}
}
return {
path: undefined,
Expand Down
6 changes: 5 additions & 1 deletion src/features/vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@
}

function ansibleVaultPath(config: vscode.WorkspaceConfiguration): string {
return `${config.ansible.path || "ansible"}-vault`;
const path = config.get("ansible.path");

Check warning on line 48 in src/features/vault.ts

View check run for this annotation

Codecov / codecov/patch

src/features/vault.ts#L48

Added line #L48 was not covered by tests
if (typeof path === "string") {
return `${path || "ansible"}-vault`;
}
return "ansible-vault";

Check warning on line 52 in src/features/vault.ts

View check run for this annotation

Codecov / codecov/patch

src/features/vault.ts#L52

Added line #L52 was not covered by tests
}

export const toggleEncrypt = async (): Promise<void> => {
Expand Down
8 changes: 3 additions & 5 deletions src/utils/telemetryUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,10 @@
isInitialized: boolean,
errorMessage?: string,
): Promise<void> {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const startUpData: any = {
"ansible.server.initialized": isInitialized,
};
const startUpData: Map<string, string | boolean> = new Map();
startUpData.set("ansible.server.initialized", isInitialized);
if (errorMessage) {
startUpData["error"] = errorMessage;
startUpData.set("error", errorMessage);

Check warning on line 118 in src/utils/telemetryUtils.ts

View check run for this annotation

Codecov / codecov/patch

src/utils/telemetryUtils.ts#L118

Added line #L118 was not covered by tests
}
await this.sendTelemetry("startup", startUpData);
}
Expand Down
82 changes: 47 additions & 35 deletions src/webview/apps/contentCreator/scaffoldCollectionPageApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import {
provideVSCodeDesignSystem,
Dropdown,
} from "@vscode/webview-ui-toolkit";
import { AnsibleCreatorInitInterface } from "../../../features/contentCreator/types";
import {
AnsibleCreatorInitInterface,
PostMessageEvent,
} from "../../../features/contentCreator/types";

provideVSCodeDesignSystem().register(allComponents);

Expand Down Expand Up @@ -185,17 +188,20 @@ function toggleEditableModeInstallCheckBox() {
command: "check-ade-presence",
});

window.addEventListener("message", (event) => {
const message = event.data; // The JSON data our extension sent
window.addEventListener(
"message",
(event: MessageEvent<PostMessageEvent>) => {
const message = event.data; // The JSON data our extension sent

if (message.command === "ADEPresence") {
if (message.arguments) {
editableModeInstall.disabled = false;
} else {
editableModeInstall.disabled = true;
if (message.command === "ADEPresence") {
if (message.arguments) {
editableModeInstall.disabled = false;
} else {
editableModeInstall.disabled = true;
}
}
}
});
},
);
}

function handleInitClearClick() {
Expand Down Expand Up @@ -249,31 +255,37 @@ function handleInitCreateClick() {
} as AnsibleCreatorInitInterface,
});

window.addEventListener("message", async (event) => {
const message = await event.data;

switch (message.command) {
case "execution-log":
initLogsTextArea.value = message.arguments.commandOutput;
logFileUrl = message.arguments.logFileUrl;

if (logFileUrl) {
initOpenLogFileButton.disabled = false;
} else {
initOpenLogFileButton.disabled = true;
}

if (message.arguments.status && message.arguments.status === "passed") {
initOpenScaffoldedFolderButton.disabled = false;
} else {
initOpenScaffoldedFolderButton.disabled = true;
}

collectionUrl = message.arguments.collectionUrl;

return;
}
});
window.addEventListener(
"message",
async (event: MessageEvent<PostMessageEvent>) => {
const message = await event.data;

switch (message.command) {
case "execution-log":
initLogsTextArea.value = message.arguments.commandOutput;
logFileUrl = message.arguments.logFileUrl;

if (logFileUrl) {
initOpenLogFileButton.disabled = false;
} else {
initOpenLogFileButton.disabled = true;
}

if (
message.arguments.status &&
message.arguments.status === "passed"
) {
initOpenScaffoldedFolderButton.disabled = false;
} else {
initOpenScaffoldedFolderButton.disabled = true;
}

collectionUrl = message.arguments.collectionUrl;

return;
}
},
);
}

function handleInitClearLogsClick() {
Expand Down