Skip to content

Commit

Permalink
chore: Resolve Array.forEach lint warnings
Browse files Browse the repository at this point in the history
Fixes #9632
  • Loading branch information
siarhei-agoric committed Jul 11, 2024
1 parent 12ce494 commit c7687e8
Show file tree
Hide file tree
Showing 24 changed files with 92 additions and 64 deletions.
20 changes: 10 additions & 10 deletions packages/cosmic-swingset/src/kernel-stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,13 +316,13 @@ export function exportKernelStats({
}
kernelStatsLast = now;
kernelStatsCache = controller.getStats();
Object.keys(kernelStatsCache).forEach(key => {
for (const key of Object.keys(kernelStatsCache)) {
warnUnexpectedKernelStat(key);
});
}
return kernelStatsCache;
};

KERNEL_STATS_SUM_METRICS.forEach(({ key, name, sub, ...options }) => {
for (const { key, name, sub, ...options } of KERNEL_STATS_SUM_METRICS) {
expectedKernelStats.add(key);
let counter = kernelStatsCounters.get(name);
if (!counter) {
Expand All @@ -337,9 +337,9 @@ export function exportKernelStats({
observableResult.observe(getKernelStats()[key], reportedAttributes);
});
kernelStatsMetrics.add(key);
});
}

KERNEL_STATS_UPDOWN_METRICS.forEach(({ key, name, sub, ...options }) => {
for (const { key, name, sub, ...options } of KERNEL_STATS_UPDOWN_METRICS) {
expectedKernelStats.add(key);
expectedKernelStats.add(`${key}Up`);
expectedKernelStats.add(`${key}Down`);
Expand All @@ -357,7 +357,7 @@ export function exportKernelStats({
observableResult.observe(getKernelStats()[key], reportedAttributes);
});
kernelStatsMetrics.add(key);
});
}

if (inboundQueueMetrics) {
// These are not kernelStatsMetrics, they're outside the kernel.
Expand Down Expand Up @@ -425,13 +425,13 @@ export function exportKernelStats({

function checkKernelStats(stats) {
const notYetFoundKernelStats = new Set(kernelStatsMetrics.keys());
Object.keys(stats).forEach(key => {
for (const key of Object.keys(stats)) {
notYetFoundKernelStats.delete(key);
warnUnexpectedKernelStat(key);
});
notYetFoundKernelStats.forEach(key => {
}
for (const key of notYetFoundKernelStats) {
log.warn(`Expected SwingSet kernel statistic`, key, `not found`);
});
}
}

// We check everything on initialization. Other checks happen when scraping.
Expand Down
6 changes: 5 additions & 1 deletion packages/cosmic-swingset/test/export-storage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ const makeBatchChainStorage = published => {
return entries(path).map(([key]) => key);
}
case 'setWithoutNotify':
args.forEach(([path]) => deleted.push(path));
{
for (const [path] of args) {
deleted.push(path);
}
}
return;
default:
throw Error(`not impl: ${method}`);
Expand Down
4 changes: 3 additions & 1 deletion packages/internal/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,9 @@ export const synchronizedTee = (sourceStream, readerCount) => {
doneResult = { done: true, value: undefined };
},
);
resolvers.forEach(resolve => resolve(result));
for (const resolve of resolvers) {
resolve(result);
}
return pullNext();
};

Expand Down
2 changes: 2 additions & 0 deletions packages/notifier/test/publish-kit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ const assertCells = (t, label, cells, publishCount, expected, options = {}) => {
}
} else {
const { tail: _tail, ...props } = firstCell;
// We need an element and an index here, which for..of does not give us in one go
// eslint-disable-next-line github/array-foreach
cells.slice(1).forEach((cell, i) => {
t.like(cell, props, `${label} cell ${i + 1} must match cell 0`);
});
Expand Down
1 change: 1 addition & 0 deletions packages/solo/src/chain-cosmos-sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ export async function connectToChain(

// Find only the latest value in the events.
let storageValue;
// eslint-disable-next-line github/array-foreach
paths.forEach((key, i) => {
if (key === storagePath) {
storageValue = values[i];
Expand Down
4 changes: 2 additions & 2 deletions packages/solo/src/outbound.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function deliver(mbs) {
}
const t = knownTargets.get(target);
const newMessages = [];
data[target].outbox.forEach(m => {
for (const m of data[target].outbox) {
const [msgnum, body] = m;
if (msgnum > t.highestSent) {
log.debug(
Expand All @@ -44,7 +44,7 @@ export function deliver(mbs) {
);
newMessages.push(m);
}
});
}
newMessages.sort((a, b) => a[0] - b[0]);
// console.debug(` ${newMessages.length} new messages`);
const acknum = data[target].inboundAck;
Expand Down
10 changes: 6 additions & 4 deletions packages/solo/src/set-fake-chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,18 @@ export default function setFakeChain(basedir, GCI, fakeDelay) {
}
};

JSON.parse(fs.readFileSync(fn)).forEach(add);
for (const conn of JSON.parse(fs.readFileSync(fn))) {
add(conn);
}
const newconn = {
type: 'fake-chain',
GCI,
fakeDelay,
};
add(newconn);
const connections = [];
Object.entries(connsByType).forEach(([_type, conns]) =>
connections.push(...conns),
);
for (const [_type, conns] of Object.entries(connsByType)) {
connections.push(...conns);
}
fs.writeFileSync(fn, `${JSON.stringify(connections, undefined, 2)}\n`);
}
12 changes: 7 additions & 5 deletions packages/solo/src/set-gci-ingress.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ export default function setGCIIngress(basedir, GCI, rpcAddresses, chainID) {
}
};

JSON.parse(fs.readFileSync(fn)).forEach(add);
for (const conn of JSON.parse(fs.readFileSync(fn))) {
add(conn);
}
const newconn = {
type: 'chain-cosmos-sdk',
chainID,
Expand All @@ -68,9 +70,9 @@ export default function setGCIIngress(basedir, GCI, rpcAddresses, chainID) {
};
add(newconn);
const connections = [];
// eslint-disable-next-line no-unused-vars
Object.entries(connsByType).forEach(([type, conns]) =>
connections.push(...conns),
);

for (const conns of Object.values(connsByType)) {
connections.push(...conns);
}
fs.writeFileSync(fn, `${JSON.stringify(connections, undefined, 2)}\n`);
}
4 changes: 2 additions & 2 deletions packages/solo/src/web.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,14 +306,14 @@ export async function makeHTTPListener(
server.listen(port, host, () => log.info('Listening on', `${host}:${port}`));

const pingInterval = setInterval(function ping() {
wss.clients.forEach(ws => {
for (const ws of wss.clients) {
if (!ws.isAlive) {
ws.terminate();
return;
}
ws.isAlive = false;
ws.ping(() => {});
});
}
}, 30000);

wss.on('close', () => clearInterval(pingInterval));
Expand Down
6 changes: 3 additions & 3 deletions packages/vats/test/demoAMM.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ test('poolRates: spot check WETH', t => {
interestRate: '0.025',
mintFee: '0.0001',
};
Object.entries(expected).forEach(([prop, val]) =>
t.is(showRatio(rates[prop]), val),
);
for (const [prop, val] of Object.entries(expected)) {
t.is(showRatio(rates[prop]), val);
}
});
4 changes: 2 additions & 2 deletions packages/wallet/api/src/pubsub.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ export default function makePubsub(E) {
},
publish(m) {
lastPublished = m;
subscribers.forEach(s => {
for (const s of subscribers) {
E(s).notify(m);
});
}
},
});
}
4 changes: 2 additions & 2 deletions packages/wallet/api/src/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export function buildRootObject(vatPowers) {

const pushOfferSubscriptions = (channelHandle, offers) => {
const subs = offerSubscriptions.get(channelHandle);
(subs || []).forEach(({ origin, status }) => {
for (const { origin, status } of subs || []) {
// Filter by optional status and origin.
const result = harden(
offers.filter(
Expand All @@ -75,7 +75,7 @@ export function buildRootObject(vatPowers) {
},
[channelHandle],
);
});
}
};

const subscribeToOffers = (channelHandle, { origin, status = null }) => {
Expand Down
4 changes: 3 additions & 1 deletion packages/xsnap/src/avaXS.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,9 @@ export async function main(

stats.total += results.total;
stats.pass += results.pass;
results.fail.forEach(info => stats.fail.push(info));
for (const info of results.fail) {
stats.fail.push(info);
}
}

console.log(stats.pass, 'tests passed');
Expand Down
4 changes: 3 additions & 1 deletion packages/zoe/src/cleanProposal.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ export const cleanKeywords = uncleanKeywordRecord => {

// Assert all names are ascii identifiers starting with
// an upper case letter.
keywords.forEach(assertKeywordName);
for (const keyword of keywords) {
assertKeywordName(keyword);
}

return /** @type {string[]} */ (keywords);
};
Expand Down
8 changes: 4 additions & 4 deletions packages/zoe/src/contractFacet/rightsConservation.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ import '../internal-types.js';
const sumByBrand = amounts => {
/** @type {MapStore<Brand, Amount>} */
const sumsByBrand = makeScalarMapStore('brand');
amounts.forEach(amount => {
for (const amount of amounts) {
const { brand } = amount;
if (!sumsByBrand.has(brand)) {
sumsByBrand.init(brand, amount);
} else {
const sumSoFar = sumsByBrand.get(brand);
sumsByBrand.set(brand, AmountMath.add(sumSoFar, amount));
}
});
}
return sumsByBrand;
};

Expand Down Expand Up @@ -76,11 +76,11 @@ const assertEqualPerBrand = (leftSumsByBrand, rightSumsByBrand) => {
...rightSumsByBrand.keys(),
]);

allBrands.forEach(brand => {
for (const brand of allBrands) {
const { leftSum, rightSum } = getSums(brand);
AmountMath.isEqual(leftSum, rightSum) ||
Fail`rights were not conserved for brand ${brand} ${leftSum.value} != ${rightSum.value}`;
});
}
};

/**
Expand Down
13 changes: 9 additions & 4 deletions packages/zoe/src/contractFacet/zcfSeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,12 @@ export const createSeatManager = (
}
},
reallocate(/** @type {ZCFSeat[]} */ ...seats) {
seats.forEach(assertActive);
seats.forEach(assertStagedAllocation);
for (const seat of seats) {
assertActive(seat);
}
for (const seat of seats) {
assertStagedAllocation(seat);
}

// Ensure that rights are conserved overall.
const flattenAllocations = allocations =>
Expand Down Expand Up @@ -458,8 +462,9 @@ export const createSeatManager = (
// for each of the seats) and inform Zoe of the
// newAllocation.

seats.forEach(commitStagedAllocation);

for (const seat of seats) {
commitStagedAllocation(seat);
}
const seatHandleAllocations = seats.map(seat => {
const seatHandle = zcfSeatToSeatHandle.get(seat);
return { seatHandle, allocation: seat.getCurrentAllocation() };
Expand Down
9 changes: 4 additions & 5 deletions packages/zoe/src/contractSupport/zoeHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,10 @@ export const assertProposalShape = (seat, expected) => {
!Array.isArray(expected) || Fail`Expected must be an non-array object`;
const assertValuesNull = e => {
if (e !== undefined) {
Object.values(e).forEach(
value =>
value === null ||
Fail`The value of the expected record must be null but was ${value}`,
);
for (const value of Object.values(e)) {
value === null ||
Fail`The value of the expected record must be null but was ${value}`;
}
}
};

Expand Down
8 changes: 4 additions & 4 deletions packages/zoe/src/contracts/auction/secondPriceLogic.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const calcWinnerAndClose = (zcf, sellSeat, bidSeats) => {
let highestBidSeat = bidSeats[0];
let activeBidsCount = 0n;

bidSeats.forEach(bidSeat => {
for (const bidSeat of bidSeats) {
if (!bidSeat.hasExited()) {
activeBidsCount += 1n;
const bid = bidSeat.getAmountAllocated('Bid', bidBrand);
Expand All @@ -35,7 +35,7 @@ export const calcWinnerAndClose = (zcf, sellSeat, bidSeats) => {
secondHighestBid = bid;
}
}
});
}

if (activeBidsCount === 0n) {
throw sellSeat.fail(Error(`Could not close auction. No bids were active`));
Expand All @@ -59,10 +59,10 @@ export const calcWinnerAndClose = (zcf, sellSeat, bidSeats) => {
);

sellSeat.exit();
bidSeats.forEach(bidSeat => {
for (const bidSeat of bidSeats) {
if (!bidSeat.hasExited()) {
bidSeat.exit();
}
});
}
zcf.shutdown('Auction closed.');
};
4 changes: 3 additions & 1 deletion packages/zoe/src/contracts/autoswap.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ const start = async zcf => {
// In order to get all the brands, we must call zcf.getTerms() after
// we create the liquidityIssuer
const { brands } = zcf.getTerms();
Object.values(brands).forEach(brand => assertNatAssetKind(zcf, brand));
for (const brand of Object.values(brands)) {
assertNatAssetKind(zcf, brand);
}
/** @type {Map<Brand,Keyword>} */
const brandToKeyword = new Map(
Object.entries(brands).map(([keyword, brand]) => [brand, keyword]),
Expand Down
4 changes: 2 additions & 2 deletions packages/zoe/src/contracts/priceAggregator.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,11 @@ const start = async (zcf, privateArgs) => {
async wake(timestamp) {
// Run all the queriers.
const querierPs = [];
oracleRecords.forEach(({ querier }) => {
for (const { querier } of oracleRecords) {
if (querier) {
querierPs.push(querier(timestamp));
}
});
}
if (!querierPs.length) {
// Only have push results, so publish them.
// eslint-disable-next-line no-use-before-define
Expand Down
4 changes: 3 additions & 1 deletion packages/zoe/src/issuerStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@ export const provideIssuerStorage = zcfBaggage => {
if (!zcfBaggage.has(STORAGE_INSTANTIATED_KEY)) {
zcfBaggage.init(STORAGE_INSTANTIATED_KEY, true);
instantiated = true;
issuerRecords.forEach(storeIssuerRecord);
for (const record of issuerRecords) {
storeIssuerRecord(record);
}
}
};

Expand Down
Loading

0 comments on commit c7687e8

Please sign in to comment.