Skip to content

Commit

Permalink
chore: add eslint rule to prevent unused expressions (#6445)
Browse files Browse the repository at this point in the history
* chore: add eslint rule to prevent unused expressions

* Fix unit tests
  • Loading branch information
nflaig committed Feb 22, 2024
1 parent c3523e1 commit 2f71c32
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 16 deletions.
8 changes: 8 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ module.exports = {
"@typescript-eslint/no-unsafe-call": "error",
"@typescript-eslint/no-unsafe-member-access": "error",
"@typescript-eslint/no-unsafe-return": "error",
"@typescript-eslint/no-unused-expressions": "error",
"@typescript-eslint/no-unused-vars": ["error", {varsIgnorePattern: "^_", argsIgnorePattern: "^_"}],
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/restrict-template-expressions": [
Expand Down Expand Up @@ -209,6 +210,13 @@ module.exports = {
"import/no-named-as-default-member": "off",
},
},
{
files: ["**/perf/**/*.ts"],
rules: {
// A lot of benchmarks just need to execute expressions without using the result
"@typescript-eslint/no-unused-expressions": "off",
},
},
{
files: ["**/test/**/*.test.ts"],
plugins: ["vitest"],
Expand Down
1 change: 0 additions & 1 deletion packages/beacon-node/src/eth1/utils/eth1Vote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ export function pickEth1Vote(state: BeaconStateAllForks, votesToConsider: phase0
else {
const latestMostVotedRoot =
eth1DataVotesOrder[Math.max(...eth1DataRootsMaxVotes.map((root) => eth1DataVotesOrder.indexOf(root)))];
eth1DataHashToEth1Data;
return eth1DataHashToEth1Data.get(latestMostVotedRoot) ?? state.eth1Data;
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/src/network/peers/discover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,6 @@ function formatLibp2pDialError(e: Error): void {
e.message.includes("stream ended before 1 bytes became available") ||
e.message.includes("The operation was aborted")
) {
e.stack === undefined;
e.stack = undefined;
}
}
2 changes: 1 addition & 1 deletion packages/beacon-node/test/unit/monitoring/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ describe("monitoring / service", () => {
await waitForInterval();

afterAll(() => {
service.close;
service.close();
});

return service;
Expand Down
10 changes: 5 additions & 5 deletions packages/cli/test/utils/simulation/TableReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,19 @@ export class TableReporter extends SimulationReporter<typeof defaultAssertions>

for (const node of nodes) {
const finalized = stores["finalized"][node.beacon.id][slot];
!isNullish(finalized) && finalizedSlots.push(finalized);
if (!isNullish(finalized)) finalizedSlots.push(finalized);

const inclusionDelay = stores["inclusionDelay"][node.beacon.id][slot];
!isNullish(inclusionDelay) && inclusionDelays.push(inclusionDelay);
if (!isNullish(inclusionDelay)) inclusionDelays.push(inclusionDelay);

const attestationsCount = stores["attestationsCount"][node.beacon.id][slot];
!isNullish(attestationsCount) && attestationCounts.push(attestationsCount);
if (!isNullish(attestationsCount)) attestationCounts.push(attestationsCount);

const head = stores["head"][node.beacon.id][slot];
!isNullish(head) && heads.push(head);
if (!isNullish(head)) heads.push(head);

const connectedPeerCount = stores["connectedPeerCount"][node.beacon.id][slot];
!isNullish(connectedPeerCount) && peersCount.push(connectedPeerCount);
if (!isNullish(connectedPeerCount)) peersCount.push(connectedPeerCount);
}

const head0 = heads.length > 0 ? heads[0] : null;
Expand Down
6 changes: 2 additions & 4 deletions packages/params/test/e2e/overridePresetError.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
// This script is should be run in an e2e !!
// It demostrates how NOT to change the Lodestar preset
// It demonstrates how NOT to change the Lodestar preset

// 1. Import from not only @lodestar/params/setPreset will trigger an error
import {SLOTS_PER_EPOCH} from "../../lib/index.js";
import "../../lib/index.js";
import {setActivePreset, PresetName} from "../../lib/setPreset.js";
// This line should throw
// eslint-disable-next-line @typescript-eslint/naming-convention
setActivePreset(PresetName.minimal, {SLOTS_PER_EPOCH: 2});

SLOTS_PER_EPOCH;
6 changes: 2 additions & 4 deletions packages/params/test/e2e/setPresetError.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// This script is should be run in an e2e !!
// It demostrates how NOT to change the Lodestar preset
// It demonstrates how NOT to change the Lodestar preset

// 1. Import from not only @lodestar/params/setPreset will trigger an error
import {SLOTS_PER_EPOCH} from "../../lib/index.js";
import "../../lib/index.js";
import {setActivePreset, PresetName} from "../../lib/setPreset.js";
// This line should throw
setActivePreset(PresetName.minimal);

SLOTS_PER_EPOCH;

0 comments on commit 2f71c32

Please sign in to comment.