From 19505effeba2dc772e2afbf6d721eeaa2666e830 Mon Sep 17 00:00:00 2001 From: Red-Asuka Date: Fri, 1 Nov 2024 16:00:18 +0800 Subject: [PATCH 1/4] chore(format): remove Prettier configuration and related files --- .prettierignore | 10 ---------- .prettierrc.json | 9 --------- package.json | 3 +-- pnpm-lock.yaml | 9 --------- 4 files changed, 1 insertion(+), 30 deletions(-) delete mode 100644 .prettierignore delete mode 100644 .prettierrc.json diff --git a/.prettierignore b/.prettierignore deleted file mode 100644 index f3ad0a25f..000000000 --- a/.prettierignore +++ /dev/null @@ -1,10 +0,0 @@ -out -dist -release -pnpm-lock.yaml -pnpm-workspace.yaml -LICENSE -LICENSE.md -tsconfig.json -tsconfig.*.json -node_modules diff --git a/.prettierrc.json b/.prettierrc.json deleted file mode 100644 index fb5a06e0a..000000000 --- a/.prettierrc.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "singleQuote": true, - "tabWidth": 2, - "useTabs": false, - "semi": false, - "trailingComma": "all", - "printWidth": 120, - "bracketSpacing": true -} diff --git a/package.json b/package.json index 8aa0c770d..adc2b4bf1 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "build:linux": "turbo run build:linux", "build:mac": "turbo run build:mac", "generate:ui": "turbo run generate:ui", - "format": "prettier --write .", + "format": "", "lint": "turbo run lint", "test": "turbo run test" }, @@ -30,7 +30,6 @@ "eslint": "^8.48.0", "husky": "^8.0.3", "lint-staged": "^15.0.2", - "prettier": "^3.0.3", "turbo": "^2.2.3", "typescript": "^4.9.5" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index cfbd25b08..11d532f91 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -20,9 +20,6 @@ importers: lint-staged: specifier: ^15.0.2 version: 15.0.2 - prettier: - specifier: ^3.0.3 - version: 3.0.3 turbo: specifier: ^2.2.3 version: 2.2.3 @@ -5954,12 +5951,6 @@ packages: fast-diff: 1.3.0 dev: true - /prettier@3.0.3: - resolution: {integrity: sha512-L/4pUDMxcNa8R/EthV08Zt42WBO4h1rarVtK0K+QJG0X187OLo7l699jWw0GKuwzkPQ//jMFA/8Xm6Fh3J/DAg==} - engines: {node: '>=14'} - hasBin: true - dev: true - /prettier@3.3.3: resolution: {integrity: sha512-i2tDNA0O5IrMO757lfrdQZCc2jPNDVntV0m/+4whiDfWaTKfMNgR7Qz0NAeGz/nRqF4m5/6CLzbP4/liHt12Ew==} engines: {node: '>=14'} From 1fd475854e44a47138423fd7d97b74ce511c00c9 Mon Sep 17 00:00:00 2001 From: Red-Asuka Date: Fri, 1 Nov 2024 17:59:34 +0800 Subject: [PATCH 2/4] chore(format): use eslint as the formatting tool --- .vscode/settings.json | 54 + apps/cli/package.json | 6 +- apps/desktop/.eslintrc.cjs | 3 - apps/desktop/package.json | 8 +- apps/web/.eslintrc.cjs | 4 - apps/web/package.json | 10 +- eslint.config.mjs | 34 + lint-staged.config.js | 2 +- package.json | 15 +- packages/eslint-config-custom/README.md | 3 - packages/eslint-config-custom/base.js | 21 - packages/eslint-config-custom/desktop.js | 4 - packages/eslint-config-custom/package.json | 16 - packages/eslint-config-custom/web.js | 4 - packages/ui/.eslintrc.cjs | 4 - packages/ui/package.json | 4 +- pnpm-lock.yaml | 2406 +++++++++++++------- 17 files changed, 1692 insertions(+), 906 deletions(-) create mode 100644 .vscode/settings.json delete mode 100644 apps/desktop/.eslintrc.cjs delete mode 100644 apps/web/.eslintrc.cjs create mode 100644 eslint.config.mjs delete mode 100644 packages/eslint-config-custom/README.md delete mode 100644 packages/eslint-config-custom/base.js delete mode 100644 packages/eslint-config-custom/desktop.js delete mode 100644 packages/eslint-config-custom/package.json delete mode 100644 packages/eslint-config-custom/web.js delete mode 100644 packages/ui/.eslintrc.cjs diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..75529c9b3 --- /dev/null +++ b/.vscode/settings.json @@ -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" + ] +} diff --git a/apps/cli/package.json b/apps/cli/package.json index 4c35187b0..a7c927c8c 100644 --- a/apps/cli/package.json +++ b/apps/cli/package.json @@ -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": [ diff --git a/apps/desktop/.eslintrc.cjs b/apps/desktop/.eslintrc.cjs deleted file mode 100644 index 19104ebb0..000000000 --- a/apps/desktop/.eslintrc.cjs +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - extends: ['custom/desktop'], -} diff --git a/apps/desktop/package.json b/apps/desktop/package.json index 37270eb8f..cdb5f901e 100644 --- a/apps/desktop/package.json +++ b/apps/desktop/package.json @@ -5,6 +5,9 @@ "author": "EMQX Team ", "homepage": "https://mqttx.app", "main": "./out/main/index.js", + "engines": { + "node": ">=18" + }, "scripts": { "dev": "electron-vite dev", "prebuild": "npm run typecheck && electron-vite build", @@ -14,7 +17,6 @@ "build:mac": "npm run prebuild && electron-builder --mac --config", "build:linux": "npm run prebuild && electron-builder --linux --config", "preview": "electron-vite preview", - "lint": "eslint . --ext .js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts,.vue --fix", "typecheck:node": "tsc --noEmit -p tsconfig.node.json --composite false", "typecheck:web": "vue-tsc --noEmit -p tsconfig.web.json --composite false", "typecheck": "npm run typecheck:node && npm run typecheck:web" @@ -43,7 +45,6 @@ "electron": "^27.0.2", "electron-builder": "^24.6.3", "electron-vite": "^1.0.27", - "eslint-config-custom": "workspace:*", "jsdom": "^22.1.0", "postcss": "^8.4.31", "sass": "^1.69.3", @@ -55,8 +56,5 @@ "vitest": "^0.34.6", "vue": "^3.3.4", "vue-tsc": "^1.8.8" - }, - "engines": { - "node": ">=18" } } diff --git a/apps/web/.eslintrc.cjs b/apps/web/.eslintrc.cjs deleted file mode 100644 index 8530ca167..000000000 --- a/apps/web/.eslintrc.cjs +++ /dev/null @@ -1,4 +0,0 @@ -/* eslint-env node */ -module.exports = { - extends: ['custom/web'], -} diff --git a/apps/web/package.json b/apps/web/package.json index 1188120fc..b8cb2f29b 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -4,13 +4,15 @@ "description": "MQTTX Web - An MQTT client for the Web", "author": "EMQX Team ", "homepage": "https://mqttx.app/web", + "engines": { + "node": ">=18" + }, "scripts": { "dev": "vite", "build": "run-p type-check \"build-only {@}\" --", "preview": "vite preview", "build-only": "vite build", - "type-check": "vue-tsc --noEmit -p tsconfig.app.json --composite false", - "lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix" + "type-check": "vue-tsc --noEmit -p tsconfig.app.json --composite false" }, "dependencies": { "@element-plus/icons-vue": "^2.1.0", @@ -34,7 +36,6 @@ "@vue/test-utils": "^2.4.1", "@vue/tsconfig": "^0.4.0", "autoprefixer": "^10.4.16", - "eslint-config-custom": "workspace:*", "jsdom": "^22.1.0", "npm-run-all2": "^6.0.6", "postcss": "^8.4.31", @@ -46,8 +47,5 @@ "vite": "^4.4.9", "vitest": "^0.34.6", "vue-tsc": "^1.8.11" - }, - "engines": { - "node": ">=18" } } diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 000000000..e381fc060 --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,34 @@ +import antfu from '@antfu/eslint-config' + +export default antfu( + { + vue: true, + formatters: { + /** + * Format CSS, LESS, SCSS files, also the `', - ) - } catch (c) { - console && console.log(c) - } - } - ;(a = function () { - var c, - h = document.createElement('div') - ;(h.innerHTML = t._iconfont_svg_string_1257443), - (h = h.getElementsByTagName('svg')[0]) && - (h.setAttribute('aria-hidden', 'true'), - (h.style.position = 'absolute'), - (h.style.width = 0), - (h.style.height = 0), - (h.style.overflow = 'hidden'), - (h = h), - (c = document.body).firstChild ? d(h, c.firstChild) : c.appendChild(h)) - }), - document.addEventListener - ? ~['complete', 'loaded', 'interactive'].indexOf(document.readyState) - ? setTimeout(a, 0) - : ((l = function () { - document.removeEventListener('DOMContentLoaded', l, !1), a() - }), - document.addEventListener('DOMContentLoaded', l, !1)) - : document.attachEvent && - ((s = a), - (o = t.document), - (i = !1), - e(), - (o.onreadystatechange = function () { - 'complete' == o.readyState && ((o.onreadystatechange = null), p()) - })) +;(window._iconfont_svg_string_1257443 + = ''), +(function (t) { + var c = (c = document.getElementsByTagName('script'))[c.length - 1] + const h = c.getAttribute('data-injectcss') + var c = c.getAttribute('data-disable-injectsvg') + if (!c) { + let a + let l + var s + var o + var i + const d = function (c, h) { + h.parentNode.insertBefore(c, h) } - function p() { - i || ((i = !0), s()) - } - function e() { + if (h && !t.__iconfont__svg__cssinject__) { + t.__iconfont__svg__cssinject__ = !0 try { - o.documentElement.doScroll('left') - } catch (c) { - return void setTimeout(e, 50) + document.write( + '', + ) + } + catch (c) { + console && console.log(c) } - p() } - })(window) + ;(a = function () { + let c + let h = document.createElement('div') + ;(h.innerHTML = t._iconfont_svg_string_1257443), + (h = h.getElementsByTagName('svg')[0]) + && (h.setAttribute('aria-hidden', 'true'), + (h.style.position = 'absolute'), + (h.style.width = 0), + (h.style.height = 0), + (h.style.overflow = 'hidden'), + (h = h), + (c = document.body).firstChild ? d(h, c.firstChild) : c.appendChild(h)) + }), + document.addEventListener + ? ~['complete', 'loaded', 'interactive'].indexOf(document.readyState) + ? setTimeout(a, 0) + : ((l = function () { + document.removeEventListener('DOMContentLoaded', l, !1), a() + }), + document.addEventListener('DOMContentLoaded', l, !1)) + : document.attachEvent + && ((s = a), + (o = t.document), + (i = !1), + e(), + (o.onreadystatechange = function () { + o.readyState == 'complete' && ((o.onreadystatechange = null), p()) + })) + } + function p() { + i || ((i = !0), s()) + } + function e() { + try { + o.documentElement.doScroll('left') + } + catch (c) { + return void setTimeout(e, 50) + } + p() + } +})(window) diff --git a/packages/ui/src/components/__test__/EmptyView.spec.ts b/packages/ui/src/components/__test__/EmptyView.spec.ts index 49870f5a2..d5593b68b 100644 --- a/packages/ui/src/components/__test__/EmptyView.spec.ts +++ b/packages/ui/src/components/__test__/EmptyView.spec.ts @@ -1,9 +1,9 @@ -// ExampleComponent.spec.ts -import { describe, it, expect } from 'vitest' import { mount } from '@vue/test-utils' +// ExampleComponent.spec.ts +import { describe, expect, it } from 'vitest' import EmptyView from '../common/EmptyView.vue' -describe('EmptyView', () => { +describe('emptyView', () => { it('should render correctly', () => { const wrapper = mount(EmptyView) expect(wrapper.text()).toContain('No Data!') diff --git a/packages/ui/src/components/__test__/SplitView.spec.ts b/packages/ui/src/components/__test__/SplitView.spec.ts index 750c856bd..e38256e0f 100644 --- a/packages/ui/src/components/__test__/SplitView.spec.ts +++ b/packages/ui/src/components/__test__/SplitView.spec.ts @@ -1,5 +1,5 @@ -import { describe, it, expect, beforeEach, afterEach } from 'vitest' import { mount } from '@vue/test-utils' +import { afterEach, beforeEach, describe, expect, it } from 'vitest' import SplitView from '../common/SplitView.vue' interface SplitViewInstance { @@ -16,7 +16,7 @@ interface SplitViewInstance { // Add other properties and methods as needed } -describe('SplitView', () => { +describe('splitView', () => { let wrapper: ReturnType beforeEach(() => { wrapper = mount(SplitView, { @@ -117,13 +117,13 @@ describe('SplitView', () => { splitViewInstance.handleMouseMove(moveEvent) // Wait for the animation frame and Vue's next tick - await new Promise((resolve) => requestAnimationFrame(resolve)) + await new Promise(resolve => requestAnimationFrame(resolve)) await wrapper.vm.$nextTick() // Assert const expectedSize = 310 // 260 + 50 = 310 - const minSize = parseInt(wrapper.props('minSize'), 10) - const maxSize = parseInt(wrapper.props('maxSize'), 10) + const minSize = Number.parseInt(wrapper.props('minSize'), 10) + const maxSize = Number.parseInt(wrapper.props('maxSize'), 10) // Check that the panel size has updated correctly within the constraints expect(splitViewInstance.panelSize).toBeGreaterThanOrEqual(minSize) @@ -131,9 +131,11 @@ describe('SplitView', () => { // Ensure the panel size has updated to what we expect (within the constraints) if (expectedSize >= minSize && expectedSize <= maxSize) { expect(splitViewInstance.panelSize).toBe(expectedSize) - } else if (expectedSize < minSize) { + } + else if (expectedSize < minSize) { expect(splitViewInstance.panelSize).toBe(minSize) - } else if (expectedSize > maxSize) { + } + else if (expectedSize > maxSize) { expect(splitViewInstance.panelSize).toBe(maxSize) } }) diff --git a/packages/ui/src/components/common/EmptyView.vue b/packages/ui/src/components/common/EmptyView.vue index d9b253397..9042ecc99 100644 --- a/packages/ui/src/components/common/EmptyView.vue +++ b/packages/ui/src/components/common/EmptyView.vue @@ -1 +1,3 @@ - + diff --git a/packages/ui/src/components/common/LeftMenu.vue b/packages/ui/src/components/common/LeftMenu.vue index d4a0723c0..0dadcd08b 100644 --- a/packages/ui/src/components/common/LeftMenu.vue +++ b/packages/ui/src/components/common/LeftMenu.vue @@ -42,16 +42,16 @@ const helpMenus = reactive({