Skip to content

Commit

Permalink
Fix clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
cetra3 committed Feb 24, 2022
1 parent d0abe2e commit 20b2b8f
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 26 deletions.
2 changes: 1 addition & 1 deletion jmespath/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ fn generate_fn_name(
let expr = get_expr(case);
// Use the comment as the fn description if it is present.
let description = match case.get("comment") {
Some(ref c) => c.as_str().expect("comment is not a string"),
Some(c) => c.as_str().expect("comment is not a string"),
None => expr,
};
format!(
Expand Down
2 changes: 1 addition & 1 deletion jmespath/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl From<serde_json::Error> for JmespathError {

fn inject_carat(column: usize, buff: &mut String) {
buff.push_str(&(0..column).map(|_| ' ').collect::<String>());
buff.push_str(&"^\n");
buff.push_str("^\n");
}

impl fmt::Display for JmespathError {
Expand Down
12 changes: 6 additions & 6 deletions jmespath/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ macro_rules! min_and_max_by {
expected: format!("expression->{}", entered_type),
actual: mapped.get_type().to_string(),
position: 1,
invocation: invocation,
invocation,
}),
));
}
Expand Down Expand Up @@ -416,7 +416,7 @@ impl Function for ContainsFn {
let haystack = &args[0];
let needle = &args[1];
match **haystack {
Variable::Array(ref a) => Ok(Rcvar::new(Variable::Bool(a.contains(&needle)))),
Variable::Array(ref a) => Ok(Rcvar::new(Variable::Bool(a.contains(needle)))),
Variable::String(ref subj) => match needle.as_string() {
None => Ok(Rcvar::new(Variable::Bool(false))),
Some(s) => Ok(Rcvar::new(Variable::Bool(subj.contains(s)))),
Expand Down Expand Up @@ -504,7 +504,7 @@ impl Function for JoinFn {
})
})
.collect::<Result<Vec<String>, JmespathError>>()?
.join(&glue);
.join(glue);
Ok(Rcvar::new(Variable::String(result)))
}
}
Expand Down Expand Up @@ -567,7 +567,7 @@ impl Function for MapFn {
})?;
let mut results = vec![];
for value in values {
results.push(interpret(&value, &ast, ctx)?);
results.push(interpret(value, ast, ctx)?);
}
Ok(Rcvar::new(Variable::Array(results)))
}
Expand Down Expand Up @@ -728,7 +728,7 @@ impl Function for SortByFn {
)
})?;
let mut mapped: Vec<(Rcvar, Rcvar)> = vec![];
let first_value = interpret(&vals[0], &ast, ctx)?;
let first_value = interpret(&vals[0], ast, ctx)?;
let first_type = first_value.get_type();
if first_type != JmespathType::String && first_type != JmespathType::Number {
let reason = ErrorReason::Runtime(RuntimeError::InvalidReturnType {
Expand All @@ -741,7 +741,7 @@ impl Function for SortByFn {
}
mapped.push((vals[0].clone(), first_value));
for (invocation, v) in vals.iter().enumerate().skip(1) {
let mapped_value = interpret(v, &ast, ctx)?;
let mapped_value = interpret(v, ast, ctx)?;
if mapped_value.get_type() != first_type {
return Err(JmespathError::from_ctx(
ctx,
Expand Down
8 changes: 4 additions & 4 deletions jmespath/src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,10 @@ impl<'a> Lexer<'a> {
// Consume identifiers: ( ALPHA / "_" ) *( DIGIT / ALPHA / "_" )
#[inline]
fn consume_identifier(&mut self, first_char: char) -> Token {
Identifier(self.consume_while(first_char.to_string(), |c| match c {
'a'..='z' | '_' | 'A'..='Z' | '0'..='9' => true,
_ => false,
}))
Identifier(self.consume_while(
first_char.to_string(),
|c| matches!(c, 'a'..='z' | '_' | 'A'..='Z' | '0'..='9'),
))
}

// Consumes numbers: *"-" "0" / ( %x31-39 *DIGIT )
Expand Down
4 changes: 2 additions & 2 deletions jmespath/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,12 @@ pub trait ToJmespath {
impl<'a, T: ser::Serialize> ToJmespath for T {
#[cfg(not(feature = "specialized"))]
fn to_jmespath(self) -> Result<Rcvar, JmespathError> {
Ok(Variable::from_serializable(self).map(Rcvar::new)?)
Variable::from_serializable(self).map(Rcvar::new)
}

#[cfg(feature = "specialized")]
default fn to_jmespath(self) -> Result<Rcvar, JmespathError> {
Ok(Variable::from_serializable(self).map(|var| Rcvar::new(var))?)
Variable::from_serializable(self).map(|var| Rcvar::new(var))
}
}

Expand Down
10 changes: 5 additions & 5 deletions jmespath/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl<'a> Parser<'a> {
actual_pos = p;
}
}
JmespathError::new(&self.expr, actual_pos, ErrorReason::Parse(buff))
JmespathError::new(self.expr, actual_pos, ErrorReason::Parse(buff))
}

/// Main parse function of the Pratt parser that parses while RBP < LBP
Expand Down Expand Up @@ -339,12 +339,12 @@ impl<'a> Parser<'a> {
if match self.peek(0) {
&Token::Dot => true,
&Token::Lbracket | &Token::Filter => false,
ref t if t.lbp() < PROJECTION_STOP => {
t if t.lbp() < PROJECTION_STOP => {
return Ok(Ast::Identity {
offset: self.offset,
});
}
ref t => {
t => {
return Err(self.err(t, "Expected '.', '[', or '[?'", true));
}
} {
Expand Down Expand Up @@ -404,7 +404,7 @@ impl<'a> Parser<'a> {
pos += 1;
match self.peek(0) {
&Token::Number(_) | &Token::Colon | &Token::Rbracket => continue,
ref t => return Err(self.err(t, "Expected number, ':', or ']'", true)),
t => return Err(self.err(t, "Expected number, ':', or ']'", true)),
};
}
ref t => return Err(self.err(t, "Expected number, ':', or ']'", false)),
Expand All @@ -417,7 +417,7 @@ impl<'a> Parser<'a> {
offset: self.offset,
idx: parts[0].ok_or_else(|| {
JmespathError::new(
&self.expr,
self.expr,
self.offset,
ErrorReason::Parse(
"Expected parts[0] to be Some; but found None".to_owned(),
Expand Down
11 changes: 4 additions & 7 deletions jmespath/src/variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,7 @@ impl Variable {

/// Returns true if the value is a Number. Returns false otherwise.
pub fn is_number(&self) -> bool {
match self {
Variable::Number(_) => true,
_ => false,
}
matches!(self, Variable::Number(_))
}

/// If the value is a number, return or cast it to a f64.
Expand Down Expand Up @@ -1615,7 +1612,7 @@ mod tests {
#[derive(serde_derive::Serialize)]
struct Map {
num: usize,
};
}

let map = Map { num: 231 };

Expand All @@ -1630,7 +1627,7 @@ mod tests {
#[derive(serde_derive::Serialize)]
struct Map {
num: isize,
};
}

let map = Map { num: -2141 };

Expand All @@ -1645,7 +1642,7 @@ mod tests {
#[derive(serde_derive::Serialize)]
struct Map {
num: f64,
};
}

let map = Map { num: 41.0 };

Expand Down

0 comments on commit 20b2b8f

Please sign in to comment.