Skip to content

Commit

Permalink
style(lint): modify brace style config
Browse files Browse the repository at this point in the history
  • Loading branch information
Red-Asuka authored and ysfscream committed Nov 4, 2024
1 parent 3e21a1e commit a7060bc
Show file tree
Hide file tree
Showing 23 changed files with 87 additions and 168 deletions.
3 changes: 1 addition & 2 deletions apps/cli/bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ try {
const commander = new Commander()
commander.init()
commander.program.parse(process.argv)
}
catch (e) {
} catch (e) {
console.error(e)
}
9 changes: 3 additions & 6 deletions apps/cli/src/lib/conn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ function conn(options: ConnectOptions) {
client.end(false, {}, () => {
basicLog.reconnectTimesLimit()
})
}
else {
} else {
basicLog.reconnecting()
}
})
Expand Down Expand Up @@ -91,8 +90,7 @@ async function benchConn(options: BenchConnectOptions) {
const end = Date.now()
signale.info(`Done, total time: ${(end - start) / 1000}s`)
}
}
else {
} else {
benchLog.reconnected(connectedCount, count, opts.clientId!)
}
})
Expand All @@ -108,8 +106,7 @@ async function benchConn(options: BenchConnectOptions) {
client.end(false, {}, () => {
benchLog.reconnectTimesLimit(connectedCount, count, opts.clientId!)
})
}
else {
} else {
benchLog.reconnecting(connectedCount, count, opts.clientId!)
isNewConnArray[i - 1] = false
}
Expand Down
6 changes: 2 additions & 4 deletions apps/cli/src/lib/ls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ async function listScenarios(): Promise<Scenario[]> {
})
}
}
}
catch (error) {
} catch (error) {
console.error(`Error reading scenarios directory: ${error}`)
}
return scenarios
Expand All @@ -46,8 +45,7 @@ async function ls(options: LsOptions) {
console.log('You can use any of the above scenario names as a parameter to run the scenario.')
// Log the table
console.log(table.toString())
}
catch (err) {
} catch (err) {
console.log(err)
}
}
Expand Down
33 changes: 11 additions & 22 deletions apps/cli/src/lib/pub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,15 @@ function send(config: boolean | string | undefined, connOpts: IClientOptions, pu
client.publish(topic, publishMessage, pubOpts.opts, (err) => {
if (err) {
signale.warn(err)
}
else {
} else {
basicLog.published()
}
// FIXME: When using the ws and wss protocols to connect, and QoS is 0, the message may not have been successfully sent when the publish callback is triggered. Therefore, delay closing the connection for 2 seconds.
if (['ws', 'wss'].includes(connOpts.protocol ?? '') && pubOpts.opts.qos === 0) {
setTimeout(() => {
client.end()
}, 2000)
}
else {
} else {
client.end()
}
})
Expand Down Expand Up @@ -117,8 +115,7 @@ function multisend(config: boolean | string | undefined, connOpts: IClientOption
basicLog.reconnectTimesLimit()
process.exit(1)
})
}
else {
} else {
basicLog.reconnecting()
isNewConnection = false
sender.uncork()
Expand Down Expand Up @@ -148,17 +145,15 @@ function pub(options: PublishOptions) {
if (options.stdin) {
if (options.multiline) {
multisend(config, connOpts, pubOpts, options.maximumReconnectTimes)
}
else {
} else {
process.stdin.pipe(
concat((data) => {
pubOpts.message = data
send(config, connOpts, pubOpts)
}),
)
}
}
else {
} else {
send(config, connOpts, pubOpts)
}
}
Expand All @@ -174,8 +169,7 @@ async function multiPub(commandType: CommandType, options: BenchPublishOptions |
const simulateOptions = options as SimulatePubOptions
checkScenarioExists(simulateOptions.scenario, simulateOptions.file)
simulator = loadSimulator(simulateOptions.scenario, simulateOptions.file)
}
else {
} else {
options = config ? loadConfig('benchPub', config) : options
save && saveConfig('benchPub', options)
}
Expand Down Expand Up @@ -214,8 +208,7 @@ async function multiPub(commandType: CommandType, options: BenchPublishOptions |
topic,
simulator.name || simulator.file,
)
}
else if (commandType === 'benchPub') {
} else if (commandType === 'benchPub') {
benchLog.start.pub(config, count, interval, messageInterval, hostname, port, topic, message.toString())
}

Expand Down Expand Up @@ -261,8 +254,7 @@ async function multiPub(commandType: CommandType, options: BenchPublishOptions |
client.publish(publishTopic, publishMessage, pubOpts.opts, (err) => {
if (err) {
signale.warn(err)
}
else {
} else {
total += 1
rate += 1
}
Expand All @@ -282,16 +274,14 @@ async function multiPub(commandType: CommandType, options: BenchPublishOptions |
simpleInteractive.info(`Published total: ${total}, message rate: ${rate}/s`)
rate = 0
}, 1000)
}
else {
} else {
setInterval(() => {
signale.info(`Published total: ${total}, message rate: ${rate}/s`)
rate = 0
}, 1000)
}
}
}
else {
} else {
benchLog.reconnected(connectedCount, count, opts.clientId!)
}
})
Expand All @@ -310,8 +300,7 @@ async function multiPub(commandType: CommandType, options: BenchPublishOptions |
process.exit(1)
}
})
}
else {
} else {
benchLog.reconnecting(connectedCount, count, opts.clientId!)
isNewConnArray[i - 1] = false
}
Expand Down
21 changes: 7 additions & 14 deletions apps/cli/src/lib/sub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ function sub(options: SubscribeOptions) {
if (err) {
!outputModeClean && basicLog.error(err)
process.exit(1)
}
else {
} else {
!outputModeClean && basicLog.subscribed(t)
}

Expand Down Expand Up @@ -102,8 +101,7 @@ function sub(options: SubscribeOptions) {
Object.entries(packet.properties.userProperties).forEach(([key, value]) => {
if (typeof value === 'string') {
up.push({ key, value })
}
else {
} else {
value.forEach((v) => {
up.push({ key, value: v })
})
Expand All @@ -128,8 +126,7 @@ function sub(options: SubscribeOptions) {
client.end(false, {}, () => {
!outputModeClean && basicLog.reconnectTimesLimit()
})
}
else {
} else {
!outputModeClean && basicLog.reconnecting()
}
})
Expand Down Expand Up @@ -203,8 +200,7 @@ async function benchSub(options: BenchSubscribeOptions) {
if (err) {
signale.error(`[${i}/${count}] - Client ID: ${opts.clientId}, ${err}`)
process.exit(1)
}
else {
} else {
interactive.success('[%d/%d] - Subscribed to %s', connectedCount, count, topicName)
}

Expand All @@ -230,8 +226,7 @@ async function benchSub(options: BenchSubscribeOptions) {
simpleInteractive.info(`Received total: ${total}, rate: ${rate}/s`)
oldTotal = total
}, 1000)
}
else {
} else {
setInterval(() => {
if (total > oldTotal) {
const rate = total - oldTotal
Expand All @@ -243,8 +238,7 @@ async function benchSub(options: BenchSubscribeOptions) {
}
})
})
}
else {
} else {
benchLog.reconnected(connectedCount, count, opts.clientId!)
}
})
Expand All @@ -267,8 +261,7 @@ async function benchSub(options: BenchSubscribeOptions) {
process.exit(1)
}
})
}
else {
} else {
benchLog.reconnecting(connectedCount, count, opts.clientId!)
isNewConnArray[i - 1] = false
}
Expand Down
18 changes: 6 additions & 12 deletions apps/cli/src/scenarios/weather.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,17 @@ const dataCache: Record<string, any> = {}
function getCurrentSeason() {
const today = new Date()
const month = today.getUTCMonth()
if (month < 2 || month > 10)
return 'Winter'
if (month < 5)
return 'Spring'
if (month < 8)
return 'Summer'
if (month < 2 || month > 10) return 'Winter'
if (month < 5) return 'Spring'
if (month < 8) return 'Summer'
return 'Autumn'
}

function getTimeOfDay() {
const hour = new Date().getUTCHours()
if (hour < 6 || hour > 20)
return 'Night'
if (hour < 12)
return 'Morning'
if (hour < 18)
return 'Afternoon'
if (hour < 6 || hour > 20) return 'Night'
if (hour < 12) return 'Morning'
if (hour < 18) return 'Afternoon'
return 'Evening'
}

Expand Down
6 changes: 2 additions & 4 deletions apps/cli/src/utils/checkUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ async function checkUpdate() {
)}\nhttps://github.com/emqx/MQTTX/releases/tag/v${latestVersion}`,
),
)
}
else {
} else {
console.log(chalk.green('There are currently no updates available.'))
}
}
}
catch (error) {
} catch (error) {
console.error(error)
}
}
Expand Down
21 changes: 7 additions & 14 deletions apps/cli/src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ function writeFile(filePath: string, data: Config) {
fs.mkdirSync(path.dirname(filePath), { recursive: true })
if (filePath.endsWith('.yaml') || filePath.endsWith('.yml')) {
fs.writeFileSync(filePath, YAML.dump(data))
}
else {
} else {
fs.writeFileSync(filePath, JSON.stringify(data, null, 2))
}
}
catch (error) {
} catch (error) {
signale.error(error)
process.exit(1)
}
Expand All @@ -41,8 +39,7 @@ function readFile(path: string) {
return YAML.load(config) as Config
}
return JSON.parse(config) as Config
}
catch (error) {
} catch (error) {
signale.error(error)
process.exit(1)
}
Expand All @@ -54,8 +51,7 @@ function processPath(savePath: boolean | string) {
let filePath = ''
if (savePath === true) {
filePath = defaultPath
}
else if (typeof savePath === 'string') {
} else if (typeof savePath === 'string') {
filePath = path.normalize(savePath)
if (!path.isAbsolute(filePath)) {
filePath = path.resolve(filePath)
Expand Down Expand Up @@ -100,8 +96,7 @@ function saveConfig(commandType: CommandType, opts:
}
writeFile(filePath, data)
signale.success(`Configurations saved to ${filePath}`)
}
catch (error) {
} catch (error) {
signale.error(error)
process.exit(1)
}
Expand All @@ -121,13 +116,11 @@ function loadConfig(commandType: CommandType, savePath: boolean | string) {
const config = readFile(filePath)
validateConfig(commandType, filePath, config)
return config[commandType]
}
else {
} else {
signale.error(`Configuration file ${filePath} not found`)
process.exit(1)
}
}
catch (error) {
} catch (error) {
signale.error(error)
process.exit(1)
}
Expand Down
6 changes: 2 additions & 4 deletions apps/cli/src/utils/convertPayload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ function convertJSON(value: Buffer | string, action: 'encode' | 'decode') {
try {
if (action === 'decode') {
return JSON.stringify(JSON.parse(value.toString()), null, 2)
}
else {
} else {
return Buffer.from(JSON.stringify(JSON.parse(value.toString())))
}
}
catch (err) {
} catch (err) {
return chalk.red(err)
}
}
Expand Down
9 changes: 3 additions & 6 deletions apps/cli/src/utils/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,10 @@ function getSpecialTypesOption(
defaultVal?: number | boolean,
) {
const typelist = ['boolean', 'number']
if (typelist.includes(typeof option))
return option
if (typelist.includes(typeof option)) return option
if (Array.isArray(option)) {
if (typelist.includes(typeof option[index]))
return option[index]
if (typelist.includes(typeof option[0]))
return option[0]
if (typelist.includes(typeof option[index])) return option[index]
if (typelist.includes(typeof option[0])) return option[0]
}
return defaultVal
}
Expand Down
Loading

0 comments on commit a7060bc

Please sign in to comment.