diff --git a/scripts/updateVersion.ts b/scripts/updateVersion.ts index 1fe8b78..7f7b712 100644 --- a/scripts/updateVersion.ts +++ b/scripts/updateVersion.ts @@ -59,7 +59,7 @@ function validateVersion(): string { function getVersion(filePath: string, regex: RegExp): string { const fileContents = readFileSync(filePath).toString(); const match = fileContents.match(regex); - if (!match) { + if (!match || !match[1]) { throw new Error(`Failed to find match for "${regex.source}".`); } return match[1]; @@ -79,11 +79,10 @@ function updatePackageJsonVersion(cwd: string, newVersion: string) { function updateVersionByRegex(filePath: string, regex: RegExp, newVersion: string) { const oldFileContents = readFileSync(filePath).toString(); const match = oldFileContents.match(regex); - if (!match) { + if (!match || !match[0] || !match[1]) { throw new Error(`Failed to find match for "${regex.source}".`); } - const oldLine = match[0]; - const oldVersion = match[1]; + const [oldLine, oldVersion] = match; const newLine = oldLine.replace(oldVersion, newVersion); const newFileContents = oldFileContents.replace(oldLine, newLine); writeFileSync(filePath, newFileContents); diff --git a/scripts/validateRelease.ts b/scripts/validateRelease.ts index b499e53..dea8c6f 100644 --- a/scripts/validateRelease.ts +++ b/scripts/validateRelease.ts @@ -22,8 +22,8 @@ function validateRelease(publishTag: string, dropPath: string): void { throw new Error('Drop path should have one tgz file'); } - const match = files[0].match(/^azure-functions-(.*)\.tgz$/); - if (!match) { + const match = files[0]?.match(/^azure-functions-(.*)\.tgz$/); + if (!match || !match[1]) { throw new Error(`Unrecognized tgz file name "${files[0]}"`); } diff --git a/src/InvocationModel.ts b/src/InvocationModel.ts index 5cafda2..7dd49f1 100644 --- a/src/InvocationModel.ts +++ b/src/InvocationModel.ts @@ -62,7 +62,7 @@ export class InvocationModel implements coreTypes.InvocationModel { const bindingName = nonNullProp(binding, 'name'); let input: unknown = fromRpcTypedData(binding.data); - const bindingType = this.#bindings[bindingName].type; + const bindingType = nonNullProp(this.#bindings, bindingName).type; if (isTimerTrigger(bindingType)) { input = toCamelCaseValue(input); } diff --git a/src/converters/fromRpcNullable.ts b/src/converters/fromRpcNullable.ts index 1c53b89..613be93 100644 --- a/src/converters/fromRpcNullable.ts +++ b/src/converters/fromRpcNullable.ts @@ -10,7 +10,7 @@ export function fromNullableMapping( let converted: Record = {}; if (nullableMapping && Object.keys(nullableMapping).length > 0) { for (const key in nullableMapping) { - converted[key] = nullableMapping[key].value || ''; + converted[key] = nullableMapping[key]?.value || ''; } } else if (originalMapping && Object.keys(originalMapping).length > 0) { converted = originalMapping; diff --git a/test/converters/toRpcHttpCookie.test.ts b/test/converters/toRpcHttpCookie.test.ts index 3febba0..8750fd9 100644 --- a/test/converters/toRpcHttpCookie.test.ts +++ b/test/converters/toRpcHttpCookie.test.ts @@ -28,18 +28,18 @@ describe('toRpcHttpCookie', () => { ]; const rpcCookies = cookieInputs.map(toRpcHttpCookie); - expect(rpcCookies[0].name).to.equal('mycookie'); - expect(rpcCookies[0].value).to.equal('myvalue'); - expect((rpcCookies[0].maxAge).value).to.equal(200000); + expect(rpcCookies[0]?.name).to.equal('mycookie'); + expect(rpcCookies[0]?.value).to.equal('myvalue'); + expect((rpcCookies[0]?.maxAge).value).to.equal(200000); - expect(rpcCookies[1].name).to.equal('mycookie2'); - expect(rpcCookies[1].value).to.equal('myvalue2'); - expect((rpcCookies[1].path).value).to.equal('/'); - expect((rpcCookies[1].maxAge).value).to.equal(200000); + expect(rpcCookies[1]?.name).to.equal('mycookie2'); + expect(rpcCookies[1]?.value).to.equal('myvalue2'); + expect((rpcCookies[1]?.path).value).to.equal('/'); + expect((rpcCookies[1]?.maxAge).value).to.equal(200000); - expect(rpcCookies[2].name).to.equal('mycookie3-expires'); - expect(rpcCookies[2].value).to.equal('myvalue3-expires'); - expect((rpcCookies[2].expires).value.seconds).to.equal(819199440); + expect(rpcCookies[2]?.name).to.equal('mycookie3-expires'); + expect(rpcCookies[2]?.value).to.equal('myvalue3-expires'); + expect((rpcCookies[2]?.expires).value.seconds).to.equal(819199440); }); it('http cookie SameSite', () => { @@ -66,17 +66,17 @@ describe('toRpcHttpCookie', () => { ]; const rpcCookies = cookieInputs.map(toRpcHttpCookie); - expect(rpcCookies[0].name).to.equal('none-cookie'); - expect(rpcCookies[0].sameSite).to.equal('explicitNone'); + expect(rpcCookies[0]?.name).to.equal('none-cookie'); + expect(rpcCookies[0]?.sameSite).to.equal('explicitNone'); - expect(rpcCookies[1].name).to.equal('lax-cookie'); - expect(rpcCookies[1].sameSite).to.equal('lax'); + expect(rpcCookies[1]?.name).to.equal('lax-cookie'); + expect(rpcCookies[1]?.sameSite).to.equal('lax'); - expect(rpcCookies[2].name).to.equal('strict-cookie'); - expect(rpcCookies[2].sameSite).to.equal('strict'); + expect(rpcCookies[2]?.name).to.equal('strict-cookie'); + expect(rpcCookies[2]?.sameSite).to.equal('strict'); - expect(rpcCookies[3].name).to.equal('default-cookie'); - expect(rpcCookies[3].sameSite).to.equal('none'); + expect(rpcCookies[3]?.name).to.equal('default-cookie'); + expect(rpcCookies[3]?.sameSite).to.equal('none'); }); it('throws on invalid input', () => { diff --git a/test/index.ts b/test/index.ts index e94e98b..77e8852 100644 --- a/test/index.ts +++ b/test/index.ts @@ -42,7 +42,7 @@ export async function run(): Promise { function addEnvVarsToMochaOptions(options: Mocha.MochaOptions): void { for (const envVar of Object.keys(process.env)) { const match: RegExpMatchArray | null = envVar.match(/^mocha_(.+)/i); - if (match) { + if (match && match[1]) { const [, option] = match; let value: string | number = process.env[envVar] || ''; if (typeof value === 'string' && !isNaN(parseInt(value))) { diff --git a/tsconfig.json b/tsconfig.json index aaecfa6..a4d6514 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,6 +4,7 @@ "target": "es6", "strict": true, "noUnusedLocals": true, + "noUncheckedIndexedAccess": true, "outDir": "out", "sourceMap": true, "baseUrl": "./",