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

chore: clippy lints #737

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open

chore: clippy lints #737

wants to merge 4 commits into from

Conversation

ntn-x2
Copy link
Member

@ntn-x2 ntn-x2 commented Sep 23, 2024

Fixes https://github.com/KILTprotocol/ticket/issues/3325.

Add some basic lints (can always be expanded for either runtime-specific code or all code via the configurable rustc flags in the new config file). I updated the code to address all places in which the new lints generate an error, including all weight files and weight templates. I also updated the CI check step to check for the specific WASM-targeted, no-std code that will be part of our runtime.

How to test

To check runtime code against the new lint, just run the same command as in the check workflow file:

cargo clippy --locked --target wasm32-unknown-unknown --no-default-features --workspace --exclude kilt-parachain --exclude standalone-node --exclude xcm-integration-tests --exclude 'dip-provider*' --exclude 'dip-consumer*'

@ntn-x2 ntn-x2 self-assigned this Sep 23, 2024
@ntn-x2 ntn-x2 marked this pull request as ready for review October 17, 2024 09:28
@ntn-x2 ntn-x2 requested a review from Ad96el October 17, 2024 09:28
@ntn-x2 ntn-x2 assigned ntn-x2 and Ad96el and unassigned ntn-x2 Oct 17, 2024
- --all-features
cargo-flags:
# Generic clippy checks for all features
- --all-targets --all-features
Copy link
Member Author

Choose a reason for hiding this comment

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

This line and the one below maintain the same behaviour as before.

# Generic clippy checks for no features (catches some missing `no_std`-only lints)
- --all-targets
# Clippy lints specifically for all runtime code, excluding all test and binary crates
- --target wasm32-unknown-unknown --no-default-features --workspace --exclude kilt-parachain --exclude standalone-node --exclude xcm-integration-tests --exclude 'dip-provider*' --exclude 'dip-consumer*'
Copy link
Member Author

Choose a reason for hiding this comment

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

This line is new and it tests all runtime-compatible code.

@@ -0,0 +1,26 @@
# Deployment runtime lints
[target.'cfg(all(target_arch = "wasm32", not(test)))']
Copy link
Member Author

Choose a reason for hiding this comment

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

These lints apply specifically to runtime code that is not used for tests. If we want to expand the set of lints, some of which might apply to the whole codebase, we can look at https://doc.rust-lang.org/cargo/reference/config.html#build to add more lints.

Copy link
Member

Choose a reason for hiding this comment

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

Do you think it might be worth moving the config file into a separate crate? Each crate might have different requirements, and specific Clippy warnings may need to be enabled or disabled accordingly. I see, that we maybe introduce a lot of boilerplate code into the repo, but I think it might be worth it to have the flexibility.

Copy link
Member

@Ad96el Ad96el left a comment

Choose a reason for hiding this comment

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

Love it. Some minor comments

@@ -50,7 +51,7 @@ use sp_std::marker::PhantomData;
pub struct WeightInfo<T>(PhantomData<T>);
impl<T: frame_system::Config> pallet_sudo::WeightInfo for WeightInfo<T> {

fn remove_key() -> cumulus_primitives_core::Weight { todo!() }
fn remove_key() -> cumulus_primitives_core::Weight { Weight::MAX }
Copy link
Member

Choose a reason for hiding this comment

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

Upss... Could we maybe benchmark the extrinsic?

Comment on lines +27 to +38
impl<T: frame_system::Config> {{pallet}}::WeightInfo for WeightInfo<T> {
{{#each benchmarks as |benchmark|}}
{{#each benchmark.comments as |comment|}}
/// {{comment}}
{{/each}}
{{#each benchmark.component_ranges as |range|}}
/// The range of component `{{range.name}}` is `[{{range.min}}, {{range.max}}]`.
{{/each}}
fn {{benchmark.name~}}
(
{{~#each benchmark.components as |c| ~}}
{{~#if (not c.is_used)}}_{{/if}}{{c.name}}: u32, {{/each~}}
Copy link
Member

Choose a reason for hiding this comment

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

Why those fmt changes? I found it previously clearer

@@ -0,0 +1,26 @@
# Deployment runtime lints
[target.'cfg(all(target_arch = "wasm32", not(test)))']
Copy link
Member

Choose a reason for hiding this comment

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

Do you think it might be worth moving the config file into a separate crate? Each crate might have different requirements, and specific Clippy warnings may need to be enabled or disabled accordingly. I see, that we maybe introduce a lot of boilerplate code into the repo, but I think it might be worth it to have the flexibility.

"-Funsafe_code",
"-Wclippy::integer_division",
"-Wclippy::modulo_arithmetic",
"-Wclippy::print_stderr",
Copy link
Member

Choose a reason for hiding this comment

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

@@ -484,6 +488,7 @@ pub mod pallet {
/// `check_releasing_preconditions` as it does not verify all the
/// preconditions again.
fn unregister_name(name: &Web3NameOf<T>) -> Result<Web3OwnershipOf<T>, DispatchError> {
#[allow(clippy::unwrap_used)]
Copy link
Member

Choose a reason for hiding this comment

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

I see that the checks are already made and the unwrap is safe, but should we maybe not still try to solve that without unwrap?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants