#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere
TypeScript dockerhacktoberfestjavapdfpdf-converterpdf-editorpdf-manipulationpdf-mergerpdf-ocrpdf-toolspdf-web-appspdfmergerself-hosted
chore(rust): add Clippy to Rust crates, tasks, and CI (#8785)
briosb7f6db16ac27
diff --git a/.github/config/.files.yaml b/.github/config/.files.yamlindex 648ca08e01..b1f308fac3 100644--- a/.github/config/.files.yaml+++ b/.github/config/.files.yaml@@ -111,6 +111,7 @@ tauri: &tauri- frontend/package-lock.json- frontend/vite.config.ts- .github/workflows/tauri-build.yml+ - .github/workflows/rust-lint.yml- Taskfile.yml- .taskfiles/desktop.ymldiff --git a/.github/workflows/build.yml b/.github/workflows/build.ymlindex 7b5dc21eb2..19c90084e4 100644--- a/.github/workflows/build.yml+++ b/.github/workflows/build.yml@@ -216,6 +216,15 @@ jobs:sign: trueuse_shared_cache: true+ rust-lint:+ if: |+ !cancelled() &&+ needs.files-changed.outputs.tauri == 'true'+ needs: [files-changed]+ permissions:+ contents: read+ uses: ./.github/workflows/rust-lint.yml+ai-engine:if: needs.files-changed.outputs.engine == 'true'needs: [files-changed]@@ -303,6 +312,7 @@ jobs:- docker-compose-tests- test-build-docker-images- tauri-build+ - rust-lint- ai-engine- generated-models- pre-commit@@ -331,6 +341,7 @@ jobs:docker-compose-tests=${{ needs.docker-compose-tests.result }}test-build-docker-images=${{ needs.test-build-docker-images.result }}tauri-build=${{ needs.tauri-build.result }}+ rust-lint=${{ needs.rust-lint.result }}ai-engine=${{ needs.ai-engine.result }}generated-models=${{ needs.generated-models.result }}pre-commit=${{ needs.pre-commit.result }}diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.ymlindex 2217555e8f..ddc194366d 100644--- a/.github/workflows/nightly.yml+++ b/.github/workflows/nightly.yml@@ -100,6 +100,16 @@ jobs:sign: falsesecrets: inherit+ # Same reason as warm-tauri-cache: PR runs restore the Rust lint cache but+ # never write it, because Actions scopes a cache written on a PR to that PR+ # alone. The nightly run on main is what makes the key reusable.+ lint:+ name: Rust Lint+ if: github.event_name == 'schedule' || github.ref == 'refs/heads/main'+ permissions:+ contents: read+ uses: ./.github/workflows/rust-lint.yml+# Runs the @nightly tag (conversion scenarios) plus a 10-shard concurrency run# of every other feature.cucumber-nightly:diff --git a/.github/workflows/rust-lint.yml b/.github/workflows/rust-lint.ymlnew file mode 100644index 0000000000..64b1be5e63--- /dev/null+++ b/.github/workflows/rust-lint.yml@@ -0,0 +1,71 @@+name: Rust Lint++# Reusable workflow called from build.yml when desktop / Rust sources change.+#+# The task behind it is `desktop:lint`, so swapping Clippy for another linter+# does not rename the job. Clippy only analyses the `cfg` branches for the host+# it runs on, and the Tauri crate carries Linux-, macOS- and Windows-only+# modules. The matrix therefore runs on all three so every platform branch is+# linted where it actually compiles, including the Windows-only thumbnail+# handler crate.+on:+ workflow_call:++permissions:+ contents: read++jobs:+ lint:+ name: Lint (${{ matrix.os }})+ # Matches tauri-build's matrix gate: the lite CI profile skips desktop work.+ if: ${{ vars.CI_PROFILE != 'lite' }}+ runs-on: ${{ matrix.os }}+ timeout-minutes: 45+ strategy:+ fail-fast: false+ matrix:+ os: [ubuntu-22.04, macos-latest, windows-latest]+ steps:+ - name: Harden Runner+ uses: step-security/harden-runner@ccd8616d44fd3846e67624a50d5aad6d37bf2d25 # v2.22.1+ with:+ egress-policy: audit++ - name: Checkout repository+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1+ with:+ # Cargo build scripts run third-party code; none of it needs the token.+ persist-credentials: false++ - name: Install dependencies (ubuntu only)+ if: runner.os == 'Linux'+ run: |+ sudo apt-get update+ sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf libjavascriptcoregtk-4.0-dev libsoup2.4-dev libjavascriptcoregtk-4.1-dev libsoup-3.0-dev++ - name: Setup Rust+ uses: dtolnay/rust-toolchain@4be9e76fd7c4901c61fb841f559994984270fce7 # stable+ with:+ toolchain: stable+ components: clippy++ # Registry + compiled dependencies; a cold Clippy run rebuilds the whole+ # Tauri graph, which is what dominates this job.+ - name: Cache Rust build+ uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3+ with:+ workspaces: |+ frontend/src-tauri+ frontend/src-tauri/provisioner+ frontend/src-tauri/thumbnail-handler+ shared-key: rust-lint+ save-if: ${{ github.ref == 'refs/heads/main' }}+ cache-on-failure: true++ - name: Install Task+ uses: go-task/setup-task@a00fbb05ce67b35648be3c78cbc9fd85354c757e # v2.2.0+ with:+ version: 3.54.0++ - name: Run desktop lint+ run: task desktop:lintdiff --git a/.taskfiles/desktop.yml b/.taskfiles/desktop.ymlindex 9a471cdf6b..8e40c63bf0 100644--- a/.taskfiles/desktop.yml+++ b/.taskfiles/desktop.yml@@ -92,6 +92,56 @@ tasks:cmds:- cargo test+ # ============================================================+ # Lint, format, test+ # ============================================================++ lint:+ desc: "Run linting"+ cmds:+ - task: lint:app+ - task: lint:provisioner+ - task: lint:thumbnail-handler++ lint:app:+ desc: "Lint the Tauri app crate"+ dir: src-tauri+ env:+ # Clippy only needs the crate graph. Blanking the bundle resources stops+ # tauri-build failing on the libs/*.jar and runtime/jre globs that only+ # `desktop:prepare` produces, so linting does not need a backend build.+ TAURI_CONFIG: '{"bundle":{"resources":[]}}'+ cmds:+ - cargo clippy --all-targets --all-features -- -D warnings++ lint:provisioner:+ desc: "Lint the installer provisioner crate"+ dir: src-tauri/provisioner+ cmds:+ - cargo clippy --all-targets -- -D warnings++ lint:thumbnail-handler:+ desc: "Lint the Windows thumbnail handler crate"+ platforms: [windows]+ dir: src-tauri/thumbnail-handler+ cmds:+ - cargo clippy --all-targets -- -D warnings++ format:+ desc: "Auto-fix Rust formatting (not implemented yet)"+ cmds: []++ format:check:+ desc: "Check Rust formatting (not implemented yet)"+ cmds: []++ check:+ desc: "Full desktop quality gate"+ cmds:+ - task: lint+ - task: format:check+ - task: test+clean:desc: "Clean Tauri/Cargo build artifacts"cmds:diff --git a/Taskfile.yml b/Taskfile.ymlindex eb67d903a5..407872bdde 100644--- a/Taskfile.yml+++ b/Taskfile.yml@@ -270,6 +270,7 @@ tasks:cmds:- task: frontend:lint- task: engine:lint+ - task: desktop:lint- task: comment-lintcomment-lint:@@ -332,6 +333,7 @@ tasks:- task: backend:check- task: frontend:check- task: engine:check+ - task: desktop:checkcheck:all:desc: "Full CI quality gate"@@ -339,6 +341,7 @@ tasks:- task: backend:check- task: frontend:check:all- task: engine:check+ - task: desktop:check# ============================================================# Cleandiff --git a/docs/developer/DeveloperGuide.md b/docs/developer/DeveloperGuide.mdindex 96e722243f..2670c80b18 100644--- a/docs/developer/DeveloperGuide.md+++ b/docs/developer/DeveloperGuide.md@@ -49,8 +49,9 @@ This guide focuses on developing for Stirling 2.0, including both the React fron- Node.js 22+ and npm (required for frontend development)- Gradle 9.0 or later (Included within the repo)- [uv](https://docs.astral.sh/uv/) β Python package manager (required for engine development)-- Rust and Cargo (required for Tauri desktop app development)+- Rust and Cargo (required for the `task check` quality gate and Tauri desktop development)- Tauri CLI (install with `cargo install tauri-cli`)+- Linux only: Tauri system libraries (`libgtk-3-dev libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf`)### Optional System Dependencies@@ -97,7 +98,7 @@ For local testing, you should generally be testing the full 'Security' version o### Verify Setup-Run `task install` to install all project dependencies (frontend npm packages, engine Python packages). Gradle manages its own dependencies automatically. Then run `task check` to verify everything builds and passes.+Run `task install` to install all project dependencies (frontend npm packages, engine Python packages). Gradle manages its own dependencies automatically. Then run `task check` to verify everything builds and passes. `task check` includes `desktop:check`, which runs `desktop:lint`, so it needs Rust and Cargo, plus the Tauri system libraries on Linux.## 4. Stirling 2.0 Development Workflowdiff --git a/frontend/src-tauri/Cargo.toml b/frontend/src-tauri/Cargo.tomlindex 0507e4d8a1..4513132f77 100644--- a/frontend/src-tauri/Cargo.toml+++ b/frontend/src-tauri/Cargo.toml@@ -13,6 +13,9 @@ rust-version = "1.77.2"[lints.rust]warnings = "deny"+[lints.clippy]+all = "deny"+[lib]name = "app_lib"crate-type = ["staticlib", "cdylib", "rlib"]diff --git a/frontend/src-tauri/provisioner/Cargo.toml b/frontend/src-tauri/provisioner/Cargo.tomlindex 5565c98547..de03f3fd44 100644--- a/frontend/src-tauri/provisioner/Cargo.toml+++ b/frontend/src-tauri/provisioner/Cargo.toml@@ -3,6 +3,12 @@ name = "stirling-provisioner"version = "0.1.0"edition = "2021"+[lints.rust]+warnings = "deny"++[lints.clippy]+all = "deny"+[dependencies]serde = { version = "1.0", features = ["derive"] }serde_json = "1.0"diff --git a/frontend/src-tauri/src/commands/auth.rs b/frontend/src-tauri/src/commands/auth.rsindex f170f64fcf..48eaa03f12 100644--- a/frontend/src-tauri/src/commands/auth.rs+++ b/frontend/src-tauri/src/commands/auth.rs@@ -506,7 +506,7 @@ pub async fn login(.as_ref().and_then(|m| m.full_name.clone()).or_else(|| email.clone())- .unwrap_or_else(|| username);+ .unwrap_or(username);Ok(LoginResponse {token: login_response.access_token,@@ -565,7 +565,7 @@ pub async fn login(} else if error_lower.contains("timeout") {format!("Connection timeout: Server at {} is not responding. Check your network connection.", login_url)} else if error_lower.contains("dns") || error_lower.contains("resolve") {- format!("DNS resolution failed: Cannot resolve hostname. Check if the server URL is correct.")+ "DNS resolution failed: Cannot resolve hostname. Check if the server URL is correct.".to_string()} else {format!("Network error: {}", e)}diff --git a/frontend/src-tauri/src/commands/backend.rs b/frontend/src-tauri/src/commands/backend.rsindex 5ccef61603..d0d015b7e4 100644--- a/frontend/src-tauri/src/commands/backend.rs+++ b/frontend/src-tauri/src/commands/backend.rs@@ -80,7 +80,7 @@ fn check_backend_status() -> Result<(), String> {}// Find the bundled JRE and return the java executable path-fn find_bundled_jre(resource_dir: &PathBuf) -> Result<PathBuf, String> {+fn find_bundled_jre(resource_dir: &Path) -> Result<PathBuf, String> {let jre_dir = resource_dir.join("runtime").join("jre");let java_executable = if cfg!(windows) {jre_dir.join("bin").join("java.exe")@@ -99,7 +99,7 @@ fn find_bundled_jre(resource_dir: &PathBuf) -> Result<PathBuf, String> {}// Find the Stirling-PDF JAR file-fn find_stirling_jar(resource_dir: &PathBuf) -> Result<PathBuf, String> {+fn find_stirling_jar(resource_dir: &Path) -> Result<PathBuf, String> {let libs_dir = resource_dir.join("libs");let mut jar_files: Vec<_> = std::fs::read_dir(&libs_dir).map_err(|e| {@@ -229,20 +229,17 @@ fn version_key(name: &str) -> (Vec<u64>, u8, Vec<PrereleaseToken>) {}// Normalize path to remove Windows UNC prefix-fn normalize_path(path: &PathBuf) -> PathBuf {+fn normalize_path(path: &Path) -> PathBuf {if cfg!(windows) {let path_str = path.to_string_lossy();- if path_str.starts_with(r"\\?\") {- PathBuf::from(&path_str[4..]) // Remove \\?\ prefix- } else {- path.clone()+ if let Some(stripped) = path_str.strip_prefix(r"\\?\") {+ return PathBuf::from(stripped);}- } else {- path.clone()}+ path.to_path_buf()}-fn migrate_legacy_workspace(legacy_dir: &PathBuf, target_root: &PathBuf) -> std::io::Result<()> {+fn migrate_legacy_workspace(legacy_dir: &Path, target_root: &Path) -> std::io::Result<()> {for entry in std::fs::read_dir(legacy_dir)? {let entry = entry?;let file_type = entry.file_type()?;@@ -445,7 +442,7 @@ fn monitor_backend_output(mut rx: tauri::async_runtime::Receiver<tauri_plugin_sh// Format: "Stirling-PDF running on port: PORT"if output_str.contains("running on port:") {_startup_detected = true;- if let Some(port) = extract_port_from_running_log(&output_str) {+ if let Some(port) = extract_port_from_running_log(output_str) {let mut port_guard = BACKEND_PORT.lock().unwrap();*port_guard = Some(port);add_log(format!("π Backend started on port: {}", port));@@ -560,16 +557,11 @@ pub async fn start_backend(add_log(format!("π Resource directory: {:?}", resource_dir));// Find the bundled JRE- let java_executable = find_bundled_jre(&resource_dir).map_err(|e| {- reset_starting_flag();- e- })?;+ let java_executable =+ find_bundled_jre(&resource_dir).inspect_err(|_| reset_starting_flag())?;// Find the Stirling-PDF JAR- let jar_path = find_stirling_jar(&resource_dir).map_err(|e| {- reset_starting_flag();- e- })?;+ let jar_path = find_stirling_jar(&resource_dir).inspect_err(|_| reset_starting_flag())?;// Normalize the paths to remove Windows UNC prefixlet normalized_java_path = normalize_path(&java_executable);@@ -580,10 +572,8 @@ pub async fn start_backend(add_log(format!("π¦ Normalized Java path: {:?}", normalized_java_path));// Create and start the Java command- run_stirling_pdf_jar(&app, &normalized_java_path, &normalized_jar_path).map_err(|e| {- reset_starting_flag();- e- })?;+ run_stirling_pdf_jar(&app, &normalized_java_path, &normalized_jar_path)+ .inspect_err(|_| reset_starting_flag())?;// Reset the starting flag since startup is completereset_starting_flag();diff --git a/frontend/src-tauri/src/commands/connection.rs b/frontend/src-tauri/src/commands/connection.rsindex fd85ed6506..560f33b173 100644--- a/frontend/src-tauri/src/commands/connection.rs+++ b/frontend/src-tauri/src/commands/connection.rs@@ -27,27 +27,23 @@ const PROVISIONING_FILE_NAME: &str = "stirling-provisioning.json";/// How the desktop auto-updater should behave on startup.///-/// * `Prompt` β default. Show the update popup when a new version is available-/// and let the user decide whether to install.-/// * `Auto` β silently download and install updates on startup, then restart.-/// Intended for managed deployments (Intune/MDM) where the user-/// cannot (or should not) be prompted.-/// * `Disabled` β never check for updates, never show the update UI. Administrators-/// are expected to push updates through their normal packaging flow.-#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]+/// * `Prompt` β default. Show the update popup when a new version is available+/// and let the user decide whether to install.+/// * `Auto` β silently download and install updates on startup, then restart.+/// Intended for managed deployments (Intune/MDM) where the user cannot+/// (or should not) be prompted.+/// * `Disabled` β never check for updates, never show the update UI.+/// Administrators are expected to push updates through their normal+/// packaging flow.+#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]#[serde(rename_all = "lowercase")]pub enum UpdateMode {+ #[default]Prompt,Auto,Disabled,}-impl Default for UpdateMode {- fn default() -> Self {- UpdateMode::Prompt- }-}-/// Current update mode plus whether the UI is allowed to change it. Returned/// by [`get_update_mode`] so the settings page can show a "managed by/// administrator" hint instead of silently ignoring clicks.@@ -449,7 +445,7 @@ pub fn apply_provisioning_if_present(app_handle: &AppHandle) -> Result<(), Strinif let Some(mode) = parsed.update_mode {store.set(UPDATE_MODE_KEY,- serde_json::to_value(&mode)+ serde_json::to_value(mode).map_err(|e| format!("Failed to serialize update mode: {}", e))?,);// Only lock the UI when the provisioning file came from a path that@@ -607,7 +603,7 @@ pub async fn set_update_mode(app_handle: AppHandle, mode: UpdateMode) -> Result<store.set(UPDATE_MODE_KEY,- serde_json::to_value(&mode)+ serde_json::to_value(mode).map_err(|e| format!("Failed to serialize update mode: {}", e))?,);storediff --git a/frontend/src-tauri/src/commands/updater.rs b/frontend/src-tauri/src/commands/updater.rsindex 10139a276b..9afa9a18f4 100644--- a/frontend/src-tauri/src/commands/updater.rs+++ b/frontend/src-tauri/src/commands/updater.rs@@ -212,11 +212,11 @@ pub struct CanInstallResult {pub fn can_install_updates() -> CanInstallResult {#[cfg(not(target_os = "windows"))]{- return CanInstallResult {+ CanInstallResult {can_install: true,reason: None,install_dir: None,- };+ }}#[cfg(target_os = "windows")]diff --git a/frontend/src-tauri/thumbnail-handler/Cargo.toml b/frontend/src-tauri/thumbnail-handler/Cargo.tomlindex 87b40cad19..834494ce43 100644--- a/frontend/src-tauri/thumbnail-handler/Cargo.toml+++ b/frontend/src-tauri/thumbnail-handler/Cargo.toml@@ -3,6 +3,12 @@ name = "stirling-thumbnail-handler"version = "0.1.0"edition = "2021"+[lints.rust]+warnings = "deny"++[lints.clippy]+all = "deny"+[lib]crate-type = ["cdylib"]diff --git a/frontend/src-tauri/thumbnail-handler/src/lib.rs b/frontend/src-tauri/thumbnail-handler/src/lib.rsindex f75b10d030..1649321bd2 100644--- a/frontend/src-tauri/thumbnail-handler/src/lib.rs+++ b/frontend/src-tauri/thumbnail-handler/src/lib.rs@@ -215,7 +215,7 @@ fn bytes_to_random_access_stream(bytes: &[u8]) -> windows::core::Result<IRandomA// Seek back to beginningmem_stream.Seek(0)?;- Ok(mem_stream.cast()?)+ mem_stream.cast()}// ---------------------------------------------------------------------------