Skip to content

Commit 142fc32

Browse files
authored
Add rustfmt rules to the project. (#575)
* Rebase master * Added `rustfmt` into needs * Removed default fields in from the `rustfmt` * Removed `force_multiline_blocks` modification * Remove `combine_control_expr` * Updated `CONTRIBUTING.md` with nightly `rustfmt`
1 parent 5ad0dfd commit 142fc32

File tree

144 files changed

+4502
-1810
lines changed

Some content is hidden

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

144 files changed

+4502
-1810
lines changed

.github/workflows/ci.yml

+15-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@ env:
1919
REGISTRY: ghcr.io
2020

2121
jobs:
22+
rustfmt:
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: actions/checkout@v3
26+
- name: Install latest nightly
27+
uses: actions-rs/toolchain@v1
28+
with:
29+
toolchain: nightly
30+
override: true
31+
components: rustfmt
32+
33+
- name: Rustfmt check
34+
run: cargo +nightly fmt --all -- --check
35+
2236
lint-toml-files:
2337
runs-on: ubuntu-latest
2438
steps:
@@ -71,12 +85,11 @@ jobs:
7185
needs:
7286
- lint-toml-files
7387
- prevent-openssl
88+
- rustfmt
7489
runs-on: ubuntu-latest
7590
strategy:
7691
matrix:
7792
include:
78-
- command: fmt
79-
args: --all --verbose -- --check
8093
- command: clippy
8194
args: --all-targets --all-features
8295
- command: make

.rustfmt.toml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
max_width = 90 # changed
2+
normalize_comments = true # changed
3+
imports_layout = "Vertical" # changed
4+
imports_granularity = "Crate" # changed
5+
trailing_semicolon = false # changed
6+
edition = "2021" # changed
7+
use_try_shorthand = true # changed
8+
use_field_init_shorthand = true # changed

CONTRIBUTING.md

+9-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ We use an RFC process to maintain our code standards. They currently live in the
1010

1111
## Building and setting up a development workspace
1212

13-
Fuel Core is mostly written in Rust, but includes components written in C++ (RocksDB). We are currently using the latest Rust stable toolchain.
13+
Fuel Core is mostly written in Rust, but includes components written in C++ (RocksDB).
14+
We are currently using the latest Rust stable toolchain to build the project.
15+
But for `rustfmt`, we use Rust nightly toolchain because it provides more code style features(you can check [`rustfmt.toml`](.rustfmt.toml)).
1416

1517
### Prerequisites
1618

@@ -34,11 +36,12 @@ cd fuel-core
3436

3537
`rustup` is the official toolchain manager for Rust.
3638

37-
We use some additional components such as `rustfmt` and `clippy`, to install those:
39+
We use some additional components such as `clippy` and `rustfmt`(nightly), to install those:
3840

3941
```sh
40-
rustup component add rustfmt
4142
rustup component add clippy
43+
rustup toolchain install nightly
44+
rustup component add rustfmt --toolchain nightly
4245
```
4346

4447
### Building and testing
@@ -56,14 +59,15 @@ This command will run `cargo build` and also dump the latest schema into `/asset
5659
Linting is done using rustfmt and clippy, which are each separate commands:
5760

5861
```sh
59-
cargo fmt --all --check
62+
cargo +nightly fmt --all --check
6063
```
6164

6265
```sh
6366
cargo clippy --all-targets
6467
```
6568

66-
The test suite follows the Rust cargo standards. The GraphQL service will be instantiated by Tower and will emulate a server/client structure.
69+
The test suite follows the Rust cargo standards. The GraphQL service will be instantiated by
70+
Tower and will emulate a server/client structure.
6771

6872
Testing is simply done using Cargo:
6973

fuel-block-importer/src/service.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
use crate::Config;
2-
use fuel_core_interfaces::block_importer::{ImportBlockBroadcast, ImportBlockMpsc};
2+
use fuel_core_interfaces::block_importer::{
3+
ImportBlockBroadcast,
4+
ImportBlockMpsc,
5+
};
36
use parking_lot::Mutex;
47
use tokio::{
5-
sync::{broadcast, mpsc},
8+
sync::{
9+
broadcast,
10+
mpsc,
11+
},
612
task::JoinHandle,
713
};
814

fuel-block-producer/src/service.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
use crate::Config;
2-
use fuel_core_interfaces::{block_producer::BlockProducerMpsc, txpool};
2+
use fuel_core_interfaces::{
3+
block_producer::BlockProducerMpsc,
4+
txpool,
5+
};
36
use parking_lot::Mutex;
4-
use tokio::{sync::mpsc, task::JoinHandle};
7+
use tokio::{
8+
sync::mpsc,
9+
task::JoinHandle,
10+
};
511

612
pub struct Service {
713
join: Mutex<Option<JoinHandle<()>>>,

fuel-client/build.rs

+15-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1-
use schemafy_lib::{Expander, Schema};
2-
use std::env;
3-
use std::fs::{self, File};
4-
use std::io::prelude::*;
5-
use std::path::PathBuf;
1+
use schemafy_lib::{
2+
Expander,
3+
Schema,
4+
};
5+
use std::{
6+
env,
7+
fs::{
8+
self,
9+
File,
10+
},
11+
io::prelude::*,
12+
path::PathBuf,
13+
};
614

715
fn main() {
816
println!("cargo:rerun-if-changed=./assets/debugAdapterProtocol.json");
@@ -13,7 +21,8 @@ fn main() {
1321
.expect("Failed to fetch JSON schema");
1422

1523
let json = fs::read_to_string(&path).expect("Failed to parse JSON from schema");
16-
let schema: Schema = serde_json::from_str(&json).expect("Failed to parse Schema from JSON");
24+
let schema: Schema =
25+
serde_json::from_str(&json).expect("Failed to parse Schema from JSON");
1726
let root_name = schema.title.clone().unwrap_or_else(|| "Root".to_owned());
1827

1928
let path = path.into_os_string();

fuel-client/src/client.rs

+90-24
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,71 @@
11
use crate::client::schema::contract::ContractBalanceQueryArgs;
22
use anyhow::Context;
3-
use cynic::{http::SurfExt, Id, MutationBuilder, Operation, QueryBuilder};
3+
use cynic::{
4+
http::SurfExt,
5+
Id,
6+
MutationBuilder,
7+
Operation,
8+
QueryBuilder,
9+
};
410
use fuel_vm::prelude::*;
511
use itertools::Itertools;
612
use schema::{
713
balance::BalanceArgs,
814
block::BlockByIdArgs,
9-
coin::{Coin, CoinByIdArgs, SpendQueryElementInput},
10-
contract::{Contract, ContractByIdArgs},
11-
tx::{TxArg, TxIdArgs},
12-
Bytes, ContinueTx, ContinueTxArgs, ConversionError, HexString, IdArg, MemoryArgs, RegisterArgs,
13-
RunResult, SetBreakpoint, SetBreakpointArgs, SetSingleStepping, SetSingleSteppingArgs, StartTx,
14-
StartTxArgs, TransactionId, U64,
15+
coin::{
16+
Coin,
17+
CoinByIdArgs,
18+
SpendQueryElementInput,
19+
},
20+
contract::{
21+
Contract,
22+
ContractByIdArgs,
23+
},
24+
tx::{
25+
TxArg,
26+
TxIdArgs,
27+
},
28+
Bytes,
29+
ContinueTx,
30+
ContinueTxArgs,
31+
ConversionError,
32+
HexString,
33+
IdArg,
34+
MemoryArgs,
35+
RegisterArgs,
36+
RunResult,
37+
SetBreakpoint,
38+
SetBreakpointArgs,
39+
SetSingleStepping,
40+
SetSingleSteppingArgs,
41+
StartTx,
42+
StartTxArgs,
43+
TransactionId,
44+
U64,
1545
};
1646
use std::{
1747
convert::TryInto,
18-
io::{self, ErrorKind},
48+
io::{
49+
self,
50+
ErrorKind,
51+
},
1952
net,
20-
str::{self, FromStr},
53+
str::{
54+
self,
55+
FromStr,
56+
},
57+
};
58+
use types::{
59+
TransactionResponse,
60+
TransactionStatus,
2161
};
22-
use types::{TransactionResponse, TransactionStatus};
2362

2463
use crate::client::schema::tx::DryRunArg;
25-
pub use schema::{PageDirection, PaginatedResult, PaginationRequest};
64+
pub use schema::{
65+
PageDirection,
66+
PaginatedResult,
67+
PaginationRequest,
68+
};
2669

2770
use self::schema::block::ProduceBlockArgs;
2871

@@ -175,7 +218,12 @@ impl FuelClient {
175218
Ok(self.query(query).await?.register.0 as Word)
176219
}
177220

178-
pub async fn memory(&self, id: &str, start: usize, size: usize) -> io::Result<Vec<u8>> {
221+
pub async fn memory(
222+
&self,
223+
id: &str,
224+
start: usize,
225+
size: usize,
226+
) -> io::Result<Vec<u8>> {
179227
let query = schema::Memory::build(&MemoryArgs {
180228
id: id.into(),
181229
start: start.into(),
@@ -209,7 +257,11 @@ impl FuelClient {
209257
Ok(())
210258
}
211259

212-
pub async fn set_single_stepping(&self, session_id: &str, enable: bool) -> io::Result<()> {
260+
pub async fn set_single_stepping(
261+
&self,
262+
session_id: &str,
263+
enable: bool,
264+
) -> io::Result<()> {
213265
let operation = SetSingleStepping::build(SetSingleSteppingArgs {
214266
id: Id::new(session_id),
215267
enable,
@@ -218,7 +270,11 @@ impl FuelClient {
218270
Ok(())
219271
}
220272

221-
pub async fn start_tx(&self, session_id: &str, tx: &Transaction) -> io::Result<RunResult> {
273+
pub async fn start_tx(
274+
&self,
275+
session_id: &str,
276+
tx: &Transaction,
277+
) -> io::Result<RunResult> {
222278
let operation = StartTx::build(StartTxArgs {
223279
id: Id::new(session_id),
224280
tx: serde_json::to_string(tx).expect("Couldn't serialize tx to json"),
@@ -314,7 +370,8 @@ impl FuelClient {
314370
}
315371

316372
pub async fn block(&self, id: &str) -> io::Result<Option<schema::block::Block>> {
317-
let query = schema::block::BlockByIdQuery::build(&BlockByIdArgs { id: id.parse()? });
373+
let query =
374+
schema::block::BlockByIdQuery::build(&BlockByIdArgs { id: id.parse()? });
318375

319376
let block = self.query(query).await?.block;
320377

@@ -389,22 +446,28 @@ impl FuelClient {
389446
}
390447

391448
pub async fn contract(&self, id: &str) -> io::Result<Option<Contract>> {
392-
let query =
393-
schema::contract::ContractByIdQuery::build(ContractByIdArgs { id: id.parse()? });
449+
let query = schema::contract::ContractByIdQuery::build(ContractByIdArgs {
450+
id: id.parse()?,
451+
});
394452
let contract = self.query(query).await?.contract;
395453
Ok(contract)
396454
}
397455

398-
pub async fn contract_balance(&self, id: &str, asset: Option<&str>) -> io::Result<u64> {
456+
pub async fn contract_balance(
457+
&self,
458+
id: &str,
459+
asset: Option<&str>,
460+
) -> io::Result<u64> {
399461
let asset_id: schema::AssetId = match asset {
400462
Some(asset) => asset.parse()?,
401463
None => schema::AssetId::default(),
402464
};
403465

404-
let query = schema::contract::ContractBalanceQuery::build(ContractBalanceQueryArgs {
405-
id: id.parse()?,
406-
asset: asset_id,
407-
});
466+
let query =
467+
schema::contract::ContractBalanceQuery::build(ContractBalanceQueryArgs {
468+
id: id.parse()?,
469+
asset: asset_id,
470+
});
408471

409472
let balance = self.query(query).await.unwrap().contract_balance.amount;
410473
Ok(balance.into())
@@ -440,7 +503,9 @@ impl FuelClient {
440503
request: PaginationRequest<String>,
441504
) -> io::Result<PaginatedResult<schema::contract::ContractBalance, String>> {
442505
let contract_id: schema::ContractId = contract.parse()?;
443-
let query = schema::contract::ContractBalancesQuery::build(&(contract_id, request).into());
506+
let query = schema::contract::ContractBalancesQuery::build(
507+
&(contract_id, request).into(),
508+
);
444509

445510
let balances = self.query(query).await?.contract_balances.into();
446511

@@ -452,7 +517,8 @@ impl FuelClient {
452517
owner: Option<&str>,
453518
request: PaginationRequest<String>,
454519
) -> io::Result<PaginatedResult<schema::message::Message, String>> {
455-
let owner: Option<schema::Address> = owner.map(|owner| owner.parse()).transpose()?;
520+
let owner: Option<schema::Address> =
521+
owner.map(|owner| owner.parse()).transpose()?;
456522
let query = schema::message::OwnedMessageQuery::build(&(owner, request).into());
457523

458524
let messages = self.query(query).await?.messages.into();

fuel-client/src/client/schema.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@ pub mod schema {
55
}
66

77
use hex::FromHexError;
8-
use std::array::TryFromSliceError;
9-
use std::fmt::{self, Debug};
10-
use std::io::ErrorKind;
11-
use std::num::TryFromIntError;
8+
use std::{
9+
array::TryFromSliceError,
10+
fmt::{
11+
self,
12+
Debug,
13+
},
14+
io::ErrorKind,
15+
num::TryFromIntError,
16+
};
1217
use thiserror::Error;
1318

1419
pub use primitives::*;

fuel-client/src/client/schema/balance.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1-
use crate::client::schema::{schema, Address, AssetId, PageInfo, U64};
2-
use crate::client::{PageDirection, PaginatedResult, PaginationRequest};
1+
use crate::client::{
2+
schema::{
3+
schema,
4+
Address,
5+
AssetId,
6+
PageInfo,
7+
U64,
8+
},
9+
PageDirection,
10+
PaginatedResult,
11+
PaginationRequest,
12+
};
313

414
#[derive(cynic::FragmentArguments, Debug)]
515
pub struct BalanceArgs {

0 commit comments

Comments
 (0)