Skip to content

Commit f75f6f7

Browse files
🧹 Enforce curly braces (LayerZero-Labs#444)
1 parent 0dace79 commit f75f6f7

File tree

37 files changed

+231
-82
lines changed

37 files changed

+231
-82
lines changed

‎.eslintrc.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"ignorePatterns": ["node_modules/", "dist/", ".turbo/"],
3131
"rules": {
3232
"prettier/prettier": "error",
33-
33+
"curly": "error",
3434
// This rule needs to be disabled otherwise ESLint will error out
3535
// on things like TypeScript enums or function types
3636
"no-unused-vars": "off",
@@ -41,9 +41,7 @@
4141
"varsIgnorePattern": "^_"
4242
}
4343
],
44-
4544
"@typescript-eslint/no-explicit-any": "warn",
46-
4745
// Since none of our environment variables affect the build output, we're safe
4846
// to ignore any errors related to undeclared environment variables
4947
"turbo/no-undeclared-env-vars": "warn"

‎packages/create-lz-oapp/src/utilities/terminal.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ const EXIT_ALT_SCREEN_ANSI = '\x1b[?1049l'
1010
const createWrite = (socket: NodeJS.WriteStream) => (content: string) => {
1111
return new Promise<void>((resolve, reject) => {
1212
socket.write(content, (error) => {
13-
if (error != null) reject(error)
14-
else resolve()
13+
if (error != null) {
14+
reject(error)
15+
} else {
16+
resolve()
17+
}
1518
})
1619
})
1720
}

‎packages/devtools-evm-hardhat/src/config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,9 @@ export const withLayerZeroArtifacts = (...packageNames: string[]) => {
154154
const newArtifacts = new Set(
155155
resolvedArtifactsDirectories.filter((artifact) => !existingArtifacts.has(artifact))
156156
)
157-
if (newArtifacts.size === 0) return config
157+
if (newArtifacts.size === 0) {
158+
return config
159+
}
158160

159161
return {
160162
...config,

‎packages/devtools-evm-hardhat/src/internal/assertions.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ export function assertDefinedNetworks<TNetworkNames extends Iterable<string>>(
3333
const definedNetworkNames = new Set(Object.keys(getEidsByNetworkName(hre)))
3434

3535
for (const networkName of networkNames) {
36-
if (definedNetworkNames.has(networkName)) continue
36+
if (definedNetworkNames.has(networkName)) {
37+
continue
38+
}
3739

3840
throw new AssertionError({
3941
message: `Network '${networkName}' has not been defined. Defined networks are ${Array.from(definedNetworkNames).join(', ')}`,

‎packages/devtools-evm-hardhat/src/runtime.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,9 @@ export const getNetworkNameForEid = (
172172
const eidsByNetworkName = getEidsByNetworkName(hre)
173173

174174
for (const [networkName, networkEid] of Object.entries(eidsByNetworkName)) {
175-
if (networkEid === eid) return networkName
175+
if (networkEid === eid) {
176+
return networkName
177+
}
176178
}
177179

178180
// Here we error out if there are no networks with this eid
@@ -211,7 +213,9 @@ export const getEidsByNetworkName = memoize(
211213
const allNetworkNames = new Set(Object.keys(definedEidsByNetworkName))
212214

213215
// If the number of unique networks matches the number of unique endpoint IDs, there are no duplicates
214-
if (allDefinedEids.size === allNetworkNames.size) return eidsByNetworkName
216+
if (allDefinedEids.size === allNetworkNames.size) {
217+
return eidsByNetworkName
218+
}
215219

216220
// At this point the number of defined endpoint IDs can only be lower than
217221
// the number of defined network names (since network names are taken from the keys

‎packages/devtools-evm-hardhat/src/tasks/deploy.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@ const action: ActionType<TaskArgs> = async (
134134
}
135135

136136
// If no networks have been selected, we exit
137-
if (selectedNetworks.length === 0) return logger.warn(`No networks selected, exiting`), {}
137+
if (selectedNetworks.length === 0) {
138+
return logger.warn(`No networks selected, exiting`), {}
139+
}
138140

139141
// We'll tell the user what's about to happen
140142
logger.info(
@@ -154,7 +156,9 @@ const action: ActionType<TaskArgs> = async (
154156

155157
// Now we confirm with the user that they want to continue
156158
const shouldDeploy = isInteractive ? await promptToContinue() : true
157-
if (!shouldDeploy) return logger.verbose(`User cancelled the operation, exiting`), {}
159+
if (!shouldDeploy) {
160+
return logger.verbose(`User cancelled the operation, exiting`), {}
161+
}
158162

159163
// We talk we talk we talk
160164
logger.verbose(`Running deployment scripts`)
@@ -244,7 +248,9 @@ const action: ActionType<TaskArgs> = async (
244248
)
245249

246250
// If nothing went wrong we just exit
247-
if (errors.length === 0) return logger.info(`${printBoolean(true)} Your contracts are now deployed`), results
251+
if (errors.length === 0) {
252+
return logger.info(`${printBoolean(true)} Your contracts are now deployed`), results
253+
}
248254

249255
// We log the fact that there were some errors
250256
logger.error(
@@ -253,13 +259,14 @@ const action: ActionType<TaskArgs> = async (
253259

254260
// If some of the deployments failed, we let the user know
255261
const previewErrors = isInteractive ? await promptToContinue(`Would you like to see the deployment errors?`) : true
256-
if (previewErrors)
262+
if (previewErrors) {
257263
printRecords(
258264
errors.map(({ networkName, error }) => ({
259265
Network: networkName,
260266
Error: String(error),
261267
}))
262268
)
269+
}
263270

264271
// Mark the process as unsuccessful (only if it has not yet been marked as such)
265272
process.exitCode = process.exitCode || 1

‎packages/devtools-evm-hardhat/src/tasks/transactions/subtask.sign-and-send.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,19 @@ const action: ActionType<SignAndSendTaskArgs> = async ({
4646
const previewTransactions = isInteractive
4747
? await promptToContinue(`Would you like to preview the transactions before continuing?`)
4848
: true
49-
if (previewTransactions) printRecords(transactions.map(formatOmniTransaction))
49+
if (previewTransactions) {
50+
printRecords(transactions.map(formatOmniTransaction))
51+
}
5052

5153
// Now ask the user whether they want to go ahead with signing them
5254
//
5355
// If they don't, we'll just return the list of pending transactions
5456
const shouldSubmit = isInteractive
5557
? await promptToContinue(`Would you like to submit the required transactions?`)
5658
: true
57-
if (!shouldSubmit) return subtaskLogger.verbose(`User cancelled the operation, exiting`), [[], [], transactions]
59+
if (!shouldSubmit) {
60+
return subtaskLogger.verbose(`User cancelled the operation, exiting`), [[], [], transactions]
61+
}
5862

5963
subtaskLogger.verbose(`Signing and sending transactions:\n\n${printJson(transactions)}`)
6064

@@ -141,13 +145,14 @@ const action: ActionType<SignAndSendTaskArgs> = async ({
141145
const previewErrors = isInteractive
142146
? await promptToContinue(`Would you like to preview the failed transactions?`)
143147
: true
144-
if (previewErrors)
148+
if (previewErrors) {
145149
printRecords(
146150
errors.map(({ error, transaction }) => ({
147151
error: String(error),
148152
...formatOmniTransaction(transaction),
149153
}))
150154
)
155+
}
151156

152157
// We'll ask the user if they want to retry if we're in interactive mode
153158
//

‎packages/devtools-evm/src/errors/parser.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ export const createContractErrorParser: OmniContractErrorParserFactory = (contra
2222

2323
export const parseContractError = (error: unknown, contract: Contract): ContractError | undefined => {
2424
// If the error already is a ContractError, we'll continue
25-
if (error instanceof ContractError) return error
25+
if (error instanceof ContractError) {
26+
return error
27+
}
2628

2729
try {
2830
// If the error is unknown we'll try to decode basic errors
@@ -37,7 +39,9 @@ export const parseContractError = (error: unknown, contract: Contract): Contract
3739

3840
export const parseGenericError = (error: unknown): ContractError | undefined => {
3941
// If the error already is a ContractError, we'll continue
40-
if (error instanceof ContractError) return error
42+
if (error instanceof ContractError) {
43+
return error
44+
}
4145

4246
try {
4347
// If the error is unknown we'll try to decode basic errors
@@ -64,14 +68,18 @@ const PANIC_ERROR_PREFIX = '0x4e487b71'
6468
* @returns `ContractError[]` Decoded errors, if any
6569
*/
6670
const basicDecoder = (data: string): ContractError[] => {
67-
if (data === '' || data === '0x') return [new UnknownError(`Reverted with empty data`)]
71+
if (data === '' || data === '0x') {
72+
return [new UnknownError(`Reverted with empty data`)]
73+
}
6874

6975
// This covers the case for assert()
7076
if (data.startsWith(PANIC_ERROR_PREFIX)) {
7177
const reason = data.slice(PANIC_ERROR_PREFIX.length)
7278

7379
// If the reason is empty, we'll assume the default 0 exit code
74-
if (reason === '') return [new PanicError(BigInt(0))]
80+
if (reason === '') {
81+
return [new PanicError(BigInt(0))]
82+
}
7583

7684
try {
7785
// The codes should follow the docs here https://docs.soliditylang.org/en/latest/control-structures.html#error-handling-assert-require-revert-and-exceptions

‎packages/devtools/src/common/promise.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,9 @@ export const createRetryFactory =
168168
const strategyOutput = await strategy(attempt, error, currentInput, input)
169169

170170
// The strategy can simply return true/false, in which case we'll not be adjusting the input at all
171-
if (typeof strategyOutput === 'boolean') return strategyOutput
171+
if (typeof strategyOutput === 'boolean') {
172+
return strategyOutput
173+
}
172174

173175
// If we got an input back, we'll adjust it and keep trying
174176
return (currentInput = strategyOutput), true
@@ -197,8 +199,12 @@ export const createSimpleRetryStrategy = <TInput extends unknown[]>(
197199
assert(numAttempts > 0, `Number of attempts for a strategy must be larger than 0`)
198200

199201
return (attempt, error, previousInput, originalInput) => {
200-
if (attempt > numAttempts) return false
201-
if (wrappedStrategy == null) return true
202+
if (attempt > numAttempts) {
203+
return false
204+
}
205+
if (wrappedStrategy == null) {
206+
return true
207+
}
202208

203209
return wrappedStrategy(attempt, error, previousInput, originalInput)
204210
}

‎packages/devtools/src/transactions/signer.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ export const createSignAndSend =
2929
const n = transactions.length
3030

3131
// Just exit when there is nothing to sign
32-
if (n === 0) return logger.debug(`No transactions to sign, exiting`), [[], [], []]
32+
if (n === 0) {
33+
return logger.debug(`No transactions to sign, exiting`), [[], [], []]
34+
}
3335

3436
// Tell the user how many we are signing
3537
logger.debug(`Signing ${n} ${pluralizeNoun(n, 'transaction')}`)

0 commit comments

Comments
 (0)