Skip to content

Commit

Permalink
Enable clippy in CI (paritytech#184)
Browse files Browse the repository at this point in the history
* Enable clippy in CI

* Fix typo in workflow yml

* Fix some clippy complaints

* lint rpc

* lint dev service

* lint command.rs

* lint runtime lib

* lint author inherent

* disable clippy on stake

* disable some lints in txpool primitives because of macro-generated code.

* less strict clippy command to make something pass

* cargo fmt

Co-authored-by: Joshy Orndorff <admin@joshyorndorff.com>
  • Loading branch information
notlesh and JoshOrndorff committed Feb 8, 2021
1 parent b19ee67 commit a61d13e
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 28 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ jobs:
target: wasm32-unknown-unknown
default: true

# - name: Check with Clippy
# run: cargo clippy --workspace --tests -- -D warnings
- name: Check with Clippy
run: cargo clippy --workspace

- name: Format code with rustfmt
run: cargo fmt -- --check
Expand Down
4 changes: 2 additions & 2 deletions client/rpc-core/txpool/src/types/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ fn block_hash_serialize<S>(hash: &Option<H256>, serializer: S) -> Result<S::Ok,
where
S: Serializer,
{
serializer.serialize_str(&format!("0x{:x}", hash.unwrap_or(H256::default())))
serializer.serialize_str(&format!("0x{:x}", hash.unwrap_or_default()))
}

fn to_serialize<S>(hash: &Option<H160>, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str(&format!("0x{:x}", hash.unwrap_or(H160::default())))
serializer.serialize_str(&format!("0x{:x}", hash.unwrap_or_default()))
}

impl GetT for Transaction {
Expand Down
2 changes: 1 addition & 1 deletion client/rpc-core/txpool/src/types/inspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl Serialize for Summary {
{
let res = format!(
"0x{:x}: {} wei + {} gas x {} wei",
self.to.unwrap_or(H160::default()),
self.to.unwrap_or_default(),
self.value,
self.gas,
self.gas_price
Expand Down
16 changes: 8 additions & 8 deletions node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,21 +281,21 @@ pub fn run() -> Result<()> {
let runner = cli.create_runner(&*cli.run)?;
let collator = cli.run.base.validator || cli.collator;
let author_id: Option<H160> = cli.run.author_id;
if collator {
if author_id.is_none() {
return Err("Collator nodes must specify an author account id".into());
}
if collator && author_id.is_none() {
return Err("Collator nodes must specify an author account id".into());
}

runner.run_node_until_exit(|config| async move {
// If this is a --dev node, start up manual or instant seal.
// Otherwise continue with the normal parachain node.
if cli.run.base.shared_params.dev {
// If no author id was supplied, use the one that is staked at genesis
let author_id = author_id.or(Some(
AccountId::from_str("6Be02d1d3665660d22FF9624b7BE0551ee1Ac91b")
.expect("Gerald is a valid account"),
));
let author_id = author_id.or_else(|| {
Some(
AccountId::from_str("6Be02d1d3665660d22FF9624b7BE0551ee1Ac91b")
.expect("Gerald is a valid account"),
)
});

return crate::dev_service::new_full(config, cli.run.sealing, author_id);
}
Expand Down
3 changes: 2 additions & 1 deletion node/src/dev_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type FullClient = sc_service::TFullClient<Block, RuntimeApi, Executor>;
type FullBackend = sc_service::TFullBackend<Block>;
type FullSelectChain = sc_consensus::LongestChain<FullBackend, Block>;

#[allow(clippy::type_complexity)]
pub fn new_partial(
config: &Configuration,
author: Option<H160>,
Expand Down Expand Up @@ -228,7 +229,7 @@ pub fn new_full(
};

sc_service::spawn_tasks(sc_service::SpawnTasksParams {
network: network.clone(),
network,
client: client.clone(),
keystore: keystore_container.sync_keystore(),
task_manager: &mut task_manager,
Expand Down
21 changes: 9 additions & 12 deletions node/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ where
graph,
moonbeam_runtime::TransactionConverter,
network.clone(),
pending_transactions.clone(),
pending_transactions,
signers,
is_authority,
)));
Expand All @@ -127,24 +127,21 @@ where
io.extend_with(EthPubSubApiServer::to_delegate(EthPubSubApi::new(
pool.clone(),
client.clone(),
network.clone(),
network,
SubscriptionManager::<HexEncodedIdProvider>::with_id_provider(
HexEncodedIdProvider::default(),
Arc::new(subscription_task_executor),
),
)));
io.extend_with(TxPoolServer::to_delegate(TxPool::new(client, pool)));

match command_sink {
Some(command_sink) => {
io.extend_with(
// We provide the rpc handler with the sending end of the channel to allow the rpc
// send EngineCommands to the background block authorship task.
ManualSealApi::to_delegate(ManualSeal::new(command_sink)),
);
}
_ => {}
}
if let Some(command_sink) = command_sink {
io.extend_with(
// We provide the rpc handler with the sending end of the channel to allow the rpc
// send EngineCommands to the background block authorship task.
ManualSealApi::to_delegate(ManualSeal::new(command_sink)),
);
};

io
}
2 changes: 1 addition & 1 deletion pallets/author-inherent/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ decl_module! {
));

// Notify any other pallets that are listening (eg rewards) about the author
T::EventHandler::note_author(author.clone());
T::EventHandler::note_author(author);
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions pallets/stake/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@

#![recursion_limit = "256"]
#![cfg_attr(not(feature = "std"), no_std)]
//TODO enable clippy and solve lints here. This was disabled to avoid merge conflicts with
// https://github.com/PureStake/moonbeam/pull/189
#![allow(clippy::all)]

mod set;
use frame_support::{
Expand Down
3 changes: 3 additions & 0 deletions primitives/rpc/txpool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
// along with Moonbeam. If not, see <http://www.gnu.org/licenses/>.

#![cfg_attr(not(feature = "std"), no_std)]
// These clippy lints are disabled because the macro-generated code triggers them.
#![allow(clippy::unnecessary_mut_passed)]
#![allow(clippy::too_many_arguments)]

use ethereum::Transaction;
use sp_runtime::traits::Block as BlockT;
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ pub struct MoonbeamGasWeightMapping;

impl pallet_evm::GasWeightMapping for MoonbeamGasWeightMapping {
fn gas_to_weight(gas: usize) -> Weight {
Weight::try_from((gas as u64).saturating_mul(WEIGHT_PER_GAS)).unwrap_or(Weight::MAX)
(gas as u64).saturating_mul(WEIGHT_PER_GAS)
}
fn weight_to_gas(weight: Weight) -> usize {
usize::try_from(weight.wrapping_div(WEIGHT_PER_GAS)).unwrap_or(usize::MAX)
Expand Down

0 comments on commit a61d13e

Please sign in to comment.