Skip to content

Commit

Permalink
Add clippy::disallowed_method lint
Browse files Browse the repository at this point in the history
  • Loading branch information
benluelo committed Dec 20, 2021
1 parent 7c4d2a4 commit 62f6e5b
Show file tree
Hide file tree
Showing 26 changed files with 54 additions and 20 deletions.
4 changes: 4 additions & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
disallowed-methods = [
"core::result::Result::unwrap", # { path = "core::result::Result::unwrap", reason = "Errors should be handled properly. If panicking is valid in this context, make sure to write a comment explaining why." },
"core::option::Option::unwrap", # { path = "core::option::Option::unwrap", reason = "Errors should be handled properly. If panicking is valid in this context, make sure to write a comment explaining why." },
]
27 changes: 17 additions & 10 deletions frame/assets-registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
//! 2. Assets map added as candidate and waits for approval.
//! 3. After approval map return mapped value.
//! 4. Map of native token to this chain(here) is added unconditionally.

#![cfg_attr(not(test), warn(clippy::disallowed_method))] // allow in tests
#![cfg_attr(not(feature = "std"), no_std)]

pub use pallet::*;
Expand Down Expand Up @@ -246,7 +248,7 @@ pub mod pallet {
let local_admin = <LocalAdmin<T>>::get();
let foreign_admin = <ForeignAdmin<T>>::get();
match current_candidate_status {
None =>
None => {
if who == local_admin {
<AssetsMappingCandidates<T>>::insert(
(local_asset_id, foreign_asset_id),
Expand All @@ -257,17 +259,20 @@ pub mod pallet {
(local_asset_id, foreign_asset_id),
CandidateStatus::ForeignAdminApproved,
);
},
Some(CandidateStatus::LocalAdminApproved) =>
}
}
Some(CandidateStatus::LocalAdminApproved) => {
if who == foreign_admin {
Self::set_location(local_asset_id, foreign_asset_id.clone())?;
<AssetsMappingCandidates<T>>::remove((local_asset_id, foreign_asset_id));
},
Some(CandidateStatus::ForeignAdminApproved) =>
}
}
Some(CandidateStatus::ForeignAdminApproved) => {
if who == local_admin {
Self::set_location(local_asset_id, foreign_asset_id.clone())?;
<AssetsMappingCandidates<T>>::remove((local_asset_id, foreign_asset_id));
},
}
}
};
Ok(().into())
}
Expand All @@ -278,8 +283,9 @@ pub mod pallet {
type Success = T::AccountId;
fn try_origin(o: T::Origin) -> Result<Self::Success, T::Origin> {
o.into().and_then(|o| match (o, LocalAdmin::<T>::try_get()) {
(frame_system::RawOrigin::Signed(ref who), Ok(ref f)) if who == f =>
Ok(who.clone()),
(frame_system::RawOrigin::Signed(ref who), Ok(ref f)) if who == f => {
Ok(who.clone())
}
(r, _) => Err(T::Origin::from(r)),
})
}
Expand All @@ -296,8 +302,9 @@ pub mod pallet {
type Success = T::AccountId;
fn try_origin(o: T::Origin) -> Result<Self::Success, T::Origin> {
o.into().and_then(|o| match (o, ForeignAdmin::<T>::try_get()) {
(frame_system::RawOrigin::Signed(ref who), Ok(ref f)) if who == f =>
Ok(who.clone()),
(frame_system::RawOrigin::Signed(ref who), Ok(ref f)) if who == f => {
Ok(who.clone())
}
(r, _) => Err(T::Origin::from(r)),
})
}
Expand Down
1 change: 1 addition & 0 deletions frame/assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
//! - `mint_into`
//! - `burn_from`

#![cfg_attr(not(test), warn(clippy::disallowed_method))] // allow in tests
#![cfg_attr(not(feature = "std"), no_std)]

pub use pallet::*;
Expand Down
1 change: 1 addition & 0 deletions frame/bonded-finance/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg_attr(not(test), warn(clippy::disallowed_method))] // allow in tests
#![cfg_attr(not(feature = "std"), no_std)]
#![warn(
bad_style,
Expand Down
1 change: 1 addition & 0 deletions frame/call-filter/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg_attr(not(test), warn(clippy::disallowed_method))] // allow in tests
#![cfg_attr(not(feature = "std"), no_std)]
#![allow(clippy::unused_unit)]

Expand Down
1 change: 1 addition & 0 deletions frame/composable-traits/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg_attr(not(test), warn(clippy::disallowed_method))] // allow in tests
#![cfg_attr(not(feature = "std"), no_std)]

pub mod assets;
Expand Down
1 change: 1 addition & 0 deletions frame/crowdloan-bonus/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg_attr(not(test), warn(clippy::disallowed_method))] // allow in tests
#![cfg_attr(not(feature = "std"), no_std)]

pub use pallet::*;
Expand Down
13 changes: 7 additions & 6 deletions frame/crowdloan-rewards/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ proof = sign (concat prefix (hex reward_account))
Reference for proof mechanism: https://github.com/paritytech/polkadot/blob/master/runtime/common/src/claims.rs
*/

#![cfg_attr(not(test), warn(clippy::disallowed_method))] // allow in tests
#![cfg_attr(not(feature = "std"), no_std)]
#![warn(
bad_style,
Expand Down Expand Up @@ -252,7 +253,7 @@ pub mod pallet {
ethereum_recover(T::Prefix::get(), &reward_account_encoded, &eth_proof)
.ok_or(Error::<T>::InvalidProof)?;
Result::<_, DispatchError>::Ok(RemoteAccount::Ethereum(ethereum_address))
},
}
Proof::RelayChain(relay_account, relay_proof) => {
ensure!(
verify_relay(
Expand All @@ -264,7 +265,7 @@ pub mod pallet {
Error::<T>::InvalidProof
);
Ok(RemoteAccount::RelayChain(relay_account))
},
}
}?;
let claimed = Self::do_claim(remote_account.clone(), &reward_account)?;
Associations::<T>::insert(reward_account.clone(), remote_account.clone());
Expand Down Expand Up @@ -320,10 +321,10 @@ pub mod pallet {
// The user should have claimed the upfront payment + the vested
// amount until this window point.
let vested_reward = reward.total - upfront_payment;
upfront_payment +
(vested_reward
.saturating_mul(T::Convert::convert(vesting_window)) /
T::Convert::convert(reward.vesting_period))
upfront_payment
+ (vested_reward
.saturating_mul(T::Convert::convert(vesting_window))
/ T::Convert::convert(reward.vesting_period))
}
};
let available_to_claim = should_have_claimed - reward.claimed;
Expand Down
1 change: 1 addition & 0 deletions frame/currency-factory/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg_attr(not(test), warn(clippy::disallowed_method))] // allow in tests
#![cfg_attr(not(feature = "std"), no_std)]
#![warn(
bad_style,
Expand Down
3 changes: 1 addition & 2 deletions frame/curve-amm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//

#![cfg_attr(not(test), warn(clippy::disallowed_method))] // allow in tests
#![cfg_attr(not(feature = "std"), no_std)]
#![warn(
bad_style,
Expand Down
1 change: 1 addition & 0 deletions frame/dutch-auction/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg_attr(not(test), warn(clippy::disallowed_method))] // allow in tests
#![cfg_attr(not(feature = "std"), no_std)]
#![warn(
bad_style,
Expand Down
2 changes: 2 additions & 0 deletions frame/governance-registry/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//! # Governance Registry Pallet
//!
//! Is used to add new assets into chain.

#![cfg_attr(not(test), warn(clippy::disallowed_method))] // allow in tests
#![cfg_attr(not(feature = "std"), no_std)]

pub use pallet::*;
Expand Down
3 changes: 1 addition & 2 deletions frame/lending/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//!

#![cfg_attr(not(test), warn(clippy::disallowed_method))] // allow in tests
#![cfg_attr(not(feature = "std"), no_std)]
#![warn(
bad_style,
Expand Down
1 change: 1 addition & 0 deletions frame/liquidations/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg_attr(not(test), warn(clippy::disallowed_method))] // allow in tests
#![cfg_attr(not(feature = "std"), no_std)]
#![warn(
bad_style,
Expand Down
1 change: 1 addition & 0 deletions frame/oracle/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg_attr(not(test), warn(clippy::disallowed_method))] // allow in tests
#![cfg_attr(not(feature = "std"), no_std)]
#![allow(clippy::too_many_arguments)]

Expand Down
2 changes: 2 additions & 0 deletions frame/order-book-dex/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//! on chain state to handle state of cross chain exchanges

#![cfg_attr(not(test), warn(clippy::disallowed_method))] // allow in tests
#![cfg_attr(not(feature = "std"), no_std)]
#![warn(
bad_style,
Expand Down
1 change: 1 addition & 0 deletions frame/ping/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

//! Pallet to spam the XCM/UMP.

#![cfg_attr(not(test), warn(clippy::disallowed_method))] // allow in tests
#![cfg_attr(not(feature = "std"), no_std)]

use cumulus_pallet_xcm::{ensure_sibling_para, Origin as CumulusOrigin};
Expand Down
1 change: 1 addition & 0 deletions frame/privilege/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg_attr(not(test), warn(clippy::disallowed_method))] // allow in tests
#![cfg_attr(not(feature = "std"), no_std)]
#![warn(
bad_style,
Expand Down
1 change: 1 addition & 0 deletions frame/transaction-fee/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//! Loosely based on https://github.com/paritytech/substrate/blob/master/frame/transaction-payment/src/lib.rs
//! but with added support for `MultiCurrency` using a `Dex` interface.

#![cfg_attr(not(test), warn(clippy::disallowed_method))] // allow in tests
#![cfg_attr(not(feature = "std"), no_std)]

use codec::{Decode, Encode};
Expand Down
1 change: 1 addition & 0 deletions frame/vault/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg_attr(not(test), warn(clippy::disallowed_method))] // allow in tests
#![cfg_attr(not(feature = "std"), no_std)]
#![deny(
dead_code,
Expand Down
1 change: 1 addition & 0 deletions frame/vesting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
//! - `update_vesting_schedules` - Update all vesting schedules under an account, `root` origin
//! required.

#![cfg_attr(not(test), warn(clippy::disallowed_method))] // allow in tests
#![cfg_attr(not(feature = "std"), no_std)]
#![allow(clippy::unused_unit)]

Expand Down
2 changes: 2 additions & 0 deletions node/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg_attr(not(test), warn(clippy::disallowed_method))] // allow in tests

pub mod chain_spec;
mod client;
pub mod rpc;
Expand Down
1 change: 1 addition & 0 deletions runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg_attr(not(test), warn(clippy::disallowed_method))] // allow in tests
#![cfg_attr(not(feature = "std"), no_std)]

pub mod impls;
Expand Down
1 change: 1 addition & 0 deletions runtime/composable/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg_attr(not(test), warn(clippy::disallowed_method))] // allow in tests
#![cfg_attr(not(feature = "std"), no_std)]
// `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256.
#![recursion_limit = "256"]
Expand Down
1 change: 1 addition & 0 deletions runtime/picasso/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg_attr(not(test), warn(clippy::disallowed_method))] // allow in tests
#![cfg_attr(not(feature = "std"), no_std)]
// `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256.
#![recursion_limit = "256"]
Expand Down
1 change: 1 addition & 0 deletions runtime/primitives/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg_attr(not(test), warn(clippy::disallowed_method))] // allow in tests
#![cfg_attr(not(feature = "std"), no_std)]

pub mod currency;

0 comments on commit 62f6e5b

Please sign in to comment.