diff --git a/src/app.rs b/src/app.rs index 6c90a590..73a08ee6 100644 --- a/src/app.rs +++ b/src/app.rs @@ -64,9 +64,9 @@ impl App { help: HelpComponent::new(&theme), msg: MsgComponent::new(&theme), tab: 0, - revlog: Revlog::new(&sender, &theme), - status_tab: Status::new(&sender, &queue, &theme), - stashing_tab: Stashing::new(&sender, &queue, &theme), + revlog: Revlog::new(sender, &theme), + status_tab: Status::new(sender, &queue, &theme), + stashing_tab: Stashing::new(sender, &queue, &theme), stashlist_tab: StashList::new(&queue, &theme), queue, theme, @@ -191,7 +191,7 @@ impl App { } /// - pub fn is_quit(&self) -> bool { + pub const fn is_quit(&self) -> bool { self.do_quit } diff --git a/src/components/command.rs b/src/components/command.rs index a6268bfa..bd336cb8 100644 --- a/src/components/command.rs +++ b/src/components/command.rs @@ -50,7 +50,7 @@ pub struct CommandInfo { impl CommandInfo { /// - pub fn new( + pub const fn new( text: CommandText, enabled: bool, available: bool, @@ -64,13 +64,13 @@ impl CommandInfo { } } /// - pub fn order(self, order: i8) -> Self { + pub const fn order(self, order: i8) -> Self { let mut res = self; res.order = order; res } /// - pub fn hidden(self) -> Self { + pub const fn hidden(self) -> Self { let mut res = self; res.quick_bar = false; res diff --git a/src/components/commitlist.rs b/src/components/commitlist.rs index 3119d3c3..b07d2fd0 100644 --- a/src/components/commitlist.rs +++ b/src/components/commitlist.rs @@ -58,12 +58,12 @@ impl CommitList { } /// - pub fn selection(&self) -> usize { + pub const fn selection(&self) -> usize { self.selection } /// - pub fn current_size(&self) -> (u16, u16) { + pub const fn current_size(&self) -> (u16, u16) { self.current_size } @@ -73,12 +73,13 @@ impl CommitList { } /// + #[allow(clippy::missing_const_for_fn)] pub fn selection_max(&self) -> usize { self.count_total.saturating_sub(1) } /// - pub fn tags(&self) -> &Tags { + pub const fn tags(&self) -> &Tags { &self.tags } @@ -242,6 +243,7 @@ impl CommitList { txt } + #[allow(clippy::missing_const_for_fn)] fn relative_selection(&self) -> usize { self.selection.saturating_sub(self.items.index_offset()) } diff --git a/src/components/diff.rs b/src/components/diff.rs index c9254f86..43fb33f0 100644 --- a/src/components/diff.rs +++ b/src/components/diff.rs @@ -54,7 +54,7 @@ impl DiffComponent { } } /// - fn can_scroll(&self) -> bool { + const fn can_scroll(&self) -> bool { self.diff.lines > 1 } /// diff --git a/src/components/msg.rs b/src/components/msg.rs index 739fb646..642f99b0 100644 --- a/src/components/msg.rs +++ b/src/components/msg.rs @@ -96,7 +96,7 @@ impl Component for MsgComponent { } impl MsgComponent { - pub fn new(theme: &Theme) -> Self { + pub const fn new(theme: &Theme) -> Self { Self { msg: String::new(), visible: false, diff --git a/src/components/textinput.rs b/src/components/textinput.rs index b7d25ea2..d32316c4 100644 --- a/src/components/textinput.rs +++ b/src/components/textinput.rs @@ -48,7 +48,7 @@ impl TextInputComponent { } /// - pub fn get_text(&self) -> &String { + pub const fn get_text(&self) -> &String { &self.msg } } diff --git a/src/components/utils/filetree.rs b/src/components/utils/filetree.rs index 2d2c1566..34540d43 100644 --- a/src/components/utils/filetree.rs +++ b/src/components/utils/filetree.rs @@ -23,7 +23,11 @@ pub struct TreeItemInfo { } impl TreeItemInfo { - fn new(indent: u8, path: String, full_path: String) -> Self { + const fn new( + indent: u8, + path: String, + full_path: String, + ) -> Self { Self { indent, visible: true, @@ -147,22 +151,22 @@ impl FileTreeItems { { let item_path = Path::new(&e.path); - FileTreeItems::push_dirs( + Self::push_dirs( item_path, &mut nodes, &mut paths_added, - &collapsed, + collapsed, )?; } - nodes.push(FileTreeItem::new_file(&e)?); + nodes.push(FileTreeItem::new_file(e)?); } Ok(Self(nodes)) } /// - pub(crate) fn items(&self) -> &Vec { + pub(crate) const fn items(&self) -> &Vec { &self.0 } diff --git a/src/components/utils/logitems.rs b/src/components/utils/logitems.rs index d6d8c9f1..38f4cd9a 100644 --- a/src/components/utils/logitems.rs +++ b/src/components/utils/logitems.rs @@ -45,7 +45,7 @@ impl ItemBatch { } /// - pub fn index_offset(&self) -> usize { + pub const fn index_offset(&self) -> usize { self.index_offset } diff --git a/src/components/utils/statustree.rs b/src/components/utils/statustree.rs index f13b25fd..c6d5d6c5 100644 --- a/src/components/utils/statustree.rs +++ b/src/components/utils/statustree.rs @@ -29,7 +29,7 @@ struct SelectionChange { changes: bool, } impl SelectionChange { - fn new(new_index: usize, changes: bool) -> Self { + const fn new(new_index: usize, changes: bool) -> Self { Self { new_index, changes } } } diff --git a/src/main.rs b/src/main.rs index 4ef37e09..26f9a57a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,6 +4,7 @@ //https://github.com/crossterm-rs/crossterm/issues/432 #![allow(clippy::cargo::multiple_crate_versions)] #![deny(clippy::pedantic)] +#![deny(clippy::nursery)] #![deny(clippy::result_unwrap_used)] #![deny(clippy::panic)] #![allow(clippy::module_name_repetitions)] diff --git a/src/ui/style.rs b/src/ui/style.rs index c52c9744..689e45e3 100644 --- a/src/ui/style.rs +++ b/src/ui/style.rs @@ -194,19 +194,19 @@ impl Theme { Ok(app_home.join("theme.ron")) } - fn read_file(theme_file: PathBuf) -> Result { + fn read_file(theme_file: PathBuf) -> Result { let mut f = File::open(theme_file)?; let mut buffer = Vec::new(); f.read_to_end(&mut buffer)?; Ok(from_bytes(&buffer)?) } - fn init_internal() -> Result { - let file = Theme::get_theme_file()?; + fn init_internal() -> Result { + let file = Self::get_theme_file()?; if file.exists() { - Ok(Theme::read_file(file)?) + Ok(Self::read_file(file)?) } else { - let def = Theme::default(); + let def = Self::default(); if def.save().is_err() { log::warn!("failed to store default theme to disk.") } @@ -214,8 +214,8 @@ impl Theme { } } - pub fn init() -> Theme { - Theme::init_internal().unwrap_or_default() + pub fn init() -> Self { + Self::init_internal().unwrap_or_default() } }