Skip to content

Commit

Permalink
allow use before define (#9361)
Browse files Browse the repository at this point in the history
no ticket

## Description

The [no-use-before-define rule](https://eslint.org/docs/latest/rules/no-use-before-define) was motivated by when variables could hoist up in surprising ways. We always use `let` and `const` which have the Temporal Dead Zone that will throw an error if used before declaration.

So we don't need this rule anymore and it's mostly noise.

This also removes `no-constant-condition`. 

Whenever someone wants the rule they can still opt in,
```
/* eslint no-use-before-define: "error" */
```

### Security Considerations

n/a, lint

### Scaling Considerations

n/a, lint

### Documentation Considerations

reduces need for docs

### Testing Considerations

CI

### Upgrade Considerations

n/a, lint
  • Loading branch information
mergify[bot] authored Nov 20, 2024
2 parents 3ba7ca7 + babf0ea commit 59b637f
Show file tree
Hide file tree
Showing 72 changed files with 26 additions and 151 deletions.
21 changes: 15 additions & 6 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ module.exports = {
'prettier/prettier': 'warn',

// Not a risk with our coding style
'no-constant-condition': 'off',
'no-use-before-define': 'off',
},
settings: {
jsdoc: {
Expand Down Expand Up @@ -177,8 +177,8 @@ module.exports = {
{
files: [
'packages/**/demo/**/*.js',
'packages/*/test/**/*.js',
'packages/*/test/**/*.test.js',
'packages/*/test/**/*.*s',
'packages/*/test/**/*.test.*s',
'packages/wallet/api/test/**/*.js',
],
rules: {
Expand All @@ -188,12 +188,23 @@ module.exports = {
// NOTE: This rule is enabled for the repository in general. We turn it
// off for test code for now.
'@jessie.js/safe-await-separator': 'off',

// Like `'ava/no-only-test`, but works with @endo/ses-ava
'no-restricted-properties': [
'error',
{
object: 'test',
property: 'only',
message:
'Do not commit .only tests - they prevent other tests from running',
},
],
},
},
{
// These tests use EV() instead of E(), which are easy to confuse.
// Help by erroring when E() packages are imported.
files: ['packages/boot/test/**/*.test.*'],
files: ['packages/boot/test/**/*.test.*s'],
rules: {
'no-restricted-imports': [
'error',
Expand Down Expand Up @@ -229,8 +240,6 @@ module.exports = {
{
files: ['*.d.ts'],
rules: {
// Irrelevant in a typedef
'no-use-before-define': 'off',
// Linter confuses the type declaration with value declaration
'no-redeclare': 'off',
},
Expand Down
1 change: 0 additions & 1 deletion packages/ERTP/src/paymentLedger.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

/// <reference types="@agoric/store/exported.js" />

/* eslint-disable no-use-before-define */
import { X, q, Fail, annotateError } from '@endo/errors';
import { isPromise } from '@endo/promise-kit';
import { mustMatch, M, keyEQ } from '@agoric/store';
Expand Down
1 change: 0 additions & 1 deletion packages/ERTP/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-use-before-define */
import type { LatestTopic } from '@agoric/notifier';
import type { ERef } from '@endo/far';
import type { RemotableObject } from '@endo/pass-style';
Expand Down
2 changes: 0 additions & 2 deletions packages/SwingSet/src/controller/initializeKernel.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable no-use-before-define */

import { assert, Fail } from '@endo/errors';
import { makeMarshal } from '@endo/marshal';
import { Far } from '@endo/far';
Expand Down
1 change: 0 additions & 1 deletion packages/SwingSet/src/devices/lib/deviceTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export function buildSerializationTools(syscall, deviceName) {
send(method, args) {
assert.typeof(method, 'string');
assert(Array.isArray(args), args);
// eslint-disable-next-line no-use-before-define
const capdata = serialize([method, args]);
syscall.sendOnly(slot, capdata);
},
Expand Down
1 change: 0 additions & 1 deletion packages/SwingSet/src/kernel/kernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -1128,7 +1128,6 @@ export default function buildKernel(
} else if (message.type === 'changeVatOptions') {
// prettier-ignore
return `changeVatOptions ${message.vatID} options: ${JSON.stringify(message.options)}`;
// eslint-disable-next-line no-use-before-define
} else if (gcMessages.includes(message.type)) {
// prettier-ignore
return `${message.type} ${message.vatID} ${message.krefs.map(e=>`@${e}`).join(' ')}`;
Expand Down
1 change: 0 additions & 1 deletion packages/SwingSet/src/kernel/state/kernelKeeper.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-use-before-define */
import { Nat, isNat } from '@endo/nat';
import { assert, Fail } from '@endo/errors';
import {
Expand Down
2 changes: 0 additions & 2 deletions packages/SwingSet/src/kernel/vat-warehouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,6 @@ export function makeVatWarehouse({
// entriesReplayed, // retval of replayTranscript() above
// );
ephemeral.vats.set(vatID, result);
// eslint-disable-next-line no-use-before-define
await applyAvailabilityPolicy(vatID);
return result;
}
Expand Down Expand Up @@ -596,7 +595,6 @@ export function makeVatWarehouse({
//
/** @type { KernelDeliveryObject } */
const kd = harden(['bringOutYourDead']);
// eslint-disable-next-line no-use-before-define
const vd = kernelDeliveryToVatDelivery(vatID, kd);
const vs = kernelSlog.provideVatSlogger(vatID).vatSlog;
await deliverToVat(vatID, kd, vd, vs);
Expand Down
2 changes: 0 additions & 2 deletions packages/SwingSet/src/vats/comms/delivery.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable no-use-before-define */

import { assert, Fail } from '@endo/errors';
import { kser } from '@agoric/kmarshal';
import { parseLocalSlot, insistLocalType } from './parseLocalSlots.js';
Expand Down
4 changes: 0 additions & 4 deletions packages/SwingSet/src/vats/comms/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ export function makeState(syscall) {
store.set('r.nextID', '1');
store.set('initialized', 'true');
if (controller) {
// eslint-disable-next-line no-use-before-define
addMetaObject(controller);
cdebug(`comms controller is ${controller}`);
}
Expand Down Expand Up @@ -393,7 +392,6 @@ export function makeState(syscall) {
// the object is unreachable

const { owner, isReachable, isRecognizable } =
// eslint-disable-next-line no-use-before-define
getOwnerAndStatus(lref);
if (isReachable) {
// but the exporter doesn't realize it yet, so schedule a
Expand Down Expand Up @@ -558,7 +556,6 @@ export function makeState(syscall) {
isReachable = isReachableByKernel(lref);
isRecognizable = !!mapToKernel(lref);
} else {
// eslint-disable-next-line no-use-before-define
const remote = getRemote(owner);
isReachable = remote.isReachable(lref);
isRecognizable = !!remote.mapToRemote(lref);
Expand Down Expand Up @@ -794,7 +791,6 @@ export function makeState(syscall) {
insistPromiseIsUnresolved,
markPromiseAsResolved,

// eslint-disable-next-line no-use-before-define
getRemote,
addRemote,
getRemoteIDForName,
Expand Down
2 changes: 0 additions & 2 deletions packages/SwingSet/src/vats/timer/vat-timer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable no-use-before-define */

import { assert } from '@endo/errors';
import { Far, E, passStyleOf } from '@endo/far';
import { makePromiseKit } from '@endo/promise-kit';
Expand Down
4 changes: 0 additions & 4 deletions packages/SwingSet/src/vats/vat-admin/vat-vat-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ export function buildRootObject(vatPowers, _vatParameters, baggage) {
// getNotifier: ({ state }) => state.notifier, // XXX RESTORE
getNotifier: ({ _self }) => Fail`not implemented, see #7234`, // XXX TEMP
},
// eslint-disable-next-line no-use-before-define
{ finish: finishMeter },
);

Expand All @@ -120,18 +119,15 @@ export function buildRootObject(vatPowers, _vatParameters, baggage) {
// getNotifier: ({ state }) => state.notifier, // will never fire // XXX RESTORE
getNotifier: ({ _self }) => Fail`not implemented, see #7234`, // XXX TEMP
},
// eslint-disable-next-line no-use-before-define
{ finish: finishMeter },
);

function finishMeter({ state, self }) {
// eslint-disable-next-line no-use-before-define
meterByID.init(
state.meterID,
// harden({ meter: self, updater: state.updater }), // XXX RESTORE
harden({ meter: self }), // XXX TEMP
);
// eslint-disable-next-line no-use-before-define
meterIDByMeter.set(self, state.meterID);
}

Expand Down
8 changes: 4 additions & 4 deletions packages/SwingSet/test/snapshots/xsnap-store.test.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ Generated by [AVA](https://avajs.dev).
archiveWriteSeconds: undefined,
compressSeconds: 0,
dbSaveSeconds: 0,
hash: '7623fab3851503c9904ed7b76e832dee6cfcb414b409677376cd47a1a5589a18',
uncompressedSize: 854339,
hash: '8da7b45fc3fbb377376a4569e8d8f8f971b2d1cd82e5b0d2e7210532c350568e',
uncompressedSize: 854315,
}

> after use of harden() - sensitive to SES-shim, XS, and supervisor
Expand All @@ -32,6 +32,6 @@ Generated by [AVA](https://avajs.dev).
archiveWriteSeconds: undefined,
compressSeconds: 0,
dbSaveSeconds: 0,
hash: 'f5619dc112ea57402d8dea36bd8886f1bd22e5534c0b101693ef20a154152860',
uncompressedSize: 854499,
hash: 'f4adb516a299d85752f93ee1191844efc77ae73313ab93971b2d1eb10a04f5f9',
uncompressedSize: 854475,
}
Binary file modified packages/SwingSet/test/snapshots/xsnap-store.test.js.snap
Binary file not shown.
2 changes: 0 additions & 2 deletions packages/SwingSet/tools/baggage-check.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { makeMarshal } from '@endo/marshal';
import { Far } from '@endo/far';

/* eslint-disable no-use-before-define */

function fakeSTV(slot, iface = 'Remotable') {
return Far(iface, {
getSlot: () => slot,
Expand Down
1 change: 0 additions & 1 deletion packages/SwingSet/tools/bootstrap-dvo-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export function buildRootObject() {
async function runTests(phase) {
testLog = [];
doneP = makePromiseKit();
// eslint-disable-next-line no-use-before-define
await E(testVatRoot).runTests(self, phase);
await doneP.promise;
return testLog;
Expand Down
1 change: 0 additions & 1 deletion packages/agoric-cli/src/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ export default async function installMain(progname, rawArgs, powers, opts) {
// Ensure we update the package.json before exiting.
const updatePackageJson = async () => {
// Don't update on exit anymore.
// eslint-disable-next-line no-use-before-define
process.off('beforeExit', updatePackageJsonOnExit);
log.info(`updating ${pjson}`);
await fs.writeFile(
Expand Down
2 changes: 0 additions & 2 deletions packages/async-flow/src/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ const makeConvert = (convertRemotable, convertPromiseOrVow, convertError) => {
// to keep track of the error labeling.
// See https://github.com/endojs/endo/pull/1795#issuecomment-1756093032
if (label === undefined) {
// eslint-disable-next-line no-use-before-define
return innerConvert(specimen);
}
try {
// eslint-disable-next-line no-use-before-define
return innerConvert(specimen);
} catch (err) {
throwLabeled(err, label);
Expand Down
2 changes: 0 additions & 2 deletions packages/async-flow/src/equate.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ export const makeEquate = bijection => {
// TODO switch to Richard Gibson's suggestion for a better way
// to keep track of the error labeling.
if (label === undefined) {
// eslint-disable-next-line no-use-before-define
innerEquate(g, h);
}
try {
// eslint-disable-next-line no-use-before-define
innerEquate(g, h);
} catch (err) {
throwLabeled(err, label);
Expand Down
1 change: 0 additions & 1 deletion packages/async-flow/src/replay-membrane.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-use-before-define */
import { isVow } from '@agoric/vow/src/vow-utils.js';
import { heapVowE } from '@agoric/vow/vat.js';
import { throwLabeled } from '@endo/common/throw-labeled.js';
Expand Down
1 change: 0 additions & 1 deletion packages/async-flow/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-use-before-define */
import type { Passable } from '@endo/pass-style';
import type { Vow, VowTools } from '@agoric/vow';
import type { LogStore } from './log-store.js';
Expand Down
1 change: 0 additions & 1 deletion packages/boot/tools/supports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,6 @@ export const makeSwingsetTestKit = async (
...args
) => {
console.log('inbound', ...args);
// eslint-disable-next-line no-use-before-define
bridgeInbound!(...args);
};

Expand Down
6 changes: 1 addition & 5 deletions packages/casting/src/leader.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export const makeRoundRobinLeader = (endpoints, leaderOptions = {}) => {
}
throw err;
},
// eslint-disable-next-line no-use-before-define
watchCasting: _castingSpecP => pollingChangeFollower,
/**
* @template T
Expand All @@ -55,10 +54,7 @@ export const makeRoundRobinLeader = (endpoints, leaderOptions = {}) => {
});
}

retrying
.then(() => jitter && jitter(where))
// eslint-disable-next-line no-use-before-define
.then(applyOne, reject);
retrying.then(() => jitter && jitter(where)).then(applyOne, reject);
thisAttempt += 1;
};

Expand Down
1 change: 0 additions & 1 deletion packages/cosmic-swingset/src/chain-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ export default async function main(progname, args, { env, homedir, agcc }) {

// Actually run the main ag-chain-cosmos program. Before we start the daemon,
// there will be a call to nodePort/AG_COSMOS_INIT, otherwise exit.
// eslint-disable-next-line no-use-before-define
const nodePort = registerPortHandler(toSwingSet);

// Need to keep the process alive until Go exits.
Expand Down
1 change: 0 additions & 1 deletion packages/cosmic-swingset/src/sim-chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ export async function connectToFakeChain(basedir, GCI, delay, inbound) {
await blockingSend({ type: 'COMMIT_BLOCK', blockHeight, blockTime });

clearTimeout(nextBlockTimeout);
// eslint-disable-next-line no-use-before-define
nextBlockTimeout = setTimeout(simulateBlock, maximumDelay);

// TODO: maybe add latency to the inbound messages.
Expand Down
5 changes: 0 additions & 5 deletions packages/fast-usdc/src/fast-usdc.contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ export const contract = async (zcf, privateArgs, zone, tools) => {
testBorrow(amounts) {
console.log('🚧🚧 UNTIL: borrow is integrated (#10388) 🚧🚧', amounts);
const { zcfSeat: tmpAssetManagerSeat } = zcf.makeEmptySeatKit();
// eslint-disable-next-line no-use-before-define
poolKit.borrower.borrow(tmpAssetManagerSeat, amounts);
return tmpAssetManagerSeat.getCurrentAllocation();
},
Expand All @@ -141,7 +140,6 @@ export const contract = async (zcf, privateArgs, zone, tools) => {
),
payments,
);
// eslint-disable-next-line no-use-before-define
poolKit.repayer.repay(tmpAssetManagerSeat, amounts);
return tmpAssetManagerSeat.getCurrentAllocation();
},
Expand All @@ -164,15 +162,12 @@ export const contract = async (zcf, privateArgs, zone, tools) => {
return makeTestInvitation();
},
makeDepositInvitation() {
// eslint-disable-next-line no-use-before-define
return poolKit.public.makeDepositInvitation();
},
makeWithdrawInvitation() {
// eslint-disable-next-line no-use-before-define
return poolKit.public.makeWithdrawInvitation();
},
getPublicTopics() {
// eslint-disable-next-line no-use-before-define
return poolKit.public.getPublicTopics();
},
});
Expand Down
2 changes: 0 additions & 2 deletions packages/governance/src/contractGovernance/paramManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ const makeParamManagerBuilder = (publisherKit, zoe) => {
});

// names are keywords so they will necessarily be TitleCase
// eslint-disable-next-line no-use-before-define
getters[`get${name}`] = () => getTypedParam(type, name);
// CRUCIAL: here we're creating the update functions that can change the
// values of the governed contract's parameters. We'll return the updateFns
Expand Down Expand Up @@ -292,7 +291,6 @@ const makeParamManagerBuilder = (publisherKit, zoe) => {
getVisibleValue,
});

// eslint-disable-next-line no-use-before-define
getters[`get${name}`] = () => getTypedParam(ParamTypes.INVITATION, name);
// CRUCIAL: here we're creating the update functions that can change the
// values of the governed contract's parameters. We'll return updateParams
Expand Down
2 changes: 0 additions & 2 deletions packages/inter-protocol/src/auction/auctioneer.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,6 @@ export const start = async (zcf, privateArgs, baggage) => {
},
});

// eslint-disable-next-line no-use-before-define
const isActive = () => scheduler.getAuctionState() === AuctionState.ACTIVE;

/**
Expand Down Expand Up @@ -653,7 +652,6 @@ export const start = async (zcf, privateArgs, baggage) => {
);
},
getSchedules() {
// eslint-disable-next-line no-use-before-define
return scheduler.getSchedule();
},
getScheduleUpdates() {
Expand Down
1 change: 0 additions & 1 deletion packages/inter-protocol/src/auction/scheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ export const makeScheduler = async (
try {
setTimeMonotonically(time);
auctionDriver.capturePrices();
// eslint-disable-next-line no-use-before-define
return startAuction();
} catch (e) {
console.error(`⚠️ Auction threw ${e}. Caught in SchedulerWaker.`);
Expand Down
4 changes: 2 additions & 2 deletions packages/internal/src/node/fs-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ export const fsStreamReady = stream =>
}

const onReady = () => {
cleanup(); // eslint-disable-line no-use-before-define
cleanup();
resolve();
};

/** @param {Error} err */
const onError = err => {
cleanup(); // eslint-disable-line no-use-before-define
cleanup();
reject(err);
};

Expand Down
1 change: 0 additions & 1 deletion packages/internal/src/node/shutdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export const makeFreshShutdown = (verbose = true) => {
process.off('SIGINT', shutdown);
process.off('SIGTERM', shutdown);
process.off('beforeExit', shutdown);
// eslint-disable-next-line no-use-before-define
process.off('uncaughtException', uncaughtShutdown);
verbose && console.error(`Shutting down cleanly...`);
const shutdowners = [...shutdownThunks.keys()];
Expand Down
Loading

0 comments on commit 59b637f

Please sign in to comment.