From daff7a52a4e915cc0f1736af2b881c0c4aa089a1 Mon Sep 17 00:00:00 2001 From: Steve Myers Date: Wed, 31 Jul 2024 21:07:48 -0500 Subject: [PATCH] chore(ci): add fmt and clippy checks --- .github/workflows/cont_integration.yml | 45 ++++++++++++++++++++------ src/client.rs | 1 - src/socks/v4.rs | 5 +-- src/socks/v5.rs | 16 ++------- 4 files changed, 39 insertions(+), 28 deletions(-) diff --git a/.github/workflows/cont_integration.yml b/.github/workflows/cont_integration.yml index 753a6b3..ed34db7 100644 --- a/.github/workflows/cont_integration.yml +++ b/.github/workflows/cont_integration.yml @@ -3,7 +3,7 @@ on: [push, pull_request] name: CI jobs: - test-fmt: + test: name: Test runs-on: ubuntu-20.04 env: @@ -16,7 +16,7 @@ jobs: - 1.63.0 # MSRV steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Cache uses: actions/cache@v2 with: @@ -25,14 +25,10 @@ jobs: ~/.cargo/git target key: ${{ runner.os }}-cargo-${{ github.job }}-${{ hashFiles('**/Cargo.toml','**/Cargo.lock') }} - - name: Install rustup - run: curl https://sh.rustup.rs -sSf | sh -s -- -y - - name: Set default toolchain - run: $HOME/.cargo/bin/rustup default ${{ matrix.rust }} - - name: Set profile - run: $HOME/.cargo/bin/rustup set profile minimal - - name: Fmt - run: cargo fmt -- --check --verbose + - name: Install rust + uses: dtolnay/rust-toolchain@stable + with: + toolchain: ${{ matrix.rust }} - name: Test run: cargo test --verbose --all-features - name: Setup iptables for the timeout test @@ -46,3 +42,32 @@ jobs: - run: cargo check --verbose --no-default-features --features=proxy,use-openssl - run: cargo check --verbose --no-default-features --features=proxy,use-rustls - run: cargo check --verbose --no-default-features --features=proxy,use-rustls-ring + + fmt: + name: Rust fmt + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + with: + toolchain: stable + components: rustfmt + - name: Check fmt + run: cargo fmt --all -- --config format_code_in_doc_comments=true --check + + clippy_check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + with: + toolchain: 1.78.0 + components: clippy + - name: Rust Cache + uses: Swatinem/rust-cache@v2.2.1 + - uses: actions-rs/clippy-check@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + args: --all-features --all-targets -- -D warnings \ No newline at end of file diff --git a/src/client.rs b/src/client.rs index 7a79668..3511724 100644 --- a/src/client.rs +++ b/src/client.rs @@ -148,7 +148,6 @@ impl Client { /// If no prefix is specified, then `tcp://` is assumed. /// /// See [Client::from_config] for more configuration options - /// pub fn new(url: &str) -> Result { Self::from_config(url, Config::default()) } diff --git a/src/socks/v4.rs b/src/socks/v4.rs index fbdbe62..ed269b1 100644 --- a/src/socks/v4.rs +++ b/src/socks/v4.rs @@ -117,10 +117,7 @@ impl Socks4Stream { socket.write_all(&packet)?; let proxy_addr = read_response(&mut socket)?; - Ok(Socks4Stream { - socket, - proxy_addr, - }) + Ok(Socks4Stream { socket, proxy_addr }) } /// Returns the proxy-side address of the connection between the proxy and diff --git a/src/socks/v5.rs b/src/socks/v5.rs index f2a2cce..de54747 100644 --- a/src/socks/v5.rs +++ b/src/socks/v5.rs @@ -253,10 +253,7 @@ impl Socks5Stream { let proxy_addr = read_response(&mut socket)?; - Ok(Socks5Stream { - socket, - proxy_addr, - }) + Ok(Socks5Stream { socket, proxy_addr }) } fn password_authentication( @@ -470,10 +467,7 @@ impl Socks5Datagram { let socket = UdpSocket::bind(addr)?; socket.connect(&stream.proxy_addr)?; - Ok(Socks5Datagram { - socket, - stream, - }) + Ok(Socks5Datagram { socket, stream }) } /// Like `UdpSocket::send_to`. @@ -522,11 +516,7 @@ impl Socks5Datagram { let addr = read_addr(&mut header)?; unsafe { - ptr::copy( - buf.as_ptr(), - buf.as_mut_ptr().add(header.len()), - overflow, - ); + ptr::copy(buf.as_ptr(), buf.as_mut_ptr().add(header.len()), overflow); } buf[..header.len()].copy_from_slice(header);