Skip to content

Commit

Permalink
🧹 Enforce curly braces (#444)
Browse files Browse the repository at this point in the history
  • Loading branch information
janjakubnanista committed Mar 1, 2024
1 parent 0dace79 commit f75f6f7
Show file tree
Hide file tree
Showing 37 changed files with 231 additions and 82 deletions.
4 changes: 1 addition & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"ignorePatterns": ["node_modules/", "dist/", ".turbo/"],
"rules": {
"prettier/prettier": "error",

"curly": "error",
// This rule needs to be disabled otherwise ESLint will error out
// on things like TypeScript enums or function types
"no-unused-vars": "off",
Expand All @@ -41,9 +41,7 @@
"varsIgnorePattern": "^_"
}
],

"@typescript-eslint/no-explicit-any": "warn",

// Since none of our environment variables affect the build output, we're safe
// to ignore any errors related to undeclared environment variables
"turbo/no-undeclared-env-vars": "warn"
Expand Down
7 changes: 5 additions & 2 deletions packages/create-lz-oapp/src/utilities/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ const EXIT_ALT_SCREEN_ANSI = '\x1b[?1049l'
const createWrite = (socket: NodeJS.WriteStream) => (content: string) => {
return new Promise<void>((resolve, reject) => {
socket.write(content, (error) => {
if (error != null) reject(error)
else resolve()
if (error != null) {
reject(error)
} else {
resolve()
}
})
})
}
Expand Down
4 changes: 3 additions & 1 deletion packages/devtools-evm-hardhat/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ export const withLayerZeroArtifacts = (...packageNames: string[]) => {
const newArtifacts = new Set(
resolvedArtifactsDirectories.filter((artifact) => !existingArtifacts.has(artifact))
)
if (newArtifacts.size === 0) return config
if (newArtifacts.size === 0) {
return config
}

return {
...config,
Expand Down
4 changes: 3 additions & 1 deletion packages/devtools-evm-hardhat/src/internal/assertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ export function assertDefinedNetworks<TNetworkNames extends Iterable<string>>(
const definedNetworkNames = new Set(Object.keys(getEidsByNetworkName(hre)))

for (const networkName of networkNames) {
if (definedNetworkNames.has(networkName)) continue
if (definedNetworkNames.has(networkName)) {
continue
}

throw new AssertionError({
message: `Network '${networkName}' has not been defined. Defined networks are ${Array.from(definedNetworkNames).join(', ')}`,
Expand Down
8 changes: 6 additions & 2 deletions packages/devtools-evm-hardhat/src/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ export const getNetworkNameForEid = (
const eidsByNetworkName = getEidsByNetworkName(hre)

for (const [networkName, networkEid] of Object.entries(eidsByNetworkName)) {
if (networkEid === eid) return networkName
if (networkEid === eid) {
return networkName
}
}

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

// If the number of unique networks matches the number of unique endpoint IDs, there are no duplicates
if (allDefinedEids.size === allNetworkNames.size) return eidsByNetworkName
if (allDefinedEids.size === allNetworkNames.size) {
return eidsByNetworkName
}

// At this point the number of defined endpoint IDs can only be lower than
// the number of defined network names (since network names are taken from the keys
Expand Down
15 changes: 11 additions & 4 deletions packages/devtools-evm-hardhat/src/tasks/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ const action: ActionType<TaskArgs> = async (
}

// If no networks have been selected, we exit
if (selectedNetworks.length === 0) return logger.warn(`No networks selected, exiting`), {}
if (selectedNetworks.length === 0) {
return logger.warn(`No networks selected, exiting`), {}
}

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

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

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

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

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

// If some of the deployments failed, we let the user know
const previewErrors = isInteractive ? await promptToContinue(`Would you like to see the deployment errors?`) : true
if (previewErrors)
if (previewErrors) {
printRecords(
errors.map(({ networkName, error }) => ({
Network: networkName,
Error: String(error),
}))
)
}

// Mark the process as unsuccessful (only if it has not yet been marked as such)
process.exitCode = process.exitCode || 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,19 @@ const action: ActionType<SignAndSendTaskArgs> = async ({
const previewTransactions = isInteractive
? await promptToContinue(`Would you like to preview the transactions before continuing?`)
: true
if (previewTransactions) printRecords(transactions.map(formatOmniTransaction))
if (previewTransactions) {
printRecords(transactions.map(formatOmniTransaction))
}

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

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

Expand Down Expand Up @@ -141,13 +145,14 @@ const action: ActionType<SignAndSendTaskArgs> = async ({
const previewErrors = isInteractive
? await promptToContinue(`Would you like to preview the failed transactions?`)
: true
if (previewErrors)
if (previewErrors) {
printRecords(
errors.map(({ error, transaction }) => ({
error: String(error),
...formatOmniTransaction(transaction),
}))
)
}

// We'll ask the user if they want to retry if we're in interactive mode
//
Expand Down
16 changes: 12 additions & 4 deletions packages/devtools-evm/src/errors/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ export const createContractErrorParser: OmniContractErrorParserFactory = (contra

export const parseContractError = (error: unknown, contract: Contract): ContractError | undefined => {
// If the error already is a ContractError, we'll continue
if (error instanceof ContractError) return error
if (error instanceof ContractError) {
return error
}

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

export const parseGenericError = (error: unknown): ContractError | undefined => {
// If the error already is a ContractError, we'll continue
if (error instanceof ContractError) return error
if (error instanceof ContractError) {
return error
}

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

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

// If the reason is empty, we'll assume the default 0 exit code
if (reason === '') return [new PanicError(BigInt(0))]
if (reason === '') {
return [new PanicError(BigInt(0))]
}

try {
// The codes should follow the docs here https://docs.soliditylang.org/en/latest/control-structures.html#error-handling-assert-require-revert-and-exceptions
Expand Down
12 changes: 9 additions & 3 deletions packages/devtools/src/common/promise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ export const createRetryFactory =
const strategyOutput = await strategy(attempt, error, currentInput, input)

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

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

return (attempt, error, previousInput, originalInput) => {
if (attempt > numAttempts) return false
if (wrappedStrategy == null) return true
if (attempt > numAttempts) {
return false
}
if (wrappedStrategy == null) {
return true
}

return wrappedStrategy(attempt, error, previousInput, originalInput)
}
Expand Down
4 changes: 3 additions & 1 deletion packages/devtools/src/transactions/signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ export const createSignAndSend =
const n = transactions.length

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

// Tell the user how many we are signing
logger.debug(`Signing ${n} ${pluralizeNoun(n, 'transaction')}`)
Expand Down
4 changes: 3 additions & 1 deletion packages/export-deployments/src/common/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ export const listEntriesSafe = (predicate: Predicate<Dirent>) =>
const subDirectories: string[] = []

while ((subDirectory = dir.readSync())) {
if (predicate(subDirectory)) subDirectories.push(resolve(path, subDirectory.name))
if (predicate(subDirectory)) {
subDirectories.push(resolve(path, subDirectory.name))
}
}

return subDirectories
Expand Down
15 changes: 11 additions & 4 deletions packages/export-deployments/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,11 @@ export const generateSafe = ({
export const generate = (options: ExportDeploymentsOptions) => {
const result = generateSafe(options)

if (E.isLeft(result)) throw result.left
else return result.right
if (E.isLeft(result)) {
throw result.left
} else {
return result.right
}
}

/**
Expand All @@ -94,8 +97,12 @@ export const createIncludeDirent =
const nameW = dir.name
const nameWo = basename(nameW, '.json')

if (exclude?.includes(nameW) || exclude?.includes(nameWo)) return false
if (include == null) return true
if (exclude?.includes(nameW) || exclude?.includes(nameWo)) {
return false
}
if (include == null) {
return true
}

return include.includes(nameW) || include.includes(nameWo)
}
Expand Down
4 changes: 3 additions & 1 deletion packages/io-devtools/src/language/plurals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ export const pluralizeOrdinal = (n: number): string => {
*/
export const pluralizeNoun = (n: number, singular: string, plural: string = `${singular}s`): string => {
const rule = cardinalRules.select(n)
if (rule === 'one') return singular
if (rule === 'one') {
return singular
}

return plural
}
8 changes: 6 additions & 2 deletions packages/io-devtools/src/stdio/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ export const printCrossTable = <TRecord extends Record<string | number, unknown>

for (const property of properties) {
// If we already added this one, we continue
if (!propertiesLeft.has(property)) continue
if (!propertiesLeft.has(property)) {
continue
}

// Now we mark the property as added
propertiesLeft.delete(property)
Expand Down Expand Up @@ -160,7 +162,9 @@ export const printZodErrors = (error: ZodError<unknown>): string => {
// of the property on which they happened, if any
const errors = error.flatten((issue) => {
const propertyPath = issue.path?.join('.') ?? ''
if (propertyPath === '') return issue.message
if (propertyPath === '') {
return issue.message
}

return `Property '${propertyPath}': ${issue.message}`
})
Expand Down
4 changes: 3 additions & 1 deletion packages/protocol-devtools/src/dvn/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ export const configureDVNDstConfig: DVNConfigurator = async (graph, createSdk) =
const dstConfig = await sdk.getDstConfig(to.eid)

// TODO Normalize the config values using a schema before comparing them
if (isDeepEqual(dstConfig, config.dstConfig)) return []
if (isDeepEqual(dstConfig, config.dstConfig)) {
return []
}

return [await sdk.setDstConfig(to.eid, config.dstConfig)]
})
Expand Down
12 changes: 9 additions & 3 deletions packages/protocol-devtools/src/endpointv2/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ export const configureEndpointV2DefaultReceiveLibraries: EndpointV2Configurator
const address = await sdk.getDefaultReceiveLibrary(to.eid)

// If the library is already set as default, do nothing
if (config.defaultReceiveLibrary === address) return []
if (config.defaultReceiveLibrary === address) {
return []
}

return [
await sdk.setDefaultReceiveLibrary(
Expand All @@ -66,7 +68,9 @@ export const configureEndpointV2DefaultSendLibraries: EndpointV2Configurator = a
const address = await sdk.getDefaultSendLibrary(to.eid)

// If the library is already set as default, do nothing
if (config.defaultSendLibrary === address) return []
if (config.defaultSendLibrary === address) {
return []
}

return [await sdk.setDefaultSendLibrary(to.eid, config.defaultSendLibrary)]
})
Expand All @@ -79,7 +83,9 @@ const registerLibraries = async (sdk: IEndpointV2, libraries: string[]): Promise
libraries.map(async (address) => {
const isRegistered = await sdk.isRegisteredLibrary(address)

if (isRegistered) return []
if (isRegistered) {
return []
}
return [await sdk.registerLibrary(address)]
})
)
Expand Down
4 changes: 3 additions & 1 deletion packages/protocol-devtools/src/executor/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ export const configureExecutorDstConfig: ExecutorConfigurator = async (graph, cr
const dstConfig = await sdk.getDstConfig(to.eid)

// TODO Normalize the config values using a schema before comparing them
if (isDeepEqual(dstConfig, config.dstConfig)) return []
if (isDeepEqual(dstConfig, config.dstConfig)) {
return []
}

return [await sdk.setDstConfig(to.eid, config.dstConfig)]
})
Expand Down
4 changes: 3 additions & 1 deletion packages/protocol-devtools/src/priceFeed/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ export const configurePriceFeedPriceData: PriceFeedConfigurator = async (graph,
const priceData = await sdk.getPrice(to.eid)

// TODO Normalize the config values using a schema before comparing them
if (isDeepEqual(priceData, config.priceData)) return []
if (isDeepEqual(priceData, config.priceData)) {
return []
}

return [await sdk.setPrice(to.eid, config.priceData)]
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ const action: ActionType<TaskArgs> = async ({ logLevel = 'info', networks: netwo
for (const localNetworkName of networks) {
configs[localNetworkName] = {}
for (const remoteNetworkName of networks) {
if (remoteNetworkName === localNetworkName) continue
if (remoteNetworkName === localNetworkName) {
continue
}

const receiveConfig = await getReceiveConfig(localNetworkName, remoteNetworkName)
const sendConfig = await getSendConfig(localNetworkName, remoteNetworkName)
Expand Down
Loading

0 comments on commit f75f6f7

Please sign in to comment.