Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fmt: update rustfmt config #31

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 8 additions & 5 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
reorder_imports = true
imports_granularity = "Crate"
use_field_init_shorthand = true
use_small_heuristics = "Max"

# Nightly
max_width = 100
comment_width = 100
imports_granularity = "Crate"
wrap_comments = true
binop_separator = "Back"
trailing_comma = "Vertical"
trailing_semicolon = false
use_field_init_shorthand = true
format_code_in_doc_comments = true
doc_comment_code_block_width = 100
format_macro_matchers = true
19 changes: 5 additions & 14 deletions src/artifact_output/configurable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ pub struct ConfigurableArtifacts {
/// _always_ be done using a public constructor or update syntax:
///
/// ```rust
///
/// use foundry_compilers::{ExtraOutputFiles, ConfigurableArtifacts};
/// use foundry_compilers::{ConfigurableArtifacts, ExtraOutputFiles};
/// let config = ConfigurableArtifacts {
/// additional_files: ExtraOutputFiles { metadata: true, ..Default::default() },
/// ..Default::default()
Expand Down Expand Up @@ -395,12 +394,8 @@ pub struct ExtraOutputValues {
/// _always_ be done using a public constructor or update syntax:
///
/// ```rust
///
/// use foundry_compilers::ExtraOutputValues;
/// let config = ExtraOutputValues {
/// ir: true,
/// ..Default::default()
/// };
/// let config = ExtraOutputValues { ir: true, ..Default::default() };
/// ```
#[doc(hidden)]
pub __non_exhaustive: (),
Expand Down Expand Up @@ -516,12 +511,8 @@ pub struct ExtraOutputFiles {
/// _always_ be done using a public constructor or update syntax:
///
/// ```rust
///
/// use foundry_compilers::ExtraOutputFiles;
/// let config = ExtraOutputFiles {
/// metadata: true,
/// ..Default::default()
/// };
/// let config = ExtraOutputFiles { metadata: true, ..Default::default() };
/// ```
#[doc(hidden)]
pub __non_exhaustive: (),
Expand Down Expand Up @@ -584,8 +575,8 @@ impl ExtraOutputFiles {
EvmOutputSelection::ByteCode(BytecodeOutputSelection::SourceMap) => {
config.source_map = true;
}
EvmOutputSelection::DeployedByteCode(DeployedBytecodeOutputSelection::All) |
EvmOutputSelection::DeployedByteCode(
EvmOutputSelection::DeployedByteCode(DeployedBytecodeOutputSelection::All)
| EvmOutputSelection::DeployedByteCode(
DeployedBytecodeOutputSelection::Object,
) => {
config.deployed_bytecode = true;
Expand Down
14 changes: 7 additions & 7 deletions src/artifact_output/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ pub trait ArtifactOutput {
let out_path = artifacts_folder.join(&candidate);
if !already_taken.contains(&out_path) {
trace!("found alternative output file={:?} for {:?}", out_path, contract_file);
return out_path
return out_path;
}
current_parent = current_parent.and_then(|f| f.parent());
}
Expand Down Expand Up @@ -739,7 +739,7 @@ pub trait ArtifactOutput {
.collect();
if !already_taken.contains(&candidate) {
trace!("found alternative output file={:?} for {:?}", candidate, contract_file);
return candidate
return candidate;
}

num += 1;
Expand Down Expand Up @@ -877,8 +877,8 @@ pub trait ArtifactOutput {
// we keep the top most conflicting file unchanged
let is_top_most =
contracts.iter().enumerate().filter(|(i, _)| *i != idx).all(|(_, c)| {
Path::new(file).components().count() <
Path::new(c.file).components().count()
Path::new(file).components().count()
< Path::new(c.file).components().count()
});
if !is_top_most {
// we resolve the conflicting by finding a new unique, alternative path
Expand Down Expand Up @@ -922,10 +922,10 @@ pub trait ArtifactOutput {
// source units
// there's also no need to create a standalone artifact for source files that
// don't contain an ast
if source.source_file.contains_contract_definition() ||
source.source_file.ast.is_none()
if source.source_file.contains_contract_definition()
|| source.source_file.ast.is_none()
{
continue
continue;
}

// we use file and file stem
Expand Down
16 changes: 8 additions & 8 deletions src/artifacts/bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl CompactBytecode {
address: Address,
) -> bool {
if !self.object.is_unlinked() {
return true
return true;
}

let file = file.as_ref();
Expand All @@ -85,7 +85,7 @@ impl CompactBytecode {
self.link_references.insert(key, contracts);
}
if self.link_references.is_empty() {
return self.object.resolve().is_some()
return self.object.resolve().is_some();
}
}
false
Expand Down Expand Up @@ -167,7 +167,7 @@ impl Bytecode {
address: Address,
) -> bool {
if !self.object.is_unlinked() {
return true
return true;
}

let file = file.as_ref();
Expand All @@ -180,7 +180,7 @@ impl Bytecode {
self.link_references.insert(key, contracts);
}
if self.link_references.is_empty() {
return self.object.resolve().is_some()
return self.object.resolve().is_some();
}
}
false
Expand All @@ -195,7 +195,7 @@ impl Bytecode {
{
for (file, lib, addr) in libs.into_iter() {
if self.link(file, lib, addr) {
return true
return true;
}
}
false
Expand All @@ -209,7 +209,7 @@ impl Bytecode {
{
for (name, addr) in libs.into_iter() {
if self.link_fully_qualified(name, addr) {
return true
return true;
}
}
false
Expand Down Expand Up @@ -362,8 +362,8 @@ impl BytecodeObject {
pub fn contains_fully_qualified_placeholder(&self, name: impl AsRef<str>) -> bool {
if let BytecodeObject::Unlinked(unlinked) = self {
let name = name.as_ref();
unlinked.contains(&utils::library_hash_placeholder(name)) ||
unlinked.contains(&utils::library_fully_qualified_placeholder(name))
unlinked.contains(&utils::library_hash_placeholder(name))
|| unlinked.contains(&utils::library_fully_qualified_placeholder(name))
} else {
false
}
Expand Down
15 changes: 6 additions & 9 deletions src/artifacts/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ impl ContractBytecode {
/// # Example
///
/// ```
/// use foundry_compilers::Project;
/// use foundry_compilers::artifacts::*;
/// use foundry_compilers::{artifacts::*, Project};
/// # fn demo(project: Project) {
/// let mut output = project.compile().unwrap().output();
/// let contract: ContractBytecode = output.remove_first("Greeter").unwrap().into();
Expand Down Expand Up @@ -236,7 +235,7 @@ impl TryFrom<ContractBytecode> for ContractBytecodeSome {

fn try_from(value: ContractBytecode) -> Result<Self, Self::Error> {
if value.abi.is_none() || value.bytecode.is_none() || value.deployed_bytecode.is_none() {
return Err(value)
return Err(value);
}
Ok(value.unwrap())
}
Expand All @@ -258,7 +257,7 @@ impl TryFrom<CompactContract> for CompactContractSome {

fn try_from(value: CompactContract) -> Result<Self, Self::Error> {
if value.abi.is_none() || value.bin.is_none() || value.bin_runtime.is_none() {
return Err(value)
return Err(value);
}
Ok(value.unwrap())
}
Expand Down Expand Up @@ -308,8 +307,7 @@ impl CompactContract {
/// # Example
///
/// ```
/// use foundry_compilers::Project;
/// use foundry_compilers::artifacts::*;
/// use foundry_compilers::{artifacts::*, Project};
/// # fn demo(project: Project) {
/// let mut output = project.compile().unwrap().output();
/// let contract: CompactContract = output.remove_first("Greeter").unwrap().into();
Expand Down Expand Up @@ -448,7 +446,7 @@ impl<'a> TryFrom<CompactContractRef<'a>> for CompactContractRefSome<'a> {

fn try_from(value: CompactContractRef<'a>) -> Result<Self, Self::Error> {
if value.abi.is_none() || value.bin.is_none() || value.bin_runtime.is_none() {
return Err(value)
return Err(value);
}
Ok(value.unwrap())
}
Expand Down Expand Up @@ -494,8 +492,7 @@ impl<'a> CompactContractRef<'a> {
/// # Example
///
/// ```
/// use foundry_compilers::Project;
/// use foundry_compilers::artifacts::*;
/// use foundry_compilers::{artifacts::*, Project};
/// # fn demo(project: Project) {
/// let output = project.compile().unwrap().output();
/// let contract = output.find_first("Greeter").unwrap();
Expand Down
39 changes: 19 additions & 20 deletions src/artifacts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,7 @@ impl Settings {
/// Inserts the value for all files and contracts
///
/// ```
/// use foundry_compilers::artifacts::output_selection::ContractOutputSelection;
/// use foundry_compilers::artifacts::Settings;
/// use foundry_compilers::artifacts::{output_selection::ContractOutputSelection, Settings};
/// let mut selection = Settings::default();
/// selection.push_output_selection(ContractOutputSelection::Metadata);
/// ```
Expand Down Expand Up @@ -608,7 +607,7 @@ impl Libraries {
if items.next().is_some() {
return Err(SolcError::msg(format!(
"failed to parse, too many arguments passed: {lib}"
)))
)));
}
libraries
.entry(file.into())
Expand Down Expand Up @@ -741,15 +740,15 @@ pub struct OptimizerDetails {
impl OptimizerDetails {
/// Returns true if no settings are set.
pub fn is_empty(&self) -> bool {
self.peephole.is_none() &&
self.inliner.is_none() &&
self.jumpdest_remover.is_none() &&
self.order_literals.is_none() &&
self.deduplicate.is_none() &&
self.cse.is_none() &&
self.constant_optimizer.is_none() &&
self.yul.is_none() &&
self.yul_details.as_ref().map(|yul| yul.is_empty()).unwrap_or(true)
self.peephole.is_none()
&& self.inliner.is_none()
&& self.jumpdest_remover.is_none()
&& self.order_literals.is_none()
&& self.deduplicate.is_none()
&& self.cse.is_none()
&& self.constant_optimizer.is_none()
&& self.yul.is_none()
&& self.yul_details.as_ref().map(|yul| yul.is_empty()).unwrap_or(true)
}
}

Expand Down Expand Up @@ -1900,7 +1899,7 @@ impl fmt::Display for Error {
let msg = self.formatted_message.as_ref().unwrap_or(&self.message);
self.fmt_severity(f)?;
f.write_str(": ")?;
return f.write_str(msg)
return f.write_str(msg);
}

// Error (XXXX): Error Message
Expand Down Expand Up @@ -2029,7 +2028,7 @@ fn fmt_source_location(f: &mut fmt::Formatter, lines: &mut std::str::Lines) -> f
f.write_str("\n")?;
f.write_str(line)?;
}
return Ok(())
return Ok(());
};

// line 1, just a frame
Expand Down Expand Up @@ -2070,7 +2069,7 @@ fn fmt_framed_location(
if let Some((space_or_line_number, rest)) = line.split_once('|') {
// if the potential frame is not just whitespace or numbers, don't color it
if !space_or_line_number.chars().all(|c| c.is_whitespace() || c.is_numeric()) {
return f.write_str(line)
return f.write_str(line);
}

styled(f, Error::frame_style(), |f| {
Expand Down Expand Up @@ -2187,7 +2186,7 @@ impl SourceFile {
pub fn contains_contract_definition(&self) -> bool {
if let Some(ref ast) = self.ast {
// contract definitions are only allowed at the source-unit level <https://docs.soliditylang.org/en/latest/grammar.html>
return ast.nodes.iter().any(|node| node.node_type == NodeType::ContractDefinition)
return ast.nodes.iter().any(|node| node.node_type == NodeType::ContractDefinition);
// abstract contract, interfaces: ContractDefinition
}

Expand All @@ -2204,10 +2203,10 @@ impl SourceFiles {
/// Returns an iterator over the source files' ids and path
///
/// ```
/// use std::collections::BTreeMap;
/// use foundry_compilers::artifacts::SourceFiles;
/// use std::collections::BTreeMap;
/// # fn demo(files: SourceFiles) {
/// let sources: BTreeMap<u32,String> = files.into_ids().collect();
/// let sources: BTreeMap<u32, String> = files.into_ids().collect();
/// # }
/// ```
pub fn into_ids(self) -> impl Iterator<Item = (u32, String)> {
Expand All @@ -2217,10 +2216,10 @@ impl SourceFiles {
/// Returns an iterator over the source files' paths and ids
///
/// ```
/// use std::collections::BTreeMap;
/// use foundry_compilers::artifacts::SourceFiles;
/// use std::collections::BTreeMap;
/// # fn demo(files: SourceFiles) {
/// let sources :BTreeMap<String, u32> = files.into_paths().collect();
/// let sources: BTreeMap<String, u32> = files.into_paths().collect();
/// # }
/// ```
pub fn into_paths(self) -> impl Iterator<Item = (String, u32)> {
Expand Down
10 changes: 5 additions & 5 deletions src/artifacts/output_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,11 +482,11 @@ impl FromStr for DeployedBytecodeOutputSelection {
"evm.deployedBytecode.functionDebugData" => {
Ok(DeployedBytecodeOutputSelection::FunctionDebugData)
}
"deployed-code" |
"deployed-bin" |
"runtime-code" |
"runtime-bin" |
"evm.deployedBytecode.object" => Ok(DeployedBytecodeOutputSelection::Object),
"deployed-code"
| "deployed-bin"
| "runtime-code"
| "runtime-bin"
| "evm.deployedBytecode.object" => Ok(DeployedBytecodeOutputSelection::Object),
"evm.deployedBytecode.opcodes" => Ok(DeployedBytecodeOutputSelection::Opcodes),
"evm.deployedBytecode.sourceMap" => Ok(DeployedBytecodeOutputSelection::SourceMap),
"evm.deployedBytecode.linkReferences" => {
Expand Down
6 changes: 3 additions & 3 deletions src/artifacts/serde_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub mod json_string_opt {
{
if let Some(s) = Option::<String>::deserialize(deserializer)? {
if s.is_empty() {
return Ok(None)
return Ok(None);
}
let value = serde_json::Value::String(s);
serde_json::from_value(value).map_err(de::Error::custom).map(Some)
Expand Down Expand Up @@ -88,10 +88,10 @@ pub mod empty_json_object_opt {
{
let json = serde_json::Value::deserialize(deserializer)?;
if json.is_null() {
return Ok(None)
return Ok(None);
}
if json.as_object().map(|obj| obj.is_empty()).unwrap_or_default() {
return Ok(None)
return Ok(None);
}
serde_json::from_value(json).map_err(de::Error::custom).map(Some)
}
Expand Down
Loading