Skip to content

Commit

Permalink
More agressive clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Apr 18, 2024
1 parent 993dfd7 commit f6d0112
Show file tree
Hide file tree
Showing 8 changed files with 211 additions and 10 deletions.
53 changes: 44 additions & 9 deletions Cranky.toml
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
# Copied from https://github.com/rerun-io/rerun_template
#
# https://github.com/ericseppanen/cargo-cranky
# cargo install cargo-cranky && cargo cranky
# See also clippy.toml

deny = [
"unsafe_code",
# Disabled waiting on https://github.com/rust-lang/rust-clippy/issues/9602
#"clippy::self_named_module_files",
#"clippy::self_named_module_files", # Disabled waiting on https://github.com/rust-lang/rust-clippy/issues/9602
]

warn = [
"clippy::all",
"clippy::as_ptr_cast_mut",
"clippy::await_holding_lock",
"clippy::bool_to_int_with_if",
"clippy::char_lit_as_u8",
"clippy::checked_conversions",
"clippy::clear_with_drain",
"clippy::cloned_instead_of_copied",
"clippy::cloned_instead_of_copied",
"clippy::dbg_macro",
"clippy::debug_assert_with_mut_call",
"clippy::derive_partial_eq_without_eq",
"clippy::disallowed_methods",
"clippy::disallowed_script_idents",
"clippy::disallowed_macros", # See clippy.toml
"clippy::disallowed_methods", # See clippy.toml
"clippy::disallowed_names", # See clippy.toml
"clippy::disallowed_script_idents", # See clippy.toml
"clippy::disallowed_types", # See clippy.toml
"clippy::doc_link_with_quotes",
"clippy::doc_markdown",
"clippy::empty_enum",
Expand All @@ -35,6 +44,7 @@ warn = [
"clippy::fn_params_excessive_bools",
"clippy::fn_to_numeric_cast_any",
"clippy::from_iter_instead_of_collect",
"clippy::get_unwrap",
"clippy::if_let_mutex",
"clippy::implicit_clone",
"clippy::imprecise_flops",
Expand All @@ -45,14 +55,19 @@ warn = [
"clippy::iter_on_empty_collections",
"clippy::iter_on_single_items",
"clippy::large_digit_groups",
"clippy::large_include_file",
"clippy::large_stack_arrays",
"clippy::large_stack_frames",
"clippy::large_types_passed_by_value",
"clippy::let_underscore_untyped",
"clippy::let_unit_value",
"clippy::linkedlist",
"clippy::lossy_float_literal",
"clippy::macro_use_imports",
"clippy::manual_assert",
"clippy::manual_clamp",
"clippy::manual_instant_elapsed",
"clippy::manual_let_else",
"clippy::manual_ok_or",
"clippy::manual_string_new",
"clippy::map_err_ignore",
Expand All @@ -65,42 +80,64 @@ warn = [
"clippy::mem_forget",
"clippy::mismatched_target_os",
"clippy::mismatching_type_param_order",
"clippy::missing_assert_message",
"clippy::missing_enforced_import_renames",
"clippy::missing_errors_doc",
"clippy::missing_safety_doc",
"clippy::mut_mut",
"clippy::mutex_integer",
"clippy::needless_borrow",
"clippy::needless_continue",
"clippy::needless_for_each",
"clippy::needless_pass_by_ref_mut",
"clippy::needless_pass_by_value",
"clippy::negative_feature_names",
"clippy::nonstandard_macro_braces",
"clippy::option_option",
"clippy::path_buf_push_overwrite",
"clippy::ptr_as_ptr",
"clippy::ptr_cast_constness",
"clippy::pub_without_shorthand",
"clippy::rc_mutex",
"clippy::readonly_write_lock",
"clippy::redundant_type_annotations",
"clippy::ref_option_ref",
"clippy::ref_patterns",
"clippy::rest_pat_in_fully_bound_structs",
"clippy::same_functions_in_if_condition",
"clippy::semicolon_if_nothing_returned",
"clippy::significant_drop_tightening",
"clippy::single_match_else",
"clippy::str_to_string",
"clippy::string_add_assign",
"clippy::string_add",
"clippy::string_lit_as_bytes",
"clippy::string_lit_chars_any",
"clippy::string_to_string",
"clippy::suspicious_command_arg_space",
"clippy::suspicious_xor_used_as_pow",
"clippy::todo",
"clippy::too_many_lines",
"clippy::trailing_empty_array",
"clippy::trait_duplication_in_bounds",
"clippy::tuple_array_conversions",
"clippy::unchecked_duration_subtraction",
"clippy::undocumented_unsafe_blocks",
"clippy::unimplemented",
"clippy::uninlined_format_args",
"clippy::unnecessary_box_returns",
"clippy::unnecessary_safety_doc",
"clippy::unnecessary_struct_initialization",
"clippy::unnecessary_wraps",
"clippy::unnested_or_patterns",
"clippy::unused_peekable",
"clippy::unused_rounding",
"clippy::unused_self",
"clippy::unwrap_used",
"clippy::useless_transmute",
"clippy::verbose_file_reads",
"clippy::wildcard_dependencies",
"clippy::wildcard_imports",
"clippy::zero_sized_map_values",
"elided_lifetimes_in_paths",
"future_incompatible",
Expand All @@ -109,17 +146,15 @@ warn = [
"rust_2021_prelude_collisions",
"rustdoc::missing_crate_level_docs",
"semicolon_in_expressions_from_macros",
"trivial_casts",
"trivial_numeric_casts",
"unsafe_op_in_unsafe_fn", # `unsafe_op_in_unsafe_fn` may become the default in future Rust versions: https://github.com/rust-lang/rust/issues/71668
"unused_extern_crates",
"unused_import_braces",
"unused_lifetimes",
"unused_qualifications",
]

allow = [
# TODO(emilk): enable more lints
"clippy::cloned_instead_of_copied",
"clippy::missing_errors_doc",
"unused_qualifications",
"trivial_casts",
"clippy::manual_range_contains", # this one is just worse imho
]
79 changes: 79 additions & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Copied from https://github.com/rerun-io/rerun_template
#
# There is also a scripts/clippy_wasm/clippy.toml which forbids some methods that are not available in wasm.

# -----------------------------------------------------------------------------
# Section identical to scripts/clippy_wasm/clippy.toml:

msrv = "1.73"

allow-unwrap-in-tests = true

# https://doc.rust-lang.org/nightly/clippy/lint_configuration.html#avoid-breaking-exported-api
# We want suggestions, even if it changes public API.
avoid-breaking-exported-api = false

excessive-nesting-threshold = 8

max-fn-params-bools = 1

# https://rust-lang.github.io/rust-clippy/master/index.html#/large_include_file
max-include-file-size = 1000000

# https://rust-lang.github.io/rust-clippy/master/index.html#/large_stack_frames
stack-size-threshold = 512000

too-many-lines-threshold = 200

# -----------------------------------------------------------------------------

# https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_macros
disallowed-macros = ['dbg']

# https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_methods
disallowed-methods = [
{ path = "egui_extras::TableBody::row", reason = "`row` doesn't scale. Use `rows` instead." },
{ path = "glam::Vec2::normalize", reason = "normalize() can create NaNs. Use try_normalize or normalize_or_zero" },
{ path = "glam::Vec3::normalize", reason = "normalize() can create NaNs. Use try_normalize or normalize_or_zero" },
{ path = "sha1::Digest::new", reason = "SHA1 is cryptographically broken" },
{ path = "std::env::temp_dir", reason = "Use the tempdir crate instead" },
{ path = "std::panic::catch_unwind", reason = "We compile with `panic = 'abort'`" },
{ path = "std::thread::spawn", reason = "Use `std::thread::Builder` and name the thread" },

# There are many things that aren't allowed on wasm,
# but we cannot disable them all here (because of e.g. https://github.com/rust-lang/rust-clippy/issues/10406)
# so we do that in `scripts/clippy_wasm/clippy.toml` instead.
]

# https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_names
disallowed-names = []

# https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_types
disallowed-types = [
{ path = "ring::digest::SHA1_FOR_LEGACY_USE_ONLY", reason = "SHA1 is cryptographically broken" },

{ path = "std::sync::Condvar", reason = "Use parking_lot instead" },
{ path = "std::sync::Mutex", reason = "Use parking_lot instead" },
{ path = "std::sync::RwLock", reason = "Use parking_lot instead" },

# "std::sync::Once", # enabled for now as the `log_once` macro uses it internally
]

# Allow-list of words for markdown in dosctrings https://rust-lang.github.io/rust-clippy/master/index.html#doc_markdown
doc-valid-idents = [
# You must also update the same list in `scripts/clippy_wasm/clippy.toml`!
"GitHub",
"GLB",
"GLTF",
"iOS",
"macOS",
"NaN",
"OBJ",
"OpenGL",
"PyPI",
"sRGB",
"sRGBA",
"WebGL",
"WebSocket",
"WebSockets",
]
1 change: 1 addition & 0 deletions echo_server/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![allow(deprecated)] // TODO(emilk): Remove when we update tungstenite
#![allow(clippy::unwrap_used, clippy::disallowed_methods)] // We are just testing here.

use std::{net::TcpListener, thread::spawn};

Expand Down
4 changes: 4 additions & 0 deletions ewebsock/src/native_tungstenite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ impl WsSender {
/// Close the connection.
///
/// This is called automatically when the sender is dropped.
///
/// # Errors
/// This should never fail, except _maybe_ on Web.
#[allow(clippy::unnecessary_wraps)] // To keep the same signature as the Web version
pub fn close(&mut self) -> Result<()> {
if self.tx.is_some() {
log::debug!("Closing WebSocket");
Expand Down
4 changes: 4 additions & 0 deletions ewebsock/src/native_tungstenite_tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ impl WsSender {
/// Close the connection.
///
/// This is called automatically when the sender is dropped.
///
/// # Errors
/// This should never fail, except _maybe_ on Web.
#[allow(clippy::unnecessary_wraps)] // To keep the same signature as the Web version
pub fn close(&mut self) -> Result<()> {
if self.tx.is_some() {
log::debug!("Closing WebSocket");
Expand Down
3 changes: 3 additions & 0 deletions ewebsock/src/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ impl WsSender {
/// Close the connection.
///
/// This is called automatically when the sender is dropped.
///
/// # Errors
/// This should never fail, except _maybe_ on Web.
pub fn close(&mut self) -> Result<()> {
if let Some(ws) = self.ws.take() {
log::debug!("Closing WebSocket");
Expand Down
2 changes: 1 addition & 1 deletion example_app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl FrontEnd {
ui.separator();
ui.heading("Received events:");
for event in &self.events {
ui.label(format!("{:?}", event));
ui.label(format!("{event:?}"));
}
});
}
Expand Down
75 changes: 75 additions & 0 deletions scripts/clippy_wasm/clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Copied from https://github.com/rerun-io/rerun_template

# This is used by the CI so we can forbid some methods that are not available in wasm.
#
# We cannot forbid all these methods in the main `clippy.toml` because of
# https://github.com/rust-lang/rust-clippy/issues/10406

# -----------------------------------------------------------------------------
# Section identical to the main clippy.toml:

msrv = "1.73"

allow-unwrap-in-tests = true

# https://doc.rust-lang.org/nightly/clippy/lint_configuration.html#avoid-breaking-exported-api
# We want suggestions, even if it changes public API.
avoid-breaking-exported-api = false

excessive-nesting-threshold = 8

max-fn-params-bools = 1

# https://rust-lang.github.io/rust-clippy/master/index.html#/large_include_file
max-include-file-size = 1000000

too-many-lines-threshold = 200

# -----------------------------------------------------------------------------

# https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_methods
disallowed-methods = [
{ path = "crossbeam::channel::Receiver::into_iter", reason = "Cannot block on Web" },
{ path = "crossbeam::channel::Receiver::iter", reason = "Cannot block on Web" },
{ path = "crossbeam::channel::Receiver::recv_timeout", reason = "Cannot block on Web" },
{ path = "crossbeam::channel::Receiver::recv", reason = "Cannot block on Web" },
{ path = "poll_promise::Promise::block_and_take", reason = "Cannot block on Web" },
{ path = "poll_promise::Promise::block_until_ready_mut", reason = "Cannot block on Web" },
{ path = "poll_promise::Promise::block_until_ready", reason = "Cannot block on Web" },
{ path = "rayon::spawn", reason = "Cannot spawn threads on wasm" },
{ path = "std::sync::mpsc::Receiver::into_iter", reason = "Cannot block on Web" },
{ path = "std::sync::mpsc::Receiver::iter", reason = "Cannot block on Web" },
{ path = "std::sync::mpsc::Receiver::recv_timeout", reason = "Cannot block on Web" },
{ path = "std::sync::mpsc::Receiver::recv", reason = "Cannot block on Web" },
{ path = "std::thread::spawn", reason = "Cannot spawn threads on wasm" },
{ path = "std::time::Duration::elapsed", reason = "use `web-time` crate instead for wasm/web compatibility" },
{ path = "std::time::Instant::now", reason = "use `web-time` crate instead for wasm/web compatibility" },
{ path = "std::time::SystemTime::now", reason = "use `web-time` or `time` crates instead for wasm/web compatibility" },
]

# https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_types
disallowed-types = [
{ path = "instant::SystemTime", reason = "Known bugs. Use web-time." },
{ path = "std::thread::Builder", reason = "Cannot spawn threads on wasm" },
# { path = "std::path::PathBuf", reason = "Can't read/write files on web" }, // Used in build.rs files (which is fine).
]

# Allow-list of words for markdown in dosctrings https://rust-lang.github.io/rust-clippy/master/index.html#doc_markdown
doc-valid-idents = [
# You must also update the same list in the root `clippy.toml`!
"..",
"GitHub",
"GLB",
"GLTF",
"iOS",
"macOS",
"NaN",
"OBJ",
"OpenGL",
"PyPI",
"sRGB",
"sRGBA",
"WebGL",
"WebSocket",
"WebSockets",
]

0 comments on commit f6d0112

Please sign in to comment.