Skip to content

Commit 4db315d

Browse files
Merge pull request #187 from ElrondNetwork/clippy-check
Clippy check github action
2 parents 65e66e5 + 2abf9d1 commit 4db315d

File tree

43 files changed

+249
-239
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+249
-239
lines changed

.github/workflows/actions.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,17 @@ jobs:
4343
toolchain: nightly
4444
- name: Run rust tests
4545
run: cargo test
46+
clippy_check:
47+
name: Clippy linter check
48+
runs-on: ubuntu-latest
49+
steps:
50+
- uses: actions/checkout@v2
51+
- uses: actions-rs/toolchain@v1
52+
with:
53+
toolchain: nightly
54+
components: clippy
55+
default: true
56+
- uses: actions-rs/clippy-check@v1
57+
with:
58+
token: ${{ secrets.GITHUB_TOKEN }}
59+
args:

contracts/examples/crypto-kitties/common/kitty/src/color.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,16 @@ impl Color {
1313
// ratios are integers, 0 < ratio < 100, ratioFirst + ratioSecond = 100
1414
// checks should be done in the caller
1515
pub fn mix_with(&self, other_color: &Color, ratio_first: u8, ratio_second: u8) -> Color {
16-
let mut result = Color::default();
17-
18-
result.r = ((self.r as u16 * ratio_first as u16
19-
+ other_color.r as u16 * ratio_second as u16)
16+
let r = ((self.r as u16 * ratio_first as u16 + other_color.r as u16 * ratio_second as u16)
2017
/ 100) as u8;
2118

22-
result.g = ((self.g as u16 * ratio_first as u16
23-
+ other_color.g as u16 * ratio_second as u16)
19+
let g = ((self.g as u16 * ratio_first as u16 + other_color.g as u16 * ratio_second as u16)
2420
/ 100) as u8;
2521

26-
result.b = ((self.b as u16 * ratio_first as u16
27-
+ other_color.b as u16 * ratio_second as u16)
22+
let b = ((self.b as u16 * ratio_first as u16 + other_color.b as u16 * ratio_second as u16)
2823
/ 100) as u8;
2924

30-
result
25+
Color { r, g, b }
3126
}
3227
}
3328

contracts/examples/crypto-kitties/kitty-auction/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![no_std]
22
#![allow(non_snake_case)]
3+
#![allow(clippy::too_many_arguments)]
34

45
elrond_wasm::imports!();
56

contracts/examples/crypto-kitties/kitty-ownership/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![no_std]
22
#![allow(non_snake_case)]
3+
#![allow(clippy::suspicious_operation_groupings)]
34

45
elrond_wasm::imports!();
56

@@ -519,7 +520,7 @@ pub trait KittyOwnership {
519520
return false;
520521
}
521522

522-
return true;
523+
true
523524
}
524525

525526
// getters

contracts/examples/egld-esdt-swap/src/lib.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,17 @@ pub trait EgldEsdtSwap {
4141
&token_display_name,
4242
&token_ticker,
4343
&initial_supply,
44-
EGLD_NUM_DECIMALS,
45-
false,
46-
false,
47-
false,
48-
true,
49-
false,
50-
true,
51-
true,
52-
false,
44+
FungibleTokenProperties {
45+
num_decimals: EGLD_NUM_DECIMALS,
46+
can_freeze: false,
47+
can_wipe: false,
48+
can_pause: false,
49+
can_mint: true,
50+
can_burn: false,
51+
can_change_owner: true,
52+
can_upgrade: true,
53+
can_add_special_roles: false,
54+
},
5355
)
5456
.async_call()
5557
.with_callback(self.callbacks().esdt_issue_callback(&caller)))

contracts/examples/erc1155-marketplace/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![no_std]
22
#![allow(unused_attributes)]
33
#![allow(non_snake_case)]
4+
#![allow(clippy::too_many_arguments)]
45

56
elrond_wasm::imports!();
67
elrond_wasm::derive_imports!();
@@ -368,9 +369,7 @@ pub trait Erc1155Marketplace {
368369

369370
fn add_claimable_funds(&self, token_identifier: &TokenIdentifier, amount: &BigUint) {
370371
let mut mapper = self.get_claimable_funds_mapper();
371-
let mut total = mapper
372-
.get(token_identifier)
373-
.unwrap_or_else(|| BigUint::zero());
372+
let mut total = mapper.get(token_identifier).unwrap_or_else(BigUint::zero);
374373
total += amount;
375374
mapper.insert(token_identifier.clone(), total);
376375
}

contracts/examples/erc1155/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ pub trait Erc1155 {
225225
fn balance_of(&self, owner: &Address, type_id: &BigUint) -> BigUint {
226226
self.get_balance_mapper(&owner)
227227
.get(&type_id)
228-
.unwrap_or_else(|| BigUint::zero())
228+
.unwrap_or_else(BigUint::zero)
229229
}
230230

231231
// returns balance for each (owner, id) pair

contracts/examples/lottery-erc20/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ pub trait Lottery {
313313
)
314314
}
315315

316-
fn get_random_winning_ticket_id(&self, prev_winners: &Vec<u32>, total_tickets: u32) -> u32 {
316+
fn get_random_winning_ticket_id(&self, prev_winners: &[u32], total_tickets: u32) -> u32 {
317317
let seed = self.get_block_random_seed();
318318
let mut rand = Random::new(*seed);
319319

contracts/examples/multisig/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ pub trait Multisig {
269269
#[endpoint]
270270
fn sign(&self, action_id: usize) -> SCResult<()> {
271271
require!(
272-
!self.action_mapper().is_empty_unchecked(action_id),
272+
!self.action_mapper().item_is_empty_unchecked(action_id),
273273
"action does not exist"
274274
);
275275

@@ -292,7 +292,7 @@ pub trait Multisig {
292292
#[endpoint]
293293
fn unsign(&self, action_id: usize) -> SCResult<()> {
294294
require!(
295-
!self.action_mapper().is_empty_unchecked(action_id),
295+
!self.action_mapper().item_is_empty_unchecked(action_id),
296296
"action does not exist"
297297
);
298298

@@ -331,7 +331,7 @@ pub trait Multisig {
331331
self.set_user_id_to_role(user_id, new_role);
332332

333333
// update board size
334-
#[allow(clippy::collapsible_if)]
334+
#[allow(clippy::collapsible_else_if)]
335335
if old_role == UserRole::BoardMember {
336336
if new_role != UserRole::BoardMember {
337337
self.num_board_members().update(|value| *value -= 1);
@@ -343,7 +343,7 @@ pub trait Multisig {
343343
}
344344

345345
// update num_proposers
346-
#[allow(clippy::collapsible_if)]
346+
#[allow(clippy::collapsible_else_if)]
347347
if old_role == UserRole::Proposer {
348348
if new_role != UserRole::Proposer {
349349
self.num_proposers().update(|value| *value -= 1);

contracts/feature-tests/basic-features/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use ser_ex1::*;
1818
use ser_ex2::*;
1919
use simple_enum::*;
2020

21-
use core::iter::FromIterator;
2221
use core::num::NonZeroUsize;
2322

2423
#[elrond_wasm_derive::contract(BasicFeaturesImpl)]
@@ -504,12 +503,12 @@ pub trait BasicFeatures {
504503

505504
#[view]
506505
fn map_mapper_keys(&self) -> MultiResultVec<u32> {
507-
MultiResultVec::from_iter(self.map_mapper().keys())
506+
self.map_mapper().keys().collect()
508507
}
509508

510509
#[view]
511510
fn map_mapper_values(&self) -> MultiResultVec<u32> {
512-
MultiResultVec::from_iter(self.map_mapper().values())
511+
self.map_mapper().values().collect()
513512
}
514513

515514
#[endpoint]

0 commit comments

Comments
 (0)