Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add rule @typescript-eslint/restrict-template-expressions #5562

Merged
merged 2 commits into from
May 29, 2023

Conversation

dapplion
Copy link
Contributor

Motivation

We have had many instances of attempting to log data in bad formats, this rule prevents such errors

Description

Closes #4650

@dapplion dapplion requested a review from a team as a code owner May 29, 2023 08:02
@github-actions
Copy link
Contributor

github-actions bot commented May 29, 2023

Performance Report

✔️ no performance regression detected

Full benchmark results
Benchmark suite Current: 2c6e8eb Previous: 8fa4b1f Ratio
getPubkeys - index2pubkey - req 1000 vs - 250000 vc 705.92 us/op 496.87 us/op 1.42
getPubkeys - validatorsArr - req 1000 vs - 250000 vc 43.248 us/op 45.271 us/op 0.96
BLS verify - blst-native 1.1671 ms/op 1.2100 ms/op 0.96
BLS verifyMultipleSignatures 3 - blst-native 2.3725 ms/op 2.4895 ms/op 0.95
BLS verifyMultipleSignatures 8 - blst-native 5.0911 ms/op 5.3022 ms/op 0.96
BLS verifyMultipleSignatures 32 - blst-native 18.980 ms/op 19.255 ms/op 0.99
BLS aggregatePubkeys 32 - blst-native 25.530 us/op 25.761 us/op 0.99
BLS aggregatePubkeys 128 - blst-native 99.672 us/op 100.55 us/op 0.99
getAttestationsForBlock 51.257 ms/op 57.481 ms/op 0.89
isKnown best case - 1 super set check 260.00 ns/op 258.00 ns/op 1.01
isKnown normal case - 2 super set checks 249.00 ns/op 244.00 ns/op 1.02
isKnown worse case - 16 super set checks 251.00 ns/op 246.00 ns/op 1.02
CheckpointStateCache - add get delete 4.9060 us/op 5.0150 us/op 0.98
validate gossip signedAggregateAndProof - struct 2.7536 ms/op 2.7898 ms/op 0.99
validate gossip attestation - struct 1.3126 ms/op 1.3342 ms/op 0.98
pickEth1Vote - no votes 1.2221 ms/op 1.3232 ms/op 0.92
pickEth1Vote - max votes 9.9338 ms/op 8.4395 ms/op 1.18
pickEth1Vote - Eth1Data hashTreeRoot value x2048 8.7755 ms/op 8.6190 ms/op 1.02
pickEth1Vote - Eth1Data hashTreeRoot tree x2048 14.224 ms/op 14.625 ms/op 0.97
pickEth1Vote - Eth1Data fastSerialize value x2048 626.87 us/op 672.46 us/op 0.93
pickEth1Vote - Eth1Data fastSerialize tree x2048 7.2459 ms/op 6.7303 ms/op 1.08
bytes32 toHexString 512.00 ns/op 456.00 ns/op 1.12
bytes32 Buffer.toString(hex) 345.00 ns/op 332.00 ns/op 1.04
bytes32 Buffer.toString(hex) from Uint8Array 558.00 ns/op 537.00 ns/op 1.04
bytes32 Buffer.toString(hex) + 0x 355.00 ns/op 351.00 ns/op 1.01
Object access 1 prop 0.17300 ns/op 0.15700 ns/op 1.10
Map access 1 prop 0.16000 ns/op 0.15500 ns/op 1.03
Object get x1000 6.8960 ns/op 6.9580 ns/op 0.99
Map get x1000 0.56300 ns/op 0.53200 ns/op 1.06
Object set x1000 53.191 ns/op 50.862 ns/op 1.05
Map set x1000 43.504 ns/op 43.491 ns/op 1.00
Return object 10000 times 0.23900 ns/op 0.23330 ns/op 1.02
Throw Error 10000 times 4.2609 us/op 4.3973 us/op 0.97
fastMsgIdFn sha256 / 200 bytes 3.4650 us/op 3.3920 us/op 1.02
fastMsgIdFn h32 xxhash / 200 bytes 295.00 ns/op 275.00 ns/op 1.07
fastMsgIdFn h64 xxhash / 200 bytes 407.00 ns/op 376.00 ns/op 1.08
fastMsgIdFn sha256 / 1000 bytes 11.669 us/op 11.148 us/op 1.05
fastMsgIdFn h32 xxhash / 1000 bytes 420.00 ns/op 400.00 ns/op 1.05
fastMsgIdFn h64 xxhash / 1000 bytes 479.00 ns/op 450.00 ns/op 1.06
fastMsgIdFn sha256 / 10000 bytes 103.84 us/op 99.885 us/op 1.04
fastMsgIdFn h32 xxhash / 10000 bytes 1.9310 us/op 1.8200 us/op 1.06
fastMsgIdFn h64 xxhash / 10000 bytes 1.3750 us/op 1.2930 us/op 1.06
enrSubnets - fastDeserialize 64 bits 1.2920 us/op 1.2560 us/op 1.03
enrSubnets - ssz BitVector 64 bits 490.00 ns/op 476.00 ns/op 1.03
enrSubnets - fastDeserialize 4 bits 180.00 ns/op 165.00 ns/op 1.09
enrSubnets - ssz BitVector 4 bits 525.00 ns/op 474.00 ns/op 1.11
prioritizePeers score -10:0 att 32-0.1 sync 2-0 105.83 us/op 103.27 us/op 1.02
prioritizePeers score 0:0 att 32-0.25 sync 2-0.25 134.73 us/op 127.37 us/op 1.06
prioritizePeers score 0:0 att 32-0.5 sync 2-0.5 171.25 us/op 159.15 us/op 1.08
prioritizePeers score 0:0 att 64-0.75 sync 4-0.75 304.83 us/op 287.54 us/op 1.06
prioritizePeers score 0:0 att 64-1 sync 4-1 368.73 us/op 345.76 us/op 1.07
array of 16000 items push then shift 1.6476 us/op 1.5552 us/op 1.06
LinkedList of 16000 items push then shift 8.9980 ns/op 8.4430 ns/op 1.07
array of 16000 items push then pop 91.606 ns/op 80.512 ns/op 1.14
LinkedList of 16000 items push then pop 8.5730 ns/op 8.1700 ns/op 1.05
array of 24000 items push then shift 2.3580 us/op 2.2626 us/op 1.04
LinkedList of 24000 items push then shift 8.6920 ns/op 8.4100 ns/op 1.03
array of 24000 items push then pop 74.595 ns/op 75.667 ns/op 0.99
LinkedList of 24000 items push then pop 8.3230 ns/op 8.1370 ns/op 1.02
intersect bitArray bitLen 8 13.170 ns/op 12.694 ns/op 1.04
intersect array and set length 8 75.859 ns/op 73.877 ns/op 1.03
intersect bitArray bitLen 128 43.255 ns/op 42.132 ns/op 1.03
intersect array and set length 128 1.0435 us/op 1.0251 us/op 1.02
Buffer.concat 32 items 2.8480 us/op 2.7750 us/op 1.03
Uint8Array.set 32 items 2.2270 us/op 2.5760 us/op 0.86
pass gossip attestations to forkchoice per slot 2.7990 ms/op 2.7388 ms/op 1.02
computeDeltas 3.2914 ms/op 2.8515 ms/op 1.15
computeProposerBoostScoreFromBalances 1.7534 ms/op 1.7247 ms/op 1.02
altair processAttestation - 250000 vs - 7PWei normalcase 2.1451 ms/op 2.0086 ms/op 1.07
altair processAttestation - 250000 vs - 7PWei worstcase 3.7087 ms/op 3.1575 ms/op 1.17
altair processAttestation - setStatus - 1/6 committees join 138.68 us/op 134.89 us/op 1.03
altair processAttestation - setStatus - 1/3 committees join 273.56 us/op 271.33 us/op 1.01
altair processAttestation - setStatus - 1/2 committees join 371.67 us/op 363.18 us/op 1.02
altair processAttestation - setStatus - 2/3 committees join 467.01 us/op 438.36 us/op 1.07
altair processAttestation - setStatus - 4/5 committees join 667.22 us/op 623.69 us/op 1.07
altair processAttestation - setStatus - 100% committees join 766.80 us/op 741.49 us/op 1.03
altair processBlock - 250000 vs - 7PWei normalcase 16.974 ms/op 18.911 ms/op 0.90
altair processBlock - 250000 vs - 7PWei normalcase hashState 27.564 ms/op 26.376 ms/op 1.05
altair processBlock - 250000 vs - 7PWei worstcase 52.412 ms/op 53.026 ms/op 0.99
altair processBlock - 250000 vs - 7PWei worstcase hashState 72.281 ms/op 67.052 ms/op 1.08
phase0 processBlock - 250000 vs - 7PWei normalcase 1.9130 ms/op 1.9368 ms/op 0.99
phase0 processBlock - 250000 vs - 7PWei worstcase 26.664 ms/op 27.696 ms/op 0.96
altair processEth1Data - 250000 vs - 7PWei normalcase 465.87 us/op 461.64 us/op 1.01
getExpectedWithdrawals 250000 eb:1,eth1:1,we:0,wn:0,smpl:15 6.6270 us/op 6.6410 us/op 1.00
getExpectedWithdrawals 250000 eb:0.95,eth1:0.1,we:0.05,wn:0,smpl:219 19.269 us/op 19.090 us/op 1.01
getExpectedWithdrawals 250000 eb:0.95,eth1:0.3,we:0.05,wn:0,smpl:42 8.5690 us/op 8.0240 us/op 1.07
getExpectedWithdrawals 250000 eb:0.95,eth1:0.7,we:0.05,wn:0,smpl:18 6.0500 us/op 6.1730 us/op 0.98
getExpectedWithdrawals 250000 eb:0.1,eth1:0.1,we:0,wn:0,smpl:1020 74.011 us/op 74.055 us/op 1.00
getExpectedWithdrawals 250000 eb:0.03,eth1:0.03,we:0,wn:0,smpl:11777 625.90 us/op 603.56 us/op 1.04
getExpectedWithdrawals 250000 eb:0.01,eth1:0.01,we:0,wn:0,smpl:16384 889.09 us/op 891.63 us/op 1.00
getExpectedWithdrawals 250000 eb:0,eth1:0,we:0,wn:0,smpl:16384 879.15 us/op 876.13 us/op 1.00
getExpectedWithdrawals 250000 eb:0,eth1:0,we:0,wn:0,nocache,smpl:16384 2.1727 ms/op 2.3106 ms/op 0.94
getExpectedWithdrawals 250000 eb:0,eth1:1,we:0,wn:0,smpl:16384 1.5050 ms/op 1.4428 ms/op 1.04
getExpectedWithdrawals 250000 eb:0,eth1:1,we:0,wn:0,nocache,smpl:16384 3.7331 ms/op 3.7478 ms/op 1.00
Tree 40 250000 create 314.17 ms/op 297.79 ms/op 1.06
Tree 40 250000 get(125000) 180.05 ns/op 178.28 ns/op 1.01
Tree 40 250000 set(125000) 858.85 ns/op 922.55 ns/op 0.93
Tree 40 250000 toArray() 16.983 ms/op 16.675 ms/op 1.02
Tree 40 250000 iterate all - toArray() + loop 16.072 ms/op 16.811 ms/op 0.96
Tree 40 250000 iterate all - get(i) 65.341 ms/op 65.879 ms/op 0.99
MutableVector 250000 create 9.8703 ms/op 9.6129 ms/op 1.03
MutableVector 250000 get(125000) 6.2350 ns/op 6.2910 ns/op 0.99
MutableVector 250000 set(125000) 250.61 ns/op 240.88 ns/op 1.04
MutableVector 250000 toArray() 2.8345 ms/op 2.7053 ms/op 1.05
MutableVector 250000 iterate all - toArray() + loop 2.8943 ms/op 2.7452 ms/op 1.05
MutableVector 250000 iterate all - get(i) 1.4996 ms/op 1.4801 ms/op 1.01
Array 250000 create 2.4630 ms/op 2.5456 ms/op 0.97
Array 250000 clone - spread 1.0241 ms/op 1.1507 ms/op 0.89
Array 250000 get(125000) 0.50000 ns/op 0.54200 ns/op 0.92
Array 250000 set(125000) 0.56800 ns/op 0.62400 ns/op 0.91
Array 250000 iterate all - loop 89.502 us/op 105.21 us/op 0.85
effectiveBalanceIncrements clone Uint8Array 300000 22.969 us/op 24.233 us/op 0.95
effectiveBalanceIncrements clone MutableVector 300000 301.00 ns/op 350.00 ns/op 0.86
effectiveBalanceIncrements rw all Uint8Array 300000 159.87 us/op 164.24 us/op 0.97
effectiveBalanceIncrements rw all MutableVector 300000 73.082 ms/op 77.696 ms/op 0.94
phase0 afterProcessEpoch - 250000 vs - 7PWei 111.46 ms/op 108.33 ms/op 1.03
phase0 beforeProcessEpoch - 250000 vs - 7PWei 42.700 ms/op 40.135 ms/op 1.06
altair processEpoch - mainnet_e81889 315.93 ms/op 331.92 ms/op 0.95
mainnet_e81889 - altair beforeProcessEpoch 50.334 ms/op 64.824 ms/op 0.78
mainnet_e81889 - altair processJustificationAndFinalization 16.455 us/op 18.603 us/op 0.88
mainnet_e81889 - altair processInactivityUpdates 6.0101 ms/op 5.3394 ms/op 1.13
mainnet_e81889 - altair processRewardsAndPenalties 68.569 ms/op 52.511 ms/op 1.31
mainnet_e81889 - altair processRegistryUpdates 2.9090 us/op 2.4960 us/op 1.17
mainnet_e81889 - altair processSlashings 482.00 ns/op 546.00 ns/op 0.88
mainnet_e81889 - altair processEth1DataReset 496.00 ns/op 480.00 ns/op 1.03
mainnet_e81889 - altair processEffectiveBalanceUpdates 1.2076 ms/op 1.2226 ms/op 0.99
mainnet_e81889 - altair processSlashingsReset 5.8650 us/op 3.9860 us/op 1.47
mainnet_e81889 - altair processRandaoMixesReset 6.3600 us/op 4.7170 us/op 1.35
mainnet_e81889 - altair processHistoricalRootsUpdate 803.00 ns/op 818.00 ns/op 0.98
mainnet_e81889 - altair processParticipationFlagUpdates 3.7240 us/op 2.1070 us/op 1.77
mainnet_e81889 - altair processSyncCommitteeUpdates 478.00 ns/op 692.00 ns/op 0.69
mainnet_e81889 - altair afterProcessEpoch 141.35 ms/op 124.10 ms/op 1.14
phase0 processEpoch - mainnet_e58758 610.17 ms/op 359.22 ms/op 1.70
mainnet_e58758 - phase0 beforeProcessEpoch 223.44 ms/op 138.96 ms/op 1.61
mainnet_e58758 - phase0 processJustificationAndFinalization 25.949 us/op 17.796 us/op 1.46
mainnet_e58758 - phase0 processRewardsAndPenalties 78.334 ms/op 63.895 ms/op 1.23
mainnet_e58758 - phase0 processRegistryUpdates 16.018 us/op 8.7130 us/op 1.84
mainnet_e58758 - phase0 processSlashings 1.0200 us/op 531.00 ns/op 1.92
mainnet_e58758 - phase0 processEth1DataReset 687.00 ns/op 483.00 ns/op 1.42
mainnet_e58758 - phase0 processEffectiveBalanceUpdates 2.0575 ms/op 938.41 us/op 2.19
mainnet_e58758 - phase0 processSlashingsReset 9.5720 us/op 4.3400 us/op 2.21
mainnet_e58758 - phase0 processRandaoMixesReset 13.025 us/op 4.1800 us/op 3.12
mainnet_e58758 - phase0 processHistoricalRootsUpdate 2.2670 us/op 605.00 ns/op 3.75
mainnet_e58758 - phase0 processParticipationRecordUpdates 12.512 us/op 3.9450 us/op 3.17
mainnet_e58758 - phase0 afterProcessEpoch 129.77 ms/op 95.843 ms/op 1.35
phase0 processEffectiveBalanceUpdates - 250000 normalcase 2.1983 ms/op 1.2349 ms/op 1.78
phase0 processEffectiveBalanceUpdates - 250000 worstcase 0.5 4.2280 ms/op 1.6506 ms/op 2.56
altair processInactivityUpdates - 250000 normalcase 41.301 ms/op 19.495 ms/op 2.12
altair processInactivityUpdates - 250000 worstcase 29.017 ms/op 26.059 ms/op 1.11
phase0 processRegistryUpdates - 250000 normalcase 12.750 us/op 6.0420 us/op 2.11
phase0 processRegistryUpdates - 250000 badcase_full_deposits 271.53 us/op 222.30 us/op 1.22
phase0 processRegistryUpdates - 250000 worstcase 0.5 126.62 ms/op 103.63 ms/op 1.22
altair processRewardsAndPenalties - 250000 normalcase 68.386 ms/op 67.549 ms/op 1.01
altair processRewardsAndPenalties - 250000 worstcase 102.01 ms/op 70.656 ms/op 1.44
phase0 getAttestationDeltas - 250000 normalcase 12.886 ms/op 6.3696 ms/op 2.02
phase0 getAttestationDeltas - 250000 worstcase 12.528 ms/op 6.5291 ms/op 1.92
phase0 processSlashings - 250000 worstcase 7.5299 ms/op 3.2083 ms/op 2.35
altair processSyncCommitteeUpdates - 250000 240.10 ms/op 171.97 ms/op 1.40
BeaconState.hashTreeRoot - No change 326.00 ns/op 263.00 ns/op 1.24
BeaconState.hashTreeRoot - 1 full validator 61.593 us/op 52.218 us/op 1.18
BeaconState.hashTreeRoot - 32 full validator 678.89 us/op 501.32 us/op 1.35
BeaconState.hashTreeRoot - 512 full validator 10.275 ms/op 5.1890 ms/op 1.98
BeaconState.hashTreeRoot - 1 validator.effectiveBalance 86.762 us/op 61.918 us/op 1.40
BeaconState.hashTreeRoot - 32 validator.effectiveBalance 939.01 us/op 899.60 us/op 1.04
BeaconState.hashTreeRoot - 512 validator.effectiveBalance 11.519 ms/op 11.236 ms/op 1.03
BeaconState.hashTreeRoot - 1 balances 53.449 us/op 49.318 us/op 1.08
BeaconState.hashTreeRoot - 32 balances 465.77 us/op 451.00 us/op 1.03
BeaconState.hashTreeRoot - 512 balances 4.2894 ms/op 4.0005 ms/op 1.07
BeaconState.hashTreeRoot - 250000 balances 75.228 ms/op 75.999 ms/op 0.99
aggregationBits - 2048 els - zipIndexesInBitList 16.254 us/op 16.208 us/op 1.00
regular array get 100000 times 32.897 us/op 32.878 us/op 1.00
wrappedArray get 100000 times 32.887 us/op 32.686 us/op 1.01
arrayWithProxy get 100000 times 15.471 ms/op 15.521 ms/op 1.00
ssz.Root.equals 576.00 ns/op 675.00 ns/op 0.85
byteArrayEquals 533.00 ns/op 622.00 ns/op 0.86
shuffle list - 16384 els 6.6475 ms/op 6.7372 ms/op 0.99
shuffle list - 250000 els 97.393 ms/op 98.946 ms/op 0.98
processSlot - 1 slots 8.5810 us/op 8.4110 us/op 1.02
processSlot - 32 slots 1.3294 ms/op 1.3078 ms/op 1.02
getEffectiveBalanceIncrementsZeroInactive - 250000 vs - 7PWei 37.809 ms/op 37.263 ms/op 1.01
getCommitteeAssignments - req 1 vs - 250000 vc 2.8251 ms/op 2.8954 ms/op 0.98
getCommitteeAssignments - req 100 vs - 250000 vc 4.0177 ms/op 4.1052 ms/op 0.98
getCommitteeAssignments - req 1000 vs - 250000 vc 4.3488 ms/op 4.3661 ms/op 1.00
RootCache.getBlockRootAtSlot - 250000 vs - 7PWei 4.4600 ns/op 4.5000 ns/op 0.99
state getBlockRootAtSlot - 250000 vs - 7PWei 735.65 ns/op 968.48 ns/op 0.76
computeProposers - vc 250000 10.377 ms/op 10.504 ms/op 0.99
computeEpochShuffling - vc 250000 108.25 ms/op 100.04 ms/op 1.08
getNextSyncCommittee - vc 250000 173.40 ms/op 169.10 ms/op 1.03
computeSigningRoot for AttestationData 13.372 us/op 13.451 us/op 0.99
hash AttestationData serialized data then Buffer.toString(base64) 2.3296 us/op 2.4152 us/op 0.96
toHexString serialized data 1.0456 us/op 1.0430 us/op 1.00
Buffer.toString(base64) 315.12 ns/op 319.96 ns/op 0.98

by benchmarkbot/action

Copy link
Member

@nflaig nflaig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@@ -47,7 +47,7 @@ export function parseSszValidTestcase(dirpath: string, metaFilename: string): Va
const metaStr = fs.readFileSync(path.join(dirpath, metaFilename), "utf8");
const meta = jsyaml.load(metaStr) as {root: string};
if (typeof meta.root !== "string") {
throw Error(`meta.root not a string: ${meta.root}\n${fs}`);
throw Error(`meta.root not a string: ${meta.root}\n${metaStr}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

@nflaig nflaig changed the title Add rule @typescript-eslint/restrict-template-expressions chore: add rule @typescript-eslint/restrict-template-expressions May 29, 2023
@dapplion dapplion merged commit 1cecf82 into unstable May 29, 2023
@dapplion dapplion deleted the dapplion/restrict-template-expressions branch May 29, 2023 10:50
@nflaig nflaig mentioned this pull request May 31, 2023
@wemeetagain
Copy link
Member

🎉 This PR is included in v1.9.0 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add rule @typescript-eslint/restrict-template-expressions
3 participants