From 3cc4e24ad4ca560c9505df3d42e8e3a9b912e333 Mon Sep 17 00:00:00 2001 From: Jeff Date: Tue, 23 Jan 2024 17:08:26 -0500 Subject: [PATCH] Run clippy --- src/abstract_tree/for.rs | 2 +- src/abstract_tree/new.rs | 8 ++--- src/built_in_functions/mod.rs | 4 +-- src/built_in_functions/string.rs | 52 ++++++++++++++++---------------- src/value/mod.rs | 10 +++--- tests/types.rs | 2 +- 6 files changed, 39 insertions(+), 39 deletions(-) diff --git a/src/abstract_tree/for.rs b/src/abstract_tree/for.rs index 560a7d7..14bbd53 100644 --- a/src/abstract_tree/for.rs +++ b/src/abstract_tree/for.rs @@ -92,7 +92,7 @@ impl Format for For { self.item_id.format(output, indent_level); output.push_str(" in "); self.collection.format(output, indent_level); - output.push_str(" "); + output.push(' '); self.block.format(output, indent_level); } } diff --git a/src/abstract_tree/new.rs b/src/abstract_tree/new.rs index cc4d496..93a4d7e 100644 --- a/src/abstract_tree/new.rs +++ b/src/abstract_tree/new.rs @@ -16,7 +16,7 @@ impl AbstractTree for New { let identifier_node = node.child(1).unwrap(); let identifier = Identifier::from_syntax(identifier_node, source, context)?; - let mut properties = Vec::new(); + let properties = Vec::new(); Ok(New { identifier, @@ -24,17 +24,17 @@ impl AbstractTree for New { }) } - fn run(&self, source: &str, context: &crate::Map) -> crate::Result { + fn run(&self, _source: &str, _context: &crate::Map) -> crate::Result { todo!() } - fn expected_type(&self, context: &crate::Map) -> crate::Result { + fn expected_type(&self, _context: &crate::Map) -> crate::Result { todo!() } } impl Format for New { - fn format(&self, output: &mut String, indent_level: u8) { + fn format(&self, _output: &mut String, _indent_level: u8) { todo!() } } diff --git a/src/built_in_functions/mod.rs b/src/built_in_functions/mod.rs index dc57cb9..1699a1e 100644 --- a/src/built_in_functions/mod.rs +++ b/src/built_in_functions/mod.rs @@ -62,7 +62,7 @@ impl BuiltInFunction { BuiltInFunction::AssertEqual => { Error::expect_argument_amount(self.name(), 2, arguments.len())?; - let left = arguments.get(0).unwrap(); + let left = arguments.first().unwrap(); let right = arguments.get(1).unwrap(); Ok(Value::Boolean(left == right)) @@ -79,7 +79,7 @@ impl BuiltInFunction { Error::expect_argument_amount(self.name(), 1, arguments.len())?; let string = arguments.first().unwrap().as_string()?; - let value = serde_json::from_str(&string)?; + let value = serde_json::from_str(string)?; Ok(value) } diff --git a/src/built_in_functions/string.rs b/src/built_in_functions/string.rs index e5baf89..7990406 100644 --- a/src/built_in_functions/string.rs +++ b/src/built_in_functions/string.rs @@ -179,7 +179,7 @@ impl StringFunction { StringFunction::EndsWith => { Error::expect_argument_amount(self.name(), 2, arguments.len())?; - let string = arguments.get(0).unwrap().as_string()?; + let string = arguments.first().unwrap().as_string()?; let pattern_string = arguments.get(1).unwrap().as_string()?; let pattern = pattern_string.as_str(); @@ -188,7 +188,7 @@ impl StringFunction { StringFunction::Find => { Error::expect_argument_amount(self.name(), 2, arguments.len())?; - let string = arguments.get(0).unwrap().as_string()?; + let string = arguments.first().unwrap().as_string()?; let pattern_string = arguments.get(1).unwrap().as_string()?; let pattern = pattern_string.as_str(); let find = string @@ -214,11 +214,11 @@ impl StringFunction { StringFunction::Insert => { Error::expect_argument_amount(self.name(), 3, arguments.len())?; - let mut string = arguments.get(0).unwrap().as_string()?.clone(); + let mut string = arguments.first().unwrap().as_string()?.clone(); let index = arguments.get(1).unwrap().as_integer()? as usize; let insertion = arguments.get(2).unwrap().as_string()?; - string.insert_str(index, &insertion); + string.insert_str(index, insertion); Value::String(string) } @@ -236,7 +236,7 @@ impl StringFunction { StringFunction::Matches => { Error::expect_argument_amount(self.name(), 2, arguments.len())?; - let string = arguments.get(0).unwrap().as_string()?; + let string = arguments.first().unwrap().as_string()?; let pattern_string = arguments.get(1).unwrap().as_string()?; let pattern = pattern_string.as_str(); let matches = string @@ -262,11 +262,11 @@ impl StringFunction { StringFunction::Remove => { Error::expect_argument_amount(self.name(), 2, arguments.len())?; - let string = arguments.get(0).unwrap().as_string()?; + let string = arguments.first().unwrap().as_string()?; let index = arguments.get(1).unwrap().as_integer()? as usize; let chars = string.chars().collect::>(); - if index <= chars.len() - 1 { + if index < chars.len() { let new_string = chars .iter() .map(|char| char.to_string()) @@ -280,20 +280,20 @@ impl StringFunction { StringFunction::ReplaceRange => { Error::expect_argument_amount(self.name(), 3, arguments.len())?; - let mut string = arguments.get(0).unwrap().as_string()?.clone(); + let mut string = arguments.first().unwrap().as_string()?.clone(); let range = arguments.get(1).unwrap().as_list()?.items(); - let start = range.get(0).unwrap_or_default().as_integer()? as usize; + let start = range.first().unwrap_or_default().as_integer()? as usize; let end = range.get(1).unwrap_or_default().as_integer()? as usize; let pattern = arguments.get(2).unwrap().as_string()?; - string.replace_range(start..end, &pattern); + string.replace_range(start..end, pattern); Value::String(string) } StringFunction::Retain => { Error::expect_argument_amount(self.name(), 2, arguments.len())?; - let mut string = arguments.get(0).unwrap().as_string()?.clone(); + let mut string = arguments.first().unwrap().as_string()?.clone(); let predicate = arguments.get(1).unwrap().as_function()?; string.retain(|char| { @@ -309,7 +309,7 @@ impl StringFunction { StringFunction::Split => { Error::expect_argument_amount(self.name(), 2, arguments.len())?; - let string = arguments.get(0).unwrap().as_string()?; + let string = arguments.first().unwrap().as_string()?; let pattern_string = arguments.get(1).unwrap().as_string()?; let pattern = pattern_string.as_str(); let sections = string @@ -322,7 +322,7 @@ impl StringFunction { StringFunction::SplitAt => { Error::expect_argument_amount(self.name(), 2, arguments.len())?; - let string = arguments.get(0).unwrap().as_string()?; + let string = arguments.first().unwrap().as_string()?; let index = arguments.get(1).unwrap().as_integer()?; let (left, right) = string.split_at(index as usize); @@ -334,7 +334,7 @@ impl StringFunction { StringFunction::SplitInclusive => { Error::expect_argument_amount(self.name(), 2, arguments.len())?; - let string = arguments.get(0).unwrap().as_string()?; + let string = arguments.first().unwrap().as_string()?; let pattern_string = arguments.get(1).unwrap().as_string()?; let pattern = pattern_string.as_str(); let sections = string @@ -347,7 +347,7 @@ impl StringFunction { StringFunction::SplitN => { Error::expect_argument_amount(self.name(), 3, arguments.len())?; - let string = arguments.get(0).unwrap().as_string()?; + let string = arguments.first().unwrap().as_string()?; let count = arguments.get(1).unwrap().as_integer()?; let pattern_string = arguments.get(2).unwrap().as_string()?; let pattern = pattern_string.as_str(); @@ -361,7 +361,7 @@ impl StringFunction { StringFunction::SplitOnce => { Error::expect_argument_amount(self.name(), 2, arguments.len())?; - let string = arguments.get(0).unwrap().as_string()?; + let string = arguments.first().unwrap().as_string()?; let pattern_string = arguments.get(1).unwrap().as_string()?; let pattern = pattern_string.as_str(); let sections = string.split_once(pattern).map(|(left, right)| { @@ -376,7 +376,7 @@ impl StringFunction { StringFunction::SplitTerminator => { Error::expect_argument_amount(self.name(), 2, arguments.len())?; - let string = arguments.get(0).unwrap().as_string()?; + let string = arguments.first().unwrap().as_string()?; let pattern_string = arguments.get(1).unwrap().as_string()?; let pattern = pattern_string.as_str(); let sections = string @@ -389,7 +389,7 @@ impl StringFunction { StringFunction::SplitWhitespace => { Error::expect_argument_amount(self.name(), 1, arguments.len())?; - let string = arguments.get(0).unwrap().as_string()?; + let string = arguments.first().unwrap().as_string()?; let sections = string .split_whitespace() .map(|section| Value::string(section.to_string())) @@ -400,7 +400,7 @@ impl StringFunction { StringFunction::StartsWith => { Error::expect_argument_amount(self.name(), 2, arguments.len())?; - let string = arguments.get(0).unwrap().as_string()?; + let string = arguments.first().unwrap().as_string()?; let pattern_string = arguments.get(1).unwrap().as_string()?; let pattern = pattern_string.as_str(); @@ -409,7 +409,7 @@ impl StringFunction { StringFunction::StripPrefix => { Error::expect_argument_amount(self.name(), 2, arguments.len())?; - let string = arguments.get(0).unwrap().as_string()?; + let string = arguments.first().unwrap().as_string()?; let prefix_string = arguments.get(1).unwrap().as_string()?; let prefix = prefix_string.as_str(); let stripped = string @@ -421,7 +421,7 @@ impl StringFunction { StringFunction::ToLowercase => { Error::expect_argument_amount(self.name(), 1, arguments.len())?; - let string = arguments.get(0).unwrap().as_string()?; + let string = arguments.first().unwrap().as_string()?; let lowercase = string.to_lowercase(); Value::string(lowercase) @@ -429,7 +429,7 @@ impl StringFunction { StringFunction::ToUppercase => { Error::expect_argument_amount(self.name(), 1, arguments.len())?; - let string = arguments.get(0).unwrap().as_string()?; + let string = arguments.first().unwrap().as_string()?; let uppercase = string.to_uppercase(); Value::string(uppercase) @@ -456,7 +456,7 @@ impl StringFunction { StringFunction::TrimEndMatches => { Error::expect_argument_amount(self.name(), 2, arguments.len())?; - let string = arguments.get(0).unwrap().as_string()?; + let string = arguments.first().unwrap().as_string()?; let pattern_string = arguments.get(1).unwrap().as_string()?; let pattern = pattern_string.as_str(); let trimmed = string.trim_end_matches(pattern).to_string(); @@ -466,7 +466,7 @@ impl StringFunction { StringFunction::TrimMatches => { Error::expect_argument_amount(self.name(), 2, arguments.len())?; - let string = arguments.get(0).unwrap().as_string()?; + let string = arguments.first().unwrap().as_string()?; let pattern = arguments .get(1) .unwrap() @@ -492,7 +492,7 @@ impl StringFunction { StringFunction::TrimStartMatches => { Error::expect_argument_amount(self.name(), 2, arguments.len())?; - let string = arguments.get(0).unwrap().as_string()?; + let string = arguments.first().unwrap().as_string()?; let pattern = arguments .get(1) .unwrap() @@ -506,7 +506,7 @@ impl StringFunction { StringFunction::Truncate => { Error::expect_argument_amount(self.name(), 2, arguments.len())?; - let input_string = arguments.get(0).unwrap().as_string()?; + let input_string = arguments.first().unwrap().as_string()?; let new_length = arguments.get(1).unwrap().as_integer()? as usize; let new_string = input_string diff --git a/src/value/mod.rs b/src/value/mod.rs index 06f5227..9cdccd6 100644 --- a/src/value/mod.rs +++ b/src/value/mod.rs @@ -54,7 +54,9 @@ impl Value { } pub fn r#type(&self) -> Type { - let r#type = match self { + + + match self { Value::List(list) => { let mut previous_type = None; @@ -101,9 +103,7 @@ impl Value { } } Value::TypeDefinition(_) => todo!(), - }; - - r#type + } } pub fn none() -> Self { @@ -115,7 +115,7 @@ impl Value { } pub fn option(option: Option) -> Self { - Value::Option(option.map(|value| Box::new(value))) + Value::Option(option.map(Box::new)) } pub fn is_string(&self) -> bool { diff --git a/tests/types.rs b/tests/types.rs index 8dabad4..6afade9 100644 --- a/tests/types.rs +++ b/tests/types.rs @@ -18,7 +18,7 @@ fn argument_count_check() { } foo() "; - let result = interpret(&source); + let result = interpret(source); assert_eq!( "Expected 1 arguments, but got 0. Occured at (5, 12) to (5, 17). Source: foo()",