diff --git a/eslint.config.mjs b/eslint.config.mjs index 798b640f3..7943d37ae 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -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", diff --git a/src/features/ansibleTox/controller.ts b/src/features/ansibleTox/controller.ts index ee6c2adaf..c7a751e66 100644 --- a/src/features/ansibleTox/controller.ts +++ b/src/features/ansibleTox/controller.ts @@ -80,10 +80,13 @@ export class AnsibleToxController { } 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(); + if (fileName === undefined) { + throw new TypeError(`Expected filename as string from ${splittedPath}`); + } + + const parentFolderName = splittedPath.pop(); const file = this.controller.createTestItem(uri.toString(), fileName, uri); file.description = `(${parentFolderName})`; @@ -185,8 +188,10 @@ export class AnsibleToxController { 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(); + if (test === undefined || test.uri === undefined) { + continue; + } if (request.exclude?.includes(test)) { continue; @@ -194,8 +199,7 @@ export class AnsibleToxController { 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; runTox( [test.label.split("->")[0].trim()], "", diff --git a/src/features/lightspeed/inlineSuggestions.ts b/src/features/lightspeed/inlineSuggestions.ts index ea266b2a5..68c2f3777 100644 --- a/src/features/lightspeed/inlineSuggestions.ts +++ b/src/features/lightspeed/inlineSuggestions.ts @@ -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( @@ -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 { @@ -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(); } @@ -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]) { @@ -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. diff --git a/src/features/pythonMetadata.ts b/src/features/pythonMetadata.ts index e4cda0e32..d11a47b49 100644 --- a/src/features/pythonMetadata.ts +++ b/src/features/pythonMetadata.ts @@ -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( diff --git a/test/helper.ts b/test/helper.ts index 29061c5c4..43d8881a2 100644 --- a/test/helper.ts +++ b/test/helper.ts @@ -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 diff --git a/test/ui-test/lightspeedUiTest.ts b/test/ui-test/lightspeedUiTest.ts index fffc3f3b0..07f374d19 100644 --- a/test/ui-test/lightspeedUiTest.ts +++ b/test/ui-test/lightspeedUiTest.ts @@ -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 @@ -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 @@ -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 @@ -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( @@ -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;