Skip to content

Commit

Permalink
[ci] #3622: Use cargo manifest lints instead of unmaintained cargo-lints
Browse files Browse the repository at this point in the history
Since the implementation of rust-lang/rfcs#3389, it is now possible to specify workspace-level lints for rustc and clippy. This PR updates the cargo configuration and CI to use this new feature instead of cargo-lints.

Note that it was only stabilized in `nightly-2023-09-10`. Using it with out current toolchain requires either a -Zlints flag or a modification to `.cargo/config.toml`:

```
[unstable]
lints = true
```

Note that unlike the original suggestion in #3622, this doesn't make the lints crate level, but merely replaces a clunky unmaintained tool with a standard solution for configuring lints.

In particular this PR:
- Removes old lints.toml configuration files for cargo-lints
- Adds [lint] tables to Cargo.toml of the root and wasm workspaces. The lints are duplicated between the two
- Replaces `cargo lints clippy` invocations with `cargo clippy -Zlints` in CI scripts
- Silences/fixes some new lints that popped up due to differences in how between `cargo lints` and workspaces
- Does a drive-by fix to iroha_genesis: it now too shares cargo metadata as do other crates

Signed-off-by: Nikita Strygin <[email protected]>
  • Loading branch information
DCNick3 authored and mversic committed Oct 17, 2023
1 parent 1159a42 commit e10c860
Show file tree
Hide file tree
Showing 58 changed files with 463 additions and 181 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/iroha2-dev-pr-static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ jobs:
run: cargo fmt --all -- --check
- name: Lints without features
if: always()
run: cargo lints clippy --workspace --benches --tests --examples --no-default-features --quiet
run: cargo clippy -Zlints --workspace --benches --tests --examples --no-default-features --quiet
- name: Lints with all features enabled
if: always()
run: cargo lints clippy --workspace --benches --tests --examples --all-features --quiet
run: cargo clippy -Zlints --workspace --benches --tests --examples --all-features --quiet
- name: Documentation
if: always()
run: cargo doc --no-deps --quiet
2 changes: 1 addition & 1 deletion .github/workflows/iroha2-dev-pr-wasm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
run: cargo fmt --all -- --check
- name: Lints
if: always()
run: cargo lints clippy --workspace --benches --tests --examples --quiet
run: cargo clippy -Zlints --workspace --benches --tests --examples --quiet
- name: Documentation
if: always()
run: cargo doc --no-deps --quiet
Expand Down
152 changes: 152 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,158 @@ serde_with = { version = "2.2.0", default-features = false }
parity-scale-codec = { version = "3.2.1", default-features = false }
json5 = "0.4.1"

[workspace.lints]
rust.anonymous_parameters = "deny"

# lower the priority to allow overriding later
clippy.pedantic = { level = "deny", priority = -1 }
clippy.all = { level = "deny", priority = -1 }
clippy.dbg_macro = "deny"

# clippy.nursery = "deny"
clippy.debug_assert_with_mut_call = "deny"
clippy.derive_partial_eq_without_eq = "deny"
clippy.empty_line_after_outer_attr = "deny"
clippy.fallible_impl_from = "deny"
clippy.future_not_send = "deny"
clippy.iter_with_drain = "deny"
clippy.mutex_integer = "deny"
clippy.needless_collect = "deny"
clippy.path_buf_push_overwrite = "deny"
clippy.suboptimal_flops = "deny"
clippy.trailing_empty_array = "deny"
clippy.transmute_undefined_repr = "deny"
clippy.trivial_regex = "deny"
clippy.unused_peekable = "deny"
clippy.unused_rounding = "deny"

rust.future_incompatible = "deny"
rust.missing_copy_implementations = "deny"
rust.missing_docs = "deny"
rust.nonstandard_style = "deny"
rust.private_doc_tests = "deny"
rust.rust_2018_idioms = "deny"
rust.trivial_casts = "deny"
rust.trivial_numeric_casts = "deny"
rust.unconditional_recursion = "deny"
rust.unsafe_code = "deny"
rust.unused = "deny"
rust.unused_import_braces = "deny"
rust.variant_size_differences = "deny"
rust.unused_tuple_struct_fields = "deny"
rust.explicit_outlives_requirements = "deny"
rust.non_ascii_idents = "deny"
# TODO: reenable
# rust.unreachable_pub = "deny"
# rust.unsafe_op_in_unsafe_fn = "deny"

# These are up to personal taste. We don't want these to be enabled ever.
clippy.string_add = "allow"
clippy.as_conversions = "allow"
clippy.else_if_without_else = "allow"
clippy.enum_glob_use = "allow"
clippy.exhaustive_enums = "allow"
clippy.exhaustive_structs = "allow"
clippy.implicit_return = "allow"
clippy.inconsistent_struct_constructor = "allow"
clippy.indexing_slicing = "allow"
clippy.arithmetic_side_effects = "allow"
clippy.let_underscore_must_use = "allow"
clippy.match_wildcard_for_single_variants = "allow"
clippy.missing_docs_in_private_items = "allow"
clippy.module_name_repetitions = "allow"
clippy.shadow_reuse = "allow"
clippy.shadow_same = "allow"

# These are normally decisions, which need to be audited by a human.
clippy.unwrap_in_result = "allow"
clippy.expect_used = "allow"
clippy.unreachable = "allow"
clippy.wildcard_enum_match_arm = "allow"
clippy.wildcard_imports = "allow"
# Our preferred style.
clippy.non-ascii-literal = "allow"
clippy.std_instead_of_core = "allow"

# This lint could be useful in theory. The trade-off of making
# refactoring away from references difficult isn't worth it in all
# cases, so if it is enabled, it should be enabled locally.
clippy.pattern_type_mismatch = "allow"

# Style guide.
clippy.mod-module-files = "allow"
clippy.separated-literal-suffix = "allow"
# Most trybuild code triggers a false-positive.

# Not all public items should be inline. We only inline **trivial** functions.
clippy.missing_inline_in_public_items = "allow"

# --- Re-enable candidates -----

# Lots of false-positives.
clippy.self-named-module-files = "allow"
clippy.manual_let_else = "allow"

# We often need to shadow the name of the method to specialise.
# As soon as trait specialisation is stable we need to remove it.
clippy.same_name_method = "allow"
clippy.pub_use = "allow"

# Style guide candidate. Explicitly converting the return value to
# () is good for refactoring, and if there is necessary
# processing of the data returned by a function, it should
# **really** be marked as #[must_use]
clippy.semicolon_if_nothing_returned = "allow"

# This lint has way too many false-positives, so even enabling it
# as a warning is too much. Instead prefer adding explicit
# `#[deny]` directives
clippy.must_use_candidate = "allow"

# Unstable and many false-positives
## https://rust-lang.github.io/rust-clippy/master/index.html#missing_const_for_fn
clippy.missing_const_for_fn = "allow"

# Too much affected code. Often impossible to apply suggestion on stable rust.
rust.elided_lifetimes_in_paths = "allow"

# This lint produces a lot of false positives. Recommend local #[deny] directives
clippy.use_self = "allow"

# We don't want to manually deny every `clippy.restriction.*` lint.
clippy.blanket-clippy-restriction-lints = "allow"

# A lot of false-positive.
clippy.partial_pub_fields = "allow"

# Should be enabled per trait impl rather than globally.
clippy.missing_trait_methods = "allow"

# We allow this and deny `clippy.semicolon_inside_block`.
clippy.semicolon_outside_block = "allow"

# It is debatable whether it's actually easier to read,
# additionally, not all patterns are covered by the inlined syntax
clippy.uninlined_format_args = "allow"

rust.unknown_lints = "warn"
# these lints were duplicated, with `allow` taking precedence
# clippy.inconsistent_struct_constructor = "warn"
# clippy.match_wildcard_for_single_variants = "warn"
# clippy.arithmetic_side_effects = "warn"
clippy.option_if_let_else = "warn"
clippy.or_fun_call = "warn"
clippy.redundant_pub_crate = "warn"
clippy.string_lit_as_bytes = "warn"
clippy.suspicious_operation_groupings = "warn"
clippy.useless_let_if_seq = "warn"

# unstable
# rust.non_exhaustive_omitted_patterns = "warn"

rust.single_use_lifetimes = "warn"
rust.unused_lifetimes = "warn"

[workspace]
resolver = "2"
members = [
Expand Down
1 change: 0 additions & 1 deletion Dockerfile.build
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ RUN rustup component add llvm-tools-preview clippy
RUN rustup component add rust-src
RUN rustup component add rustfmt
RUN rustup target add wasm32-unknown-unknown
RUN cargo install cargo-lints
RUN cargo install webassembly-test-runner
RUN cargo install cargo-llvm-cov

Expand Down
1 change: 0 additions & 1 deletion Dockerfile.build.glibc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ RUN rustup component add llvm-tools-preview clippy
RUN rustup component add rust-src
RUN rustup component add rustfmt
RUN rustup target add wasm32-unknown-unknown
RUN cargo install cargo-lints
RUN cargo install webassembly-test-runner
RUN cargo install cargo-llvm-cov

Expand Down
3 changes: 3 additions & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ license.workspace = true
keywords.workspace = true
categories.workspace = true

[lints]
workspace = true

[features]
default = ["bridge", "telemetry", "schema-endpoint"]

Expand Down
3 changes: 3 additions & 0 deletions cli/derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ authors.workspace = true

license.workspace = true

[lints]
workspace = true

[lib]
proc-macro = true

Expand Down
3 changes: 3 additions & 0 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ license.workspace = true
keywords.workspace = true
categories.workspace = true

[lints]
workspace = true

[badges]
is-it-maintained-issue-resolution = { repository = "https://github.com/hyperledger/iroha" }
is-it-maintained-open-issues = { repository = "https://github.com/hyperledger/iroha" }
Expand Down
3 changes: 3 additions & 0 deletions client_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ license.workspace = true
keywords.workspace = true
categories = ["cryptography::cryptocurrencies", "command-line-utilities"]

[lints]
workspace = true

[badges]
is-it-maintained-issue-resolution = { repository = "https://github.com/hyperledger/iroha" }
is-it-maintained-open-issues = { repository = "https://github.com/hyperledger/iroha" }
Expand Down
3 changes: 3 additions & 0 deletions config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ authors.workspace = true

license.workspace = true

[lints]
workspace = true

[dependencies]
iroha_config_base = { workspace = true }
iroha_data_model = { workspace = true }
Expand Down
3 changes: 3 additions & 0 deletions config/base/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ authors.workspace = true

license.workspace = true

[lints]
workspace = true

[dependencies]
iroha_config_derive = { workspace = true }
iroha_crypto = { workspace = true, features = ["std"] }
Expand Down
3 changes: 3 additions & 0 deletions config/base/derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ authors.workspace = true

license.workspace = true

[lints]
workspace = true

[lib]
proc-macro = true

Expand Down
3 changes: 3 additions & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ license.workspace = true
keywords.workspace = true
categories.workspace = true

[lints]
workspace = true

[features]
default = ["bridge", "cli", "telemetry"]

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

license.workspace = true

[lints]
workspace = true

[features]
default = ["std"]
# Enable static linkage of the rust standard library.
Expand Down
2 changes: 2 additions & 0 deletions crypto/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! This module contains structures and implementations related to the cryptographic parts of the Iroha.
#![cfg_attr(not(feature = "std"), no_std)]
// in no_std some code gets cfg-ed out, so we silence the warnings
#![cfg_attr(not(feature = "std"), allow(unused, unused_tuple_struct_fields))]
#![allow(clippy::arithmetic_side_effects)]

#[cfg(not(feature = "std"))]
Expand Down
3 changes: 3 additions & 0 deletions data_model/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ authors.workspace = true
license.workspace = true
categories = ["cryptography::cryptocurrencies", "api-bindings"]

[lints]
workspace = true

[badges]
is-it-maintained-issue-resolution = { repository = "https://github.com/hyperledger/iroha" }
is-it-maintained-open-issues = { repository = "https://github.com/hyperledger/iroha" }
Expand Down
3 changes: 3 additions & 0 deletions data_model/derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ authors.workspace = true

license.workspace = true

[lints]
workspace = true

[lib]
proc-macro = true

Expand Down
2 changes: 2 additions & 0 deletions data_model/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
clippy::extra_unused_lifetimes, // Thanks to `EnumKind` not knowing how to write a derive macro.
clippy::items_after_test_module, // Clippy bug
)]
// in no_std some code gets cfg-ed out, so we silence the warnings
#![cfg_attr(not(feature = "std"), allow(unused, unused_tuple_struct_fields))]
#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(not(feature = "std"))]
Expand Down
12 changes: 9 additions & 3 deletions dsl/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
[package]
name = "iroha_dsl"
version = "2.0.0-pre-rc.19"
edition = "2021"
authors = ["Yasser"]

edition.workspace = true
version.workspace = true
authors.workspace = true

license.workspace = true

[lints]
workspace = true

[lib]
proc-macro = true
Expand Down
3 changes: 3 additions & 0 deletions dsl/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// TODO: add docs
#![allow(missing_docs)]

use std::{convert::TryFrom, iter::Peekable, str::FromStr};

use litrs::Literal;
Expand Down
3 changes: 3 additions & 0 deletions ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ authors.workspace = true
license.workspace = true
categories = ["development-tools::ffi"]

[lints]
workspace = true

[features]
# Enables sharing mutable references of non-robust transmutable types across FFI.
# When handing out non-robust mutable references across FFI, it's possible for the caller
Expand Down
3 changes: 3 additions & 0 deletions ffi/derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ authors.workspace = true
license.workspace = true
categories = ["development-tools::ffi"]

[lints]
workspace = true

[lib]
proc-macro = true

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

license.workspace = true

[lints]
workspace = true

[features]
default = []
# Support lightweight telemetry, including diagnostics
Expand Down
3 changes: 3 additions & 0 deletions futures/derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ authors.workspace = true

license.workspace = true

[lints]
workspace = true

[features]
default = ["telemetry"]
# Support lightweight telemetry, including diagnostics
Expand Down
Loading

0 comments on commit e10c860

Please sign in to comment.