diff --git a/src/checks/mod.rs b/src/checks/mod.rs index df7bd18..612b264 100644 --- a/src/checks/mod.rs +++ b/src/checks/mod.rs @@ -138,7 +138,7 @@ pub trait Fixable { } #[allow(unused_variables)] -pub fn check_file(file: &Path, password: Option) -> Result, CheckNotice> { +pub fn check_file(file: &Path, password: &Option) -> Result, CheckNotice> { match file.extension() { Some(ex) => match ex.to_str() { #[cfg(feature = "unzip-osb")] @@ -163,13 +163,6 @@ pub fn check_file(file: &Path, password: Option) -> Result { code: &'a str, name: &'a str, @@ -184,15 +177,23 @@ pub fn print_checks() { "{} {} {}\n\n{}", style(self.code).bold(), style(self.name).underlined(), - match self.fixable { - true => style("(Behebbar)").green(), - false => style("(Nicht behebbar)").red(), + if self.fixable { + style("(Behebbar)").green() + } else { + style("(Nicht behebbar)").red() }, self.description ) } } + println!( + "{}", + style("Die folgenden Probleme sind bekannt\n") + .yellow() + .bold() + ); + vec![ Problem { code: "2023-0001", @@ -247,5 +248,5 @@ pub fn print_checks() { }, ] .iter() - .for_each(|problem| println!("{}\n", problem)) + .for_each(|problem| println!("{problem}\n")); } diff --git a/src/checks/osc.rs b/src/checks/osc.rs index 3d79ce3..42f1c5e 100644 --- a/src/checks/osc.rs +++ b/src/checks/osc.rs @@ -27,7 +27,7 @@ use crate::model::onkostar_editor::OnkostarEditor; pub fn check_file(file: &Path) -> Result, CheckNotice> { match fs::read_to_string(file) { - Ok(content) => check(content), + Ok(content) => check(&content), _ => Err(CheckNotice::Error { description: "Kann Datei nicht lesen".to_string(), line: None, @@ -35,18 +35,18 @@ pub fn check_file(file: &Path) -> Result, CheckNotice> { } } -pub fn check(content: String) -> Result, CheckNotice> { +pub fn check(content: &str) -> Result, CheckNotice> { let mut result = content .lines() .enumerate() - .flat_map(|(line, content)| check_line(line, content.to_string())) + .flat_map(|(line, content)| check_line(line, content)) .collect::>(); - let inner_checks = &mut match OnkostarEditor::from_str(content.as_str()) { + let inner_checks = &mut match OnkostarEditor::from_str(content) { Ok(data) => data.check(), Err(err) => { return Err(CheckNotice::Error { - description: format!("Interner Fehler: {}", err), + description: format!("Interner Fehler: {err}"), line: None, }) } @@ -56,7 +56,7 @@ pub fn check(content: String) -> Result, CheckNotice> { Ok(result) } -fn check_line(line: usize, content: String) -> Vec { +fn check_line(line: usize, content: &str) -> Vec { let mut result = vec![]; if content.contains(" ") { @@ -67,7 +67,7 @@ fn check_line(line: usize, content: String) -> Vec { .to_string(), line: Some(line), example: Some(content.trim().to_string()), - }]) + }]); } result diff --git a/src/commands.rs b/src/commands.rs index db8959d..e9d89cc 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -69,7 +69,7 @@ pub fn handle(command: SubCommand) -> Result<(), Box> { osc @ InputFile::Osc { .. } => { let mut content: OnkostarEditor = osc.try_into()?; if sorted { - content.sorted() + content.sorted(); } if let Some(name) = filter { OnkostarEditor::print_list_filtered(&mut content, name.as_str()); @@ -90,20 +90,20 @@ pub fn handle(command: SubCommand) -> Result<(), Box> { let mut content: OnkostarEditor = match file.try_into() { Ok(oe) => oe, Err(err) => { - println!("{}", err); + println!("{err}"); continue; } }; if sorted { - content.sorted() + content.sorted(); } if let Some(name) = filter { OnkostarEditor::print_list_filtered(&mut content, name.as_str()); return Ok(()); } content.print_list(); - println!() + println!(); } _ => { println!( @@ -131,7 +131,7 @@ pub fn handle(command: SubCommand) -> Result<(), Box> { osc @ InputFile::Osc { .. } => { let mut content: OnkostarEditor = osc.try_into()?; if sorted { - content.sorted() + content.sorted(); } if let Some(name) = filter { OnkostarEditor::print_tree_filtered(&mut content, name.as_str()); @@ -165,9 +165,9 @@ pub fn handle(command: SubCommand) -> Result<(), Box> { if let Some(profile) = profile { let profile = if profile.contains('.') { - FileReader::::read(profile)? + FileReader::::read(&profile)? } else { - Profile::embedded_profile(profile.as_str())? + Profile::embedded_profile(&profile)? }; data.apply_profile(&profile); @@ -243,7 +243,7 @@ pub fn handle(command: SubCommand) -> Result<(), Box> { match outputfile { Some(filename) => write_outputfile(filename, output)?, None => { - println!("{}", output) + println!("{output}"); } } } @@ -258,8 +258,8 @@ pub fn handle(command: SubCommand) -> Result<(), Box> { style(&inputfile_b).yellow() ); - let data_a = &mut FileReader::::read(inputfile_a)?; - let data_b = &mut FileReader::::read(inputfile_b)?; + let data_a = &mut FileReader::::read(&inputfile_a)?; + let data_b = &mut FileReader::::read(&inputfile_b)?; data_a.print_diff(data_b, strict); } @@ -273,7 +273,7 @@ pub fn handle(command: SubCommand) -> Result<(), Box> { .unwrap_or_default() .to_str() .unwrap_or_default() - ) + ); } Err(err) => { eprintln!("{}", FileError::Reading(inputfile, err.to_string())); @@ -287,7 +287,7 @@ pub fn handle(command: SubCommand) -> Result<(), Box> { if list { print_checks(); } else { - match check_file(Path::new(file.unwrap_or_default().as_str()), password) { + match check_file(Path::new(file.unwrap_or_default().as_str()), &password) { Ok(notices) => { println!( "Es wurden {} Probleme gefunden\n", @@ -301,10 +301,10 @@ pub fn handle(command: SubCommand) -> Result<(), Box> { ); notices .iter() - .for_each(|check_notice| println!("{}", check_notice)); + .for_each(|check_notice| println!("{check_notice}")); } Err(err) => { - println!("{}", err) + println!("{err}"); } } } diff --git a/src/file_io.rs b/src/file_io.rs index b09322c..039875a 100644 --- a/src/file_io.rs +++ b/src/file_io.rs @@ -48,12 +48,10 @@ impl Display for FileError { f, "{}", match &self { - FileError::Reading(filename, err) => format!("Kann Datei '{}' nicht lesen: {}", filename, err), - FileError::Writing(filename, err) => format!("Kann Datei '{}' nicht schreiben: {}", filename, err), + FileError::Reading(filename, err) => format!("Kann Datei '{filename}' nicht lesen: {err}"), + FileError::Writing(filename, err) => format!("Kann Datei '{filename}' nicht schreiben: {err}"), FileError::Parsing(filename, err) => format!( - "Die Datei '{}' wird nicht unterstützt, ist fehlerhaft oder enthält zusätzliche Inhalte\n{}", - filename, - err + "Die Datei '{filename}' wird nicht unterstützt, ist fehlerhaft oder enthält zusätzliche Inhalte\n{err}" ) } ) @@ -83,10 +81,10 @@ pub enum InputFile { impl InputFile { pub fn filename(&self) -> String { match self { - InputFile::Osc { filename, .. } => filename, - InputFile::Osb { filename, .. } => filename, - InputFile::Yaml { filename, .. } => filename, - InputFile::Other { filename, .. } => filename, + InputFile::Osb { filename, .. } + | InputFile::Osc { filename, .. } + | InputFile::Yaml { filename, .. } + | InputFile::Other { filename, .. } => filename, } .to_string() } @@ -148,7 +146,7 @@ impl InputFile { content: result, }) } - Some("yml") | Some("yaml") => match fs::read_to_string(filename.clone()) { + Some("yml" | "yaml") => match fs::read_to_string(filename.clone()) { Ok(content) => Ok(InputFile::Yaml { filename, content }), Err(err) => Err(FileError::Reading(filename, err.to_string())), }, @@ -208,13 +206,13 @@ pub struct FileReader { } impl FileReader { - pub fn read(filename: String) -> Result { + pub fn read(filename: &str) -> Result { TryInto::::try_into(InputFile::read(filename.to_string(), None)?) } } impl FileReader { - pub fn read(filename: String) -> Result { + pub fn read(filename: &str) -> Result { TryInto::::try_into(InputFile::read(filename.to_string(), None)?) } } diff --git a/src/model/data_catalogue.rs b/src/model/data_catalogue.rs index 940ebec..f05febe 100644 --- a/src/model/data_catalogue.rs +++ b/src/model/data_catalogue.rs @@ -63,9 +63,10 @@ impl Listable for DataCatalogue { fn to_listed_string(&self) -> String { format!( "Datenkatalog ({}) '{}' in Revision '{}'", - match self.is_system_library_content() { - true => style("S").yellow(), - _ => style("u"), + if self.is_system_library_content() { + style("S").yellow() + } else { + style("u") }, style(&self.name).yellow(), style(&self.revision).yellow() @@ -129,11 +130,9 @@ impl Requires for DataCatalogue { self.get_required_entries(all) .iter() .map(|entry| match entry { - Requirement::PropertyCatalogue(_) => { - Some(format!(" - {}\n", entry)) - } - Requirement::ExternalPropertyCatalogue(_) => { - Some(format!(" - {}\n", entry)) + Requirement::PropertyCatalogue(_) + | Requirement::ExternalPropertyCatalogue(_) => { + Some(format!(" - {entry}\n")) } _ => None, }) @@ -231,7 +230,7 @@ impl Sortable for Entry { { if let Some(ref mut use_) = self.use_ { use_.program_module - .sort_unstable_by_key(|item| item.sorting_key()) + .sort_unstable_by_key(|item| item.sorting_key()); } self } diff --git a/src/model/form.rs b/src/model/form.rs index d711d94..8562d92 100644 --- a/src/model/form.rs +++ b/src/model/form.rs @@ -210,7 +210,7 @@ impl FormEntryContainer for Form { .form_references .iter() .for_each(|form_reference| { - apply_profile_to_form_entry(entry, form_reference) + apply_profile_to_form_entry(entry, form_reference); }); // Hide form field using filter set to "false" if requested and change default value @@ -226,7 +226,7 @@ impl FormEntryContainer for Form { column: menu_category.column.clone(), }); } - }) + }); } }); } @@ -241,9 +241,10 @@ impl Listable for Form { } else { "Unterformular" }, - match self.is_system_library_content() { - true => style("S").yellow(), - _ => style("u"), + if self.is_system_library_content() { + style("S").yellow() + } else { + style("u") }, style(&self.name).yellow(), style(&self.revision).yellow() diff --git a/src/model/mod.rs b/src/model/mod.rs index 0239b07..383f50c 100644 --- a/src/model/mod.rs +++ b/src/model/mod.rs @@ -323,7 +323,7 @@ where entry.update_scripts_code(scripts_code.clone()); } if form_reference.remove_filter { - entry.remove_filter() + entry.remove_filter(); } } } @@ -334,16 +334,16 @@ where { if entry.get_name() == form_field.name { if form_field.hide { - entry.hide() + entry.hide(); } if let Some(new_default_value) = &form_field.default_value { - entry.update_default_value(new_default_value.to_string()) + entry.update_default_value(new_default_value.to_string()); } if let Some(scripts_code) = &form_field.escaped_scripts_code() { entry.update_scripts_code(scripts_code.clone()); } if form_field.remove_filter { - entry.remove_filter() + entry.remove_filter(); } } } @@ -372,7 +372,7 @@ pub trait Comparable: Debug { fn get_revision(&self) -> u16; fn get_hash(&self) -> String { let mut h = DefaultHasher::new(); - format!("{:?}", self).hash(&mut h); + format!("{self:?}").hash(&mut h); h.finish().to_string() } fn compare_by_requirement(_: &Self, _: &Self) -> Ordering diff --git a/src/model/onkostar_editor.rs b/src/model/onkostar_editor.rs index bac5c27..78c70f2 100644 --- a/src/model/onkostar_editor.rs +++ b/src/model/onkostar_editor.rs @@ -381,7 +381,7 @@ impl OnkostarEditor { ); has_diff = true; } else if strict { - println!("{}: {}", entry_a.get_name(), style("Identisch").green()) + println!("{}: {}", entry_a.get_name(), style("Identisch").green()); } } } @@ -390,7 +390,7 @@ impl OnkostarEditor { }); if !has_diff { - println!("Keine Unterschiede") + println!("Keine Unterschiede"); } } } @@ -464,12 +464,12 @@ impl Checkable for OnkostarEditor { .for_each(|entry| match entry { Requirement::DataFormReference(item) => { if !requirement_checked_forms.contains(&item.get_name()) { - result.push(requirement_error(form, *item, "Formular")) + result.push(requirement_error(form, *item, "Formular")); } } Requirement::UnterformularReference(item) => { if !requirement_checked_forms.contains(&item.get_name()) { - result.push(requirement_error(form, *item, "Unterformular")) + result.push(requirement_error(form, *item, "Unterformular")); } } _ => {} @@ -483,12 +483,12 @@ impl Checkable for OnkostarEditor { .for_each(|entry| match entry { Requirement::DataFormReference(item) => { if !requirement_checked_forms.contains(&item.get_name()) { - result.push(requirement_error(form, *item, "Formular")) + result.push(requirement_error(form, *item, "Formular")); } } Requirement::UnterformularReference(item) => { if !requirement_checked_forms.contains(&item.get_name()) { - result.push(requirement_error(form, *item, "Unterformular")) + result.push(requirement_error(form, *item, "Unterformular")); } } _ => {} diff --git a/src/model/other.rs b/src/model/other.rs index b8229e5..7547c92 100644 --- a/src/model/other.rs +++ b/src/model/other.rs @@ -528,7 +528,7 @@ impl FormEntry for Entry { } fn update_default_value(&mut self, value: String) { - self.default_value = value + self.default_value = value; } fn hide(&mut self) { @@ -537,7 +537,7 @@ impl FormEntry for Entry { valid: true, ref_entries: Some(RefEntries { ref_entry: None }), }); - self.speichern = "0".into() + self.speichern = "0".into(); } fn remove_filter(&mut self) { @@ -557,7 +557,7 @@ impl Sortable for Entry { if let Some(ref mut filter) = self.filter { if let Some(ref mut ref_entries) = filter.ref_entries { if let Some(ref mut ref_entry) = ref_entries.ref_entry { - ref_entry.sort_unstable() + ref_entry.sort_unstable(); } } } diff --git a/src/model/requirements.rs b/src/model/requirements.rs index c741825..8d2e576 100644 --- a/src/model/requirements.rs +++ b/src/model/requirements.rs @@ -73,21 +73,21 @@ impl Display for Requirement<'_> { Requirement::DataFormSubform(item) => item.to_listed_string(), Requirement::UnterformularSubform(item) => item.to_listed_string(), Requirement::ExternalPropertyCatalogue(name) => { - format!("Merkmalskatalog (-) '{}' - hier nicht enthalten", name) + format!("Merkmalskatalog (-) '{name}' - hier nicht enthalten") } Requirement::ExternalDataCatalogue(name) => { - format!("Datenkatalog (-) '{}' - hier nicht enthalten", name) + format!("Datenkatalog (-) '{name}' - hier nicht enthalten") } Requirement::ExternalDataFormReference(name) | Requirement::ExternalDataFormSubform(name) => { - format!("Formular (-) '{}' - hier nicht enthalten", name) + format!("Formular (-) '{name}' - hier nicht enthalten") } Requirement::ExternalUnterformularReference(name) | Requirement::ExternalUnterformularSubform(name) => { - format!("Unterformular (-) '{}' - hier nicht enthalten", name) + format!("Unterformular (-) '{name}' - hier nicht enthalten") } }; - write!(f, "{}", str) + write!(f, "{str}") } } @@ -134,19 +134,19 @@ where } } Requirement::ExternalDataCatalogue(_) => { - Some(format!(" + {}\n", entry)) + Some(format!(" + {entry}\n")) } Requirement::DataFormReference(_) | Requirement::ExternalDataFormReference(_) | Requirement::UnterformularReference(_) | Requirement::ExternalUnterformularReference(_) => { - Some(format!(" > {}\n", entry)) + Some(format!(" > {entry}\n")) } Requirement::DataFormSubform(_) | Requirement::ExternalDataFormSubform(_) | Requirement::UnterformularSubform(_) | Requirement::ExternalUnterformularSubform(_) => { - Some(format!(" * {}\n", entry)) + Some(format!(" * {entry}\n")) } _ => None, })