Skip to content

Commit

Permalink
Enable Clippy (#324)
Browse files Browse the repository at this point in the history
### Description
1. Use the `stable` channel since `nightly` doesn't work for Clippy. 
2. Keep `nightly` for `rustfmt` since it uses unstable features.
3. Execute `cargo +nightly-2024-03-12 fmt`

### Types of Changes
<!--- What types of changes does your code introduce? -->
- [x] Tech Debt (Code improvements)
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Dependency upgrade (A change in substrate or any 3rd party crate
version)

### Migrations and Hooks
<!--- Check the following box with an x if the following applies: -->
- [ ] This change requires a runtime migration.
- [ ] Modifies `on_initialize`
- [ ] Modifies `on_finalize`

### Checklist
<!--- All boxes need to be checked. Follow this checklist before
requiring PR review -->
- [x] Change has been tested locally.
- [ ] Change adds / updates tests.
- [ ] Changelog doc updated.
  • Loading branch information
MRamanenkau authored May 6, 2024
1 parent 71462ce commit 7ad744e
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 25 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
- name: Install nightly toolchain
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: nightly-2024-03-12
Expand All @@ -41,10 +41,10 @@ jobs:
- uses: actions/checkout@v3
- name: Install linux dependencies
run: sudo apt update && sudo apt install -y cargo clang libssl-dev llvm libudev-dev protobuf-compiler
- name: Install nightly toolchain
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: nightly-2024-03-12
toolchain: 1.77.0
override: true
target: wasm32-unknown-unknown
- name: Rust Cache
Expand All @@ -71,10 +71,10 @@ jobs:
- uses: actions/checkout@v3
- name: Install linux dependencies
run: sudo apt update && sudo apt install -y cargo clang libssl-dev llvm libudev-dev protobuf-compiler
- name: Install nightly toolchain
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: nightly-2024-03-12
toolchain: 1.77.0
override: true
target: wasm32-unknown-unknown
components: clippy
Expand All @@ -94,10 +94,10 @@ jobs:
- uses: actions/checkout@v3
- name: Install linux dependencies
run: sudo apt update && sudo apt install -y cargo clang libssl-dev llvm libudev-dev protobuf-compiler
- name: Install nightly toolchain
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: nightly-2024-03-12
toolchain: 1.77.0
override: true
target: wasm32-unknown-unknown
- name: Rust Cache
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ First, complete the [basic Rust setup instructions](./docs/rust-setup.md).
Use the following command to build the node without launching it:

```sh
cargo +nightly-2024-03-12 build --release
cargo +1.77.0 build --release
```

## Run
Expand Down
4 changes: 2 additions & 2 deletions node/cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,14 @@ pub fn run() -> sc_cli::Result<()> {
if !cfg!(feature = "runtime-benchmarks") {
return Err("Runtime benchmarking wasn't enabled when building the node. \
You can enable it with `--features runtime-benchmarks`."
.into())
.into());
}

#[cfg(feature = "cere-dev-native")]
if chain_spec.is_cere_dev() {
return runner.sync_run(|config| {
cmd.run::<cere_service::cere_dev_runtime::Block, ()>(config)
})
});
}

#[cfg(not(feature = "cere-native"))]
Expand Down
4 changes: 2 additions & 2 deletions node/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ pub fn build_full(
disable_hardware_benchmarks,
|_, _| (),
)
.map(|full| full.with_client(Client::CereDev))
.map(|full| full.with_client(Client::CereDev));
}

#[cfg(feature = "cere-native")]
Expand Down Expand Up @@ -635,7 +635,7 @@ pub fn new_chain_ops(
> {
#[cfg(feature = "cere-dev-native")]
if config.chain_spec.is_cere_dev() {
return chain_ops!(config; cere_dev_runtime, CereDevExecutorDispatch, CereDev)
return chain_ops!(config; cere_dev_runtime, CereDevExecutorDispatch, CereDev);
}

#[cfg(feature = "cere-native")]
Expand Down
3 changes: 2 additions & 1 deletion pallets/ddc-customers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ pub mod pallet {
}
}

#[allow(unused_must_use)]
#[pallet::genesis_build]
impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
fn build(&self) {
Expand Down Expand Up @@ -612,7 +613,7 @@ pub mod pallet {
}

if unlocking_balance >= value {
break
break;
}
}

Expand Down
4 changes: 2 additions & 2 deletions pallets/ddc-nodes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ pub mod pallet {
match node {
Node::Storage(storage_node) => {
if StorageNodes::<T>::contains_key(&storage_node.pub_key) {
return Err(NodeRepositoryError::StorageNodeAlreadyExists)
return Err(NodeRepositoryError::StorageNodeAlreadyExists);
}
StorageNodes::<T>::insert(storage_node.pub_key.clone(), storage_node);
Ok(())
Expand All @@ -206,7 +206,7 @@ pub mod pallet {
match node {
Node::Storage(storage_node) => {
if !StorageNodes::<T>::contains_key(&storage_node.pub_key) {
return Err(NodeRepositoryError::StorageNodeDoesNotExist)
return Err(NodeRepositoryError::StorageNodeDoesNotExist);
}
StorageNodes::<T>::insert(storage_node.pub_key.clone(), storage_node);
},
Expand Down
10 changes: 5 additions & 5 deletions pallets/ddc-staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ pub mod pallet {
ensure!(current_cluster == cluster_id, Error::<T>::AlreadyInRole);
// Cancel previous "chill" attempts
Self::reset_chilling(&controller);
return Ok(())
return Ok(());
} else {
// Can't participate in new Storage network if provider hasn't left the previous
// cluster yet
Expand Down Expand Up @@ -646,27 +646,27 @@ pub mod pallet {
.map_err(Into::<Error<T>>::into)?;
(cluster, chill_delay)
} else {
return Ok(()) // node is already chilling or leaving the cluster
return Ok(()); // node is already chilling or leaving the cluster
};

if delay == BlockNumberFor::<T>::from(0u32) {
// No delay is set, so we can chill right away.
Self::chill_stash(&ledger.stash);
return Ok(())
return Ok(());
}

let can_chill_from = current_block.defensive_saturating_add(delay);
match ledger.chilling {
None => {
// No previous declarations of desire to chill. Note it to allow chilling soon.
Self::chill_stash_soon(&ledger.stash, &controller, cluster, can_chill_from);
return Ok(())
return Ok(());
},
Some(chilling) if can_chill_from < chilling => {
// Time to chill is not reached yet, but it is allowed to chill earlier. Update
// to allow chilling sooner.
Self::chill_stash_soon(&ledger.stash, &controller, cluster, can_chill_from);
return Ok(())
return Ok(());
},
Some(chilling) if chilling > current_block => Err(Error::<T>::TooEarly)?,
Some(_) => (),
Expand Down
4 changes: 2 additions & 2 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[toolchain]
channel = "nightly-2024-03-12"
components = ["clippy", "rustfmt"]
channel = "1.77.0"
components = ["clippy"]
targets = ["wasm32-unknown-unknown"]
4 changes: 2 additions & 2 deletions scripts/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ set -e

echo "*** Initializing WASM build environment"

rustup install nightly-2024-03-12
rustup install 1.77.0

rustup target add wasm32-unknown-unknown --toolchain nightly-2024-03-12
rustup target add wasm32-unknown-unknown --toolchain 1.77.0

ln -sf $PWD/scripts/pre-commit.sh $PWD/.git/hooks/pre-commit || true
ln -sf $PWD/scripts/pre-push.sh $PWD/.git/hooks/pre-push || true
2 changes: 1 addition & 1 deletion scripts/pre-commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Prevent committing badly formatted code

cargo fmt -- --check
cargo +nightly-2024-03-12 fmt -- --check
if [ $? -ne 0 ]; then
echo "Run \`cargo fmt\` to fix formatting issues before committing."
exit 1
Expand Down

0 comments on commit 7ad744e

Please sign in to comment.