From 6e70ebbca68a27187ad42b2f643eec191e1f3551 Mon Sep 17 00:00:00 2001 From: Westin Wrzesinski Date: Tue, 22 Nov 2022 20:38:51 -0600 Subject: [PATCH] fix: tests pass --- src/http.ts | 2 ++ src/util.ts | 92 ++++++++++++++++++++++++++--------------------------- 2 files changed, 48 insertions(+), 46 deletions(-) diff --git a/src/http.ts b/src/http.ts index 537aeec..d454589 100644 --- a/src/http.ts +++ b/src/http.ts @@ -147,6 +147,8 @@ export function request({ }, false ); + // open of a dynamic url + // eslint-disable-next-line security/detect-non-literal-fs-filename xhr.open(method, url, true); for (const key in normalizedHeaders) { diff --git a/src/util.ts b/src/util.ts index 130c0c4..ced04b5 100644 --- a/src/util.ts +++ b/src/util.ts @@ -80,7 +80,6 @@ export function base64encode(str: string): string { export function base64decode(str: string): string { if (typeof atob === "function") { return decodeURIComponent( - // $FlowFixMe[method-unbinding] Array.prototype.map .call(atob(str), (c) => { // eslint-disable-next-line prefer-template, @typescript-eslint/restrict-plus-operands @@ -153,7 +152,6 @@ export function getObjectID(obj: Record): string { function serializeArgs(args: readonly T[]): string { try { - // $FlowFixMe[method-unbinding] return JSON.stringify(Array.prototype.slice.call(args), (_subkey, val) => { // Treat each distinct function as unique for purposes of memoization // e.g. even if someFunction.stringify() is the same, we may use a different memoize cache @@ -226,7 +224,8 @@ export function memoize any>( try { cacheKey = serializeArgs(args); } catch { - // @ts-expect-error + // @ts-expect-error use rest parameter over arguments + // eslint-disable-next-line prefer-rest-params return method.apply(this, arguments); } @@ -244,7 +243,8 @@ export function memoize any>( } const time = Date.now(); - // @ts-expect-error + // @ts-expect-error use rest parameter over arguments + // eslint-disable-next-line prefer-rest-params const value = method.apply(this, arguments); // @ts-expect-error need to use a generic for cache later cache[cacheKey] = { @@ -259,8 +259,7 @@ export function memoize any>( thisCache = null; }; - // @ts-expect-error - const result: F = memoizedFunction; + const result = memoizedFunction; // @ts-expect-error memoized function vs function return setFunctionName( result, @@ -291,7 +290,8 @@ export function memoizePromise( return cache[key]; } - // @ts-expect-error + // @ts-expect-error this line just has all sorts of problems + // eslint-disable-next-line prefer-rest-params cache[key] = ZalgoPromise.try(() => method.apply(this, arguments)).finally( () => { // @ts-expect-error need to use a generic for cache later @@ -327,7 +327,8 @@ export function promisify( options: PromisifyOptions = getDefaultPromisifyOptions() ): (...args: readonly any[]) => ZalgoPromise { function promisifiedFunction(): ZalgoPromise { - // @ts-expect-error Argument of type 'IArguments' is not assignable to parameter of type 'readonly any[]'. + // @ts-expect-error use rest parameter over arguments also something with this + // eslint-disable-next-line prefer-rest-params return ZalgoPromise.try(method, this, arguments); } @@ -349,9 +350,9 @@ export function inlineMemoize( logic: (...args: readonly any[]) => R, args: readonly any[] = [] ): R { - // @ts-expect-error + // @ts-expect-error __inline_memoize_cache__ does not exist const cache: Record = (method.__inline_memoize_cache__ = - // @ts-expect-error + // @ts-expect-error __inline_memoize_cache__ does not exist method.__inline_memoize_cache__ || {}); const key = serializeArgs(args); @@ -374,7 +375,8 @@ export function once(method: (...args: any[]) => any): (...args: any[]) => any { const onceFunction = function (): unknown { if (!called) { called = true; - // @ts-expect-error + // @ts-expect-error use rest parameter over arguments + // eslint-disable-next-line prefer-rest-params return method.apply(this, arguments); } }; @@ -458,7 +460,6 @@ export function stringifyError(err: unknown, level = 1): string { try { if (!err) { - // $FlowFixMe[method-unbinding] return ``; } @@ -488,10 +489,11 @@ export function stringifyError(err: unknown, level = 1): string { (err as Error).toString && typeof (err as Error).toString === "function" ) { + // stringify of err will be [object Object] + // eslint-disable-next-line @typescript-eslint/no-base-to-string return err.toString(); } - // $FlowFixMe[method-unbinding] return Object.prototype.toString.call(err); } catch (newErr) { return `Error while stringifying error: ${stringifyError( @@ -502,7 +504,6 @@ export function stringifyError(err: unknown, level = 1): string { } export function stringifyErrorMessage(err: unknown): string { - // $FlowFixMe[method-unbinding] const defaultMessage = ``; @@ -528,10 +529,11 @@ export function stringify(item: unknown): string { } if (item && item.toString && typeof item.toString === "function") { + // stringify of item will be [object Object] + // eslint-disable-next-line @typescript-eslint/no-base-to-string return item.toString(); } - // $FlowFixMe[method-unbinding] return Object.prototype.toString.call(item); } @@ -551,9 +553,11 @@ export function patchMethod( obj[name] = function patchedMethod(): unknown { return handler({ context: this, + // eslint-disable-next-line prefer-rest-params args: Array.prototype.slice.call(arguments), original, // @ts-expect-error arguments in an arrow function + // eslint-disable-next-line prefer-rest-params callOriginal: () => original.apply(this, arguments), }); }; @@ -582,7 +586,6 @@ export function extend< export function values(obj: Record): readonly T[] { if (Object.values) { - // $FlowFixMe return Object.values(obj); } @@ -590,12 +593,10 @@ export function values(obj: Record): readonly T[] { for (const key in obj) { if (obj.hasOwnProperty(key)) { - // $FlowFixMe[escaped-generic] result.push(obj[key]); } } - // $FlowFixMe return result; } @@ -625,12 +626,14 @@ export function regexMap( handler?: () => T ): readonly T[] { const results: T[] | Array = []; - // @ts-expect-error + // @ts-expect-error no overload matches the cal of regexMapMatcher str.replace(regexp, function regexMapMatcher(item) { - // @ts-expect-error + // @ts-expect-error use rest parameter over arguments + // eslint-disable-next-line results.push(handler ? handler.apply(null, arguments) : item); }); - // @ts-expect-error + + // @ts-expect-error results doesnt match return value return results; } @@ -649,7 +652,7 @@ export function objFilter( continue; } - // @ts-expect-error + // @ts-expect-error string indexer result[key] = obj[key]; } @@ -824,10 +827,10 @@ export function undotify(obj: Record): Record { } if (isLast) { - // @ts-expect-error + // @ts-expect-error string indexer keyResult[part] = value; } else { - // @ts-expect-error + // @ts-expect-error string indexer keyResult = keyResult[part] = keyResult[part] || (isIndex ? [] : {}); } } @@ -989,17 +992,17 @@ export function defineLazyProp( configurable: true, enumerable: true, get: () => { - // @ts-expect-error + // @ts-expect-error delete on a dynamic key delete obj[key]; const value = getter(); - // @ts-expect-error + // @ts-expect-error string indexer obj[key] = value; return value; }, set: (value: T) => { - // @ts-expect-error + // @ts-expect-error delete on a dynamic key delete obj[key]; - // @ts-expect-error + // @ts-expect-error string indexer obj[key] = value; }, }); @@ -1015,7 +1018,6 @@ export function isObject(item: unknown): boolean { export function isObjectObject(obj: unknown): boolean { return ( - // $FlowFixMe[method-unbinding] isObject(obj) && Object.prototype.toString.call(obj) === "[object Object]" ); } @@ -1025,7 +1027,7 @@ export function isPlainObject(obj: unknown): boolean { return false; } - // @ts-expect-error + // @ts-expect-error obj is unknown const constructor = obj.constructor; if (typeof constructor !== "function") { @@ -1063,7 +1065,7 @@ export function replaceObject< let child = replacer(el, i, itemKey); if (isPlainObject(child) || Array.isArray(child)) { - // @ts-expect-error + // @ts-expect-error child is unknown type child = replaceObject(child, replacer, itemKey); } @@ -1071,7 +1073,7 @@ export function replaceObject< }); } - // @ts-expect-error + // @ts-expect-error unknown[] is not assignable to T return result; } else if (isPlainObject(item)) { const result = {}; @@ -1083,12 +1085,11 @@ export function replaceObject< defineLazyProp(result, key, () => { const itemKey = fullKey ? `${fullKey}.${key}` : `${key}`; - // $FlowFixMe const el = item[key]; let child = replacer(el, key, itemKey); if (isPlainObject(child) || Array.isArray(child)) { - // @ts-expect-error + // @ts-expect-error child is unknown type child = replaceObject(child, replacer, itemKey); } @@ -1096,7 +1097,7 @@ export function replaceObject< }); } - // @ts-expect-error + // @ts-expect-error unknown[] is not assignable to T return result; } else { throw new Error(`Pass an object or array`); @@ -1139,12 +1140,11 @@ export function regex( const result = string.slice(start).match(pattern); - if (!result) { + if (!result || result.index === undefined) { return; } - // @ts-expect-error - const index: number = result.index; + const index = result.index; const regmatch = result[0]; return { text: regmatch, @@ -1188,7 +1188,7 @@ export function regexAll( return matches; } -export function isDefined(value: unknown | undefined | undefined): boolean { +export function isDefined(value: unknown): boolean { return value !== null && value !== undefined; } @@ -1206,12 +1206,13 @@ export function debounce( const debounceWrapper = function () { clearTimeout(timeout); timeout = setTimeout(() => { - // @ts-expect-error + // @ts-expect-error use rest parameter over arguments + // eslint-disable-next-line return method.apply(this, arguments); }, time); }; - // @ts-expect-error + // @ts-expect-error this is a problematic helper return setFunctionName( debounceWrapper, `${getFunctionName(method)}::debounced` @@ -1219,7 +1220,6 @@ export function debounce( } export function isRegex(item: unknown): boolean { - // $FlowFixMe[method-unbinding] return Object.prototype.toString.call(item) === "[object RegExp]"; } @@ -1231,7 +1231,7 @@ export const weakMapMemoize: FunctionProxy = ( const weakmap = new WeakMap(); return function weakmapMemoized(arg: any): R { - // @ts-expect-error + // @ts-expect-error unknown is not assignable to R return weakmap.getOrSet(arg, () => method.call(this, arg)); }; }; @@ -1249,7 +1249,7 @@ export const weakMapMemoizePromise: FunctionPromiseProxy = ( return function weakmapMemoizedPromise(arg: any): ZalgoPromise { // @ts-expect-error unknown is not assignable to ZalgoPromise return weakmap.getOrSet(arg, () => - // @ts-expect-error + // @ts-expect-error this has no type annotation method.call(this, arg).finally(() => { weakmap.delete(arg); }) @@ -1267,7 +1267,7 @@ export function getOrSet, T>( } const val = getter(); - // @ts-expect-error + // @ts-expect-error string indexer obj[key] = val; return val; } @@ -1339,7 +1339,7 @@ export function cleanup(obj: Record): CleanupType { export function tryCatch(fn: () => T): | { result: T; - error: Error | unknown; + error: Error; } | { result: unknown;