Skip to content

chore: add staged lint baseline for LEZ programs#88

Open
3esmit wants to merge 3 commits intomainfrom
rust-lint-suggestion
Open

chore: add staged lint baseline for LEZ programs#88
3esmit wants to merge 3 commits intomainfrom
rust-lint-suggestion

Conversation

@3esmit
Copy link
Copy Markdown
Collaborator

@3esmit 3esmit commented May 6, 2026

Fixes #87

Summary

Adds a staged lint baseline for the LEZ workspace and the excluded guest crates.

What Changed

  • Added root workspace lint settings for hard blockers around unsafe code, placeholder macros, unchecked unwraps, lint-suppression hygiene, arithmetic, indexing, casts, and enum matching.
  • Opted root workspace member crates into inherited lints.
  • Added equivalent direct lint settings to the three excluded guest manifests.
  • Added clippy.toml with the pinned Rust MSRV and test-specific lint behavior.
  • Added CI checks for root workspace Clippy, guest Clippy, and placeholder lint-suppression reasons.
  • Replaced the existing unwrap() call in idl-gen, made AMM arithmetic use checked division where needed, removed unchecked PDA seed slicing, and gave existing lint expectations concrete reasons.

Justification

The repository contains deterministic program logic and zkVM guest wrappers. A shared lint baseline makes risky patterns visible earlier and prevents excluded guest crates from drifting outside the normal quality gate.

Benefits

  • Keeps root workspace lint policy consistent across token, AMM, ATA, method host crates, integration tests, and tooling.
  • Brings guest crates into CI lint coverage even though they are intentionally excluded from the root workspace.
  • Blocks vague lint-suppression reasons before they normalize into the codebase.
  • Makes arithmetic and indexing choices more explicit in program code.

Risks

  • Some guest wrappers still carry reasoned expectations for deprecated SPEL output helpers until the auto-claim migration is handled separately.
  • The guest CI step uses the currently working host all-targets Clippy path. A stricter riscv32im-risc0-zkvm-elf Clippy gate likely needs separate stable build-std/toolchain wiring.
  • The initial baseline is intentionally staged; broader pedantic, documentation, and panic-contract lints should be enabled after the current code is prepared for them.

Validation

cargo +nightly fmt --all -- --check
taplo fmt --check .
RISC0_SKIP_BUILD=1 cargo +1.94.0 clippy --workspace --all-targets -- -D warnings
cargo +1.94.0 clippy --manifest-path token/methods/guest/Cargo.toml --all-targets -- -D warnings
cargo +1.94.0 clippy --manifest-path amm/methods/guest/Cargo.toml --all-targets -- -D warnings
cargo +1.94.0 clippy --manifest-path ata/methods/guest/Cargo.toml --all-targets -- -D warnings

@3esmit 3esmit self-assigned this May 6, 2026
Copilot AI review requested due to automatic review settings May 6, 2026 20:10
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a staged, workspace-wide Rust/Clippy lint baseline for LEZ programs (including separate linting for the excluded zkVM guest crates) and updates several call sites to comply with the new rules.

Changes:

  • Add [workspace.lints] policy at the root and opt workspace member crates into inheriting it; add matching lint configs to the excluded guest crates.
  • Add clippy.toml to pin MSRV and configure test-specific lint behavior; extend CI to run workspace + guest Clippy and reject placeholder lint-suppression reasons.
  • Replace/adjust a number of unwrap() calls and some arithmetic/indexing patterns to satisfy the baseline (tests + AMM logic + PDA seed assembly).

Reviewed changes

Copilot reviewed 33 out of 33 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
Cargo.toml Adds workspace-level Rust/Clippy lint baseline.
clippy.toml Pins MSRV and configures Clippy behavior (incl. test allowances).
.github/workflows/ci.yml Adds CI checks for placeholder lint-suppression reasons and runs guest Clippy.
tools/idl-gen/Cargo.toml Opts the idl-gen tool into workspace lints.
tools/idl-gen/src/main.rs Replaces unwrap() with expect() for JSON serialization.
token/Cargo.toml Opts token program crate into workspace lints.
token/core/Cargo.toml Opts token core crate into workspace lints.
token/methods/Cargo.toml Opts token methods crate into workspace lints.
token/src/print_nft.rs Switches decrement to checked arithmetic to satisfy arithmetic linting.
token/src/tests.rs Adds test-level lint expectations and replaces unwrap() with expect().
token/methods/guest/Cargo.toml Adds standalone lint baseline for excluded token guest crate.
token/methods/guest/src/bin/token.rs Adjusts entry/no_main for tests and adds reasoned lint expectations.
ata/Cargo.toml Opts ATA program crate into workspace lints.
ata/core/Cargo.toml Opts ATA core crate into workspace lints.
ata/methods/Cargo.toml Opts ATA methods crate into workspace lints.
ata/core/src/lib.rs Removes direct slicing when assembling PDA seed bytes.
ata/methods/guest/Cargo.toml Adds standalone lint baseline for excluded ATA guest crate.
ata/methods/guest/src/bin/ata.rs Adjusts entry/no_main for tests and adds reasoned lint expectations.
amm/Cargo.toml Opts AMM program crate into workspace lints.
amm/core/Cargo.toml Opts AMM core crate into workspace lints.
amm/methods/Cargo.toml Opts AMM methods crate into workspace lints.
amm/core/src/lib.rs Removes direct slicing when assembling PDA seed bytes.
amm/src/add.rs Replaces integer division with checked division where needed.
amm/src/remove.rs Uses checked subtraction/division for liquidity math.
amm/src/new_definition.rs Uses checked subtraction for initial LP accounting.
amm/src/swap.rs Improves lint expectation reasons and uses checked arithmetic/division in swap math.
amm/src/tests.rs Adds test-level lint expectations and replaces unwrap() with expect().
amm/methods/guest/Cargo.toml Adds standalone lint baseline for excluded AMM guest crate.
amm/methods/guest/src/bin/amm.rs Adjusts entry/no_main for tests and adds reasoned lint expectations.
integration_tests/Cargo.toml Opts integration tests crate into workspace lints.
integration_tests/tests/token.rs Replaces unwrap() with expect() in test setup paths.
integration_tests/tests/ata.rs Replaces unwrap() with expect() in test setup paths.
integration_tests/tests/amm.rs Adds test-level lint expectations and replaces unwrap() with expect().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tools/idl-gen/src/main.rs Outdated
Comment on lines +13 to +17
Ok(idl) => println!(
"{}",
serde_json::to_string_pretty(&idl)
.expect("serializing generated IDL to JSON should not fail")
),
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in b194f42. The expect(...) on serde_json::to_string_pretty is now replaced with an explicit match that prints the error to stderr and calls process::exit(1), consistent with the other error branches in the CLI.

Comment thread .github/workflows/ci.yml Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 33 out of 33 changed files in this pull request and generated 2 comments.

Comment thread token/src/print_nft.rs
*print_balance -= 1;
*print_balance = print_balance
.checked_sub(1)
.expect("print balance must be greater than one after validation");
Comment thread .github/workflows/ci.yml
Comment on lines +63 to +66
if rg -n -U --multiline '#\[(allow|expect)\([\s\S]*?reason\s*=\s*"(TODO|FIXME|fix later|later|temporary|hack)' token amm ata integration_tests tools -g '*.rs'; then
echo "Found non-actionable lint suppression reason"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a staged lint baseline for LEZ programs

3 participants