Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed Cranky and started using Cargo's lints table #37

Merged
merged 11 commits into from
Dec 6, 2023
12 changes: 4 additions & 8 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ jobs:
uses: baptiste0928/cargo-install@v2
with:
crate: cargo-nextest
- name: install cranky
uses: baptiste0928/cargo-install@v2
with:
crate: cargo-cranky
- name: install deny
uses: baptiste0928/cargo-install@v2
with:
Expand All @@ -46,10 +42,10 @@ jobs:
run: cargo deny check
- name: fmt
run: cargo fmt --all --check
- name: cranky (all features)
run: cargo cranky --workspace --all-targets --all-features
- name: cranky (default features)
run: cargo cranky --workspace --exclude tools --all-targets
- name: clippy (all features)
run: cargo clippy --workspace --all-targets --all-features
- name: clippy (default features)
run: cargo clippy --workspace --exclude zksync_consensus_tools --all-targets
- name: build
run: cargo build --all-targets --locked
- name: test
Expand Down
18 changes: 0 additions & 18 deletions docs/style.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,6 @@ And then run tests with:
cargo nextest run
```

### Linting

We use a particular tool called `cargo cranky` in order to be able to apply a set of lints to an entire workspace. You
just need to install it with:

```
cargo install cargo-cranky
```

and then you can run it just like you would run clippy:

```
cargo cranky --all-targets --all-features
```

Note: There's a [RFC](https://github.com/rust-lang/rfcs/pull/3389) underway to add lints to `Cargo.toml``. But until that
happens, we are stuck with cranky.

## Codebase Layout

We want the files to be relatively small in general (lets say, <500 LoC), so feel free to split the module into multiple files
Expand Down
63 changes: 54 additions & 9 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,75 @@ authors = ["The Matter Labs Team <[email protected]>"]
homepage = "https://matter-labs.io/"
license = "MIT"

[workspace.lints.rust]
unsafe_code = "forbid"
noop_method_call = "warn"
missing_docs = "warn"
unreachable_pub = "warn"
unused_qualifications = "warn"
unused_tuple_struct_fields = "warn"

[workspace.lints.clippy]
# restriction group
create_dir = "warn"
empty_structs_with_brackets = "warn"
float_arithmetic = "warn"
missing_docs_in_private_items = "warn"
non_ascii_literal = "warn"
partial_pub_fields = "warn"
print_stdout = "warn"
brunoffranca marked this conversation as resolved.
Show resolved Hide resolved
string_to_string = "warn"
suspicious_xor_used_as_pow = "warn"
try_err = "warn"
separated_literal_suffix = "warn"

# pedantic group
bool_to_int_with_if = "warn"
default_trait_access = "warn"
if_not_else = "warn"
manual_assert = "warn"
manual_instant_elapsed = "warn"
manual_let_else = "warn"
manual_ok_or = "warn"
manual_string_new = "warn"
match_bool = "warn"
wildcard_imports = "warn"

# cargo group
wildcard_dependencies = "warn"

# Produces too many false positives.
redundant_locals = "allow"
needless_pass_by_ref_mut = "allow"

[workspace.dependencies]
zksync_protobuf_build = { path = "libs/protobuf_build" }
zksync_protobuf = { path = "libs/protobuf" }
zksync_concurrency = { path = "libs/concurrency" }
# Crates from this repo.
zksync_consensus_bft = { path = "actors/bft" }
zksync_consensus_crypto = { path = "libs/crypto" }
zksync_consensus_executor = { path = "actors/executor" }
zksync_consensus_network = { path = "actors/network" }
zksync_consensus_sync_blocks = { path = "actors/sync_blocks" }
zksync_consensus_roles = { path = "libs/roles" }
zksync_consensus_storage = { path = "libs/storage" }
zksync_consensus_sync_blocks = { path = "actors/sync_blocks" }
zksync_consensus_tools = { path = "tools" }
zksync_consensus_utils = { path = "libs/utils" }

# Crates from this repo that might become independent in the future.
zksync_concurrency = { path = "libs/concurrency" }
zksync_protobuf = { path = "libs/protobuf" }
zksync_protobuf_build = { path = "libs/protobuf_build" }

# Crates from Matter Labs.
pairing = { package = "pairing_ce", git = "https://github.com/matter-labs/pairing.git", rev = "f55393f" }
vise = { version = "0.1.0", git = "https://github.com/matter-labs/vise.git", rev = "dd05139b76ab0843443ab3ff730174942c825dae" }
vise-exporter = { version = "0.1.0", git = "https://github.com/matter-labs/vise.git", rev = "dd05139b76ab0843443ab3ff730174942c825dae" }

# Crates from third-parties.
anyhow = "1"
assert_matches = "1.5.0"
async-trait = "0.1.71"
bit-vec = "0.6"
blst = "0.3.10"
pairing = { package = "pairing_ce", git = "https://github.com/matter-labs/pairing.git", rev = "f55393f" }
ff_ce = "0.14.3"
clap = { version = "4.3.3", features = ["derive"] }
heck = "0.4.1"
Expand Down Expand Up @@ -70,13 +119,9 @@ tempfile = "3"
test-casing = "0.1.0"
thiserror = "1.0.40"
time = "0.3.23"
# TODO(gprusak): only concurrency crate should depend on tokio.
# All the other crates should depend on concurrency.
tokio = { version = "1.34.0", features = ["full"] }
tracing = { version = "0.1.37", features = ["attributes"] }
tracing-subscriber = { version = "0.3.16", features = ["env-filter", "fmt"] }
vise = { version = "0.1.0", git = "https://github.com/matter-labs/vise.git", rev = "dd05139b76ab0843443ab3ff730174942c825dae" }
vise-exporter = { version = "0.1.0", git = "https://github.com/matter-labs/vise.git", rev = "dd05139b76ab0843443ab3ff730174942c825dae" }

# Note that "bench" profile inherits from "release" profile and
# "test" profile inherits from "dev" profile.
Expand Down
45 changes: 0 additions & 45 deletions node/Cranky.toml

This file was deleted.

3 changes: 3 additions & 0 deletions node/actors/bft/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ authors.workspace = true
homepage.workspace = true
license.workspace = true

[lints]
workspace = true

[dependencies]
zksync_concurrency.workspace = true
zksync_consensus_crypto.workspace = true
Expand Down
3 changes: 3 additions & 0 deletions node/actors/executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ authors.workspace = true
homepage.workspace = true
license.workspace = true

[lints]
workspace = true

[dependencies]
zksync_concurrency.workspace = true
zksync_consensus_bft.workspace = true
Expand Down
3 changes: 3 additions & 0 deletions node/actors/network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ authors.workspace = true
homepage.workspace = true
license.workspace = true

[lints]
workspace = true

[dependencies]
zksync_concurrency.workspace = true
zksync_consensus_crypto.workspace = true
Expand Down
3 changes: 3 additions & 0 deletions node/actors/sync_blocks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ authors.workspace = true
homepage.workspace = true
license.workspace = true

[lints]
workspace = true

[dependencies]
zksync_concurrency.workspace = true
zksync_consensus_network.workspace = true
Expand Down
40 changes: 40 additions & 0 deletions node/libs/concurrency/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,46 @@ authors.workspace = true
homepage.workspace = true
license.workspace = true

[lints.rust]
brunoffranca marked this conversation as resolved.
Show resolved Hide resolved
noop_method_call = "warn"
missing_docs = "warn"
unreachable_pub = "warn"
unused_qualifications = "warn"
unused_tuple_struct_fields = "warn"

[lints.clippy]
# restriction group
create_dir = "warn"
empty_structs_with_brackets = "warn"
float_arithmetic = "warn"
missing_docs_in_private_items = "warn"
non_ascii_literal = "warn"
partial_pub_fields = "warn"
print_stdout = "warn"
string_to_string = "warn"
suspicious_xor_used_as_pow = "warn"
try_err = "warn"
separated_literal_suffix = "warn"

# pedantic group
bool_to_int_with_if = "warn"
default_trait_access = "warn"
if_not_else = "warn"
manual_assert = "warn"
manual_instant_elapsed = "warn"
manual_let_else = "warn"
manual_ok_or = "warn"
manual_string_new = "warn"
match_bool = "warn"
wildcard_imports = "warn"

# cargo group
wildcard_dependencies = "warn"

# Produces too many false positives.
redundant_locals = "allow"
needless_pass_by_ref_mut = "allow"

[dependencies]
anyhow.workspace = true
once_cell.workspace = true
Expand Down
1 change: 0 additions & 1 deletion node/libs/concurrency/src/scope/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
// TODO(gprusak): add more tests
// TODO(gprusak): add simple useful real-life examples
// TODO(gprusak): add a style guide on how to use scopes.
#![allow(unsafe_code)]
use crate::{ctx, time};
use std::{
future::Future,
Expand Down
3 changes: 3 additions & 0 deletions node/libs/crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ authors.workspace = true
homepage.workspace = true
license.workspace = true

[lints]
workspace = true

[dependencies]
anyhow.workspace = true
blst.workspace = true
Expand Down
4 changes: 3 additions & 1 deletion node/libs/protobuf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ edition.workspace = true
authors.workspace = true
homepage.workspace = true
license.workspace = true

links = "zksync_protobuf_proto"

[lints]
workspace = true

[[bin]]
name = "conformance_test"

Expand Down
3 changes: 3 additions & 0 deletions node/libs/protobuf_build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ authors.workspace = true
homepage.workspace = true
license.workspace = true

[lints]
workspace = true

[dependencies]
anyhow.workspace = true
heck.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion node/libs/protobuf_build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ impl Config {
.context("prepare_output_dir()")?;
let output_path = output_dir.join("gen.rs");
let descriptor_path = output_dir.join("gen.binpb");
fs::write(&descriptor_path, &descriptor.encode_to_vec())?;
fs::write(&descriptor_path, descriptor.encode_to_vec())?;

if self.is_public {
let manifest = Manifest {
Expand Down
4 changes: 3 additions & 1 deletion node/libs/roles/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ edition.workspace = true
authors.workspace = true
homepage.workspace = true
license.workspace = true

links = "zksync_consensus_roles_proto"

[lints]
workspace = true

[dependencies]
zksync_concurrency.workspace = true
zksync_consensus_crypto.workspace = true
Expand Down
3 changes: 3 additions & 0 deletions node/libs/storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ authors.workspace = true
homepage.workspace = true
license.workspace = true

[lints]
workspace = true

[dependencies]
zksync_concurrency.workspace = true
zksync_consensus_roles.workspace = true
Expand Down
3 changes: 3 additions & 0 deletions node/libs/utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ authors.workspace = true
homepage.workspace = true
license.workspace = true

[lints]
workspace = true

[dependencies]
zksync_concurrency.workspace = true

Expand Down
3 changes: 3 additions & 0 deletions node/tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ license.workspace = true
publish = false
default-run = "executor"

[lints]
workspace = true

[dependencies]
zksync_concurrency.workspace = true
zksync_consensus_bft.workspace = true
Expand Down
Loading