diff --git a/src/check/violation.rs b/src/check/violation.rs index 1f1a170..aaea7d1 100644 --- a/src/check/violation.rs +++ b/src/check/violation.rs @@ -162,26 +162,24 @@ impl ViolationKind { /// Optionally returns a help text to be used when displaying the violation kind. pub(crate) fn help(&self) -> Option> { - match self { + let text = match self { ViolationKind::ContractMissing(name) => { - let text = format!(r#"consider adding a contract with name "{name}""#); - Some(text.into()) + format!(r#"consider adding a contract with name "{name}""#).into() } ViolationKind::ContractNameNotMatches(name, _) => { - let text = format!(r#"consider renaming the contract to "{name}""#); - Some(text.into()) + format!(r#"consider renaming the contract to "{name}""#).into() } ViolationKind::SolidityFileMissing(filename) => { let filename = filename.replace(".t.sol", ".tree"); - let text = format!("consider running `bulloak scaffold {filename}`"); - Some(text.into()) + format!("consider running `bulloak scaffold {filename}`").into() } ViolationKind::FunctionOrderMismatch(_, _, _) => { - let text = "consider reordering the function in the file"; - Some(text.into()) + "consider reordering the function in the file".into() } - _ => None, - } + _ => return None, + }; + + Some(text) } pub(crate) fn fix(&self, mut ctx: Context) -> Context { @@ -190,7 +188,7 @@ impl ViolationKind { let pt = sol::Translator::new(INTERNAL_DEFAULT_SOL_VERSION, false).translate(&ctx.hir); let source = sol::Formatter::new().emit(pt.clone()); - let parsed = parse(&source).expect("should parse solidity string"); + let parsed = parse(&source).expect("should parse Solidity string"); ctx.from_parsed(parsed) } ViolationKind::ContractNameNotMatches(new_name, old_name) => { @@ -198,7 +196,7 @@ impl ViolationKind { &format!("contract {old_name}"), &format!("contract {new_name}"), ); - let parsed = parse(&source).expect("should parse solidity string"); + let parsed = parse(&source).expect("should parse Solidity string"); ctx.from_parsed(parsed) } // Assume order violations have been taken care of first. diff --git a/src/hir/hir.rs b/src/hir/hir.rs index 576d002..00a2ff4 100644 --- a/src/hir/hir.rs +++ b/src/hir/hir.rs @@ -55,12 +55,9 @@ pub struct Root { impl Root { pub(crate) fn find_contract(&self) -> Option<&ContractDefinition> { - self.children.iter().find_map(|child| { - if let Hir::ContractDefinition(contract) = child { - Some(contract) - } else { - None - } + self.children.iter().find_map(|child| match child { + Hir::ContractDefinition(contract) => Some(contract), + _ => None, }) } } diff --git a/src/sol/mod.rs b/src/sol/mod.rs index 6d9ec7f..8a89043 100644 --- a/src/sol/mod.rs +++ b/src/sol/mod.rs @@ -15,12 +15,9 @@ pub(crate) use translator::Translator; /// Searches for and returns the first `ContractDefinition` found in a given `SourceUnit`. pub(crate) fn find_contract(pt: &SourceUnit) -> Option> { - pt.0.iter().find_map(|part| { - if let SourceUnitPart::ContractDefinition(contract) = part { - Some(contract.clone()) - } else { - None - } + pt.0.iter().find_map(|part| match part { + SourceUnitPart::ContractDefinition(contract) => Some(contract.clone()), + _ => None, }) }