From 32e4b4334cead3197d728002bbd68922a5c4fbc0 Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Wed, 6 Mar 2024 16:09:13 +1100 Subject: [PATCH] chore(_tools): prepare for `noUncheckedIndexedAccess` (#4442) --- _tools/check_circular_submodule_dependencies.ts | 8 ++++---- _tools/check_doc_imports.ts | 4 ++-- _tools/check_licence.ts | 3 ++- _tools/convert_to_workspace.ts | 8 ++++---- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/_tools/check_circular_submodule_dependencies.ts b/_tools/check_circular_submodule_dependencies.ts index 605c9d01eeac..ec21f21a4c91 100644 --- a/_tools/check_circular_submodule_dependencies.ts +++ b/_tools/check_circular_submodule_dependencies.ts @@ -169,8 +169,8 @@ const STABILITY: Record = { const root = new URL("../", import.meta.url).href; const deps: Record = {}; -function getSubmoduleNameFromUrl(url: string) { - return url.replace(root, "").split("/")[0]; +function getSubmoduleNameFromUrl(url: string): string { + return url.replace(root, "").split("/")[0]!; } async function check( @@ -270,9 +270,9 @@ function stateToNodeStyle(state: DepState) { if (Deno.args.includes("--graph")) { console.log("digraph std_deps {"); for (const mod of Object.keys(deps)) { - const info = deps[mod]; + const info = deps[mod]!; console.log(` ${formatLabel(mod)} ${stateToNodeStyle(info.state)};`); - for (const dep of deps[mod].set) { + for (const dep of info.set) { console.log(` ${formatLabel(mod)} -> ${dep};`); } } diff --git a/_tools/check_doc_imports.ts b/_tools/check_doc_imports.ts index 64c7125a04ee..61c25168f816 100644 --- a/_tools/check_doc_imports.ts +++ b/_tools/check_doc_imports.ts @@ -81,11 +81,11 @@ function checkCodeBlocks( if ( ["ts", "js", "typescript", "javascript", ""].includes( - language.toLocaleLowerCase(), + language!.toLocaleLowerCase(), ) ) { checkImportStatements( - codeBlock, + codeBlock!, filePath, lineNumber + codeBlockLineNumber, ); diff --git a/_tools/check_licence.ts b/_tools/check_licence.ts index 47b20fe7d55f..504eb32ef2a4 100644 --- a/_tools/check_licence.ts +++ b/_tools/check_licence.ts @@ -45,7 +45,8 @@ for await ( console.log("Copyright header automatically added to " + path); } } else if ( - parseInt(match[1]) !== FIRST_YEAR || parseInt(match[2]) !== CURRENT_YEAR + (match[1] && parseInt(match[1]) !== FIRST_YEAR) || + (match[2] && parseInt(match[2]) !== CURRENT_YEAR) ) { if (CHECK) { console.error(`Incorrect copyright year: ${path}`); diff --git a/_tools/convert_to_workspace.ts b/_tools/convert_to_workspace.ts index 9a35bea8b9d5..aa0bd9f86699 100644 --- a/_tools/convert_to_workspace.ts +++ b/_tools/convert_to_workspace.ts @@ -94,14 +94,14 @@ for (const { specifier, dependencies } of graph.modules) { continue; } const from = relative(cwd, fromFileUrl(specifier)).replaceAll("\\", "/"); - const fromPkg = from.split("/")[0]; + const fromPkg = from.split("/")[0]!; for (const dep of dependencies ?? []) { if (dep.code) { const to = relative(cwd, fromFileUrl(dep.code.specifier)).replaceAll( "\\", "/", ); - const toPkg = to.split("/")[0]; + const toPkg = to.split("/")[0]!; if (fromPkg !== toPkg) { pkgDeps.get(fromPkg)!.add(toPkg); } @@ -111,7 +111,7 @@ for (const { specifier, dependencies } of graph.modules) { "\\", "/", ); - const toPkg = to.split("/")[0]; + const toPkg = to.split("/")[0]!; if (fromPkg !== toPkg) { pkgDeps.get(fromPkg)!.add(toPkg); } @@ -221,7 +221,7 @@ for await (const entry of walk(cwd)) { for (const pkg of packages) { const exportsList = exportsByPackage.get(pkg)!; let exports; - if (exportsList.length === 1 && exportsList[0][0] === ".") { + if (exportsList.length === 1 && exportsList[0]![0] === ".") { exports = "./mod.ts"; } else { exports = Object.fromEntries(exportsList);