Skip to content

Commit 85dc48d

Browse files
karolk91bkontur
andauthored
Introduce cargo clippy CI check (#70)
* Introduce clippy * Clippy findings fixes * Taplo formatting * Update .github/workflows/check.yml Co-authored-by: Branislav Kontur <[email protected]> * Fix clippy warning --------- Co-authored-by: Branislav Kontur <[email protected]>
1 parent f16eb16 commit 85dc48d

File tree

24 files changed

+89
-75
lines changed

24 files changed

+89
-75
lines changed

.github/workflows/check.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,31 @@ jobs:
7474
run: |
7575
cargo check --workspace --features=runtime-benchmarks
7676
77+
clippy:
78+
name: Cargo clippy
79+
# TODO: replace `parity-default` with `ubuntu-latest` when the repo becomes public.
80+
runs-on: parity-default
81+
needs: [set-image]
82+
container:
83+
image: ${{ needs.set-image.outputs.CI_IMAGE }}
84+
env:
85+
RUSTFLAGS: "-D warnings"
86+
SKIP_WASM_BUILD: 1
87+
steps:
88+
- name: Checkout sources
89+
uses: actions/checkout@v4
90+
91+
- name: Rust cache
92+
uses: Swatinem/rust-cache@v2
93+
with:
94+
cache-on-failure: true
95+
cache-all-crates: true
96+
97+
- name: Cargo clippy
98+
run: |
99+
cargo clippy --all-targets --locked --workspace --quiet
100+
cargo clippy --all-targets --all-features --locked --workspace --quiet
101+
77102
test:
78103
name: Test
79104
# TODO: replace `parity-default` with `ubuntu-latest` when the repo becomes public.

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ serde = { workspace = true }
2424
sc-chain-spec = { workspace = true }
2525
frame-support = { workspace = true, optional = true }
2626
frame-system-rpc-runtime-api = { workspace = true }
27+
frame-try-runtime = { workspace = true, optional = true }
2728
pallet-transaction-payment = { workspace = true }
2829
sc-cli = { workspace = true }
2930
sc-client-api = { workspace = true }
@@ -99,6 +100,7 @@ runtime-benchmarks = [
99100
try-runtime = [
100101
"bulletin-polkadot-runtime/try-runtime",
101102
"frame-support/try-runtime",
103+
"frame-try-runtime/try-runtime",
102104
"pallet-transaction-payment/try-runtime",
103105
"polkadot-bulletin-chain-runtime/try-runtime",
104106
"sp-runtime/try-runtime",

node/src/benchmarking.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ use std::time::Duration;
55
/// Generates inherent data for the `benchmark overhead` command.
66
///
77
/// Note: Should only be used for benchmarking.
8+
#[allow(clippy::result_large_err)]
89
pub fn inherent_benchmark_data() -> Result<InherentData> {
910
let mut inherent_data = InherentData::new();
1011
let d = Duration::from_millis(0);
1112
let timestamp = sp_timestamp::InherentDataProvider::new(d.into());
1213

1314
futures::executor::block_on(timestamp.provide_inherent_data(&mut inherent_data))
14-
.map_err(|e| format!("creating inherent data: {:?}", e))?;
15+
.map_err(|e| format!("creating inherent data: {e:?}"))?;
1516
Ok(inherent_data)
1617
}

node/src/command.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ impl SubstrateCli for Cli {
6363
}
6464

6565
/// Parse and run command line arguments
66+
#[allow(clippy::result_large_err)]
6667
pub fn run() -> sc_cli::Result<()> {
6768
let cli = Cli::from_args();
6869

@@ -163,8 +164,7 @@ pub fn run() -> sc_cli::Result<()> {
163164
return Err(sc_cli::Error::Input(
164165
"Bulletin binary does not support `--runtime` flag for `benchmark overhead`. Please provide a chain spec or use the `frame-omni-bencher`."
165166
.into(),
166-
)
167-
.into())
167+
))
168168
}
169169

170170
cmd.run_with_default_builder_and_spec::<Block, ()>(

node/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ mod fake_runtime_api;
1212
mod node_primitives;
1313
mod rpc;
1414

15+
#[allow(clippy::result_large_err)]
1516
fn main() -> sc_cli::Result<()> {
1617
command::run()
1718
}

node/src/node_primitives.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,3 @@
1515
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
1616

1717
pub use polkadot_primitives::{AccountId, Balance, Block, BlockNumber, Hash, Nonce};
18-
19-
/// Should be aligned with runtimes.
20-
#[cfg(feature = "try-runtime")]
21-
pub const MILLISECS_PER_BLOCK: u64 = 6000;
22-
/// Should be aligned with runtimes.
23-
#[cfg(feature = "try-runtime")]
24-
pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK;

node/src/service.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type FullGrandpaBlockImport =
2525
const GRANDPA_JUSTIFICATION_PERIOD: u32 = 512;
2626

2727
#[allow(clippy::type_complexity)]
28+
#[allow(clippy::result_large_err)]
2829
pub fn new_partial(
2930
config: &Configuration,
3031
) -> Result<
@@ -141,6 +142,7 @@ pub fn new_partial(
141142
}
142143

143144
/// Builds a new service for a full client.
145+
#[allow(clippy::result_large_err)]
144146
pub fn new_full<
145147
N: sc_network::NetworkBackend<Block, <Block as sp_runtime::traits::Block>::Hash>,
146148
>(
@@ -211,7 +213,7 @@ pub fn new_full<
211213
);
212214
}
213215

214-
let role = config.role.clone();
216+
let role = config.role;
215217
let force_authoring = config.force_authoring;
216218
let backoff_authoring_blocks: Option<()> = None;
217219
let name = config.network.node_name.clone();

pallets/transaction-storage/src/benchmarking.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -225,15 +225,11 @@ mod benchmarks {
225225
let hash = [0u8; 32];
226226
let max_size: u64 = 1024 * 1024;
227227
let origin2 = origin.clone();
228-
TransactionStorage::<T>::authorize_preimage(
229-
origin2 as T::RuntimeOrigin,
230-
hash.clone(),
231-
max_size,
232-
)
233-
.map_err(|_| BenchmarkError::Stop("unable to authorize account"))?;
228+
TransactionStorage::<T>::authorize_preimage(origin2 as T::RuntimeOrigin, hash, max_size)
229+
.map_err(|_| BenchmarkError::Stop("unable to authorize account"))?;
234230

235231
#[extrinsic_call]
236-
_(origin as T::RuntimeOrigin, hash.clone());
232+
_(origin as T::RuntimeOrigin, hash);
237233

238234
assert_last_event::<T>(Event::PreimageAuthorizationRefreshed { hash }.into());
239235
Ok(())

pallets/transaction-storage/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl CheckContext {
140140
}
141141

142142
fn num_chunks(bytes: u32) -> u32 {
143-
((bytes as u64 + CHUNK_SIZE as u64 - 1) / CHUNK_SIZE as u64) as u32
143+
(bytes as u64).div_ceil(CHUNK_SIZE as u64) as u32
144144
}
145145

146146
#[polkadot_sdk_frame::pallet]
@@ -742,7 +742,7 @@ pub mod pallet {
742742
Ok(())
743743
} else {
744744
// No previous authorization to refresh.
745-
return Err(Error::<T>::AuthorizationNotFound.into())
745+
Err(Error::<T>::AuthorizationNotFound.into())
746746
}
747747
})
748748
}
@@ -818,7 +818,7 @@ pub mod pallet {
818818
/// block.
819819
fn block_transactions_full() -> bool {
820820
BlockTransactions::<T>::decode_len()
821-
.map_or(false, |len| len >= T::MaxBlockTransactions::get() as usize)
821+
.is_some_and(|len| len >= T::MaxBlockTransactions::get() as usize)
822822
}
823823

824824
/// Check that authorization exists for data of the given size to be stored in a single

0 commit comments

Comments
 (0)