Skip to content

Commit

Permalink
Set clippy lints in workspace (requires rust 1.74) (paritytech#2390)
Browse files Browse the repository at this point in the history
We currently use a bit of a hack in `.cargo/config` to make sure that
clippy isn't too annoying by specifying the list of lints.

There is now a stable way to define lints for a workspace. The only down
side is that every crate seems to have to opt into this so there's a
*few* files modified in this PR.

Dependencies:

- [x] PR that upgrades CI to use rust 1.74 is merged.

---------

Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>
Co-authored-by: Branislav Kontur <bkontur@gmail.com>
Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>
  • Loading branch information
4 people authored Dec 13, 2023
1 parent 4c4407a commit be8e626
Show file tree
Hide file tree
Showing 471 changed files with 1,430 additions and 37 deletions.
34 changes: 0 additions & 34 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,6 @@ rustdocflags = [
"-Arustdoc::redundant_explicit_links", # stylistic
]

# An auto defined `clippy` feature was introduced,
# but it was found to clash with user defined features,
# so was renamed to `cargo-clippy`.
#
# If you want standard clippy run:
# RUSTFLAGS= cargo clippy
[target.'cfg(feature = "cargo-clippy")']
rustflags = [
"-Aclippy::all",
"-Dclippy::correctness",
"-Aclippy::if-same-then-else",
"-Asuspicious_double_ref_op",
"-Dclippy::complexity",
"-Aclippy::zero-prefixed-literal", # 00_1000_000
"-Aclippy::type_complexity", # raison d'etre
"-Aclippy::nonminimal-bool", # maybe
"-Aclippy::borrowed-box", # Reasonable to fix this one
"-Aclippy::too-many-arguments", # (Turning this on would lead to)
"-Aclippy::unnecessary_cast", # Types may change
"-Aclippy::identity-op", # One case where we do 0 +
"-Aclippy::useless_conversion", # Types may change
"-Aclippy::unit_arg", # styalistic.
"-Aclippy::option-map-unit-fn", # styalistic
"-Aclippy::bind_instead_of_map", # styalistic
"-Aclippy::erasing_op", # E.g. 0 * DOLLARS
"-Aclippy::eq_op", # In tests we test equality.
"-Aclippy::while_immutable_condition", # false positives
"-Aclippy::needless_option_as_deref", # false positives
"-Aclippy::derivable_impls", # false positives
"-Aclippy::stable_sort_primitive", # prefer stable sort
"-Aclippy::extra-unused-type-parameters", # stylistic
"-Aclippy::default_constructed_unit_structs", # stylistic
]

[env]
# Needed for musl builds so user doesn't have to install musl-tools.
CC_x86_64_unknown_linux_musl = { value = ".cargo/musl-gcc", force = true, relative = true }
Expand Down
2 changes: 1 addition & 1 deletion .config/taplo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ reorder_arrays = false
# don't re-order order-dependent rustflags
[[rule]]
include = [".cargo/config.toml"]
keys = ["build", "target.'cfg(feature = \"cargo-clippy\")'"]
keys = ["build"]

[rule.formatting]
reorder_arrays = false
4 changes: 3 additions & 1 deletion .gitlab/pipeline/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ cargo-clippy:
- .docker-env
- .common-refs
- .pipeline-stopper-artifacts
variables:
RUSTFLAGS: "-D warnings"
script:
- SKIP_WASM_BUILD=1 env -u RUSTFLAGS cargo clippy --all-targets --locked --workspace
- SKIP_WASM_BUILD=1 cargo clippy --all-targets --locked --workspace

check-try-runtime:
stage: check
Expand Down
28 changes: 28 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,34 @@ members = [
]
default-members = ["polkadot", "substrate/bin/node/cli"]

[workspace.lints.rust]
suspicious_double_ref_op = { level = "allow", priority = 2 }

[workspace.lints.clippy]
all = { level = "allow", priority = 0 }
correctness = { level = "deny", priority = 1 }
if-same-then-else = { level = "allow", priority = 2 }
complexity = { level = "deny", priority = 1 }
zero-prefixed-literal = { level = "allow", priority = 2 } # 00_1000_000
type_complexity = { level = "allow", priority = 2 } # raison d'etre
nonminimal-bool = { level = "allow", priority = 2 } # maybe
borrowed-box = { level = "allow", priority = 2 } # Reasonable to fix this one
too-many-arguments = { level = "allow", priority = 2 } # (Turning this on would lead to)
unnecessary_cast = { level = "allow", priority = 2 } # Types may change
identity-op = { level = "allow", priority = 2 } # One case where we do 0 +
useless_conversion = { level = "allow", priority = 2 } # Types may change
unit_arg = { level = "allow", priority = 2 } # styalistic.
option-map-unit-fn = { level = "allow", priority = 2 } # styalistic
bind_instead_of_map = { level = "allow", priority = 2 } # styalistic
erasing_op = { level = "allow", priority = 2 } # E.g. 0 * DOLLARS
eq_op = { level = "allow", priority = 2 } # In tests we test equality.
while_immutable_condition = { level = "allow", priority = 2 } # false positives
needless_option_as_deref = { level = "allow", priority = 2 } # false positives
derivable_impls = { level = "allow", priority = 2 } # false positives
stable_sort_primitive = { level = "allow", priority = 2 } # prefer stable sort
extra-unused-type-parameters = { level = "allow", priority = 2 } # stylistic
default_constructed_unit_structs = { level = "allow", priority = 2 } # stylistic

[profile.release]
# Polkadot runtime requires unwinding.
panic = "unwind"
Expand Down
3 changes: 3 additions & 0 deletions bridges/bin/runtime-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ edition.workspace = true
repository.workspace = true
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"

[lints]
workspace = true

[dependencies]
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] }
hash-db = { version = "0.16.0", default-features = false }
Expand Down
3 changes: 3 additions & 0 deletions bridges/modules/grandpa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ authors.workspace = true
edition.workspace = true
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"

[lints]
workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
Expand Down
3 changes: 3 additions & 0 deletions bridges/modules/messages/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ authors.workspace = true
edition.workspace = true
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"

[lints]
workspace = true

[dependencies]
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false }
log = { version = "0.4.20", default-features = false }
Expand Down
3 changes: 3 additions & 0 deletions bridges/modules/parachains/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ authors.workspace = true
edition.workspace = true
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"

[lints]
workspace = true

[dependencies]
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false }
log = { version = "0.4.20", default-features = false }
Expand Down
3 changes: 3 additions & 0 deletions bridges/modules/relayers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ authors.workspace = true
edition.workspace = true
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"

[lints]
workspace = true

[dependencies]
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false }
log = { version = "0.4.20", default-features = false }
Expand Down
3 changes: 3 additions & 0 deletions bridges/modules/xcm-bridge-hub-router/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ authors.workspace = true
edition.workspace = true
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"

[lints]
workspace = true

[dependencies]
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false }
log = { version = "0.4.20", default-features = false }
Expand Down
3 changes: 3 additions & 0 deletions bridges/modules/xcm-bridge-hub/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ authors.workspace = true
edition.workspace = true
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"

[lints]
workspace = true

[dependencies]
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false }
log = { version = "0.4.20", default-features = false }
Expand Down
3 changes: 3 additions & 0 deletions bridges/primitives/chain-asset-hub-rococo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ authors.workspace = true
edition.workspace = true
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"

[lints]
workspace = true

[dependencies]
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false }
scale-info = { version = "2.10.0", default-features = false, features = ["derive"] }
Expand Down
3 changes: 3 additions & 0 deletions bridges/primitives/chain-asset-hub-westend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ authors.workspace = true
edition.workspace = true
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"

[lints]
workspace = true

[dependencies]
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false }
scale-info = { version = "2.10.0", default-features = false, features = ["derive"] }
Expand Down
3 changes: 3 additions & 0 deletions bridges/primitives/chain-bridge-hub-cumulus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ authors.workspace = true
edition.workspace = true
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"

[lints]
workspace = true

[dependencies]
# Bridge Dependencies

Expand Down
3 changes: 3 additions & 0 deletions bridges/primitives/chain-bridge-hub-kusama/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ authors.workspace = true
edition.workspace = true
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"

[lints]
workspace = true

[dependencies]
# Bridge Dependencies

Expand Down
3 changes: 3 additions & 0 deletions bridges/primitives/chain-bridge-hub-polkadot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ authors.workspace = true
edition.workspace = true
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"

[lints]
workspace = true

[dependencies]

# Bridge Dependencies
Expand Down
3 changes: 3 additions & 0 deletions bridges/primitives/chain-bridge-hub-rococo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ authors.workspace = true
edition.workspace = true
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"

[lints]
workspace = true

[dependencies]
# Bridge Dependencies

Expand Down
3 changes: 3 additions & 0 deletions bridges/primitives/chain-bridge-hub-westend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ authors.workspace = true
edition.workspace = true
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"

[lints]
workspace = true

[dependencies]

# Bridge Dependencies
Expand Down
3 changes: 3 additions & 0 deletions bridges/primitives/chain-kusama/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ authors.workspace = true
edition.workspace = true
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"

[lints]
workspace = true

[dependencies]

# Bridge Dependencies
Expand Down
3 changes: 3 additions & 0 deletions bridges/primitives/chain-polkadot-bulletin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ authors.workspace = true
edition.workspace = true
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"

[lints]
workspace = true

[dependencies]
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] }
scale-info = { version = "2.10.0", default-features = false, features = ["derive"] }
Expand Down
3 changes: 3 additions & 0 deletions bridges/primitives/chain-polkadot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ authors.workspace = true
edition.workspace = true
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"

[lints]
workspace = true

[dependencies]

# Bridge Dependencies
Expand Down
3 changes: 3 additions & 0 deletions bridges/primitives/chain-rococo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ authors.workspace = true
edition.workspace = true
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"

[lints]
workspace = true

[dependencies]

# Bridge Dependencies
Expand Down
3 changes: 3 additions & 0 deletions bridges/primitives/chain-westend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ authors.workspace = true
edition.workspace = true
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"

[lints]
workspace = true

[dependencies]

# Bridge Dependencies
Expand Down
3 changes: 3 additions & 0 deletions bridges/primitives/header-chain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ authors.workspace = true
edition.workspace = true
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"

[lints]
workspace = true

[dependencies]
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false }
finality-grandpa = { version = "0.16.2", default-features = false }
Expand Down
3 changes: 3 additions & 0 deletions bridges/primitives/messages/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ authors.workspace = true
edition.workspace = true
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"

[lints]
workspace = true

[dependencies]
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["bit-vec", "derive"] }
scale-info = { version = "2.10.0", default-features = false, features = ["bit-vec", "derive"] }
Expand Down
3 changes: 3 additions & 0 deletions bridges/primitives/parachains/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ authors.workspace = true
edition.workspace = true
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"

[lints]
workspace = true

[dependencies]
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] }
impl-trait-for-tuples = "0.2"
Expand Down
3 changes: 3 additions & 0 deletions bridges/primitives/polkadot-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ authors.workspace = true
edition.workspace = true
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"

[lints]
workspace = true

[dependencies]
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] }
parity-util-mem = { version = "0.12.0", optional = true }
Expand Down
3 changes: 3 additions & 0 deletions bridges/primitives/relayers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ authors.workspace = true
edition.workspace = true
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"

[lints]
workspace = true

[dependencies]
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["bit-vec", "derive"] }
scale-info = { version = "2.10.0", default-features = false, features = ["bit-vec", "derive"] }
Expand Down
3 changes: 3 additions & 0 deletions bridges/primitives/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ authors.workspace = true
edition.workspace = true
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"

[lints]
workspace = true

[dependencies]
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false }
hash-db = { version = "0.16.0", default-features = false }
Expand Down
3 changes: 3 additions & 0 deletions bridges/primitives/test-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ authors.workspace = true
edition.workspace = true
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"

[lints]
workspace = true

[dependencies]
bp-header-chain = { path = "../header-chain", default-features = false }
bp-parachains = { path = "../parachains", default-features = false }
Expand Down
3 changes: 3 additions & 0 deletions bridges/primitives/xcm-bridge-hub-router/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ authors.workspace = true
edition.workspace = true
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"

[lints]
workspace = true

[dependencies]
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["bit-vec", "derive"] }
scale-info = { version = "2.10.0", default-features = false, features = ["bit-vec", "derive"] }
Expand Down
3 changes: 3 additions & 0 deletions bridges/primitives/xcm-bridge-hub/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ authors.workspace = true
edition.workspace = true
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"

[lints]
workspace = true

[dependencies]

# Substrate Dependencies
Expand Down
3 changes: 3 additions & 0 deletions cumulus/client/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ edition.workspace = true
description = "Parachain node CLI utilities."
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"

[lints]
workspace = true

[dependencies]
clap = { version = "4.4.11", features = ["derive"] }
codec = { package = "parity-scale-codec", version = "3.0.0" }
Expand Down
3 changes: 3 additions & 0 deletions cumulus/client/collator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ edition.workspace = true
description = "Common node-side functionality and glue code to collate parachain blocks."
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"

[lints]
workspace = true

[dependencies]
parking_lot = "0.12.1"
codec = { package = "parity-scale-codec", version = "3.0.0", features = ["derive"] }
Expand Down
Loading

0 comments on commit be8e626

Please sign in to comment.