diff --git a/.github/workflows/quality.yml b/.github/workflows/quality.yml index ba50d94..bdd3b49 100644 --- a/.github/workflows/quality.yml +++ b/.github/workflows/quality.yml @@ -19,8 +19,10 @@ jobs: uses: actions-rust-lang/setup-rust-toolchain@v1 with: components: rustfmt - - name: Check formatting - run: cargo fmt -- --check + - name: Check formatting and clippy + run: | + cargo fmt -- --check + cargo clippy --all-targets -- -D warnings build: name: Build runs-on: ubuntu-latest diff --git a/Cargo.toml b/Cargo.toml index aca9a62..0f4fc6c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -61,3 +61,35 @@ metrics = { version = "0.24.1", default-features = false } metrics-exporter-prometheus = { version = "0.16.2", default-features = false } dotenvy = "0.15.7" utoipauto = "0.2.0" + + +[workspace.lints.clippy] +# should make procedural code more readable +needless_return = "allow" +# allow explicit testing +bool_assert_comparison = "allow" +# allow `len() checks` +len_zero = "allow" +# allow to use `match` to make code look consistent +single_match = "allow" +# allow use of base struct; needed for forward compatibility +needless_update = "allow" +# allow explict impl of `Default` trait +derivable_impls = "allow" +# allow +1 comparison +int_plus_one = "allow" +# allow structured `if` +collapsible_if = "allow" +# force use of `Arc::clone(p)` for clarity +clone_on_ref_ptr = "deny" +# prefer `copy` over reference for small types +trivially_copy_pass_by_ref = "deny" +# large error variant kept unboxed to preserve thiserror `#[from]` ergonomics +result_large_err = "allow" + +[workspace.lints.rust.unexpected_cfgs] +level = "warn" +check-cfg = [ + 'cfg(target_os, values("solana"))', +] + diff --git a/Makefile b/Makefile index f4495cb..59b9955 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,11 @@ -.PHONY: run-server-example +.PHONY: cargofix run-server-example + +cargofix: + @echo "Run Fmt+Clippy Fix ...." + cargo fix + # might need to use +nightly later if we want more rules + cargo fmt --all + cargo clippy --fix --all-targets -- -D warnings run-example-server: @echo "Running RFQ API..." diff --git a/order-engine-sdk/Cargo.toml b/order-engine-sdk/Cargo.toml index e6a54bd..09e5554 100644 --- a/order-engine-sdk/Cargo.toml +++ b/order-engine-sdk/Cargo.toml @@ -11,3 +11,6 @@ agave-reserved-account-keys = "~2" base64 = { workspace = true } bincode = { workspace = true } anyhow = { workspace = true } + +[lints] +workspace = true diff --git a/order-engine-sdk/src/fill.rs b/order-engine-sdk/src/fill.rs index 7a9cb9a..f25bb13 100644 --- a/order-engine-sdk/src/fill.rs +++ b/order-engine-sdk/src/fill.rs @@ -569,14 +569,14 @@ mod tests { let input_amount = 100; let expire_at = 1000; let input_mint = Pubkey::new_unique(); - let taker_input_mint_token_account = Some(Pubkey::new_unique()); + let taker_input_mint_token_account = Pubkey::new_unique(); let fill_ix = Instruction { program_id: order_engine::ID, accounts: order_engine::client::accounts::Fill { taker, maker, - taker_input_mint_token_account, + taker_input_mint_token_account: Some(taker_input_mint_token_account), maker_input_mint_token_account: Some(Pubkey::new_unique()), taker_output_mint_token_account: Some(Pubkey::new_unique()), maker_output_mint_token_account: Some(Pubkey::new_unique()), @@ -603,8 +603,7 @@ mod tests { input_amount, input_mint, output_mint: fill_ix.accounts[8].pubkey, - taker_input_mint_token_account: taker_input_mint_token_account - .unwrap_or(order_engine::ID), + taker_input_mint_token_account, expire_at, }; @@ -729,6 +728,7 @@ mod tests { ); } + #[allow(clippy::too_many_arguments)] fn build_fill_ix( taker: Pubkey, maker: Pubkey, diff --git a/programs/order-engine/Cargo.toml b/programs/order-engine/Cargo.toml index cdb91ac..585819c 100644 --- a/programs/order-engine/Cargo.toml +++ b/programs/order-engine/Cargo.toml @@ -20,11 +20,8 @@ anchor-debug = [] custom-panic = [] production = [] -[lints.rust.unexpected_cfgs] -level = "warn" -check-cfg = [ - 'cfg(target_os, values("solana"))', -] +[lints] +workspace = true [dependencies] anchor-lang = { workspace = true } diff --git a/programs/order-engine/tests/test_fill.rs b/programs/order-engine/tests/test_fill.rs index 77e3c89..0790b53 100644 --- a/programs/order-engine/tests/test_fill.rs +++ b/programs/order-engine/tests/test_fill.rs @@ -307,7 +307,7 @@ async fn prepare_test(test_mode: TestMode) -> TestEnvironment { let banks_client = Arc::new(Mutex::new(banks_client)); let client = Arc::new(ProgramBanksClient::new_from_client( - banks_client.clone(), + Arc::clone(&banks_client), ProgramBanksClientProcessTransaction, )); @@ -341,7 +341,8 @@ async fn prepare_test(test_mode: TestMode) -> TestEnvironment { let TestMode { taker_accounts, maker_accounts, - expected_error, + // asserted by the caller, which clones it before `prepare_test` consumes `test_mode` + expected_error: _, input_mint_extensions, output_mint_extensions, } = test_mode; @@ -460,11 +461,11 @@ async fn prepare_test(test_mode: TestMode) -> TestEnvironment { anchor_spl::token::ID }; let token_a = Token::new( - client.clone(), + Arc::>::clone(&client), &token_a_program_id, &mint_a, Some(9), - payer.clone(), + Arc::::clone(&payer), ); if let Some(mint_a_keypair) = &mint_a_keypair { token_a @@ -484,11 +485,11 @@ async fn prepare_test(test_mode: TestMode) -> TestEnvironment { anchor_spl::token::ID }; let token_b = Token::new( - client.clone(), + Arc::>::clone(&client), &token_b_program_id, &mint_b, Some(9), - payer.clone(), + Arc::::clone(&payer), ); if let Some(mint_b_keypair) = &mint_b_keypair { token_b @@ -621,7 +622,7 @@ pub async fn process_instructions( signers: &[&Keypair], banks_client: &Mutex, ) -> std::result::Result<(), BanksClientError> { - let mut banks_client = banks_client.lock().await; + let banks_client = banks_client.lock().await; let recent_blockhash = banks_client.get_latest_blockhash().await.unwrap(); let mut all_signers = vec![payer]; diff --git a/rust-toolchain.toml b/rust-toolchain.toml index b8889a3..9f8f816 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,2 +1,6 @@ [toolchain] channel = "1.87.0" +components = ["clippy", "rustfmt"] +targets = [] +profile = "minimal" + diff --git a/server-example/Cargo.toml b/server-example/Cargo.toml index 4d55b9f..dec7538 100644 --- a/server-example/Cargo.toml +++ b/server-example/Cargo.toml @@ -35,3 +35,6 @@ solana-sdk = { workspace = true } dotenvy = { workspace = true } utoipauto = { workspace = true } solana-rpc-client = { workspace = true } + +[lints] +workspace = true diff --git a/squads-sdk/Cargo.toml b/squads-sdk/Cargo.toml index 325bcc7..0536292 100644 --- a/squads-sdk/Cargo.toml +++ b/squads-sdk/Cargo.toml @@ -13,3 +13,6 @@ thiserror = { workspace = true } [dev-dependencies] solana-client = { workspace = true } tokio = { workspace = true, features = ["rt-multi-thread", "macros"] } + +[lints] +workspace = true diff --git a/webhook-api/Cargo.toml b/webhook-api/Cargo.toml index 8efdf04..fad5d71 100644 --- a/webhook-api/Cargo.toml +++ b/webhook-api/Cargo.toml @@ -8,3 +8,6 @@ serde = { workspace = true } serde_json = { workspace = true } strum = { workspace = true } utoipa = { workspace = true, features = ["debug"] } + +[lints] +workspace = true