diff --git a/cargo.toml b/Cargo.toml similarity index 97% rename from cargo.toml rename to Cargo.toml index 89e71bf..931e4cc 100644 --- a/cargo.toml +++ b/Cargo.toml @@ -1,3 +1,5 @@ [workspace] members = ["htmlua-parser", "htmlua-server"] resolver = "2" + + diff --git a/htmlua-parser/Cargo.toml b/htmlua-parser/Cargo.toml index 8a18618..b611fde 100644 --- a/htmlua-parser/Cargo.toml +++ b/htmlua-parser/Cargo.toml @@ -8,3 +8,7 @@ anyhow = "1.0.98" kuchikiki = "0.8.2" mlua = { version = "0.10.5", features = ["lua54", "vendored", "serialize"] } tendril = "0.4.3" + + +[lints.clippy] +pedantic = { level = "warn", priority = -1 } diff --git a/htmlua-parser/src/lib.rs b/htmlua-parser/src/lib.rs index 80a21dd..dcbd4b1 100644 --- a/htmlua-parser/src/lib.rs +++ b/htmlua-parser/src/lib.rs @@ -1,5 +1,3 @@ -#![warn(clippy::pedantic)] - use std::cell::RefCell; use std::fmt::Write; use std::rc::Rc; @@ -24,8 +22,7 @@ fn create_luahtml_stdlib(l: &Lua, stdout: &Rc>) -> mlua::Result< "println", l.create_function(move |_, text: String| { let mut stdout_ref = stdout_println.borrow_mut(); - writeln!(stdout_ref, "{text}").map_err(mlua::Error::external)?; - Ok(()) + writeln!(stdout_ref, "{text}").map_err(mlua::Error::external) })?, )?; @@ -34,15 +31,17 @@ fn create_luahtml_stdlib(l: &Lua, stdout: &Rc>) -> mlua::Result< "print", l.create_function(move |_, text: String| { let mut stdout_ref = stdout_print.borrow_mut(); - write!(stdout_ref, "{text}").map_err(mlua::Error::external)?; - Ok(()) + write!(stdout_ref, "{text}").map_err(mlua::Error::external) })?, )?; Ok(t) } -pub fn parse>>(to_parse: T) -> Result +pub fn parse(to_parse: T) -> Result where + F: fmt::Format, + A: Atomicity, + T: Into>, tendril::Tendril: std::convert::From>, { let document = kuchikiki::parse_html().one(to_parse.into()); @@ -52,11 +51,11 @@ where let stdout: Rc> = Rc::new(RefCell::new(String::new())); let htmlua_table = create_luahtml_stdlib(&lua, &stdout) - .map_err(|e| anyhow::anyhow!("Failed to create Lua stdlib: {}", e))?; + .map_err(|e| anyhow!("Failed to create Lua stdlib: {}", e))?; globals .set("htmlua", htmlua_table) - .map_err(|e| anyhow::anyhow!("Failed to set global: {}", e))?; + .map_err(|e| anyhow!("Failed to set global: {}", e))?; let lua_elements: Vec<_> = match document.select("lua") { Ok(e) => e.collect(), @@ -69,7 +68,7 @@ where stdout.borrow_mut().clear(); lua.load(lua_code.borrow().as_str()) .exec() - .map_err(|e| anyhow::anyhow!("Failed to execute Lua: {}", e))?; + .map_err(|e| anyhow!("Failed to execute Lua: {}", e))?; node.as_node() .insert_before(NodeRef::new_text(stdout.borrow().as_str())); node.as_node().detach(); @@ -85,7 +84,7 @@ mod tests { use super::*; #[test] - fn base() -> Result<()> { + fn base() { let page = r#" @@ -100,10 +99,9 @@ mod tests { "#; - let d = parse(page)?; + let d = parse(page).unwrap(); let text = d.select_first("span").unwrap().as_node().text_contents(); assert_eq!(text, "Test from Lua!\n"); assert!(d.select_first("lua").is_err()); - Ok(()) } }