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: address forbidden non-null assertion #1231

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 eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ export default tseslint.config(
"tsdoc/syntax": "error",
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-namespace": "error",
"@typescript-eslint/no-non-null-assertion": "error",
"@typescript-eslint/no-unused-vars": "error",
// Fix temporary off/warn made during eslint v9 upgrade:
"@typescript-eslint/no-non-null-assertion": "warn",
"no-empty-function": "warn",
"no-case-declarations": "off",
"no-constant-condition": "off",
Expand Down
20 changes: 12 additions & 8 deletions src/features/ansibleTox/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,13 @@
}

const splittedPath = uri.path.split("/");
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const fileName = splittedPath.pop()!;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const parentFolderName = splittedPath.pop()!;

const fileName = splittedPath.pop();

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

View check run for this annotation

Codecov / codecov/patch

src/features/ansibleTox/controller.ts#L84

Added line #L84 was not covered by tests
if (fileName === undefined) {
throw new TypeError(`Expected filename as string from ${splittedPath}`);

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

View check run for this annotation

Codecov / codecov/patch

src/features/ansibleTox/controller.ts#L86

Added line #L86 was not covered by tests
}

const parentFolderName = splittedPath.pop();

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

View check run for this annotation

Codecov / codecov/patch

src/features/ansibleTox/controller.ts#L89

Added line #L89 was not covered by tests

const file = this.controller.createTestItem(uri.toString(), fileName, uri);
file.description = `(${parentFolderName})`;
Expand Down Expand Up @@ -185,17 +188,18 @@
const queue: vscode.TestItem[] = [...(request.include || [])];

while (queue.length > 0 && !token.isCancellationRequested) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const test = queue.pop()!;
const test = queue.pop();

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

View check run for this annotation

Codecov / codecov/patch

src/features/ansibleTox/controller.ts#L191

Added line #L191 was not covered by tests
if (test === undefined || test.uri === undefined) {
continue;

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

View check run for this annotation

Codecov / codecov/patch

src/features/ansibleTox/controller.ts#L193

Added line #L193 was not covered by tests
}

if (request.exclude?.includes(test)) {
continue;
}

const start = Date.now();
try {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const cwd = vscode.workspace.getWorkspaceFolder(test.uri!)?.uri.path;
const cwd = vscode.workspace.getWorkspaceFolder(test.uri)?.uri.path;

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

View check run for this annotation

Codecov / codecov/patch

src/features/ansibleTox/controller.ts#L202

Added line #L202 was not covered by tests
runTox(
[test.label.split("->")[0].trim()],
"",
Expand Down
17 changes: 7 additions & 10 deletions src/features/lightspeed/inlineSuggestions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ export async function inlineSuggestionHideHandler(userAction?: UserAction) {

const suggestionId = inlineSuggestionData["suggestionId"];
// Send feedback for refused suggestion
await inlineSuggestionUserActionHandler(suggestionId!, action);
await inlineSuggestionUserActionHandler(suggestionId, action);
}

export async function inlineSuggestionUserActionHandler(
Expand Down Expand Up @@ -946,9 +946,9 @@ export async function rejectPendingSuggestion() {
console.log(
"[inline-suggestions] Send a REJECTED feedback for a pending suggestion.",
);
const suggestionId = inlineSuggestionData["suggestionId"];
const suggestionId = inlineSuggestionData["suggestionId"] || "";
await inlineSuggestionUserActionHandler(
suggestionId!,
suggestionId,
UserAction.REJECTED,
);
} else {
Expand All @@ -963,11 +963,8 @@ export async function ignorePendingSuggestion() {
console.log(
"[inline-suggestions] Send a IGNORED feedback for a pending suggestion.",
);
const suggestionId = inlineSuggestionData["suggestionId"];
await inlineSuggestionUserActionHandler(
suggestionId!,
UserAction.IGNORED,
);
const suggestionId = inlineSuggestionData["suggestionId"] || "";
await inlineSuggestionUserActionHandler(suggestionId, UserAction.IGNORED);
} else {
suggestionDisplayed.reset();
}
Expand All @@ -988,7 +985,7 @@ export async function inlineSuggestionTextDocumentChangeHandler(
e.document.languageId === "ansible" &&
e.contentChanges.length > 0
) {
const suggestionId = inlineSuggestionData["suggestionId"];
const suggestionId = inlineSuggestionData["suggestionId"] || "";

e.contentChanges.forEach(async (c) => {
if (c.text === insertTexts[0]) {
Expand All @@ -997,7 +994,7 @@ export async function inlineSuggestionTextDocumentChangeHandler(
"[inline-suggestions] Detected a text change that matches to the current suggestion.",
);
await inlineSuggestionUserActionHandler(
suggestionId!,
suggestionId,
UserAction.ACCEPTED,
);
// Show training matches for the accepted suggestion.
Expand Down
2 changes: 1 addition & 1 deletion src/features/pythonMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class PythonInterpreterManager {

const interpreterPath = this.extensionSettings.settings.interpreterPath;
if (interpreterPath) {
const label = this.makeLabelFromPath(interpreterPath!);
const label = this.makeLabelFromPath(interpreterPath);
if (label) {
this.pythonInterpreterStatusBarItem.text = label;
this.pythonInterpreterStatusBarItem.tooltip = new MarkdownString(
Expand Down
2 changes: 1 addition & 1 deletion test/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ export async function testInlineSuggestion(
// It simulates the scenario that user clicks the accept button on widget.
assert(editor);
await editor.edit((editBuilder) => {
editBuilder.insert(editor!.selection.active, insertText);
editBuilder.insert(editor.selection.active, insertText);
});
} else if (typeOver || typeOverBeforeAPIReturn) {
// If typeOver is set to true, simulate typing a space character, which will
Expand Down
16 changes: 8 additions & 8 deletions test/ui-test/lightspeedUiTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,13 @@ export function lightspeedUIAssetsTest(): void {
).not.to.be.undefined;

// Set input text and invoke summaries API
const textArea = await webView!.findWebElement(
const textArea = await webView.findWebElement(
By.xpath("//vscode-text-area"),
);
expect(textArea, "textArea should not be undefined").not.to.be
.undefined;
await textArea!.sendKeys("Create an azure network.");
const submitButton = await webView!.findWebElement(
await textArea.sendKeys("Create an azure network.");
const submitButton = await webView.findWebElement(
By.xpath("//vscode-button[@id='submit-button']"),
);
expect(submitButton, "submitButton should not be undefined").not.to.be
Expand All @@ -190,10 +190,10 @@ export function lightspeedUIAssetsTest(): void {
// Test Reset button
let text = await textArea.getText();
expect(text.includes('Name: "Create an azure network..."'));
await textArea!.sendKeys("# COMMENT\n");
await textArea.sendKeys("# COMMENT\n");
text = await textArea.getText();
expect(text.includes("# COMMENT\n"));
const resetButton = await webView!.findWebElement(
const resetButton = await webView.findWebElement(
By.xpath("//vscode-button[@id='reset-button']"),
);
expect(resetButton, "resetButton should not be undefined").not.to.be
Expand All @@ -206,7 +206,7 @@ export function lightspeedUIAssetsTest(): void {
expect(!text.includes("# COMMENT\n"));

// Test Back button
const backButton = await webView!.findWebElement(
const backButton = await webView.findWebElement(
By.xpath("//vscode-button[@id='back-button']"),
);
expect(backButton, "backButton should not be undefined").not.to.be
Expand All @@ -226,7 +226,7 @@ export function lightspeedUIAssetsTest(): void {
expect(text.includes('Name: "Create an azure network..."'));

// Click Generate playbook button to invoke the generations API
const generatePlaybookButton = await webView!.findWebElement(
const generatePlaybookButton = await webView.findWebElement(
By.xpath("//vscode-button[@id='generate-button']"),
);
expect(
Expand Down Expand Up @@ -284,7 +284,7 @@ export function lightspeedUIAssetsTest(): void {
).not.to.be.undefined;

// Find the main div element of the webview and verify the expected text is found.
const mainDiv = await webView!.findWebElement(
const mainDiv = await webView.findWebElement(
By.xpath("//div[contains(@class, 'playbookGeneration') ]"),
);
expect(mainDiv, "mainDiv should not be undefined").not.to.be.undefined;
Expand Down