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

refactor: check for additional lints #200

Merged
merged 14 commits into from
Oct 2, 2023
Merged

refactor: check for additional lints #200

merged 14 commits into from
Oct 2, 2023

Conversation

CBenoit
Copy link
Member

@CBenoit CBenoit commented Sep 29, 2023

cc @pacmancoder @ibeckermayer

I realized it was possible to enforce a few guidelines by enabling additional, a bit more pedantic lints (that may be relaxed at some places).
I did not enforce with #![deny(…)] everywhere so we don’t need to be bothered until final PR clean up: these are checked only when running cargo xtask check lints or by the CI.

Comment on lines +5 to +14
"unsafe_op_in_unsafe_fn",
"invalid_reference_casting",
"pointer_structural_match",
"clippy::undocumented_unsafe_blocks",
"clippy::multiple_unsafe_ops_per_block",
"clippy::transmute_ptr_to_ptr",
"clippy::as_ptr_cast_mut",
"clippy::cast_ptr_alignment",
"clippy::fn_to_numeric_cast_any",
"clippy::ptr_cast_constness",
Copy link
Member Author

@CBenoit CBenoit Sep 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably always want these enabled when working with unsafe code (crates such as ironrdp-cliprdr-native should enable them with crate-level annotations in order to get direct feedback in editor)

Comment on lines +16 to +25
"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", // let’s either handle `None`, `Err` or use `expect` to give a reason
"clippy::large_stack_frames",
Copy link
Member Author

@CBenoit CBenoit Sep 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check for additional potential correctness issues. Legacy code is full of such code so I disabled the check in some crates for now. Ideally, new code should not ignore these warnings.

clippy::arithmetic_side_effects is sometimes a bit too pedantic and we may relax it at some places. Let’s see how it turns out.

Comment on lines +27 to +54
"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::unreadable_literal",
"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
Copy link
Member Author

@CBenoit CBenoit Sep 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Helps ensuring consistent, straightforward and more readable code style across the codebase

Comment on lines +56 to +60
"unused_crate_dependencies",
"unused_macro_rules",
"clippy::inline_always",
"clippy::or_fun_call",
"clippy::unnecessary_box_returns",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code which may hurt compile-time or runtime performance and generally easy to fix

Comment on lines +74 to +76
"clippy::print_stderr",
"clippy::print_stdout",
"clippy::dbg_macro",
Copy link
Member Author

@CBenoit CBenoit Sep 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Protects us from merging unintended temporary print!/eprint!/dbg! statements that are often artifacts of ad-hoc print statement debugging

Comment on lines +42 to +43
"clippy::str_to_string",
"clippy::string_to_string",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taking something that is a string and converting it to a string using to_string() kind of misses the point of why we are doing the conversion in the first place, and also fails to document this to the reader. to_owned() fully captures the reason that a conversion is required at a particular spot: borrowed (&str) to owned (String).

// == Style, readability == //
"absolute_paths_not_starting_with_crate",
"single_use_lifetimes",
"unreachable_pub",
Copy link
Member Author

@CBenoit CBenoit Sep 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Protects us from leaving unreachable pub items. In most cases, it’s either a mistake or an implementation detail which is not intended to be exposed. We should use pub(crate) or no pub at all for implementation details. In some cases it’s actually desirable to make a type pub without it being reachable (effectively preventing the user from naming this type), but it’s rare enough that we can just explicitly add an #[allow] annotation when necessary.

@github-actions
Copy link

github-actions bot commented Sep 29, 2023

Coverage Report 🤖 ⚙️

Past:
Total lines: 23230
Covered lines: 15625 (67.26%)

New:
Total lines: 23259
Covered lines: 15639 (67.24%)

Diff: -0.02%

[this comment will be updated automatically]

@CBenoit CBenoit enabled auto-merge (squash) September 29, 2023 04:10
@CBenoit CBenoit force-pushed the hardened-lints branch 2 times, most recently from bac1b43 to 21329b6 Compare September 29, 2023 06:34
Copy link
Contributor

@pacmancoder pacmancoder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's huge! Nice Work! 😮

@CBenoit CBenoit merged commit 6283e37 into master Oct 2, 2023
6 checks passed
@CBenoit CBenoit deleted the hardened-lints branch October 2, 2023 10:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants