chore: use workspace lints

Among other things, this allows tools and LSP to pick up our settings.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This commit is contained in:
Marc-André Lureau 2024-07-23 15:21:31 +04:00 committed by Benoît Cortier
parent 05fc85bb13
commit 7307148cb8
40 changed files with 234 additions and 80 deletions

View file

@ -70,6 +70,93 @@ lazy_static = "1.4" # prefer https://doc.rust-lang.org/std/sync/struct.OnceLock.
num-derive = "0.4"
num-traits = "0.2"
[workspace.lints.rust]
# Safer unsafe
unsafe_op_in_unsafe_fn = "warn"
invalid_reference_casting = "warn"
pointer_structural_match = "warn"
# Correctness
unused_tuple_struct_fields = "warn"
# Style, readability
# https://quinedot.github.io/rust-learning/dont-hide.htm
elided_lifetimes_in_paths = "warn"
absolute_paths_not_starting_with_crate = "warn"
single_use_lifetimes = "warn"
unreachable_pub = "warn"
unused_lifetimes = "warn"
unused_qualifications = "warn"
keyword_idents = "warn"
noop_method_call = "warn"
# TODO: NOTE(@CBenoit): we probably want to ensure this in core tier crates only
# missing_docs = "warn"
# Compile-time / optimization
unused_crate_dependencies = "warn"
unused_macro_rules = "warn"
[workspace.lints.clippy]
# Safer unsafe
undocumented_unsafe_blocks = "warn"
# FIXME: https://github.com/rust-lang/rust-clippy/issues/11312 (fixed for 1.75.0)
# multiple_unsafe_ops_per_block = "warn"
transmute_ptr_to_ptr = "warn"
as_ptr_cast_mut = "warn"
cast_ptr_alignment = "warn"
fn_to_numeric_cast_any = "warn"
ptr_cast_constness = "warn"
# Correctness
arithmetic_side_effects = "warn"
cast_lossless = "warn"
cast_possible_truncation = "warn"
cast_possible_wrap = "warn"
cast_sign_loss = "warn"
float_cmp = "warn"
as_underscore = "warn"
# TODO: lets either handle `None`, `Err` or use `expect` to give a reason
# unwrap_used = "warn"
large_stack_frames = "warn"
# Style, readability
# with semicolon-outside-block-ignore-multiline = true
semicolon_outside_block = "warn"
clone_on_ref_ptr = "warn"
cloned_instead_of_copied = "warn"
trait_duplication_in_bounds = "warn"
type_repetition_in_bounds = "warn"
checked_conversions = "warn"
get_unwrap = "warn"
# TODO: reduce risk of confusing similar names together, and protects against
# typos when variable shadowing was intended
# similar_names = "warn"
str_to_string = "warn"
string_to_string = "warn"
# TODO: std_instead_of_alloc = "warn"
# TODO: std_instead_of_core = "warn"
separated_literal_suffix = "warn"
unused_self = "warn"
# TODO: use_self = "warn" # NOTE(@CBenoit): not sure about that one
useless_let_if_seq = "warn"
# TODO: partial_pub_fields = "warn"
string_add = "warn"
range_plus_one = "warn"
# Compile-time / optimization
inline_always = "warn"
or_fun_call = "warn"
unnecessary_box_returns = "warn"
# Extra-pedantic clippy
collection_is_never_read = "warn"
copy_iterator = "warn"
expl_impl_clone_on_copy = "warn"
implicit_clone = "warn"
large_types_passed_by_value = "warn"
redundant_clone = "warn"
alloc_instead_of_core = "warn"
empty_drop = "warn"
return_self_not_must_use = "warn"
wildcard_dependencies = "warn"
# Lets not merge unintended eprint!/print! statements in libraries
print_stderr = "warn"
print_stdout = "warn"
dbg_macro = "warn"
[profile.dev]
opt-level = 1

View file

@ -1,3 +1,4 @@
msrv = "1.75"
semicolon-outside-block-ignore-multiline = true
accept-comment-above-statement = true
accept-comment-above-attributes = true

View file

@ -21,3 +21,7 @@ ironrdp-svc.workspace = true
ironrdp-connector.workspace = true
ironrdp-async.workspace = true
tracing.workspace = true
[lints]
workspace = true

View file

@ -22,3 +22,7 @@ bitflags.workspace = true
num-derive.workspace = true # TODO: remove
num-traits.workspace = true # TODO: remove
[lints]
workspace = true

View file

@ -21,3 +21,7 @@ ironrdp-connector.workspace = true
ironrdp-pdu.workspace = true
# ironrdp-session.workspace = true
tracing.workspace = true
[lints]
workspace = true

View file

@ -21,3 +21,7 @@ ironrdp-connector.workspace = true
ironrdp-pdu.workspace = true
# ironrdp-session.workspace = true
tracing.workspace = true
[lints]
workspace = true

View file

@ -43,3 +43,7 @@ anyhow = "1.0"
# GUI
glutin = "0.29"
ironrdp-glutin-renderer = { path = "../glutin-renderer"}
[lints]
workspace = true

View file

@ -64,3 +64,7 @@ url = "2.5"
windows = { version = "0.48", features = [
"Win32_Foundation",
] }
[lints]
workspace = true

View file

@ -20,3 +20,7 @@ test = false
ironrdp-pdu.workspace = true
thiserror.workspace = true
png = "0.17"
[lints]
workspace = true

View file

@ -30,3 +30,7 @@ windows = { version = "0.48", features = [
"Win32_UI_Shell",
"Win32_UI_WindowsAndMessaging"
] }
[lints]
workspace = true

View file

@ -22,3 +22,7 @@ ironrdp-svc.workspace = true
thiserror.workspace = true
tracing.workspace = true
bitflags.workspace = true
[lints]
workspace = true

View file

@ -33,3 +33,7 @@ url = "2.5"
# NOTE: can be removed after #260 is merged
[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = ["std"] }
[lints]
workspace = true

View file

@ -16,3 +16,7 @@ ironrdp-dvc.workspace = true
ironrdp-pdu.workspace = true
ironrdp-svc.workspace = true
tracing.workspace = true
[lints]
workspace = true

View file

@ -24,3 +24,7 @@ ironrdp-svc.workspace = true
ironrdp-pdu = { workspace = true, features = ["alloc"] }
tracing.workspace = true
slab = "0.4"
[lints]
workspace = true

View file

@ -19,3 +19,7 @@ test = false
default = []
std = ["alloc"]
alloc = []
[lints]
workspace = true

View file

@ -19,3 +19,7 @@ test = false
bytes = "1"
futures-util = { version = "0.3", features = ["io"] }
ironrdp-async.workspace = true
[lints]
workspace = true

View file

@ -19,3 +19,7 @@ ironrdp-rdpsnd.workspace = true
ironrdp-cliprdr-format.workspace = true
ironrdp-displaycontrol.workspace = true
ironrdp-svc.workspace = true
[lints]
workspace = true

View file

@ -18,3 +18,7 @@ thiserror.workspace = true
glow = "0.12"
glutin = { version = "0.29" }
openh264 = { version = "0.4" }
[lints]
workspace = true

View file

@ -30,3 +30,7 @@ thiserror.workspace = true
[dev-dependencies]
bmp = "0.5"
expect-test.workspace = true
[lints]
workspace = true

View file

@ -19,3 +19,7 @@ test = false
ironrdp-pdu.workspace = true
bitvec = "1.0"
smallvec = "1.13"
[lints]
workspace = true

View file

@ -12,3 +12,7 @@ test = false
[dependencies]
# ironrdp-pdu.workspace = true
# proptest.workspace = true
[lints]
workspace = true

View file

@ -42,3 +42,7 @@ pkcs1 = "0.7"
[dev-dependencies]
expect-test.workspace = true
lazy_static.workspace = true # TODO: remove in favor of https://doc.rust-lang.org/std/sync/struct.OnceLock.html
[lints]
workspace = true

View file

@ -16,4 +16,7 @@ doctest = false
test = false
[dependencies]
der = { version = "0.7", features = ["alloc", "derive"] }
der = { version = "0.7", features = ["alloc", "derive"] }
[lints]
workspace = true

View file

@ -21,3 +21,7 @@ ironrdp-pdu.workspace = true
ironrdp-svc.workspace = true
tracing.workspace = true
bitflags.workspace = true
[lints]
workspace = true

View file

@ -22,3 +22,7 @@ tracing.workspace = true
[dev-dependencies]
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
[lints]
workspace = true

View file

@ -24,3 +24,7 @@ bitflags.workspace = true
tracing.workspace = true
ironrdp-svc.workspace = true
ironrdp-pdu = { workspace = true, features = ["alloc"] }
[lints]
workspace = true

View file

@ -18,3 +18,7 @@ tracing.workspace = true
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
clap = { version = "4.2", features = ["derive", "cargo"] }
glutin = { version = "0.29" }
[lints]
workspace = true

View file

@ -34,3 +34,7 @@ tracing.workspace = true
[dev-dependencies]
tokio = { version = "1", features = ["sync"] }
[lints]
workspace = true

View file

@ -13,3 +13,7 @@ test = false
# ironrdp-session.workspace = true
# ironrdp-pdu-generators.workspace = true
# proptest.workspace = true
[lints]
workspace = true

View file

@ -24,3 +24,7 @@ ironrdp-graphics.workspace = true
ironrdp-pdu = { workspace = true, features = ["std"] }
ironrdp-displaycontrol.workspace = true
tracing.workspace = true
[lints]
workspace = true

View file

@ -22,3 +22,7 @@ std = []
[dependencies]
ironrdp-pdu = { workspace = true, features = ["alloc"] }
bitflags.workspace = true
[lints]
workspace = true

View file

@ -40,3 +40,7 @@ proptest.workspace = true
rstest.workspace = true
expect-test.workspace = true
anyhow = "1"
[lints]
workspace = true

View file

@ -26,3 +26,7 @@ tokio = { version = "1.36" }
x509-cert = { version = "0.2", default-features = false, features = ["std"], optional = true }
tokio-native-tls = { version = "0.3", optional = true }
tokio-rustls = { version = "0.26", optional = true }
[lints]
workspace = true

View file

@ -19,3 +19,7 @@ test = false
bytes = "1"
ironrdp-async.workspace = true
tokio = { version = "1", features = ["io-util"] }
[lints]
workspace = true

View file

@ -71,3 +71,7 @@ tap = "1"
semver = "1"
url = "2.5"
base64 = "0.22"
[lints]
workspace = true

View file

@ -74,3 +74,7 @@ doc-scrape-examples = true
[[example]]
name = "server"
doc-scrape-examples = true
[lints]
workspace = true

View file

@ -33,3 +33,7 @@ embed-resource = "2.4"
windows = { version = "0.48", features = [
"Win32_Foundation",
] }
[lints]
workspace = true

View file

@ -47,3 +47,4 @@ path = "fuzz_targets/channel_processing.rs"
test = false
doc = false
bench = false

View file

@ -13,3 +13,7 @@ anyhow = "1"
pico-args = "0.5"
xshell = "0.2"
tinyjson = "2.5"
[lints]
workspace = true

View file

@ -1,81 +1,5 @@
use crate::prelude::*;
// TODO: when 1.74 is released use `[lints]`: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#lints
const EXTRA_LINTS: &[&str] = &[
// == Safer unsafe == //
"unsafe_op_in_unsafe_fn",
"invalid_reference_casting",
"pointer_structural_match",
"clippy::undocumented_unsafe_blocks",
// "clippy::multiple_unsafe_ops_per_block", // FIXME: https://github.com/rust-lang/rust-clippy/issues/11312 (fixed for 1.75.0)
"clippy::transmute_ptr_to_ptr",
"clippy::as_ptr_cast_mut",
"clippy::cast_ptr_alignment",
"clippy::fn_to_numeric_cast_any",
"clippy::ptr_cast_constness",
// == Correctness == //
"unused_tuple_struct_fields",
"clippy::arithmetic_side_effects",
"clippy::cast_lossless",
"clippy::cast_possible_truncation",
"clippy::cast_possible_wrap",
"clippy::cast_sign_loss",
"clippy::float_cmp",
"clippy::as_underscore",
// TODO: "clippy::unwrap_used", // lets either handle `None`, `Err` or use `expect` to give a reason
"clippy::large_stack_frames",
// == Style, readability == //
"elided_lifetimes_in_paths", // https://quinedot.github.io/rust-learning/dont-hide.html
"absolute_paths_not_starting_with_crate",
"single_use_lifetimes",
"unreachable_pub",
"unused_lifetimes",
"unused_qualifications",
"keyword_idents",
"noop_method_call",
"clippy::semicolon_outside_block", // with semicolon-outside-block-ignore-multiline = true
"clippy::clone_on_ref_ptr",
"clippy::cloned_instead_of_copied",
"clippy::trait_duplication_in_bounds",
"clippy::type_repetition_in_bounds",
"clippy::checked_conversions",
"clippy::get_unwrap",
// TODO: "clippy::similar_names", // reduce risk of confusing similar names together, and protects against typos when variable shadowing was intended
"clippy::str_to_string",
"clippy::string_to_string",
// TODO: "clippy::std_instead_of_alloc",
// TODO: "clippy::std_instead_of_core",
"clippy::separated_literal_suffix",
"clippy::unused_self",
// TODO: "clippy::use_self", // NOTE(@CBenoit): not sure about that one
"clippy::useless_let_if_seq",
// TODO: "clippy::partial_pub_fields",
"clippy::string_add",
"clippy::range_plus_one",
// TODO: "missing_docs" // NOTE(@CBenoit): we probably want to ensure this in core tier crates only
// == Compile-time / optimization == //
"unused_crate_dependencies",
"unused_macro_rules",
"clippy::inline_always",
"clippy::or_fun_call",
"clippy::unnecessary_box_returns",
// == Extra-pedantic clippy == //
"clippy::collection_is_never_read",
"clippy::copy_iterator",
"clippy::expl_impl_clone_on_copy",
"clippy::implicit_clone",
"clippy::large_types_passed_by_value",
"clippy::redundant_clone",
"clippy::alloc_instead_of_core",
"clippy::empty_drop",
"clippy::return_self_not_must_use",
"clippy::wildcard_dependencies",
// == Lets not merge unintended eprint!/print! statements in libraries == //
"clippy::print_stderr",
"clippy::print_stdout",
"clippy::dbg_macro",
];
pub fn fmt(sh: &Shell) -> anyhow::Result<()> {
let _s = Section::new("FORMATTING");
@ -94,9 +18,7 @@ pub fn lints(sh: &Shell) -> anyhow::Result<()> {
let _s = Section::new("LINTS");
// TODO: when 1.74 is released use `--keep-going`: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#keep-going
let cmd = cmd!(sh, "{CARGO} clippy --workspace --locked -- -D warnings");
EXTRA_LINTS.iter().fold(cmd, |cmd, lint| cmd.args(["-W", lint])).run()?;
cmd!(sh, "{CARGO} clippy --workspace --locked -- -D warnings").run()?;
println!("All good!");