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(format): use eslint as the formatting tool #1797

Merged
merged 4 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions .prettierignore

This file was deleted.

9 changes: 0 additions & 9 deletions .prettierrc.json

This file was deleted.

54 changes: 54 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
// Disable the default formatter, use eslint instead
"prettier.enable": false,
"editor.formatOnSave": false,

// Auto fix
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit",
"source.organizeImports": "never"
},

// remove tailwindcss directives(like @apply) warnings
"css.lint.unknownAtRules": "ignore",
"scss.lint.unknownAtRules": "ignore",

// Silent the stylistic rules in you IDE, but still auto fix them
"eslint.rules.customizations": [
{ "rule": "style/*", "severity": "off", "fixable": true },
{ "rule": "format/*", "severity": "off", "fixable": true },
{ "rule": "*-indent", "severity": "off", "fixable": true },
{ "rule": "*-spacing", "severity": "off", "fixable": true },
{ "rule": "*-spaces", "severity": "off", "fixable": true },
{ "rule": "*-order", "severity": "off", "fixable": true },
{ "rule": "*-dangle", "severity": "off", "fixable": true },
{ "rule": "*-newline", "severity": "off", "fixable": true },
{ "rule": "*quotes", "severity": "off", "fixable": true },
{ "rule": "*semi", "severity": "off", "fixable": true }
],

// Enable eslint for all supported languages
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact",
"vue",
"html",
"markdown",
"json",
"jsonc",
"yaml",
"toml",
"xml",
"gql",
"graphql",
"astro",
"svelte",
"css",
"less",
"scss",
"pcss",
"postcss"
]
}
5 changes: 3 additions & 2 deletions apps/cli/bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ try {
const commander = new Commander()
commander.init()
commander.program.parse(process.argv)
} catch (e) {
console.log(e)
}
catch (e) {
console.error(e)
Red-Asuka marked this conversation as resolved.
Show resolved Hide resolved
}
16 changes: 8 additions & 8 deletions apps/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@
"version": "2.0.0-alpha.1",
"description": "MQTTX CLI - An MQTT client for the command line",
"author": "EMQX Team <[email protected]>",
"license": "Apache-2.0",
"homepage": "https://mqttx.app/cli",
"keywords": [
"mqtt",
"publish/subscribe",
"publish",
"subscribe"
],
"scripts": {
"dev": "tsc -w",
"build": "tsc && pkg . -o ./release/mqttx-cli"
},
"main": "./dist/src/index.js",
"bin": {
"mqttx": "./bin/index.js"
},
"license": "Apache-2.0",
"engines": {
"node": ">=16"
},
"scripts": {
"dev": "tsc -w",
"build": "tsc && pkg . -o ./release/mqttx-cli"
},
"dependencies": {
"axios": "^0.27.2",
"chalk": "~4.1.2",
Expand All @@ -40,16 +40,16 @@
},
"devDependencies": {
"@faker-js/faker": "^7.6.0",
"@mqttx/tsconfig": "workspace:*",
"@types/concat-stream": "^2.0.0",
"@types/js-yaml": "^4.0.5",
"@types/mqttx": "workspace:*",
"@types/node": "^17.0.43",
"@types/pump": "^1.1.1",
"@types/readable-stream": "^2.3.13",
"@types/signale": "^1.4.4",
"@types/split2": "^3.2.1",
"@types/ws": "^8.5.3",
"@mqttx/tsconfig": "workspace:*",
"@types/mqttx": "workspace:*"
"@types/ws": "^8.5.3"
},
"pkg": {
"targets": [
Expand Down
24 changes: 12 additions & 12 deletions apps/cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import 'core-js'
import { Command } from 'commander'
import { getClientId } from './utils/generator'
import { version } from '../package.json'
import { benchConn, conn } from './lib/conn'
import ls from './lib/ls'
import { benchPub, pub, simulatePub } from './lib/pub'
import { benchSub, sub } from './lib/sub'
import { checkUpdate } from './utils/checkUpdate'
import { getClientId } from './utils/generator'
import {
parseFormat,
parseMQTTVersion,
parseNumber,
parseOutputMode,
parseProtocol,
parseMQTTVersion,
parseUserProperties,
parsePubTopic,
parseQoS,
parseUserProperties,
parseVariadicOfBooleanType,
parsePubTopic,
parseFormat,
parseOutputMode,
} from './utils/parse'
import { conn, benchConn } from './lib/conn'
import { pub, benchPub, simulatePub } from './lib/pub'
import { sub, benchSub } from './lib/sub'
import ls from './lib/ls'
import { version } from '../package.json'
import 'core-js'

export class Commander {
program: Command
Expand Down
27 changes: 15 additions & 12 deletions apps/cli/src/lib/conn.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { BenchConnectOptions, ConnectOptions } from 'mqttx'
import * as mqtt from 'mqtt'
import { Signale, signale, basicLog, benchLog } from '../utils/signale'
import { parseConnectOptions } from '../utils/parse'
import { loadConfig, saveConfig } from '../utils/config'
import delay from '../utils/delay'
import { saveConfig, loadConfig } from '../utils/config'
import { ConnectOptions, BenchConnectOptions } from 'mqttx'
import { parseConnectOptions } from '../utils/parse'
import { basicLog, benchLog, Signale, signale } from '../utils/signale'

const conn = (options: ConnectOptions) => {
function conn(options: ConnectOptions) {
const { save, config } = options

config && (options = loadConfig('conn', config))
Expand Down Expand Up @@ -37,7 +37,8 @@ const conn = (options: ConnectOptions) => {
client.end(false, {}, () => {
basicLog.reconnectTimesLimit()
})
} else {
}
else {
basicLog.reconnecting()
}
})
Expand All @@ -47,7 +48,7 @@ const conn = (options: ConnectOptions) => {
})
}

const benchConn = async (options: BenchConnectOptions) => {
async function benchConn(options: BenchConnectOptions) {
const { save, config } = options

config && (options = loadConfig('benchConn', config))
Expand All @@ -60,9 +61,9 @@ const benchConn = async (options: BenchConnectOptions) => {

let connectedCount = 0

const isNewConnArray = Array(count).fill(true)
const isNewConnArray = Array.from({ length: count }, () => true)

const retryTimesArray = Array(count).fill(0)
const retryTimesArray = Array.from({ length: count }, () => 0)

const interactive = new Signale({ interactive: true })

Expand Down Expand Up @@ -90,7 +91,8 @@ const benchConn = async (options: BenchConnectOptions) => {
const end = Date.now()
signale.info(`Done, total time: ${(end - start) / 1000}s`)
}
} else {
}
else {
Red-Asuka marked this conversation as resolved.
Show resolved Hide resolved
benchLog.reconnected(connectedCount, count, opts.clientId!)
}
})
Expand All @@ -106,7 +108,8 @@ const benchConn = async (options: BenchConnectOptions) => {
client.end(false, {}, () => {
benchLog.reconnectTimesLimit(connectedCount, count, opts.clientId!)
})
} else {
}
else {
benchLog.reconnecting(connectedCount, count, opts.clientId!)
isNewConnArray[i - 1] = false
}
Expand All @@ -124,4 +127,4 @@ const benchConn = async (options: BenchConnectOptions) => {

export default conn

export { conn, benchConn }
export { benchConn, conn }
14 changes: 8 additions & 6 deletions apps/cli/src/lib/ls.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as fs from 'fs'
import * as path from 'path'
import type { LsOptions } from 'mqttx'
import * as fs from 'node:fs'
import * as path from 'node:path'
import Table from 'cli-table3'
import { LsOptions } from 'mqttx'

interface Scenario {
name: string
Expand All @@ -23,13 +23,14 @@ async function listScenarios(): Promise<Scenario[]> {
})
}
}
} catch (error) {
}
catch (error) {
console.error(`Error reading scenarios directory: ${error}`)
}
return scenarios
}

const ls = async (options: LsOptions) => {
async function ls(options: LsOptions) {
if (options.scenarios) {
try {
const list = await listScenarios()
Expand All @@ -45,7 +46,8 @@ const ls = async (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
Loading
Loading