From 562b8f1a1fbde4d47bd33765c05145dbc07a9251 Mon Sep 17 00:00:00 2001 From: Kiron Date: Mon, 9 Dec 2024 09:56:04 +0800 Subject: [PATCH] Use clippy and fmt from rules_rust --- .bazelrc | 6 ++++++ .github/workflows/main.yaml | 28 ++------------------------ proxydetox/src/options.rs | 8 ++++---- proxydetoxlib/tests/environment/mod.rs | 2 +- tools/toml_get.rs | 8 ++++---- 5 files changed, 17 insertions(+), 35 deletions(-) diff --git a/.bazelrc b/.bazelrc index e3fb4d14..3e123044 100644 --- a/.bazelrc +++ b/.bazelrc @@ -14,6 +14,12 @@ build --incompatible_merge_fixed_and_default_shell_env build --enable_platform_specific_config +build:clippy --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect +build:clippy --output_groups=+clippy_checks + +build:format --aspects=@rules_rust//rust:defs.bzl%rustfmt_aspect +build:format --output_groups=+rustfmt_checks + build:macos --apple_crosstool_top=@local_config_apple_cc//:toolchain build:macos --crosstool_top=@local_config_apple_cc//:toolchain build:macos --host_crosstool_top=@local_config_apple_cc//:toolchain diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 045369c4..8d48c3ec 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -112,6 +112,8 @@ jobs: bazel test --config=ci + --config=clippy + --config=format --//:version=${{ needs.version.outputs.version }} --//:rev=${{ needs.version.outputs.rev }} ${{ matrix.buildflags }} @@ -295,31 +297,6 @@ jobs: REPO: ${{ github.repository }} VERSION: v${{ needs.version.outputs.version }} - format_check: - name: Rust lint - runs-on: ubuntu-20.04 - - strategy: - matrix: - lint: [clippy, fmt] - include: - - lint: clippy - flags: --all - - lint: fmt - flags: --all -- --check - - steps: - - uses: actions/checkout@v4 - - name: Rustup - run: | - rustup update --no-self-update stable - rustup component add clippy rustfmt - - name: Install Linux dependency - run: sudo apt-get install libkrb5-dev - if: ${{ matrix.lint == 'clippy' }} - - name: Lint check - run: cargo ${{ matrix.lint }} ${{ matrix.flags }} - # The success job is here to consolidate the total success/failure state of # all other jobs. This job is then included in the GitHub branch protection # rule which prevents merges unless all other jobs are passing. This makes @@ -331,7 +308,6 @@ jobs: needs: - bazel_build - cargo_build_and_test - - format_check runs-on: ubuntu-latest steps: - run: jq --exit-status 'all(.result == "success")' <<< '${{ toJson(needs) }}' diff --git a/proxydetox/src/options.rs b/proxydetox/src/options.rs index 9dce1402..9e82cae1 100644 --- a/proxydetox/src/options.rs +++ b/proxydetox/src/options.rs @@ -438,8 +438,8 @@ mod tests { #[test] fn test_default() { let args = Options::parse_args(&["proxydetox".into()]); - assert_eq!(args.direct_fallback, false); - assert_eq!(args.always_use_connect, false); + assert!(!args.direct_fallback); + assert!(!args.always_use_connect); } #[test] @@ -449,8 +449,8 @@ mod tests { "--direct-fallback".into(), "--always-use-connect".into(), ]); - assert_eq!(args.direct_fallback, true); - assert_eq!(args.always_use_connect, true); + assert!(args.direct_fallback); + assert!(args.always_use_connect); } #[test] diff --git a/proxydetoxlib/tests/environment/mod.rs b/proxydetoxlib/tests/environment/mod.rs index 433ab2fe..ecbd7486 100644 --- a/proxydetoxlib/tests/environment/mod.rs +++ b/proxydetoxlib/tests/environment/mod.rs @@ -70,7 +70,7 @@ impl Environment { assert!(h.is_none()); let (response, connection) = tokio::join!(request_sender.send_request(request), connection); - let _ = connection.unwrap(); + connection.unwrap(); response.unwrap() } diff --git a/tools/toml_get.rs b/tools/toml_get.rs index 3bfd5272..733d4610 100644 --- a/tools/toml_get.rs +++ b/tools/toml_get.rs @@ -38,10 +38,10 @@ fn main() -> Result<(), Box> { }; } let value = match value { - Value::String(v) => format!("{v}"), - Value::Integer(v) => format!("{v}"), - Value::Float(v) => format!("{v}"), - Value::Boolean(v) => format!("{v}"), + Value::String(v) => v.to_string(), + Value::Integer(v) => v.to_string(), + Value::Float(v) => v.to_string(), + Value::Boolean(v) => v.to_string(), x => format!("{x}"), }; let stdout = std::io::stdout();