Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Add a rustfmt.toml #8982

Merged
4 commits merged into from
Jul 19, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Basic
hard_tabs = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: could be useful to sort the configuration keys. Makes it easier to compare to the docs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a rustfmt.toml formatter 😅

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting toml files is this issue: rust-lang/rustfmt#4091

max_width = 100
coriolinus marked this conversation as resolved.
Show resolved Hide resolved
use_small_heuristics = "Max"
# Imports
imports_granularity = "Crate"
reorder_imports = true
# Consistency
newline_style = "Unix"
normalize_comments = true
normalize_doc_attributes = true
# Misc
chain_width = 80
spaces_around_ranges = false
binop_separator = "Back"
reorder_impl_items = false
match_arm_leading_pipes = "Preserve"
match_arm_blocks = false
match_block_trailing_comma = true
trailing_comma = "Vertical"
trailing_semicolon = false
use_field_init_shorthand = true
49 changes: 23 additions & 26 deletions utils/browser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,27 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::pin::Pin;

pub use console_error_panic_hook::set_once as set_console_error_panic_hook;
use futures::{
channel::{mpsc, oneshot},
compat::*,
future::{ok, ready, select},
prelude::*,
};
use futures01::sync::mpsc as mpsc01;
use libp2p_wasm_ext::{ffi, ExtTransport};
use log::{debug, info};
use sc_chain_spec::Extension;
use sc_network::config::TransportConfig;
use sc_service::{
RpcSession, Role, Configuration, TaskManager, RpcHandlers,
config::{DatabaseConfig, KeystoreConfig, NetworkConfiguration},
GenericChainSpec, RuntimeGenesis,
KeepBlocks, TransactionStorageMode,
Configuration, GenericChainSpec, KeepBlocks, Role, RpcHandlers, RpcSession, RuntimeGenesis,
TaskManager, TransactionStorageMode,
};
use sc_tracing::logging::LoggerBuilder;
use wasm_bindgen::prelude::*;
use futures::{
prelude::*, channel::{oneshot, mpsc}, compat::*, future::{ready, ok, select}
};
use std::pin::Pin;
use sc_chain_spec::Extension;
use libp2p_wasm_ext::{ExtTransport, ffi};

pub use console_error_panic_hook::set_once as set_console_error_panic_hook;

/// Initialize the logger and return a `TelemetryWorker` and a wasm `ExtTransport`.
pub fn init_logging(pattern: &str) -> Result<(), sc_tracing::logging::Error> {
Expand Down Expand Up @@ -73,7 +75,8 @@ where
task_executor: (|fut, _| {
wasm_bindgen_futures::spawn_local(fut);
async {}
}).into(),
})
.into(),
telemetry_external_transport: Some(transport),
role: Role::Light,
database: {
Expand Down Expand Up @@ -114,9 +117,7 @@ where
max_runtime_instances: 8,
announce_block: true,
base_path: None,
informant_output_format: sc_informant::OutputFormat {
enable_color: false,
},
informant_output_format: sc_informant::OutputFormat { enable_color: false },
disable_log_reloading: false,
};

Expand Down Expand Up @@ -153,12 +154,11 @@ pub fn start_client(mut task_manager: TaskManager, rpc_handlers: RpcHandlers) ->
Box::pin(async move {
let _ = task_manager.future().await;
}),
).map(drop)
)
.map(drop),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, can this newline be disabled? I donno substrate's exiting style though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overflow_delimited_expr can help sometimes in these situations but on balence I think the code works better left to the default value.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the original is indeed better readable here.
Ideally would be a rule to:

  • keep (..).map(drop), as such
  • while letting (..).map(drop).foo(bar) gets split eventually, whether always or dependending on the line width (I would be fine with both options eitherway)

);

Client {
rpc_send_tx,
}
Client { rpc_send_tx }
}

#[wasm_bindgen]
Expand All @@ -175,12 +175,8 @@ impl Client {
});
wasm_bindgen_futures::future_to_promise(async {
match rx.await {
Ok(fut) => {
fut.await
.map(|s| JsValue::from_str(&s))
.ok_or_else(|| JsValue::NULL)
},
Err(_) => Err(JsValue::NULL)
Ok(fut) => fut.await.map(|s| JsValue::from_str(&s)).ok_or_else(|| JsValue::NULL),
gilescope marked this conversation as resolved.
Show resolved Hide resolved
Err(_) => Err(JsValue::NULL),
}
})
}
Expand All @@ -203,7 +199,8 @@ impl Client {
});

wasm_bindgen_futures::spawn_local(async move {
let _ = rx.compat()
let _ = rx
.compat()
.try_for_each(|s| {
let _ = callback.call1(&callback, &JsValue::from_str(&s));
ok(())
Expand Down
10 changes: 5 additions & 5 deletions utils/build-script-utils/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ pub fn rerun_if_git_head_changed() {
Err(err) => {
eprintln!("cargo:warning=Unable to read the Git repository: {}", err);

return;
}
Ok(None) => {}
return
},
drahnr marked this conversation as resolved.
Show resolved Hide resolved
Ok(None) => {},
Ok(Some(paths)) => {
for p in paths {
println!("cargo:rerun-if-changed={}", p.display());
}

return;
}
return
},
}

manifest_dir.pop();
Expand Down
2 changes: 1 addition & 1 deletion utils/build-script-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

//! Crate with utility functions for `build.rs` scripts.

mod version;
mod git;
mod version;
drahnr marked this conversation as resolved.
Show resolved Hide resolved

pub use git::*;
pub use version::*;
9 changes: 4 additions & 5 deletions utils/build-script-utils/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,19 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use platforms::*;
use std::{borrow::Cow, process::Command};

use platforms::*;

/// Generate the `cargo:` key output
pub fn generate_cargo_keys() {
let output = Command::new("git")
.args(&["rev-parse", "--short", "HEAD"])
.output();
let output = Command::new("git").args(&["rev-parse", "--short", "HEAD"]).output();

let commit = match output {
Ok(o) if o.status.success() => {
let sha = String::from_utf8_lossy(&o.stdout).trim().to_owned();
Cow::from(sha)
}
},
Ok(o) => {
println!("cargo:warning=Git command failed with status: {}", o.status);
Cow::from("unknown")
Expand Down
Loading