diff --git a/src/stdlib/assert.rs b/src/stdlib/assert.rs index 069709e6a..382620737 100644 --- a/src/stdlib/assert.rs +++ b/src/stdlib/assert.rs @@ -1,24 +1,21 @@ use crate::compiler::prelude::*; fn assert(condition: Value, message: Option, format: Option) -> Resolved { - match condition.try_boolean()? { - true => Ok(true.into()), - false => { - if let Some(message) = message { - let message = message.try_bytes_utf8_lossy()?.into_owned(); - Err(ExpressionError::Error { - message: message.clone(), - labels: vec![], - notes: vec![Note::UserErrorMessage(message)], - }) - } else { - let message = match format { - Some(string) => format!("assertion failed: {string}"), - None => "assertion failed".to_owned(), - }; - Err(ExpressionError::from(message)) - } - } + if condition.try_boolean()? { + Ok(true.into()) + } else if let Some(message) = message { + let message = message.try_bytes_utf8_lossy()?.into_owned(); + Err(ExpressionError::Error { + message: message.clone(), + labels: vec![], + notes: vec![Note::UserErrorMessage(message)], + }) + } else { + let message = match format { + Some(string) => format!("assertion failed: {string}"), + None => "assertion failed".to_owned(), + }; + Err(ExpressionError::from(message)) } } diff --git a/src/stdlib/compact.rs b/src/stdlib/compact.rs index ae56d9171..49b9facb3 100644 --- a/src/stdlib/compact.rs +++ b/src/stdlib/compact.rs @@ -291,13 +291,13 @@ mod test { vec!["".into(), Value::Null, "".into()], // original CompactOptions { string: false, - ..Default::default() + ..CompactOptions::default() }, ), ( vec![1.into(), 2.into()], vec![1.into(), Value::Array(vec![]), 2.into()], - Default::default(), + CompactOptions::default(), ), ( vec![1.into(), Value::Array(vec![3.into()]), 2.into()], @@ -306,7 +306,7 @@ mod test { Value::Array(vec![Value::Null, 3.into(), Value::Null]), 2.into(), ], - Default::default(), + CompactOptions::default(), ), ( vec![1.into(), 2.into()], @@ -315,7 +315,7 @@ mod test { Value::Array(vec![Value::Null, Value::Null]), 2.into(), ], - Default::default(), + CompactOptions::default(), ), ( vec![ @@ -334,7 +334,7 @@ mod test { ])), 2.into(), ], - Default::default(), + CompactOptions::default(), ), ]; @@ -359,7 +359,7 @@ mod test { }, // original CompactOptions { string: false, - ..Default::default() + ..CompactOptions::default() }, ), ( @@ -372,7 +372,7 @@ mod test { "key2" => Value::Array(vec![]), "key3" => Value::from(2), }, - Default::default(), + CompactOptions::default(), ), ( ObjectMap::from([ @@ -395,7 +395,7 @@ mod test { ), (KeyString::from("key3"), Value::from(2)), ]), - Default::default(), + CompactOptions::default(), ), ( ObjectMap::from([ @@ -416,7 +416,7 @@ mod test { ]), CompactOptions { recursive: false, - ..Default::default() + ..CompactOptions::default() }, ), ( @@ -432,7 +432,7 @@ mod test { ), (KeyString::from("key3"), Value::from(2)), ]), - Default::default(), + CompactOptions::default(), ), ( btreemap! { @@ -445,7 +445,7 @@ mod test { "key2" => Value::Array(vec![Value::Null, 2.into(), Value::Null]), "key3" => Value::from(2), }, - Default::default(), + CompactOptions::default(), ), ]; diff --git a/src/stdlib/encode_percent.rs b/src/stdlib/encode_percent.rs index 401a03162..5f3948729 100644 --- a/src/stdlib/encode_percent.rs +++ b/src/stdlib/encode_percent.rs @@ -20,7 +20,7 @@ fn encode_percent(value: Value, ascii_set: &Bytes) -> Resolved { Ok(utf8_percent_encode(&string, ascii_set).to_string().into()) } -/// https://url.spec.whatwg.org/#fragment-percent-encode-set +/// const FRAGMENT: &AsciiSet = &percent_encoding::CONTROLS .add(b' ') .add(b'"') @@ -28,7 +28,7 @@ const FRAGMENT: &AsciiSet = &percent_encoding::CONTROLS .add(b'>') .add(b'`'); -/// https://url.spec.whatwg.org/#query-percent-encode-set +/// const QUERY: &AsciiSet = &percent_encoding::CONTROLS .add(b' ') .add(b'"') @@ -36,13 +36,13 @@ const QUERY: &AsciiSet = &percent_encoding::CONTROLS .add(b'<') .add(b'>'); -/// https://url.spec.whatwg.org/#special-percent-encode-set +/// const SPECIAL: &AsciiSet = &QUERY.add(b'\''); -/// https://url.spec.whatwg.org/#path-percent-encode-set +/// const PATH: &AsciiSet = &QUERY.add(b'?').add(b'`').add(b'{').add(b'}'); -/// https://url.spec.whatwg.org/#userinfo-percent-encode-set +/// const USERINFO: &AsciiSet = &PATH .add(b'/') .add(b':') @@ -55,10 +55,10 @@ const USERINFO: &AsciiSet = &PATH .add(b'^') .add(b'|'); -/// https://url.spec.whatwg.org/#component-percent-encode-set +/// const COMPONENT: &AsciiSet = &USERINFO.add(b'$').add(b'%').add(b'&').add(b'+').add(b','); -/// https://url.spec.whatwg.org/#application-x-www-form-urlencoded-percent-encode-set +/// const WWW_FORM_URLENCODED: &AsciiSet = &COMPONENT.add(b'!').add(b'\'').add(b'(').add(b')').add(b'~'); diff --git a/src/stdlib/log.rs b/src/stdlib/log.rs index 9e9be2922..508f2d76a 100644 --- a/src/stdlib/log.rs +++ b/src/stdlib/log.rs @@ -170,7 +170,7 @@ mod tests { value!(1), &Bytes::from("warn"), value!("simple test message"), - Default::default(), + Span::default(), ) .unwrap(); diff --git a/src/stdlib/map_values.rs b/src/stdlib/map_values.rs index f62d12a3a..6ef908fe4 100644 --- a/src/stdlib/map_values.rs +++ b/src/stdlib/map_values.rs @@ -13,9 +13,9 @@ where for item in iter.by_ref() { let value = match item { - IterItem::KeyValue(_, value) => value, - IterItem::IndexValue(_, value) => value, - IterItem::Value(value) => value, + IterItem::KeyValue(_, value) + | IterItem::IndexValue(_, value) + | IterItem::Value(value) => value, }; runner.map_value(ctx, value)?; diff --git a/src/stdlib/mod.rs b/src/stdlib/mod.rs index eb9dc52ec..728debb3d 100644 --- a/src/stdlib/mod.rs +++ b/src/stdlib/mod.rs @@ -1,23 +1,9 @@ -#![deny( - warnings, - clippy::all, - clippy::pedantic, - unreachable_pub, - unused_allocation, - unused_extern_crates, - unused_assignments, - unused_comparisons -)] +#![deny(warnings, clippy::pedantic)] #![allow( deprecated, clippy::cast_possible_truncation, // allowed in initial deny commit clippy::cast_precision_loss, // allowed in initial deny commit clippy::cast_sign_loss, // allowed in initial deny commit - clippy::default_trait_access, // allowed in initial deny commit - clippy::doc_markdown, // allowed in initial deny commit - clippy::inefficient_to_string, // allowed in initial deny commit - clippy::match_bool, // allowed in initial deny commit - clippy::match_same_arms, // allowed in initial deny commit clippy::needless_pass_by_value, // allowed in initial deny commit )] diff --git a/src/stdlib/parse_aws_alb_log.rs b/src/stdlib/parse_aws_alb_log.rs index 2a774af69..b71c6a8d3 100644 --- a/src/stdlib/parse_aws_alb_log.rs +++ b/src/stdlib/parse_aws_alb_log.rs @@ -253,9 +253,10 @@ fn parse_log(mut input: &str) -> ExpressionResult { field_raw!("classification_reason", take_quoted1); field_tid!("traceability_id"); - match input.is_empty() { - true => Ok(log.into()), - false => Err(format!(r#"Log should be fully consumed: "{input}""#).into()), + if input.is_empty() { + Ok(log.into()) + } else { + Err(format!(r#"Log should be fully consumed: "{input}""#).into()) } } diff --git a/src/stdlib/parse_cef.rs b/src/stdlib/parse_cef.rs index 8cd422047..037eb1773 100644 --- a/src/stdlib/parse_cef.rs +++ b/src/stdlib/parse_cef.rs @@ -293,7 +293,7 @@ fn parse_value(input: &str) -> IResult<&str, String, VerboseError<&str>> { ))(input) } -/// As take take_till1 but can have condition on input instead of Input::Item. +/// As take `take_till1` but can have condition on input instead of `Input::Item`. fn take_till1_input<'a, F: Fn(&'a str) -> bool, Error: ParseError<&'a str>>( cond: F, ) -> impl Fn(&'a str) -> IResult<&'a str, &'a str, Error> { diff --git a/src/stdlib/parse_key_value.rs b/src/stdlib/parse_key_value.rs index 8ce1b498f..7d62529eb 100644 --- a/src/stdlib/parse_key_value.rs +++ b/src/stdlib/parse_key_value.rs @@ -387,10 +387,9 @@ fn escape_char(c: char, rest: &mut Peekable) -> char { let _ = rest.next(); '\"' } - // ignore escape sequences not added by encode_key_value and return the backslash untouched - Some(_) => c, - // trailing escape char is a little odd... Might need to error here! - None => c, + // Some(_): ignore escape sequences not added by encode_key_value and return the backslash untouched + // None: // trailing escape char is a little odd... Might need to error here! + Some(_) | None => c, } } else { c diff --git a/src/stdlib/parse_nginx_log.rs b/src/stdlib/parse_nginx_log.rs index a27184ff5..e11b0b7d0 100644 --- a/src/stdlib/parse_nginx_log.rs +++ b/src/stdlib/parse_nginx_log.rs @@ -121,9 +121,7 @@ fn regex_for_format(format: &[u8]) -> &Regex { fn time_format_for_format(format: &[u8]) -> String { match format { - b"combined" => "%d/%b/%Y:%T %z".to_owned(), - b"ingress_upstreaminfo" => "%d/%b/%Y:%T %z".to_owned(), - b"main" => "%d/%b/%Y:%T %z".to_owned(), + b"combined" | b"ingress_upstreaminfo" | b"main" => "%d/%b/%Y:%T %z".to_owned(), b"error" => "%Y/%m/%d %H:%M:%S".to_owned(), _ => unreachable!(), } diff --git a/src/stdlib/parse_syslog.rs b/src/stdlib/parse_syslog.rs index c22751465..c0e519bb7 100644 --- a/src/stdlib/parse_syslog.rs +++ b/src/stdlib/parse_syslog.rs @@ -150,7 +150,7 @@ fn message_to_value(message: Message<&str>) -> Value { for element in message.structured_data { let mut sdata = BTreeMap::new(); for (name, value) in element.params() { - sdata.insert(name.to_string().into(), value.into()); + sdata.insert((*name).into(), value.into()); } result.insert(element.id.to_string().into(), sdata.into()); } diff --git a/src/stdlib/string_utils.rs b/src/stdlib/string_utils.rs index b87eccba1..8f74f07dd 100644 --- a/src/stdlib/string_utils.rs +++ b/src/stdlib/string_utils.rs @@ -2,8 +2,9 @@ use crate::prelude::{Value, ValueError, VrlValueConvert}; pub(crate) fn convert_to_string(value: Value, to_lowercase: bool) -> Result { let string = value.try_bytes_utf8_lossy()?; - Ok(match to_lowercase { - true => string.to_lowercase(), - false => string.to_string(), + Ok(if to_lowercase { + string.to_lowercase() + } else { + string.to_string() }) }