Skip to content

Commit

Permalink
lint: checkArrowFunctions
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Jan 6, 2025
1 parent 34fc13a commit 322023f
Show file tree
Hide file tree
Showing 417 changed files with 1,175 additions and 994 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ module.exports = {
'@typescript-eslint/promise-function-async': [
// so throw in promise-returning function still returns a promise
'warn',
{ checkArrowFunctions: false, checkFunctionExpressions: false },
{ checkFunctionExpressions: false },
],
'@typescript-eslint/no-empty-object-type': 'warn',
'@typescript-eslint/no-unnecessary-type-constraint': 'warn',
Expand Down
11 changes: 7 additions & 4 deletions packages/ERTP/src/legacy-payment-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ export const claim = async (
) => {
const srcPayment = await srcPaymentP;
// @ts-expect-error XXX could be instantiated with a different subtype
return E.when(E(recoveryPurse).deposit(srcPayment, optAmountShape), amount =>
E(recoveryPurse).withdraw(amount),
return E.when(
E(recoveryPurse).deposit(srcPayment, optAmountShape),
async amount => E(recoveryPurse).withdraw(amount),
);
};
harden(claim);
Expand Down Expand Up @@ -70,7 +71,7 @@ export const combine = async (
...srcPaymentsPs,
]);
const emptyAmount = AmountMath.makeEmpty(brand, displayInfo.assetKind);
const amountPs = srcPayments.map(srcPayment =>
const amountPs = srcPayments.map(async srcPayment =>
E(recoveryPurse).deposit(srcPayment),
);
const amounts = await Promise.all(amountPs);
Expand Down Expand Up @@ -141,6 +142,8 @@ export const splitMany = async (recoveryPurse, srcPaymentP, amounts) => {
AmountMath.isEqual(srcAmount, total) ||
Fail`rights were not conserved: ${total} vs ${srcAmount}`;

return Promise.all(amounts.map(amount => E(recoveryPurse).withdraw(amount)));
return Promise.all(
amounts.map(async amount => E(recoveryPurse).withdraw(amount)),
);
};
harden(splitMany);
24 changes: 15 additions & 9 deletions packages/ERTP/test/unitTests/inputValidation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ test('makeIssuerKit bad optShutdownWithFailure', async t => {
test('brand.isMyIssuer bad issuer', async t => {
const { brand } = makeIssuerKit('myTokens');
// @ts-expect-error Intentional wrong type for testing
await t.throwsAsync(() => brand.isMyIssuer('not an issuer'), {
await t.throwsAsync(async () => brand.isMyIssuer('not an issuer'), {
message:
/In "isMyIssuer" method of \(myTokens brand\): arg 0: .*"not an issuer" - Must be a remotable/,
});
Expand All @@ -160,7 +160,7 @@ test('assertLivePayment', async t => {
const paymentB = E(mintB).mintPayment(AmountMath.make(brandB, 837n));

// payment is of the wrong brand
await t.throwsAsync(() => claim(E(issuer).makeEmptyPurse(), paymentB), {
await t.throwsAsync(async () => claim(E(issuer).makeEmptyPurse(), paymentB), {
message:
'"[Alleged: fungibleB payment]" was not a live payment for brand "[Alleged: fungible brand]". It could be a used-up payment, a payment for another brand, or it might not be a payment at all.',
});
Expand All @@ -170,7 +170,7 @@ test('assertLivePayment', async t => {
// use up payment
await claim(E(issuer).makeEmptyPurse(), payment);

await t.throwsAsync(() => claim(E(issuer).makeEmptyPurse(), payment), {
await t.throwsAsync(async () => claim(E(issuer).makeEmptyPurse(), payment), {
message:
'"[Alleged: fungible payment]" was not a live payment for brand "[Alleged: fungible brand]". It could be a used-up payment, a payment for another brand, or it might not be a payment at all.',
});
Expand All @@ -184,18 +184,24 @@ test('issuer.combine bad payments array', async t => {
};
// @ts-expect-error Intentional wrong type for testing

await t.throwsAsync(() => combine(E(issuer).makeEmptyPurse(), notAnArray), {
message: 'srcPaymentsPs is not iterable',
});
await t.throwsAsync(
async () => combine(E(issuer).makeEmptyPurse(), notAnArray),
{
message: 'srcPaymentsPs is not iterable',
},
);

const notAnArray2 = Far('notAnArray2', {
length: () => 2,
split: () => {},
});
// @ts-expect-error Intentional wrong type for testing
await t.throwsAsync(() => combine(E(issuer).makeEmptyPurse(), notAnArray2), {
message: 'srcPaymentsPs is not iterable',
});
await t.throwsAsync(
async () => combine(E(issuer).makeEmptyPurse(), notAnArray2),
{
message: 'srcPaymentsPs is not iterable',
},
);
});

test('amount with accessor properties', async t => {
Expand Down
35 changes: 19 additions & 16 deletions packages/ERTP/test/unitTests/issuerObj.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ test('purse.deposit promise', async t => {

await t.throwsAsync(
// @ts-expect-error deliberate invalid arguments for testing
() => E(purse).deposit(exclusivePaymentP, fungible25),
async () => E(purse).deposit(exclusivePaymentP, fungible25),
{
message:
/In "deposit" method of \(fungible Purse purse\): arg 0: .*"\[Promise\]" - Must be a remotable/,
Expand Down Expand Up @@ -261,7 +261,7 @@ test('issuer.burn', async t => {
AmountMath.isEqual(burntBalance, AmountMath.make(brand, 837n)),
`entire minted payment was burnt`,
);
await t.throwsAsync(() => issuer.getAmountOf(payment1), {
await t.throwsAsync(async () => issuer.getAmountOf(payment1), {
message: /was not a live payment for brand/,
});
});
Expand All @@ -283,7 +283,7 @@ test('issuer.claim', async t => {
t.not(newPayment1, payment1, `old payment is different than new payment`);
});

return t.throwsAsync(() => issuer.getAmountOf(payment1), {
return t.throwsAsync(async () => issuer.getAmountOf(payment1), {
message: /was not a live payment for brand/,
});
});
Expand All @@ -294,7 +294,7 @@ test('issuer.splitMany bad amount', async t => {
const payment = mint.mintPayment(AmountMath.make(brand, 1000n));
const badAmounts = harden(Array(2).fill(AmountMath.make(brand, 10n)));
await t.throwsAsync(
_ => splitMany(E(issuer).makeEmptyPurse(), payment, badAmounts),
async _ => splitMany(E(issuer).makeEmptyPurse(), payment, badAmounts),
{ message: /rights were not conserved/ },
'successfully throw if rights are not conserved in proposed new payments',
);
Expand All @@ -308,7 +308,7 @@ test('issuer.splitMany good amount', async t => {

const checkPayments = async splitPayments => {
const amounts = await Promise.all(
splitPayments.map(payment => issuer.getAmountOf(payment)),
splitPayments.map(async payment => issuer.getAmountOf(payment)),
);
for (const amount of amounts) {
t.deepEqual(
Expand All @@ -318,7 +318,7 @@ test('issuer.splitMany good amount', async t => {
);
}
await t.throwsAsync(
() => issuer.getAmountOf(oldPayment),
async () => issuer.getAmountOf(oldPayment),
{ message: /was not a live payment for brand/ },
`oldPayment no longer exists`,
);
Expand All @@ -336,7 +336,7 @@ test('issuer.split bad amount', async t => {
const { brand: otherBrand } = makeIssuerKit('other fungible');
const payment = mint.mintPayment(AmountMath.make(brand, 1000n));
await t.throwsAsync(
_ =>
async _ =>
split(
E(issuer).makeEmptyPurse(),
payment,
Expand All @@ -356,7 +356,7 @@ test('issuer.split good amount', async t => {

const checkPayments = async splitPayments => {
const amounts = await Promise.all(
splitPayments.map(payment => issuer.getAmountOf(payment)),
splitPayments.map(async payment => issuer.getAmountOf(payment)),
);
for (const amount of amounts) {
t.deepEqual(
Expand All @@ -366,7 +366,7 @@ test('issuer.split good amount', async t => {
);
}
await t.throwsAsync(
() => issuer.getAmountOf(oldPayment),
async () => issuer.getAmountOf(oldPayment),
{
message: `"[Alleged: fungible payment]" was not a live payment for brand "[Alleged: fungible brand]". It could be a used-up payment, a payment for another brand, or it might not be a payment at all.`,
},
Expand Down Expand Up @@ -399,9 +399,9 @@ test('issuer.combine good payments', async t => {
);

await Promise.all(
payments.map(payment =>
payments.map(async payment =>
t.throwsAsync(
() => issuer.getAmountOf(payment),
async () => issuer.getAmountOf(payment),
{ message: /was not a live payment for brand/ },
`original payments no longer exist`,
),
Expand All @@ -424,7 +424,7 @@ test('issuer.combine array of promises', async t => {
}
void harden(paymentsP);

const checkCombinedResult = paymentP =>
const checkCombinedResult = async paymentP =>
issuer.getAmountOf(paymentP).then(pAmount => {
t.is(pAmount.value, 100n);
});
Expand All @@ -446,8 +446,11 @@ test('issuer.combine bad payments', async t => {
payments.push(otherPayment);
harden(payments);

await t.throwsAsync(() => combine(E(issuer).makeEmptyPurse(), payments), {
message:
/^"\[Alleged: other fungible payment\]" was not a live payment for brand "\[Alleged: fungible brand\]"./,
});
await t.throwsAsync(
async () => combine(E(issuer).makeEmptyPurse(), payments),
{
message:
/^"\[Alleged: other fungible payment\]" was not a live payment for brand "\[Alleged: fungible brand\]"./,
},
);
});
20 changes: 13 additions & 7 deletions packages/ERTP/test/unitTests/legacy-payment-helpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ test('no lost assets on non-atomic combine failure', async t => {
const precious = num => AmountMath.make(brand, num);
const payment1 = mint.mintPayment(precious(39n));
const payment2 = payment1; // "accidental" aliasing
await t.throwsAsync(() => combine(recoveryPurse, [payment1, payment2]), {
message:
/^".*" was not a live payment for brand ".*". It could be a used-up payment, a payment for another brand, or it might not be a payment at all.$/,
});
await t.throwsAsync(
async () => combine(recoveryPurse, [payment1, payment2]),
{
message:
/^".*" was not a live payment for brand ".*". It could be a used-up payment, a payment for another brand, or it might not be a payment at all.$/,
},
);

const live = await issuer.isLive(payment1);
t.assert(!live); // demonstrates non-failure atomicity
Expand All @@ -30,9 +33,12 @@ test('no lost assets on non-atomic split failure', async t => {
/** @param {bigint} num */
const precious = num => AmountMath.make(brand, num);
const srcPayment = mint.mintPayment(precious(78n));
await t.throwsAsync(() => split(recoveryPurse, srcPayment, precious(100n)), {
message: '-22 is negative',
});
await t.throwsAsync(
async () => split(recoveryPurse, srcPayment, precious(100n)),
{
message: '-22 is negative',
},
);

const live = await issuer.isLive(srcPayment);
t.assert(!live); // demonstrates non-failure atomicity
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/misc-tools/replay-transcript.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ async function replay(transcriptFile) {

const updateWorkersSynced = () => {
const stepsCompleted = Promise.all(
workers.map(({ stepCompleted }) => stepCompleted),
workers.map(async ({ stepCompleted }) => stepCompleted),
);
const newWorkersSynced = stepsCompleted.then(() => {
if (workersSynced === newWorkersSynced) {
Expand Down
6 changes: 3 additions & 3 deletions packages/SwingSet/src/controller/initializeSwingset.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const allValues = async obj => {
return fromEntries(zip(keys(obj), vs));
};

const bundleRelative = rel =>
const bundleRelative = async rel =>
bundleSource(new URL(rel, import.meta.url).pathname);

/**
Expand Down Expand Up @@ -434,7 +434,7 @@ export async function initializeSwingset(
? provideBundleCache(
config.bundleCachePath,
{ dev: config.includeDevDependencies, format: config.bundleFormat },
s => import(s),
async s => import(s),
)
: null);

Expand Down Expand Up @@ -543,7 +543,7 @@ export async function initializeSwingset(
async function processGroup(groupName, nameToBundle) {
const group = config[groupName] || {};
const names = Object.keys(group).sort();
const processP = names.map(name =>
const processP = names.map(async name =>
processDesc(group[name], nameToBundle).catch(err => {
throw Error(`config.${groupName}.${name}: ${err.message}`);
}),
Expand Down
4 changes: 2 additions & 2 deletions packages/SwingSet/src/controller/startXSnap.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export function makeStartXSnap(options) {
serial += 1;
return workerTrace;
};
doXSnap = opts => {
doXSnap = async opts => {
const workerTraceDir = makeNextTraceDir();
console.log('SwingSet xsnap worker tracing:', { workerTraceDir });
fs.mkdirSync(workerTraceDir, { recursive: true });
Expand Down Expand Up @@ -174,7 +174,7 @@ export function makeStartXSnap(options) {
if (overrideBundles) {
bundles = overrideBundles; // ignore the usual bundles
} else {
const bundlePs = bundleIDs.map(id => bundleHandler.getBundle(id));
const bundlePs = bundleIDs.map(async id => bundleHandler.getBundle(id));
bundles = await Promise.all(bundlePs);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/kernel/vat-warehouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ export function makeVatWarehouse({

// mostly used by tests, only needed with thread/process-based workers
async function shutdown() {
const work = Array.from(ephemeral.vats.values(), ({ manager }) =>
const work = Array.from(ephemeral.vats.values(), async ({ manager }) =>
manager.shutdown(),
);
return Promise.all(work).then(() => {});
Expand Down
4 changes: 2 additions & 2 deletions packages/SwingSet/src/lib/recordVatOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const makeVatOptionRecorder = (kernelKeeper, bundleHandler) => {
* @param {import('../types-external.js').StaticVatOptions} staticOptions
* @returns {Promise<void>}
*/
const recordStatic = (vatID, source, staticOptions) => {
const recordStatic = async (vatID, source, staticOptions) => {
const options = { ...staticOptions, meterID: undefined };
return record(vatID, source, options);
};
Expand All @@ -81,7 +81,7 @@ export const makeVatOptionRecorder = (kernelKeeper, bundleHandler) => {
* @param {import('../types-internal.js').InternalDynamicVatOptions} dynamicOptions
* @returns {Promise<void>}
*/
const recordDynamic = (vatID, source, dynamicOptions) => {
const recordDynamic = async (vatID, source, dynamicOptions) => {
const options = { ...dynamicOptions, enableDisavow: false };
return record(vatID, source, options);
};
Expand Down
6 changes: 3 additions & 3 deletions packages/SwingSet/src/vats/timer/vat-timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ export const buildRootObject = (vatPowers, _vatParameters, baggage) => {
* @param {CancelToken} cancelToken
* @returns {Promise<Timestamp>}
*/
const wakeAtInternal = (when, now, cancelToken) => {
const wakeAtInternal = async (when, now, cancelToken) => {
if (when <= now) {
return Promise.resolve(toTimestamp(now));
}
Expand Down Expand Up @@ -612,7 +612,7 @@ export const buildRootObject = (vatPowers, _vatParameters, baggage) => {
* @param {CancelToken} [cancelToken]
* @returns { Promise<Timestamp> }
*/
const wakeAt = (whenTS, cancelToken = undefined) => {
const wakeAt = async (whenTS, cancelToken = undefined) => {
const when = fromTimestamp(whenTS);
const now = getNow();
return wakeAtInternal(when, now, cancelToken);
Expand All @@ -626,7 +626,7 @@ export const buildRootObject = (vatPowers, _vatParameters, baggage) => {
* @param {CancelToken} [cancelToken]
* @returns { Promise<Timestamp> }
*/
const addDelay = (delayRT, cancelToken = undefined) => {
const addDelay = async (delayRT, cancelToken = undefined) => {
const delay = fromRelativeTime(delayRT);
assert(delay >= 0n, 'delay must not be negative');
const now = getNow();
Expand Down
4 changes: 2 additions & 2 deletions packages/SwingSet/test/bundling/bundles-controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ test('install invalid bundle fails', async t => {
const wrong =
'b1-00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';
await t.throwsAsync(
() => controller.validateAndInstallBundle(bundle, wrong),
async () => controller.validateAndInstallBundle(bundle, wrong),
{
message:
/alleged bundleID "b1-[0-9a-f]{128}" does not match actual "b1-[0-9a-f]{128}"/,
Expand All @@ -78,7 +78,7 @@ test('install corrupt bundle fails', async t => {
endoZipBase64Sha512: wrong,
});
await t.throwsAsync(
() => controller.validateAndInstallBundle(corruptBundle),
async () => controller.validateAndInstallBundle(corruptBundle),
{
message: /expected [0-9a-f]{128}, got [0-9a-f]{128}/,
},
Expand Down
4 changes: 2 additions & 2 deletions packages/SwingSet/test/bundling/bundles-kernel.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ test('install bundle', async t => {

const badVersion =
'b2-00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';
await t.throwsAsync(() => kernel.installBundle(badVersion, bundle), {
await t.throwsAsync(async () => kernel.installBundle(badVersion, bundle), {
message: /unsupported BundleID/,
});

const tooShort = 'b1-000';
await t.throwsAsync(() => kernel.installBundle(tooShort, bundle), {
await t.throwsAsync(async () => kernel.installBundle(tooShort, bundle), {
message: /does not match bundle/,
});

Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/test/device-plugin/device.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async function setupVatController(t) {
inputQueue.push(thunk);
};

const importPlugin = mod => {
const importPlugin = async mod => {
t.is(mod, 'pingpong');
return import('./pingpong.js');
};
Expand Down
Loading

0 comments on commit 322023f

Please sign in to comment.