From 4dd811330bb732284236ae932ffeedcb982ff209 Mon Sep 17 00:00:00 2001 From: Tunglies Date: Tue, 14 Oct 2025 14:43:03 +0800 Subject: [PATCH] feat: add Clippy alias commands and improve build process for Clippy integration (#5055) * feat: add Clippy alias commands and improve build process for Clippy integration * fix(lint-clippy): update Clippy run command to use working directory for src-tauri --- .cargo/config.toml | 4 ++++ .github/workflows/lint-clippy.yml | 27 ++------------------------- src-tauri/Cargo.toml | 1 + src-tauri/build.rs | 8 +++++++- src-tauri/src/lib.rs | 15 +++++++++++++++ 5 files changed, 29 insertions(+), 26 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index beb596d4..f894a1e9 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -3,3 +3,7 @@ linker = "aarch64-linux-gnu-gcc" [target.armv7-unknown-linux-gnueabihf] linker = "arm-linux-gnueabihf-gcc" + +[alias] +clippy-all = "clippy --all-targets --all-features -- -D warnings" +clippy-only = "clippy --all-targets --features clippy -- -D warnings" diff --git a/.github/workflows/lint-clippy.yml b/.github/workflows/lint-clippy.yml index e987a37e..ce783b02 100644 --- a/.github/workflows/lint-clippy.yml +++ b/.github/workflows/lint-clippy.yml @@ -63,29 +63,6 @@ jobs: sudo apt-get update sudo apt-get install -y libxslt1.1 libwebkit2gtk-4.1-dev libayatana-appindicator3-dev librsvg2-dev patchelf - - name: Install pnpm - uses: pnpm/action-setup@v4 - with: - run_install: false - - - name: Install Node - uses: actions/setup-node@v4 - with: - node-version: "22" - cache: "pnpm" - - - name: Pnpm install and check - run: | - pnpm i - pnpm run prebuild ${{ matrix.target }} - - # This workflow runs linting using cargo clippy. - # Note: If the web build step is skipped, - # cargo clippy will fail to run due to missing web dist in the Tauri environment. - - name: Build Web Assets - run: pnpm run web:build - env: - NODE_OPTIONS: "--max_old_space_size=4096" - - name: Run Clippy - run: cargo clippy --manifest-path src-tauri/Cargo.toml --all-targets --all-features -- -D warnings + working-directory: ./src-tauri + run: cargo clippy-all diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 95ecf1c6..9693c08b 100755 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -125,6 +125,7 @@ custom-protocol = ["tauri/custom-protocol"] verge-dev = ["clash_verge_logger/color"] tauri-dev = [] tokio-trace = ["console-subscriber"] +clippy = ["tauri/test"] [profile.release] panic = "abort" diff --git a/src-tauri/build.rs b/src-tauri/build.rs index d860e1e6..b67dd4d0 100644 --- a/src-tauri/build.rs +++ b/src-tauri/build.rs @@ -1,3 +1,9 @@ fn main() { - tauri_build::build() + #[cfg(feature = "clippy")] + { + println!("cargo:warning=Skipping tauri_build during Clippy"); + } + + #[cfg(not(feature = "clippy"))] + tauri_build::build(); } diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index c9e93e00..db107a15 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -510,7 +510,22 @@ pub fn run() { } } + // Mock context for Clippy to avoid build errors + #[cfg(feature = "clippy")] + let context = tauri::test::mock_context(tauri::test::noop_assets()); + #[cfg(feature = "clippy")] + let app = builder.build(context).unwrap_or_else(|e| { + logging!( + error, + Type::Setup, + "Failed to build Tauri application: {}", + e + ); + std::process::exit(1); + }); + // Build the application + #[cfg(not(feature = "clippy"))] let app = builder .build(tauri::generate_context!()) .unwrap_or_else(|e| {