fix(clippy): bring source under -D warnings ahead of CI
Prep for the Forgejo CI gate. Adjustments per module are small
and local:
- test modules get inner `#![allow(clippy::unwrap_used,
expect_used, panic)]` so the existing assert.expect()
test idiom keeps working without rewriting every fixture
- the dead_code field that downstream consumers may still
want serialised gets an explicit #[allow(dead_code)]
- manual char/range comparisons fold to the idiomatic forms
(`['…']`, `(2..=5).contains(&n)`)
- one snake_case rename in text-readability-score
Also re-bakes module.wasm so the committed artefact matches
the post-fmt source byte-for-byte.
No behaviour change, no test change. cargo fmt --all -- --check
and cargo clippy --all-targets -- -D warnings now both pass.
Signed-off-by: flemming-it <sf@flemming.it>
This commit is contained in:
parent
acddc7137c
commit
5c5d8df0fd
2 changed files with 23 additions and 10 deletions
BIN
module.wasm
BIN
module.wasm
Binary file not shown.
27
src/lib.rs
27
src/lib.rs
|
|
@ -75,8 +75,7 @@ struct Paragraph {
|
||||||
#[fai_module]
|
#[fai_module]
|
||||||
pub fn invoke(_ctx: Context, inputs: Inputs) -> Result<Outputs, ModuleError> {
|
pub fn invoke(_ctx: Context, inputs: Inputs) -> Result<Outputs, ModuleError> {
|
||||||
let bytes = inputs.require_bytes("content")?;
|
let bytes = inputs.require_bytes("content")?;
|
||||||
let mime_hint_lower: Option<String> =
|
let mime_hint_lower: Option<String> = inputs.get("mime").and_then(|p| match p {
|
||||||
inputs.get("mime").and_then(|p| match p {
|
|
||||||
Payload::Text(s) => Some(s.to_ascii_lowercase()),
|
Payload::Text(s) => Some(s.to_ascii_lowercase()),
|
||||||
_ => None,
|
_ => None,
|
||||||
});
|
});
|
||||||
|
|
@ -206,7 +205,10 @@ fn split_paragraphs(text: &str) -> Vec<Paragraph> {
|
||||||
return Vec::new();
|
return Vec::new();
|
||||||
}
|
}
|
||||||
let mut out: Vec<Paragraph> = Vec::new();
|
let mut out: Vec<Paragraph> = Vec::new();
|
||||||
let mut current = Paragraph { number: String::new(), text: String::new() };
|
let mut current = Paragraph {
|
||||||
|
number: String::new(),
|
||||||
|
text: String::new(),
|
||||||
|
};
|
||||||
for line in text.lines() {
|
for line in text.lines() {
|
||||||
let line = line.trim();
|
let line = line.trim();
|
||||||
if line.is_empty() {
|
if line.is_empty() {
|
||||||
|
|
@ -216,7 +218,10 @@ fn split_paragraphs(text: &str) -> Vec<Paragraph> {
|
||||||
if !current.text.is_empty() {
|
if !current.text.is_empty() {
|
||||||
out.push(core::mem::replace(
|
out.push(core::mem::replace(
|
||||||
&mut current,
|
&mut current,
|
||||||
Paragraph { number: String::new(), text: String::new() },
|
Paragraph {
|
||||||
|
number: String::new(),
|
||||||
|
text: String::new(),
|
||||||
|
},
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
current.number = num.to_string();
|
current.number = num.to_string();
|
||||||
|
|
@ -242,7 +247,7 @@ fn leading_paragraph_marker(line: &str) -> Option<&str> {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let close = bytes.iter().position(|&b| b == b')')?;
|
let close = bytes.iter().position(|&b| b == b')')?;
|
||||||
if close < 2 || close > 5 {
|
if !(2..=5).contains(&close) {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let inner = line.get(1..close)?;
|
let inner = line.get(1..close)?;
|
||||||
|
|
@ -299,6 +304,7 @@ fn xml_err<E: core::fmt::Display>(e: E) -> ModuleError {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
const SAMPLE_GEWO_14: &str = r#"<?xml version="1.0" encoding="UTF-8"?>
|
const SAMPLE_GEWO_14: &str = r#"<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
@ -332,7 +338,11 @@ mod tests {
|
||||||
let norm = normalize_gii_xml(SAMPLE_GEWO_14.as_bytes()).expect("parse ok");
|
let norm = normalize_gii_xml(SAMPLE_GEWO_14.as_bytes()).expect("parse ok");
|
||||||
assert_eq!(norm.paragraphs.len(), 2);
|
assert_eq!(norm.paragraphs.len(), 2);
|
||||||
assert_eq!(norm.paragraphs[0].number, "(1)");
|
assert_eq!(norm.paragraphs[0].number, "(1)");
|
||||||
assert!(norm.paragraphs[0].text.starts_with("Wer den selbstständigen"));
|
assert!(
|
||||||
|
norm.paragraphs[0]
|
||||||
|
.text
|
||||||
|
.starts_with("Wer den selbstständigen")
|
||||||
|
);
|
||||||
assert_eq!(norm.paragraphs[1].number, "(2)");
|
assert_eq!(norm.paragraphs[1].number, "(2)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -351,7 +361,10 @@ mod tests {
|
||||||
sniff_mime(b"<?xml version=\"1.0\"?><dokumente>"),
|
sniff_mime(b"<?xml version=\"1.0\"?><dokumente>"),
|
||||||
Some("application/xml".into())
|
Some("application/xml".into())
|
||||||
);
|
);
|
||||||
assert_eq!(sniff_mime(b"<dokumente><norm/>"), Some("application/xml".into()));
|
assert_eq!(
|
||||||
|
sniff_mime(b"<dokumente><norm/>"),
|
||||||
|
Some("application/xml".into())
|
||||||
|
);
|
||||||
assert_eq!(sniff_mime(b"%PDF-1.4 ..."), None);
|
assert_eq!(sniff_mime(b"%PDF-1.4 ..."), None);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue