From 92028797043b9246f2e22dd766c2b3063a1466aa Mon Sep 17 00:00:00 2001 From: Benjamin DeMann Date: Tue, 16 Jul 2024 09:43:19 -0600 Subject: [PATCH] remove "Opt" from variable names --- examples/ethereum_json_rpc/src/index.ts | 12 ++-- .../func_types/canisters/func_types/index.ts | 6 +- .../motoko_examples/http_counter/src/index.ts | 10 ++-- .../persistent-storage/src/index.ts | 25 ++++---- examples/pre_and_post_upgrade/src/index.ts | 6 +- .../robust_imports/src/azle_coverage/index.ts | 57 ++++++++----------- .../ethereum_json_rpc/src/index.ts | 6 +- .../func_types/canisters/func_types/index.ts | 6 +- .../motoko_examples/http_counter/src/index.ts | 10 ++-- .../persistent-storage/src/index.ts | 26 ++++++--- .../pre_and_post_upgrade/src/index.ts | 6 +- 11 files changed, 85 insertions(+), 85 deletions(-) diff --git a/examples/ethereum_json_rpc/src/index.ts b/examples/ethereum_json_rpc/src/index.ts index 56f8558105..fd49fe38b4 100644 --- a/examples/ethereum_json_rpc/src/index.ts +++ b/examples/ethereum_json_rpc/src/index.ts @@ -23,25 +23,21 @@ export default Canister({ stableStorage.insert('ethereumUrl', ethereumUrl); }), ethGetBalance: update([text], text, async (ethereumAddress) => { - const urlOpt = stableStorage.get('ethereumUrl'); + const url = stableStorage.get('ethereumUrl'); - if (urlOpt === null) { + if (url === null) { throw new Error('ethereumUrl is not defined'); } - const url = urlOpt; - return await getBalance(url, ethereumAddress); }), ethGetBlockByNumber: update([nat32], text, async (number) => { - const urlOpt = stableStorage.get('ethereumUrl'); + const url = stableStorage.get('ethereumUrl'); - if (urlOpt === null) { + if (url === null) { throw new Error('ethereumUrl is not defined'); } - const url = urlOpt; - return await getBlockByNumber(url, number); }), ethTransform: query([HttpTransformArgs], HttpResponse, (args) => { diff --git a/examples/func_types/canisters/func_types/index.ts b/examples/func_types/canisters/func_types/index.ts index c87686a310..883599600f 100644 --- a/examples/func_types/canisters/func_types/index.ts +++ b/examples/func_types/canisters/func_types/index.ts @@ -60,11 +60,11 @@ export default Canister({ }), getStableFunc: query([], StableFunc, () => { - const stableFuncOpt = stableStorage.get('stableFunc'); - if (stableFuncOpt === null) { + const stableFunc = stableStorage.get('stableFunc'); + if (stableFunc === null) { return [Principal.from('aaaaa-aa'), 'raw_rand']; } - return stableFuncOpt; + return stableFunc; }), basicFuncParam: query([BasicFunc], BasicFunc, (basicFunc) => { diff --git a/examples/motoko_examples/http_counter/src/index.ts b/examples/motoko_examples/http_counter/src/index.ts index a5822c3840..358ffece28 100644 --- a/examples/motoko_examples/http_counter/src/index.ts +++ b/examples/motoko_examples/http_counter/src/index.ts @@ -48,11 +48,11 @@ export default Canister({ }; } - const counterOpt = stableStorage.get('counter'); - const counter = - counterOpt === null - ? ic.trap('counter does not exist') - : counterOpt; + const counter = stableStorage.get('counter'); + + if (counter === null) { + ic.trap('counter does not exist'); + } return { status_code: 200, diff --git a/examples/motoko_examples/persistent-storage/src/index.ts b/examples/motoko_examples/persistent-storage/src/index.ts index d9cb253efa..eb64003250 100644 --- a/examples/motoko_examples/persistent-storage/src/index.ts +++ b/examples/motoko_examples/persistent-storage/src/index.ts @@ -25,29 +25,32 @@ export default Canister({ return redeployed; }), increment: update([], nat, () => { - const counterOpt = stableStorage.get('counter'); - const counter = - counterOpt === null - ? ic.trap('counter not defined') - : counterOpt + 1n; + let counter = stableStorage.get('counter'); + if (counter === null) { + return ic.trap('counter not defined'); + } + counter = counter + 1n; stableStorage.insert('counter', counter); return counter; }), get: query([], nat, () => { - const counterOpt = stableStorage.get('counter'); - const counter = - counterOpt === null ? ic.trap('counter not defined') : counterOpt; + const counter = stableStorage.get('counter'); + + if (counter === null) { + return ic.trap('counter not defined'); + } return counter; }), reset: update([], nat, () => { stableStorage.insert('counter', 0n); - const counterOpt = stableStorage.get('counter'); - const counter = - counterOpt === null ? ic.trap('counter not defined') : counterOpt; + const counter = stableStorage.get('counter'); + if (counter === null) { + return ic.trap('counter not defined'); + } return counter; }) diff --git a/examples/pre_and_post_upgrade/src/index.ts b/examples/pre_and_post_upgrade/src/index.ts index 600d361f56..a80e0be4d6 100644 --- a/examples/pre_and_post_upgrade/src/index.ts +++ b/examples/pre_and_post_upgrade/src/index.ts @@ -34,9 +34,11 @@ export default Canister({ postUpgrade: postUpgrade([], () => { console.info('postUpgrade'); - const stableEntriesOpt = stableStorage.get('entries'); + const stableEntries = stableStorage.get('entries'); - const stableEntries = stableEntriesOpt === null ? [] : stableEntriesOpt; + if (stableEntries === null) { + return; + } entries = stableEntries.reduce((result, entry) => { return { diff --git a/examples/robust_imports/src/azle_coverage/index.ts b/examples/robust_imports/src/azle_coverage/index.ts index 6706522178..4ada359c0f 100644 --- a/examples/robust_imports/src/azle_coverage/index.ts +++ b/examples/robust_imports/src/azle_coverage/index.ts @@ -96,13 +96,12 @@ export const Watermelon = Voavanga({ let soncoya = Soncoya(0); function gatherGrapes(): void { - const opt = soncoya.get(0); + const preparedFruit = soncoya.get(0); - if (opt === null) { + if (preparedFruit === null) { return; } - const preparedFruit = opt; soncoya.remove(0); soncoya.insert(0, { ...preparedFruit, @@ -126,13 +125,12 @@ export const collectIcaco = icaco([], () => { }); export const cutPineapple = pineapple(() => { - const opt = soncoya.get(0); + const preparedFruit = soncoya.get(0); - if (opt === null) { + if (preparedFruit === null) { return; } - const preparedFruit = opt; soncoya.remove(0); soncoya.insert(0, { ...preparedFruit, @@ -141,13 +139,12 @@ export const cutPineapple = pineapple(() => { }); export const separateArilsFromPith = pomegranate([], () => { - const opt = soncoya.get(0); + const preparedFruit = soncoya.get(0); - if (opt === null) { + if (preparedFruit === null) { return; } - const preparedFruit = opt; soncoya.remove(0); soncoya.insert(0, { ...preparedFruit, @@ -156,13 +153,12 @@ export const separateArilsFromPith = pomegranate([], () => { }); export const buyHoneydew = honeydew(() => { - const opt = soncoya.get(0); + const preparedFruit = soncoya.get(0); - if (opt === null) { + if (preparedFruit === null) { return; } - const preparedFruit = opt; soncoya.remove(0); soncoya.insert(0, { ...preparedFruit, @@ -273,34 +269,31 @@ export const isMangoTrickyToEat = kiwi( export const isFruitPrepared = quince([], boysenberry, () => { gatherGrapes(); - const opt = soncoya.get(0); + const preparedFruit = soncoya.get(0); - if (opt === null) { + if (preparedFruit === null) { return false; } - const pf = opt; - return ( - pf.honeydewCount > 0 && - pf.areIcacosCollected && - pf.isPineappleCut && - pf.arePomegranateArilsSeparated && - pf.areGrapesGathered && - pf.isIlamaWashed && - pf.areRambutanSkinsRemoved && - !pf.haveElderberriesBeenPicked + preparedFruit.honeydewCount > 0 && + preparedFruit.areIcacosCollected && + preparedFruit.isPineappleCut && + preparedFruit.arePomegranateArilsSeparated && + preparedFruit.areGrapesGathered && + preparedFruit.isIlamaWashed && + preparedFruit.areRambutanSkinsRemoved && + !preparedFruit.haveElderberriesBeenPicked ); }); export const removeRambutanSkins = ugni([], rambutan, () => { - const opt = soncoya.get(0); + const preparedFruit = soncoya.get(0); - if (opt === null) { + if (preparedFruit === null) { return ic.trap('soncoya is None'); } - const preparedFruit = opt; soncoya.remove(0); soncoya.insert(0, { ...preparedFruit, @@ -311,13 +304,12 @@ export const removeRambutanSkins = ugni([], rambutan, () => { }); export const dirtyIlama = ugni([], Vanilla, () => { - const opt = soncoya.get(0); + const preparedFruit = soncoya.get(0); - if (opt === null) { + if (preparedFruit === null) { return; } - const preparedFruit = opt; soncoya.remove(0); soncoya.insert(0, { ...preparedFruit, @@ -326,13 +318,12 @@ export const dirtyIlama = ugni([], Vanilla, () => { }); export const pickElderberry = ugni([], elderberry, () => { - const opt = soncoya.get(0); + const preparedFruit = soncoya.get(0); - if (opt === null) { + if (preparedFruit === null) { return ic.trap('soncoya is None'); } - const preparedFruit = opt; soncoya.remove(0); soncoya.insert(0, { ...preparedFruit, diff --git a/tests/end_to_end/candid_rpc/class_syntax/ethereum_json_rpc/src/index.ts b/tests/end_to_end/candid_rpc/class_syntax/ethereum_json_rpc/src/index.ts index 60a2357480..7af9d53158 100644 --- a/tests/end_to_end/candid_rpc/class_syntax/ethereum_json_rpc/src/index.ts +++ b/tests/end_to_end/candid_rpc/class_syntax/ethereum_json_rpc/src/index.ts @@ -26,14 +26,12 @@ export default class { @update([IDL.Text], IDL.Text) async ethGetBalance(ethereumAddress: string): Promise { - const urlOpt = stableStorage.get('ethereumUrl'); + const url = stableStorage.get('ethereumUrl'); - if (urlOpt === null) { + if (url === null) { throw new Error('ethereumUrl is not defined'); } - const url = urlOpt; - return await getBalance(url, ethereumAddress); } diff --git a/tests/end_to_end/candid_rpc/class_syntax/func_types/canisters/func_types/index.ts b/tests/end_to_end/candid_rpc/class_syntax/func_types/canisters/func_types/index.ts index 30781f7f42..f012b8e5ed 100644 --- a/tests/end_to_end/candid_rpc/class_syntax/func_types/canisters/func_types/index.ts +++ b/tests/end_to_end/candid_rpc/class_syntax/func_types/canisters/func_types/index.ts @@ -68,11 +68,11 @@ export default class { @query([], StableFunc) getStableFunc(): StableFunc { - const stableFuncOpt = stableStorage.get('stableFunc'); - if (stableFuncOpt === null) { + const stableFunc = stableStorage.get('stableFunc'); + if (stableFunc === null) { return [Principal.from('aaaaa-aa'), 'raw_rand']; } - return stableFuncOpt; + return stableFunc; } @query([BasicFunc], BasicFunc) diff --git a/tests/end_to_end/candid_rpc/class_syntax/motoko_examples/http_counter/src/index.ts b/tests/end_to_end/candid_rpc/class_syntax/motoko_examples/http_counter/src/index.ts index 94bb71c1f3..c50d9e43f6 100644 --- a/tests/end_to_end/candid_rpc/class_syntax/motoko_examples/http_counter/src/index.ts +++ b/tests/end_to_end/candid_rpc/class_syntax/motoko_examples/http_counter/src/index.ts @@ -128,11 +128,11 @@ export default class { }; } - const counterOpt = stableStorage.get('counter'); - const counter = - counterOpt === null - ? trap('counter does not exist') - : counterOpt; + const counter = stableStorage.get('counter'); + + if (counter === null) { + trap('counter does not exist'); + } return { status_code: 200, diff --git a/tests/end_to_end/candid_rpc/class_syntax/motoko_examples/persistent-storage/src/index.ts b/tests/end_to_end/candid_rpc/class_syntax/motoko_examples/persistent-storage/src/index.ts index eb8fedc741..95572777d7 100644 --- a/tests/end_to_end/candid_rpc/class_syntax/motoko_examples/persistent-storage/src/index.ts +++ b/tests/end_to_end/candid_rpc/class_syntax/motoko_examples/persistent-storage/src/index.ts @@ -29,9 +29,13 @@ export default class { @update([], IDL.Nat) increment(): bigint { - const counterOpt = stableStorage.get('counter'); - const counter = - counterOpt === null ? trap('counter not defined') : counterOpt + 1n; + let counter = stableStorage.get('counter'); + + if (counter === null) { + trap('counter not defined'); + } + + counter = counter + 1n; stableStorage.insert('counter', counter); @@ -40,9 +44,11 @@ export default class { @query([], IDL.Nat) get(): bigint { - const counterOpt = stableStorage.get('counter'); - const counter = - counterOpt === null ? trap('counter not defined') : counterOpt; + const counter = stableStorage.get('counter'); + + if (counter === null) { + trap('counter not defined'); + } return counter; } @@ -51,9 +57,11 @@ export default class { reset(): bigint { stableStorage.insert('counter', 0n); - const counterOpt = stableStorage.get('counter'); - const counter = - counterOpt === null ? trap('counter not defined') : counterOpt; + const counter = stableStorage.get('counter'); + + if (counter === null) { + trap('counter not defined'); + } return counter; } diff --git a/tests/end_to_end/candid_rpc/class_syntax/pre_and_post_upgrade/src/index.ts b/tests/end_to_end/candid_rpc/class_syntax/pre_and_post_upgrade/src/index.ts index e648cfaa71..9387c0df33 100644 --- a/tests/end_to_end/candid_rpc/class_syntax/pre_and_post_upgrade/src/index.ts +++ b/tests/end_to_end/candid_rpc/class_syntax/pre_and_post_upgrade/src/index.ts @@ -35,9 +35,11 @@ export default class { postUpgrade(): void { console.info('postUpgrade'); - const stableEntriesOpt = stableStorage.get('entries'); + const stableEntries = stableStorage.get('entries'); - const stableEntries = stableEntriesOpt === null ? [] : stableEntriesOpt; + if (stableEntries === null) { + return; + } entries = stableEntries.reduce((result, entry) => { return {