Skip to content

Commit

Permalink
Clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
qarmin committed Dec 7, 2024
1 parent 9519ddc commit 02e2626
Show file tree
Hide file tree
Showing 22 changed files with 58 additions and 63 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
linux-default:
strategy:
matrix:
toolchain: [ stable, 1.69.0 ]
toolchain: [ stable, 1.70.0 ]
type: [ release ]
runs-on: ubuntu-22.04
steps:
Expand Down
3 changes: 3 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
newline_style = "Unix"
max_width = 180
remove_nested_parens = true

# Enable only with nightly channel via - cargo +nightly fmt
imports_granularity = "Module"
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ description = "Fast, powerful and easy to use file renamer"
license = "MIT"
homepage = "https://github.com/qarmin/szyszka"
repository = "https://github.com/qarmin/szyszka"
rust-version = "1.69.0"
rust-version = "1.70.0"

[dependencies]
gio = "0.20"
Expand Down
4 changes: 2 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ upgrade:

fix:
cargo +nightly fmt
cargo clippy --fix --allow-dirty --allow-staged -- -Wclippy::pedantic -Aclippy::comparison_chain -Aclippy::default_trait_access -Aclippy::cast_possible_truncation -Aclippy::must_use_candidate -Aclippy::missing_panics_doc -Aclippy::too_many_lines -Aclippy::cast_precision_loss -Aclippy::cast_sign_loss -Aclippy::module_name_repetitions -Aclippy::struct_excessive_bools -Aclippy::cast_possible_wrap -Aclippy::cast_lossless -Aclippy::if_not_else -Aclippy::wildcard_imports -Aclippy::return_self_not_must_use -Aclippy::missing_errors_doc -Aclippy::match_wildcard_for_single_variants -Aclippy::assigning_clones -Aclippy::unused_self -Aclippy::manual_is_variant_and -Aclippy::new_without_default
cargo clippy --fix --allow-dirty --allow-staged -- -Wclippy::pedantic -Aclippy::struct_field_names -Aclippy::comparison_chain -Aclippy::default_trait_access -Aclippy::cast_possible_truncation -Aclippy::must_use_candidate -Aclippy::missing_panics_doc -Aclippy::too_many_lines -Aclippy::cast_precision_loss -Aclippy::cast_sign_loss -Aclippy::module_name_repetitions -Aclippy::struct_excessive_bools -Aclippy::cast_possible_wrap -Aclippy::cast_lossless -Aclippy::if_not_else -Aclippy::wildcard_imports -Aclippy::return_self_not_must_use -Aclippy::missing_errors_doc -Aclippy::match_wildcard_for_single_variants -Aclippy::assigning_clones -Aclippy::unused_self -Aclippy::manual_is_variant_and -Aclippy::new_without_default
cargo +nightly fmt

clippy_nightly:
Expand All @@ -20,4 +20,4 @@ clippy_nightly:
# if_not_else
# unused_self
# manual_is_variant_and - generated by slint code
# new_without_default
# new_without_default
4 changes: 2 additions & 2 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ donation: https://github.com/sponsors/qarmin
parts:
rust-deps:
plugin: nil
override-pull: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain 1.69.0
override-pull: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain 1.70.0
czkawka:
plugin: rust
after: [ rust-deps ]
Expand All @@ -30,7 +30,7 @@ parts:
apps:
szyszka:
command: bin/szyszka
extensions: [gnome]
extensions: [ gnome ]
plugs:
- home
- removable-media
Expand Down
2 changes: 1 addition & 1 deletion src/gui_connection/connect_add_files_button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub fn connect_add_files_button(gui_data: &GuiData) {
add_files_to_check(files_to_check, &list_store, &mut result_entries);
}

update_records(&tree_view_results, &shared_result_entries, &rules, &UpdateMode::FileAdded, &label_files_folders);
update_records(&tree_view_results, &shared_result_entries, &rules, UpdateMode::FileAdded, &label_files_folders);
}
});

Expand Down
2 changes: 1 addition & 1 deletion src/gui_connection/connect_add_folders_button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ fn create_scan_inside_ignore_files_dialog(
let mut result_entries = shared_result_entries.borrow_mut();
add_folders_to_check(folders_to_check, &list_store, &mut result_entries, check_folders_inside, ignore_folders);
}
update_records(&tree_view_results, &shared_result_entries, &rules, &UpdateMode::FileAdded, &label_files_folders);
update_records(&tree_view_results, &shared_result_entries, &rules, UpdateMode::FileAdded, &label_files_folders);
}
dialog.close();
});
Expand Down
2 changes: 1 addition & 1 deletion src/gui_connection/connect_button_update_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ pub fn connect_button_update_names(gui_data: &GuiData) {
let label_files_folders = gui_data.upper_buttons.label_files_folders.clone();

button_update_names.connect_clicked(move |_| {
update_records(&tree_view_results, &shared_result_entries, &rules, &UpdateMode::UpdateRecords, &label_files_folders);
update_records(&tree_view_results, &shared_result_entries, &rules, UpdateMode::UpdateRecords, &label_files_folders);
});
}
9 changes: 3 additions & 6 deletions src/gui_connection/connect_change_language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,9 @@ pub fn load_language(gui_data: &GuiData) {
}

pub fn load_settings_language() -> Option<String> {
let Some(lang_path) = get_language_config_path() else {
return None;
};
let Ok(short_lang) = read_to_string(lang_path) else {
return None;
};
let lang_path = get_language_config_path()?;
let short_lang = read_to_string(lang_path).ok()?;

Some(short_lang)
}
pub fn save_language(gui_data: &GuiData) {
Expand Down
2 changes: 1 addition & 1 deletion src/gui_connection/connect_remove_files_button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ pub fn connect_remove_files_button(gui_data: &GuiData) {
}

remove_selected_rows(&tree_view_results);
update_records(&tree_view_results, &shared_result_entries, &rules, &UpdateMode::FileRemoved, &label_files_folders);
update_records(&tree_view_results, &shared_result_entries, &rules, UpdateMode::FileRemoved, &label_files_folders);
});
}
4 changes: 2 additions & 2 deletions src/gui_connection/connect_results_move.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn connect_results_modify_one_up(gui_data: &GuiData) {

button_results_one_up.connect_clicked(move |_e| {
move_items_multiple(&tree_view_results, true);
update_records(&tree_view_results, &shared_result_entries, &rules, &UpdateMode::FileMoved, &label_files_folders);
update_records(&tree_view_results, &shared_result_entries, &rules, UpdateMode::FileMoved, &label_files_folders);
});
}
fn move_items_multiple(tree_view: &TreeView, going_up: bool) {
Expand Down Expand Up @@ -59,6 +59,6 @@ pub fn connect_results_modify_one_down(gui_data: &GuiData) {

button_results_one_down.connect_clicked(move |_e| {
move_items_multiple(&tree_view_results, false);
update_records(&tree_view_results, &shared_result_entries, &rules, &UpdateMode::FileMoved, &label_files_folders);
update_records(&tree_view_results, &shared_result_entries, &rules, UpdateMode::FileMoved, &label_files_folders);
});
}
2 changes: 1 addition & 1 deletion src/gui_connection/connect_rule_add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub fn connect_rule_add(gui_data: &GuiData) {

// Reset TreeView and populate it again

update_records(&tree_view_results, &shared_result_entries, &rules, &UpdateMode::RuleAdded, &label_files_folders); // TODO Not only RuleAdded but also RuleEdited, but for now there is no difference
update_records(&tree_view_results, &shared_result_entries, &rules, UpdateMode::RuleAdded, &label_files_folders); // TODO Not only RuleAdded but also RuleEdited, but for now there is no difference
populate_rules_tree_view(&tree_view_window_rules, &rules.borrow().rules);
});
}
8 changes: 4 additions & 4 deletions src/gui_connection/connect_rule_buttons_modify_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub fn connect_rule_modify_remove(gui_data: &GuiData) {
}
}

update_records(&tree_view_results, &shared_result_entries, &rules, &UpdateMode::RuleRemoved, &label_files_folders);
update_records(&tree_view_results, &shared_result_entries, &rules, UpdateMode::RuleRemoved, &label_files_folders);
});
}

Expand All @@ -72,7 +72,7 @@ pub fn connect_rule_modify_one_up(gui_data: &GuiData) {
if !try_to_move_item(&tree_view_window_rules, &rules, true) {
return;
}
update_records(&tree_view_results, &shared_result_entries, &rules, &UpdateMode::RuleRemoved, &label_files_folders);
update_records(&tree_view_results, &shared_result_entries, &rules, UpdateMode::RuleRemoved, &label_files_folders);
});
}

Expand All @@ -89,7 +89,7 @@ pub fn connect_rule_modify_one_down(gui_data: &GuiData) {
if !try_to_move_item(&tree_view_window_rules, &rules, false) {
return;
}
update_records(&tree_view_results, &shared_result_entries, &rules, &UpdateMode::RuleRemoved, &label_files_folders);
update_records(&tree_view_results, &shared_result_entries, &rules, UpdateMode::RuleRemoved, &label_files_folders);
});
}

Expand Down Expand Up @@ -465,7 +465,7 @@ fn set_rules_popover(
let rules = rules.clone();
rules.borrow_mut().rules = cloned_item.rules.clone();
populate_rules_tree_view(&tree_view_window_rules, &cloned_item.rules);
update_records(&tree_view_results, &shared_result_entries, &rules, &UpdateMode::RuleAdded, &label_files_folders);
update_records(&tree_view_results, &shared_result_entries, &rules, UpdateMode::RuleAdded, &label_files_folders);
popover_clone.hide();
});

Expand Down
3 changes: 1 addition & 2 deletions src/gui_connection/connect_start_renaming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ use std::rc::Rc;

use crate::fls;
use gtk4::prelude::*;
use gtk4::Label;
use gtk4::{Dialog, DialogFlags, ListStore, ScrolledWindow, TextView, Widget, Window};
use gtk4::{Dialog, DialogFlags, Label, ListStore, ScrolledWindow, TextView, Widget, Window};

use crate::gui_data_things::gui_data::GuiData;
use crate::help_function::{
Expand Down
3 changes: 1 addition & 2 deletions src/gui_data_things/gui_data_results.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::fls;
use gtk4::prelude::*;
use gtk4::GestureClick;
use gtk4::TreeView;
use gtk4::{GestureClick, TreeView};

#[derive(Clone)]
pub struct GuiResults {
Expand Down
4 changes: 2 additions & 2 deletions src/help_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ pub fn populate_rules_tree_view(tree_view: &TreeView, rules: &[SingleRule]) {

for rule in rules {
let values: [(u32, &dyn ToValue); 3] = [
(ColumnsRules::RuleType as u32, &rule_type_to_string(&rule.rule_type)),
(ColumnsRules::UsageType as u32, &rule_place_to_string(&rule.rule_place)),
(ColumnsRules::RuleType as u32, &rule_type_to_string(rule.rule_type)),
(ColumnsRules::UsageType as u32, &rule_place_to_string(rule.rule_place)),
(ColumnsRules::Description as u32, &rule.rule_description),
];
list_store.set(&list_store.append(), &values);
Expand Down
6 changes: 3 additions & 3 deletions src/initialize_gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ fn create_tree_view_in_scrolled_window(gui_data: &GuiData) {

if number_of_clicks == 2 {
if gesture_click.current_button() == 1 {
common_open_function(&tree_view, ColumnsResults::CurrentName as i32, ColumnsResults::Path as i32, &OpenMode::PathAndName);
common_open_function(&tree_view, ColumnsResults::CurrentName as i32, ColumnsResults::Path as i32, OpenMode::PathAndName);
} else if gesture_click.current_button() == 3 {
common_open_function(&tree_view, ColumnsResults::CurrentName as i32, ColumnsResults::Path as i32, &OpenMode::OnlyPath);
common_open_function(&tree_view, ColumnsResults::CurrentName as i32, ColumnsResults::Path as i32, OpenMode::OnlyPath);
}
}
});
Expand Down Expand Up @@ -91,7 +91,7 @@ fn set_example_name(gui_data: &GuiData) {
update_examples(&gui_data.window_rules, None);
}

fn common_open_function(tree_view: &TreeView, column_name: i32, column_path: i32, opening_mode: &OpenMode) {
fn common_open_function(tree_view: &TreeView, column_name: i32, column_path: i32, opening_mode: OpenMode) {
let selection = tree_view.selection();
let (selected_rows, tree_model) = selection.selected_rows();

Expand Down
6 changes: 2 additions & 4 deletions src/localizer.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use std::collections::HashMap;

use i18n_embed::{
fluent::{fluent_language_loader, FluentLanguageLoader},
DefaultLocalizer, LanguageLoader, Localizer,
};
use i18n_embed::fluent::{fluent_language_loader, FluentLanguageLoader};
use i18n_embed::{DefaultLocalizer, LanguageLoader, Localizer};
use once_cell::sync::Lazy;
use rust_embed::RustEmbed;

Expand Down
17 changes: 8 additions & 9 deletions src/rule/rule_custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ use std::path::Component::Normal;
use std::path::Path;

use chrono::DateTime;
use humansize::format_size;
use humansize::BINARY;
use humansize::{format_size, BINARY};

use crate::help_function::split_file_name;
use crate::rule::rules::*;
Expand Down Expand Up @@ -66,8 +65,8 @@ pub fn rule_custom(data_to_change: &str, rule: &SingleRule, general_rule_number:
let invalid_data = parse_string_rules(
&typ,
&mut new_string,
&general_rule_number,
&rule_number_in_folder,
general_rule_number,
rule_number_in_folder,
&name,
&creation_date,
&modification_date,
Expand Down Expand Up @@ -106,8 +105,8 @@ pub fn rule_custom(data_to_change: &str, rule: &SingleRule, general_rule_number:
pub fn parse_string_rules(
typ: &[&str],
new_string: &mut String,
general_rule_number: &u64,
rule_number_in_folder: &u64,
general_rule_number: u64,
rule_number_in_folder: u64,
name: &str,
creation_date: &str,
modification_date: &str,
Expand Down Expand Up @@ -197,7 +196,7 @@ pub fn parse_string_rules(
// TODO think about putting it to docs or explaining it somewhere that bigger values will crash entire app, so value must be clamped
let fill_zeros = min(fill_zeros, 50);

let used_number = (if typ[0] == "N" { *general_rule_number } else { *rule_number_in_folder }) as i64;
let used_number = (if typ[0] == "N" { general_rule_number } else { rule_number_in_folder }) as i64;

let mut number;
if step_number.checked_mul(used_number).is_none() {
Expand Down Expand Up @@ -278,10 +277,10 @@ mod test {
rule.rule_data.custom_text = "$(K)".to_string();
assert_eq!(rule_custom("wombat.txt", &rule, 0, 1, None), "1");
rule.rule_data.custom_text = "$(K)".to_string();
assert_eq!(rule_custom("wombat.txt", &rule, 1111111110, 0, None), "0");
assert_eq!(rule_custom("wombat.txt", &rule, 1_111_111_110, 0, None), "0");

rule.rule_data.custom_text = "$(N)".to_string();
assert_eq!(rule_custom("wombat.txt", &rule, 0, 111110, None), "0");
assert_eq!(rule_custom("wombat.txt", &rule, 0, 111_110, None), "0");
rule.rule_data.custom_text = "$(N)".to_string();
assert_eq!(rule_custom("wombat.txt", &rule, 1, 0, None), "1");
rule.rule_data.custom_text = "$(N:)".to_string();
Expand Down
26 changes: 13 additions & 13 deletions src/rule/rule_replace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::path::Path;
use crate::help_function::split_file_name;
use crate::rule::rules::*;

pub fn rule_replace(data_to_change: &str, rule: &SingleRule, regex: &Option<Regex>) -> String {
pub fn rule_replace(data_to_change: &str, rule: &SingleRule, regex: Option<&Regex>) -> String {
// No data to change
if rule.rule_data.text_to_find.is_empty() {
return data_to_change.to_string();
Expand Down Expand Up @@ -119,33 +119,33 @@ mod test {
rule.rule_data.text_to_find = "konstantynopolitańczykiewiczówna".to_string();
rule.rule_data.text_to_replace = "rar".to_string();
rule.rule_data.case_sensitive = false;
assert_eq!(rule_replace("QKonstantynopolitańczykiewiczówna.txt", &rule, &None), "Qrar.txt");
assert_eq!(rule_replace("QKonstantynopolitańczykiewiczówna.txt", &rule, None), "Qrar.txt");
rule.rule_data.case_sensitive = true;
assert_eq!(rule_replace("QKonstantynopolitańczykiewiczówna.txt", &rule, &None), "QKonstantynopolitańczykiewiczówna.txt");
assert_eq!(rule_replace("QKonstantynopolitańczykiewiczówna.txt", &rule, None), "QKonstantynopolitańczykiewiczówna.txt");

rule.rule_place = RulePlace::ExtensionAndName;
rule.rule_data.text_to_find = "qw.".to_string();
rule.rule_data.text_to_replace = "tw".to_string();
rule.rule_data.case_sensitive = false;
assert_eq!(rule_replace("QQw.Qw.txt", &rule, &None), "Qtwtwtxt");
assert_eq!(rule_replace("QQw.Qw.txt", &rule, None), "Qtwtwtxt");
rule.rule_data.case_sensitive = true;
assert_eq!(rule_replace("QQw.txt", &rule, &None), "QQw.txt");
assert_eq!(rule_replace("QQw.txt", &rule, None), "QQw.txt");

rule.rule_place = RulePlace::ExtensionAndName;
rule.rule_data.text_to_find = "rrra".to_string();
rule.rule_data.text_to_replace = "rr".to_string();
rule.rule_data.case_sensitive = false;
assert_eq!(rule_replace("Qsr.RrRa", &rule, &None), "Qsr.rr");
assert_eq!(rule_replace("Qsr.RrRa", &rule, None), "Qsr.rr");
rule.rule_data.case_sensitive = true;
assert_eq!(rule_replace("Qsr.RrRarrra", &rule, &None), "Qsr.RrRarr");
assert_eq!(rule_replace("Qsr.RrRarrra", &rule, None), "Qsr.RrRarr");

rule.rule_place = RulePlace::ExtensionAndName;
rule.rule_data.text_to_find = "a".to_string();
rule.rule_data.text_to_replace = "aa".to_string();
rule.rule_data.case_sensitive = false;
assert_eq!(rule_replace("aaa", &rule, &None), "aaaaaa");
assert_eq!(rule_replace("aaa", &rule, None), "aaaaaa");
rule.rule_data.case_sensitive = true;
assert_eq!(rule_replace("aaa", &rule, &None), "aaaaaa");
assert_eq!(rule_replace("aaa", &rule, None), "aaaaaa");
}
#[test]
fn test_replace_regex() {
Expand All @@ -158,24 +158,24 @@ mod test {
rule.rule_data.text_to_replace = "RRR".to_string();
regex = Regex::new(&rule.rule_data.text_to_find).unwrap();
rule.rule_data.regex_replace_all = true;
assert_eq!(rule_replace("ABCD_roman_staszek_BSDE", &rule, &Some(regex)), "ABCD_RRR_BSDE");
assert_eq!(rule_replace("ABCD_roman_staszek_BSDE", &rule, Some(&regex)), "ABCD_RRR_BSDE");

rule.rule_data.text_to_find = "([a-z]+)".to_string();
rule.rule_data.text_to_replace = "PRP".to_string();
regex = Regex::new(&rule.rule_data.text_to_find).unwrap();
rule.rule_data.regex_replace_all = true;
assert_eq!(rule_replace("ABCD_roman_staszek_BSDE", &rule, &Some(regex)), "ABCD_PRP_PRP_BSDE");
assert_eq!(rule_replace("ABCD_roman_staszek_BSDE", &rule, Some(&regex)), "ABCD_PRP_PRP_BSDE");

rule.rule_data.text_to_find = "([a-z]+)".to_string();
rule.rule_data.text_to_replace = "PRP".to_string();
regex = Regex::new(&rule.rule_data.text_to_find).unwrap();
rule.rule_data.regex_replace_all = false;
assert_eq!(rule_replace("ABCD_roman_staszek_BSDE", &rule, &Some(regex)), "ABCD_PRP_staszek_BSDE");
assert_eq!(rule_replace("ABCD_roman_staszek_BSDE", &rule, Some(&regex)), "ABCD_PRP_staszek_BSDE");

rule.rule_data.text_to_find = "([a-z]+_[a-z]+)".to_string();
rule.rule_data.text_to_replace = "PRP".to_string();
regex = Regex::new(&rule.rule_data.text_to_find).unwrap();
rule.rule_data.regex_replace_all = true;
assert_eq!(rule_replace("ABCD_roman_staszek_BSDE", &rule, &Some(regex)), "ABCD_PRP_BSDE");
assert_eq!(rule_replace("ABCD_roman_staszek_BSDE", &rule, Some(&regex)), "ABCD_PRP_BSDE");
}
}
6 changes: 3 additions & 3 deletions src/rule/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl Rules {
item = rule_custom(item.as_str(), rule, current_index, current_index_in_folder as u64, Some(file_data));
}
RuleType::Replace => {
item = rule_replace(item.as_str(), rule, regex);
item = rule_replace(item.as_str(), rule, regex.as_ref());
}
RuleType::AddNumber => {
item = rule_add_number(item.as_str(), rule, current_index);
Expand Down Expand Up @@ -138,7 +138,7 @@ pub enum RulePlace {
FromExtensionEndReverse,
}

pub fn rule_type_to_string(rule_type: &RuleType) -> String {
pub fn rule_type_to_string(rule_type: RuleType) -> String {
match rule_type {
RuleType::Custom => fls!("rule_type_custom"),
RuleType::CaseSize => fls!("rule_type_case_size"),
Expand All @@ -151,7 +151,7 @@ pub fn rule_type_to_string(rule_type: &RuleType) -> String {
}
}

pub fn rule_place_to_string(rule_type: &RulePlace) -> String {
pub fn rule_place_to_string(rule_type: RulePlace) -> String {
match rule_type {
RulePlace::None => fls!("rule_place_none"),
RulePlace::Extension => fls!("rule_place_extension"),
Expand Down
Loading

0 comments on commit 02e2626

Please sign in to comment.