1
0

Run clippy

This commit is contained in:
Jeff 2024-01-23 17:08:26 -05:00
parent e4bd0a51d6
commit 3cc4e24ad4
6 changed files with 39 additions and 39 deletions

View File

@ -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);
}
}

View File

@ -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<Value> {
fn run(&self, _source: &str, _context: &crate::Map) -> crate::Result<Value> {
todo!()
}
fn expected_type(&self, context: &crate::Map) -> crate::Result<Type> {
fn expected_type(&self, _context: &crate::Map) -> crate::Result<Type> {
todo!()
}
}
impl Format for New {
fn format(&self, output: &mut String, indent_level: u8) {
fn format(&self, _output: &mut String, _indent_level: u8) {
todo!()
}
}

View File

@ -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)
}

View File

@ -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::<Vec<char>>();
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

View File

@ -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<Value>) -> Self {
Value::Option(option.map(|value| Box::new(value)))
Value::Option(option.map(Box::new))
}
pub fn is_string(&self) -> bool {

View File

@ -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()",