diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 51abc67..d310ebd 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -18,7 +18,13 @@ jobs: - uses: actions/checkout@v3 - name: Add musl target run: rustup target add x86_64-unknown-linux-musl + - name: Format Check + run: cargo fmt --check - name: Build run: cargo build --verbose + - name: Build Tests + run: cargo build --all-targets --verbose + - name: Clippy + run: cargo clippy --all-targets --no-deps -- -Dwarnings - name: Run tests run: cargo test --verbose diff --git a/src/interpreter.rs b/src/interpreter.rs index d6274d9..31d477d 100644 --- a/src/interpreter.rs +++ b/src/interpreter.rs @@ -941,7 +941,7 @@ impl<'source> Interpreter<'source> { Value::Set(s) if !s.is_empty() => Err(span.source.error( span.line, span.col, - format!("function produced multiple outputs {:?}", value).as_str(), + format!("function produced multiple outputs {value:?}").as_str(), )), // If the function successfully executed, but did not return any value, then return true. Value::Set(s) if s.is_empty() && output_expr.is_none() => Ok(Value::Bool(true)), @@ -1040,7 +1040,7 @@ impl<'source> Interpreter<'source> { Err(e) => Err(span.source.error( span.line, span.col, - format!("could not parse number. {}", e).as_str(), + format!("could not parse number. {e}").as_str(), )), }, // TODO: Handle string vs rawstring diff --git a/src/lexer.rs b/src/lexer.rs index 3d58624..cfa479f 100644 --- a/src/lexer.rs +++ b/src/lexer.rs @@ -21,7 +21,7 @@ impl<'source> Source<'source> { return format!("{}: invalid line {} specified", self.file, line); } - let line_str = format!("{}", line); + let line_str = format!("{line}"); let line_num_width = line_str.len() + 1; let col_spaces = col as usize - 1; diff --git a/src/parser.rs b/src/parser.rs index ee64a3b..db7449d 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -46,7 +46,7 @@ impl<'source> Parser<'source> { if self.tok.1.text() == text { self.next_token() } else { - let msg = format!("expecting `{}` {}", text, context); + let msg = format!("expecting `{text}` {context}"); Err(self.source.error(self.tok.1.line, self.tok.1.col, &msg)) } } @@ -801,7 +801,7 @@ impl<'source> Parser<'source> { return Err(self.source.error( span.line, span.col, - format!("Failed to parse `every` statement.\n{}", e).as_str(), + format!("Failed to parse `every` statement.\n{e}").as_str(), )) } } diff --git a/src/value.rs b/src/value.rs index 6be6926..5d07639 100644 --- a/src/value.rs +++ b/src/value.rs @@ -137,7 +137,7 @@ impl Serialize for Value { impl fmt::Display for Value { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match serde_json::to_string(self) { - Ok(s) => write!(f, "{}", s), + Ok(s) => write!(f, "{s}"), Err(_e) => Err(std::fmt::Error), } } diff --git a/tests/interpreter/mod.rs b/tests/interpreter/mod.rs index 60f24b1..514e72c 100644 --- a/tests/interpreter/mod.rs +++ b/tests/interpreter/mod.rs @@ -270,7 +270,7 @@ fn yaml_test_impl(file: &str) -> Result<()> { let yaml_str = std::fs::read_to_string(file)?; let test: YamlTest = serde_yaml::from_str(&yaml_str)?; - println!("running {}", file); + println!("running {file}"); for case in test.cases { print!("case {} ", case.note); if case.skip == Some(true) { diff --git a/tests/lexer/mod.rs b/tests/lexer/mod.rs index e9fdfba..4c53424 100644 --- a/tests/lexer/mod.rs +++ b/tests/lexer/mod.rs @@ -92,7 +92,7 @@ fn one_file() -> Result<()> { if verbose { println!("{}", tok.1.source.message(tok.1.line, tok.1.col, "", "")); } - println!("{:?}", tok); + println!("{tok:?}"); } Ok(()) @@ -113,7 +113,7 @@ struct Test { } fn yaml_test_impl(file: &str) -> Result<()> { - println!("\nrunning {}", file); + println!("\nrunning {file}"); let yaml = std::fs::read_to_string(file)?; let test: Test = serde_yaml::from_str(&yaml)?; @@ -163,15 +163,13 @@ fn yaml_test_impl(file: &str) -> Result<()> { assert_eq!( tokens.len(), case.tokens.len(), - "\n. Token count mismatch.\nLexed tokens:{:?}", - tokens + "\n. Token count mismatch.\nLexed tokens:{tokens:?}" ); if let Some(k) = &case.kinds { assert_eq!( tokens.len(), k.len(), - "\n. Kind count mismatch.\nLexed tokens:{:?}", - tokens + "\n. Kind count mismatch.\nLexed tokens:{tokens:?}" ); } } @@ -179,11 +177,7 @@ fn yaml_test_impl(file: &str) -> Result<()> { Some(expected) => { let actual = actual.to_string(); if !actual.contains(expected) { - bail!( - "Error message\n`{}\n`\ndoes not contain `{}`", - actual, - expected - ); + bail!("Error message\n`{actual}\n`\ndoes not contain `{expected}`"); } } _ => return Err(actual), diff --git a/tests/parser/mod.rs b/tests/parser/mod.rs index 254ebed..aada829 100644 --- a/tests/parser/mod.rs +++ b/tests/parser/mod.rs @@ -47,7 +47,7 @@ fn one_file() -> Result<()> { }; let mut parser = Parser::new(&source)?; let ast = parser.parse()?; - println!("{:#?}", ast); + println!("{ast:#?}"); Ok(()) } @@ -364,7 +364,7 @@ fn match_bin_op(s: &Span, op: &BinOp, v: &Value) -> Result<()> { s.line, s.col, "mismatch-error", - format!("left = {:?}\nright = {:?}\n", op, v).as_str() + format!("left = {op:?}\nright = {v:?}\n").as_str() ) ), } @@ -382,7 +382,7 @@ fn match_arith_op(s: &Span, op: &ArithOp, v: &Value) -> Result<()> { s.line, s.col, "mismatch-error", - format!("left = {:?}\nright = {:?}\n", op, v).as_str() + format!("left = {op:?}\nright = {v:?}\n").as_str() ) ), } @@ -401,7 +401,7 @@ fn match_bool_op(s: &Span, op: &BoolOp, v: &Value) -> Result<()> { s.line, s.col, "mismatch-error", - format!("left = {:?}\nright = {:?}\n", op, v).as_str() + format!("left = {op:?}\nright = {v:?}\n").as_str() ) ), } @@ -417,7 +417,7 @@ fn match_assign_op(s: &Span, op: &AssignOp, v: &Value) -> Result<()> { s.line, s.col, "mismatch-error", - format!("left = {:?}\nright = {:?}\n", op, v).as_str() + format!("left = {op:?}\nright = {v:?}\n").as_str() ) ), } @@ -653,7 +653,7 @@ struct YamlTest { } fn yaml_test_impl(file: &str) -> Result<()> { - println!("\nrunning {}", file); + println!("\nrunning {file}"); let yaml_str = std::fs::read_to_string(file)?; let test: YamlTest = serde_yaml::from_str(&yaml_str)?; diff --git a/tests/value/mod.rs b/tests/value/mod.rs index 2ee56db..3a9b3fb 100644 --- a/tests/value/mod.rs +++ b/tests/value/mod.rs @@ -37,7 +37,7 @@ fn non_string_key() -> Result<()> { obj.as_object_mut()?.insert(key_obj, Value::Null); let json = serde_json::to_string_pretty(&obj)?; - println!("{}", json); + println!("{json}"); let expected = r#"{ "null": null,