From 3f680588cd5ada3a44245fd77b5b87d7ee4c478e Mon Sep 17 00:00:00 2001 From: Tony <68118705+Legend-Master@users.noreply.github.com> Date: Sun, 16 Feb 2025 20:34:19 +0800 Subject: [PATCH] chore: update prettier to 3.5.1 and enable `experimentalOperatorPosition` (#12715) --- .prettierrc | 3 +- .scripts/ci/check-license-header.js | 14 +++---- bench/tests/cpu_intensive/public/index.css | 5 ++- crates/tauri-utils/src/pattern/isolation.js | 16 ++++---- crates/tauri/scripts/ipc-protocol.js | 4 +- crates/tauri/scripts/ipc.js | 38 +++++++++---------- .../src/webview/scripts/toggle-devtools.js | 4 +- crates/tauri/src/window/scripts/drag.js | 16 ++++---- package.json | 2 +- packages/api/src/menu/base.ts | 16 ++++---- packages/api/src/menu/submenu.ts | 4 +- packages/api/src/webviewWindow.ts | 14 +++---- pnpm-lock.yaml | 10 ++--- 13 files changed, 74 insertions(+), 72 deletions(-) diff --git a/.prettierrc b/.prettierrc index 299b9e14e..6ca6fdd25 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,5 +1,6 @@ { "singleQuote": true, "semi": false, - "trailingComma": "none" + "trailingComma": "none", + "experimentalOperatorPosition": "start" } diff --git a/.scripts/ci/check-license-header.js b/.scripts/ci/check-license-header.js index 5afd062f8..03ad824e4 100644 --- a/.scripts/ci/check-license-header.js +++ b/.scripts/ci/check-license-header.js @@ -28,8 +28,8 @@ const ignore = [ async function checkFile(file) { if ( - extensions.some((e) => file.endsWith(e)) && - !ignore.some((i) => file.includes(`/${i}/`) || path.basename(file) == i) + extensions.some((e) => file.endsWith(e)) + && !ignore.some((i) => file.includes(`/${i}/`) || path.basename(file) == i) ) { const fileStream = fs.createReadStream(file) const rl = readline.createInterface({ @@ -42,11 +42,11 @@ async function checkFile(file) { for await (let line of rl) { // ignore empty lines, allow shebang and bundler license if ( - line.length === 0 || - line.startsWith('#!') || - line.startsWith('// swift-tools-version:') || - line === bundlerLicense || - line === denoLicense + line.length === 0 + || line.startsWith('#!') + || line.startsWith('// swift-tools-version:') + || line === bundlerLicense + || line === denoLicense ) { continue } diff --git a/bench/tests/cpu_intensive/public/index.css b/bench/tests/cpu_intensive/public/index.css index 8856f90b3..3a16b1c77 100644 --- a/bench/tests/cpu_intensive/public/index.css +++ b/bench/tests/cpu_intensive/public/index.css @@ -1,6 +1,7 @@ body { - font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, - Arial, sans-serif; + font-family: + -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, + sans-serif; margin: auto; max-width: 38rem; padding: 2rem; diff --git a/crates/tauri-utils/src/pattern/isolation.js b/crates/tauri-utils/src/pattern/isolation.js index 9a44611c6..586d080e5 100644 --- a/crates/tauri-utils/src/pattern/isolation.js +++ b/crates/tauri-utils/src/pattern/isolation.js @@ -77,8 +77,8 @@ if (typeof data === 'object' && typeof data.payload === 'object') { const keys = data.payload ? Object.keys(data.payload) : [] return ( - keys.length > 0 && - keys.every( + keys.length > 0 + && keys.every( (key) => key === 'nonce' || key === 'payload' || key === 'contentType' ) ) @@ -94,10 +94,10 @@ */ function isIsolationPayload(data) { return ( - typeof data === 'object' && - 'callback' in data && - 'error' in data && - !isIsolationMessage(data) + typeof data === 'object' + && 'callback' in data + && 'error' in data + && !isIsolationMessage(data) ) } @@ -139,8 +139,8 @@ function waitUntilReady() { // consider either a function or an explicitly set null value as the ready signal if ( - typeof window.__TAURI_ISOLATION_HOOK__ === 'function' || - window.__TAURI_ISOLATION_HOOK__ === null + typeof window.__TAURI_ISOLATION_HOOK__ === 'function' + || window.__TAURI_ISOLATION_HOOK__ === null ) { sendMessage('__TAURI_ISOLATION_READY__') } else { diff --git a/crates/tauri/scripts/ipc-protocol.js b/crates/tauri/scripts/ipc-protocol.js index ee5d4dc65..7bab6d9ee 100644 --- a/crates/tauri/scripts/ipc-protocol.js +++ b/crates/tauri/scripts/ipc-protocol.js @@ -23,8 +23,8 @@ const { cmd, callback, error, payload, options } = message if ( - !customProtocolIpcFailed && - (canUseCustomProtocol || cmd === fetchChannelDataCommand) + !customProtocolIpcFailed + && (canUseCustomProtocol || cmd === fetchChannelDataCommand) ) { const { contentType, data } = processIpcMessage(payload) fetch(window.__TAURI_INTERNALS__.convertFileSrc(cmd, 'ipc'), { diff --git a/crates/tauri/scripts/ipc.js b/crates/tauri/scripts/ipc.js index 84013187d..d6aa08011 100644 --- a/crates/tauri/scripts/ipc.js +++ b/crates/tauri/scripts/ipc.js @@ -33,13 +33,13 @@ */ function isIsolationMessage(event) { if ( - typeof event.data === 'object' && - typeof event.data.payload === 'object' + typeof event.data === 'object' + && typeof event.data.payload === 'object' ) { const keys = Object.keys(event.data.payload || {}) return ( - keys.length > 0 && - keys.every( + keys.length > 0 + && keys.every( (key) => key === 'contentType' || key === 'nonce' || key === 'payload' ) ) @@ -55,10 +55,10 @@ */ function isIsolationPayload(data) { return ( - typeof data === 'object' && - 'callback' in data && - 'error' in data && - !isIsolationMessage(data) + typeof data === 'object' + && 'callback' in data + && 'error' in data + && !isIsolationMessage(data) ) } @@ -99,27 +99,27 @@ const SERIALIZE_TO_IPC_FN = '__TAURI_TO_IPC_KEY__' if ( - typeof data === 'object' && - data !== null && - 'constructor' in data && - data.constructor === Array + typeof data === 'object' + && data !== null + && 'constructor' in data + && data.constructor === Array ) { return data.map((v) => serializeIpcPayload(v)) } if ( - typeof data === 'object' && - data !== null && - SERIALIZE_TO_IPC_FN in data + typeof data === 'object' + && data !== null + && SERIALIZE_TO_IPC_FN in data ) { return data[SERIALIZE_TO_IPC_FN]() } if ( - typeof data === 'object' && - data !== null && - 'constructor' in data && - data.constructor === Object + typeof data === 'object' + && data !== null + && 'constructor' in data + && data.constructor === Object ) { const acc = {} Object.entries(data).forEach(([k, v]) => { diff --git a/crates/tauri/src/webview/scripts/toggle-devtools.js b/crates/tauri/src/webview/scripts/toggle-devtools.js index 5ef423cae..5997187a1 100644 --- a/crates/tauri/src/webview/scripts/toggle-devtools.js +++ b/crates/tauri/src/webview/scripts/toggle-devtools.js @@ -21,8 +21,8 @@ } if ( - document.readyState === 'complete' || - document.readyState === 'interactive' + document.readyState === 'complete' + || document.readyState === 'interactive' ) { toggleDevtoolsHotkey() } else { diff --git a/crates/tauri/src/window/scripts/drag.js b/crates/tauri/src/window/scripts/drag.js index a247a41bb..882ba4aca 100644 --- a/crates/tauri/src/window/scripts/drag.js +++ b/crates/tauri/src/window/scripts/drag.js @@ -16,11 +16,11 @@ document.addEventListener('mousedown', (e) => { if ( // element has the magic data attribute - e.target.hasAttribute(TAURI_DRAG_REGION_ATTR) && + e.target.hasAttribute(TAURI_DRAG_REGION_ATTR) // and was left mouse button - e.button === 0 && + && e.button === 0 // and was normal click to drag or double click to maximize - (e.detail === 1 || e.detail === 2) + && (e.detail === 1 || e.detail === 2) ) { // macOS maximization happens on `mouseup`, // so we save needed state and early return @@ -48,14 +48,14 @@ document.addEventListener('mouseup', (e) => { if ( // element has the magic data attribute - e.target.hasAttribute(TAURI_DRAG_REGION_ATTR) && + e.target.hasAttribute(TAURI_DRAG_REGION_ATTR) // and was left mouse button - e.button === 0 && + && e.button === 0 // and was double click - e.detail === 2 && + && e.detail === 2 // and the cursor hasn't moved from initial mousedown - e.clientX === x && - e.clientY === y + && e.clientX === x + && e.clientY === y ) { window.__TAURI_INTERNALS__.invoke( 'plugin:window|internal_toggle_maximize' diff --git a/package.json b/package.json index 2a855b11c..686e2d85e 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "example:api:dev": "pnpm run --filter \"api\" tauri dev" }, "devDependencies": { - "prettier": "^3.4.2" + "prettier": "^3.5.1" }, "packageManager": "pnpm@9.9.0", "pnpm": { diff --git a/packages/api/src/menu/base.ts b/packages/api/src/menu/base.ts index b268b6131..c46614ecb 100644 --- a/packages/api/src/menu/base.ts +++ b/packages/api/src/menu/base.ts @@ -62,14 +62,14 @@ export async function newMenu( // about predefined menu item icon if ( - 'item' in opts && - opts.item && - typeof opts.item === 'object' && - 'About' in opts.item && - opts.item.About && - typeof opts.item.About === 'object' && - 'icon' in opts.item.About && - opts.item.About.icon + 'item' in opts + && opts.item + && typeof opts.item === 'object' + && 'About' in opts.item + && opts.item.About + && typeof opts.item.About === 'object' + && 'icon' in opts.item.About + && opts.item.About.icon ) { opts.item.About.icon = transformImage(opts.item.About.icon) } diff --git a/packages/api/src/menu/submenu.ts b/packages/api/src/menu/submenu.ts index 01c12bd0a..c4528556a 100644 --- a/packages/api/src/menu/submenu.ts +++ b/packages/api/src/menu/submenu.ts @@ -46,8 +46,8 @@ export function itemFromKind([rid, id, kind]: [number, string, ItemKind]): /* eslint-enable @typescript-eslint/no-unsafe-return */ } -export type SubmenuOptions = Omit & - MenuOptions +export type SubmenuOptions = Omit + & MenuOptions /** A type that is a submenu inside a {@linkcode Menu} or {@linkcode Submenu}. */ export class Submenu extends MenuItemBase { diff --git a/packages/api/src/webviewWindow.ts b/packages/api/src/webviewWindow.ts index d2bfab8c2..f73d5cab5 100644 --- a/packages/api/src/webviewWindow.ts +++ b/packages/api/src/webviewWindow.ts @@ -74,8 +74,8 @@ class WebviewWindow { */ constructor( label: WebviewLabel, - options: Omit & - WindowOptions = {} + options: Omit + & WindowOptions = {} ) { this.label = label // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment @@ -240,17 +240,17 @@ function applyMixins( ).forEach((extendedClass: { prototype: unknown }) => { Object.getOwnPropertyNames(extendedClass.prototype).forEach((name) => { if ( - typeof baseClass.prototype === 'object' && - baseClass.prototype && - name in baseClass.prototype + typeof baseClass.prototype === 'object' + && baseClass.prototype + && name in baseClass.prototype ) return Object.defineProperty( baseClass.prototype, name, // eslint-disable-next-line - Object.getOwnPropertyDescriptor(extendedClass.prototype, name) ?? - Object.create(null) + Object.getOwnPropertyDescriptor(extendedClass.prototype, name) + ?? Object.create(null) ) }) }) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index dbe7630b1..49d6c56ed 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -13,8 +13,8 @@ importers: .: devDependencies: prettier: - specifier: ^3.4.2 - version: 3.4.2 + specifier: ^3.5.1 + version: 3.5.1 crates/tauri-schema-worker: devDependencies: @@ -1698,8 +1698,8 @@ packages: resolution: {integrity: sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==} engines: {node: '>= 0.8.0'} - prettier@3.4.2: - resolution: {integrity: sha512-e9MewbtFo+Fevyuxn/4rrcDAaq0IYxPGLvObpQjiZBMAzB9IGmzlnG9RZy3FFas+eBMu2vA0CszMeduow5dIuQ==} + prettier@3.5.1: + resolution: {integrity: sha512-hPpFQvHwL3Qv5AdRvBFMhnKo4tYxp0ReXiPn2bxkiohEX6mBeBwEpBSQTkD458RaaDKQMYSp4hX4UtfUTA5wDw==} engines: {node: '>=14'} hasBin: true @@ -3592,7 +3592,7 @@ snapshots: prelude-ls@1.2.1: {} - prettier@3.4.2: {} + prettier@3.5.1: {} printable-characters@1.0.42: {}