From 465669caef57c876d77ffe87a2e9e855edbfbb5b Mon Sep 17 00:00:00 2001 From: Dmytro Stebaiev Date: Mon, 18 Sep 2023 17:28:00 +0300 Subject: [PATCH] Stop using undefined value --- .eslintrc.cjs | 1 - src/contractFactory.ts | 4 ++-- src/deploy.ts | 2 +- src/submitters/safe-to-ima-submitter.ts | 2 +- src/upgrader.ts | 21 ++++++++++----------- src/version.ts | 2 +- 6 files changed, 15 insertions(+), 17 deletions(-) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 0c0ed4c..22befe7 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -31,7 +31,6 @@ module.exports = { "never" ], - "no-undefined": "warn", "no-underscore-dangle": "warn", "no-use-before-define": "warn", "no-warning-comments": "warn", diff --git a/src/contractFactory.ts b/src/contractFactory.ts index 0d3c153..147e0bc 100644 --- a/src/contractFactory.ts +++ b/src/contractFactory.ts @@ -15,7 +15,7 @@ const getSkaleManifest = async () => { await getManifestFile(), "utf-8" )); - if (manifest.libraries === undefined) { + if (typeof manifest.libraries === "undefined") { manifest.libraries = {}; } return manifest as SkaleManifestData; @@ -119,7 +119,7 @@ const getLibrariesToUpgrade = async ( const librariesNames = getLibrariesNames(linkReferences); const byteCodes = await loadBytesCodes(librariesNames); for (const libraryName of librariesNames) { - if (manifest.libraries[libraryName] === undefined) { + if (typeof manifest.libraries[libraryName] === "undefined") { librariesToUpgrade.push(libraryName); } else if ( hashBytecode(byteCodes.get(libraryName) as string) === diff --git a/src/deploy.ts b/src/deploy.ts index 91fc8eb..af36a56 100644 --- a/src/deploy.ts +++ b/src/deploy.ts @@ -100,7 +100,7 @@ const updateManifest = async (libraryArtifacts: LibraryArtifacts) => { await getManifestFile(), "utf-8" )) as SkaleManifestData; - if (manifest.libraries === undefined) { + if (typeof manifest.libraries === "undefined") { Object.assign( manifest, {"libraries": libraryArtifacts} diff --git a/src/submitters/safe-to-ima-submitter.ts b/src/submitters/safe-to-ima-submitter.ts index 66d5f75..73e4ef0 100644 --- a/src/submitters/safe-to-ima-submitter.ts +++ b/src/submitters/safe-to-ima-submitter.ts @@ -48,7 +48,7 @@ export class SafeToImaSubmitter extends SafeSubmitter { } private async _getMessageProxyForMainnet () { - if (this._messageProxyForMainnet === undefined) { + if (typeof this._messageProxyForMainnet === "undefined") { this._messageProxyForMainnet = await this.imaInstance.getContract("MessageProxyForMainnet"); } diff --git a/src/upgrader.ts b/src/upgrader.ts index 95115bc..dea962c 100644 --- a/src/upgrader.ts +++ b/src/upgrader.ts @@ -30,8 +30,8 @@ interface Target { contractNamesToUpgrade: string[] } -const withoutUndefined = (array: Array) => array. - filter((element) => element !== undefined) as Array; +const withoutNull = (array: Array) => array. + filter((element) => element !== null) as Array; export abstract class Upgrader { @@ -106,13 +106,13 @@ export abstract class Upgrader { // Private private async callInitialize () { - if (this.initialize !== undefined) { + if (typeof this.initialize !== "undefined") { await this.initialize(); } } private async callDeployNewContracts () { - if (this.deployNewContracts !== undefined) { + if (typeof this.deployNewContracts !== "undefined") { // Deploy new contracts await this.deployNewContracts(); } @@ -176,7 +176,7 @@ export abstract class Upgrader { private async deployNewImplementations () { const contracts = await Promise.all(this.contractNamesToUpgrade. map(this.deployNewImplementation)); - return withoutUndefined(contracts); + return withoutNull(contracts); } private async deployNewImplementation (contract: string) { @@ -186,11 +186,10 @@ export abstract class Upgrader { (await this.instance.getContract(contract)).address; console.log(`Prepare upgrade of ${contract}`); - const - currentImplementationAddress = await getImplementationAddress( - network.provider, - proxyAddress - ); + const currentImplementationAddress = await getImplementationAddress( + network.provider, + proxyAddress + ); const newImplementationAddress = await upgrades.prepareUpgrade( proxyAddress, contractFactory, @@ -207,7 +206,7 @@ export abstract class Upgrader { }; } console.log(chalk.gray(`Contract ${contract} is up to date`)); - return undefined; + return null; } private async getNormalizedDeployedVersion () { diff --git a/src/version.ts b/src/version.ts index bb03bd2..cc23402 100644 --- a/src/version.ts +++ b/src/version.ts @@ -8,7 +8,7 @@ const exec = util.promisify(asyncExec); class VersionNotFound extends Error {} const getVersionFilename = async (folder?: string): Promise => { - if (folder === undefined) { + if (typeof folder === "undefined") { return getVersionFilename(( await exec("git rev-parse --show-toplevel") ).stdout.trim());