clean with pedantic clippy
Some checks are pending
CI/CD Pipeline / test (push) Waiting to run

This commit is contained in:
philipp 2024-02-21 14:21:22 +01:00
parent 287d7bdb8b
commit cc6bedfdf1
6 changed files with 53 additions and 58 deletions

View File

@ -165,7 +165,7 @@ impl PartialEq for LawBuilder {
impl Default for LawBuilder {
fn default() -> Self {
Self::new("".into())
Self::new(String::new())
}
}
@ -347,7 +347,7 @@ impl fmt::Display for Section {
format!("{}\n{}", self.symb, self.content)
};
if let Some(note) = &self.par_note {
to_write.push_str(&format!("\nBeachte: {}\n", note));
to_write.push_str(&format!("\nBeachte: {note}\n"));
}
f.write_str(&to_write)

View File

@ -104,10 +104,9 @@ fn fetch_page(overview_id: usize, page: usize) -> Result<String, Error> {
use std::fs;
let expected_filename = format!("{}law-{overview_id}-{page}", get_cache_dir()?);
match fs::read_to_string(&expected_filename) {
Ok(data) => Ok(data),
Err(_) => {
if let Ok(data) = fs::read_to_string(&expected_filename) {
Ok(data)
} else {
info!("Not finding law_id {overview_id} (page {page}) in the cache, downloading...");
let data = ureq::post("https://data.bka.gv.at/ris/api/v2.6/Bundesrecht")
.send_form(&[
@ -126,7 +125,6 @@ fn fetch_page(overview_id: usize, page: usize) -> Result<String, Error> {
fs::write(expected_filename, &data).expect("Unable to write file");
Ok(data)
}
}
}
#[cfg(test)]

View File

@ -25,7 +25,7 @@ use std::{
path::Path,
};
use log::{info};
use log::info;
use crate::{
law::LawBuilder,
@ -87,7 +87,7 @@ impl Parser {
}
let xml = if self.move_para_headers_into_content {
Self::do_move_para_headers_into_content(xml)
Self::do_move_para_headers_into_content(&xml)
} else {
xml
};
@ -95,8 +95,8 @@ impl Parser {
Risdok::from_str(&xml, builder)
}
fn do_move_para_headers_into_content(xml: String) -> String {
let mut result = String::from(&xml);
fn do_move_para_headers_into_content(xml: &str) -> String {
let mut result = String::from(xml);
let ueberschrift_regex = Regex::new(
"<ueberschrift typ=\"[^\"]*\" ct=\"[^\"]*\" halign=\"[^\"]*\">(§.*?)</ueberschrift>",
)
@ -116,7 +116,7 @@ impl Parser {
// Insert the <gldsym> tag with the ueberschrift content into the result string
result.insert_str(
insert_point,
&format!("<gldsym>{}</gldsym>", ueberschrift_content),
&format!("<gldsym>{ueberschrift_content}</gldsym>"),
);
}
@ -133,10 +133,9 @@ fn fetch(url: &str) -> Result<String, Error> {
let hash = format!("{:x}", hasher.finish());
let expected_filename = format!("{}par-{hash}", get_cache_dir()?);
match fs::read_to_string(&expected_filename) {
Ok(data) => Ok(data),
Err(_) => {
if let Ok(data) = fs::read_to_string(&expected_filename) {
Ok(data)
} else {
info!("Not finding url {url} in the cache, downloading...");
let data = fetch_with_retries(url)?;
let path = Path::new(&expected_filename);
@ -147,7 +146,6 @@ fn fetch(url: &str) -> Result<String, Error> {
fs::write(expected_filename, &data).expect("Unable to write file");
Ok(data)
}
}
}
#[cfg(test)]

View File

@ -62,7 +62,7 @@ impl Absatz {
{
// After a 'absatz' there can be a '<absatz typ="[satz|erltext]"' which should be part of the first absatz
// (e.g. 1209 ABGB)
content.push(Content::Text(Absatz::parse(c.next().unwrap()).content))
content.push(Content::Text(Absatz::parse(c.next().unwrap()).content));
} else {
break;
}

View File

@ -41,7 +41,7 @@ impl Abschnitt {
ret.handle_metadata(&mut c, builder);
if !ret.handle_headers(&mut c, builder) {
if !Self::handle_headers(&mut c, builder) {
return ret;
}
@ -49,9 +49,8 @@ impl Abschnitt {
// Special handling of first paragraph (needs id)...
let (par_id, first_abs) = Absatz::parse_full(&mut c);
let par_id = match par_id {
Some(par_id) => par_id,
None => panic!("First paragraph needs to have an id, not found"),
let Some(par_id) = par_id else {
panic!("First paragraph needs to have an id, not found")
};
absatze.push(first_abs);
@ -118,9 +117,10 @@ impl Abschnitt {
}
}
value = value.trim().into();
if value.is_empty() {
panic!("Expected at least on erltext-absatz after title meta-data");
}
assert!(
!value.is_empty(),
"Expected at least on erltext-absatz after title meta-data"
);
// We want ot use this information in our markdown output.
// TODO: Use all metadata, instead of this specific call
@ -146,7 +146,7 @@ impl Abschnitt {
// we have optionally headers. Such as "Einleitung", "Von den bürgerlichen Gesetzen üerhaupt,"
// etc. If we have headers which indicate that we are done and we want to stop parsing
// ("anlage" + "Artikel" we indicate this wish by returning false.
fn handle_headers(&self, c: &mut Peekable<Children>, builder: &mut LawBuilder) -> bool {
fn handle_headers(c: &mut Peekable<Children>, builder: &mut LawBuilder) -> bool {
while let Some(child) = c.peek() {
// Schiffahrtsgesetz: stop @ anlagen (for now)
if Ueberschrift::test(child, "anlage") {

View File

@ -43,15 +43,14 @@ impl<'a> From<&'a Node<'a, 'a>> for Expect<'a> {
impl<'a> Expect<'a> {
fn tag(&self, value: &str) {
if self.node.tag_name().name() != value {
panic!(
assert!(
!(self.node.tag_name().name() != value),
"Expected tag '{value}', got {} (tag: {}, content: {:?})",
self.node.tag_name().name(),
self.node.tag_name().name(),
self.node.text(),
);
}
}
}
#[derive(Debug, PartialEq)]