add clippy::nursery checks

This commit is contained in:
Stephan Dilly 2020-05-31 01:04:04 +02:00
parent 9cff56c33d
commit f96343061c
11 changed files with 34 additions and 27 deletions

View File

@ -64,9 +64,9 @@ impl App {
help: HelpComponent::new(&theme), help: HelpComponent::new(&theme),
msg: MsgComponent::new(&theme), msg: MsgComponent::new(&theme),
tab: 0, tab: 0,
revlog: Revlog::new(&sender, &theme), revlog: Revlog::new(sender, &theme),
status_tab: Status::new(&sender, &queue, &theme), status_tab: Status::new(sender, &queue, &theme),
stashing_tab: Stashing::new(&sender, &queue, &theme), stashing_tab: Stashing::new(sender, &queue, &theme),
stashlist_tab: StashList::new(&queue, &theme), stashlist_tab: StashList::new(&queue, &theme),
queue, queue,
theme, theme,
@ -191,7 +191,7 @@ impl App {
} }
/// ///
pub fn is_quit(&self) -> bool { pub const fn is_quit(&self) -> bool {
self.do_quit self.do_quit
} }

View File

@ -50,7 +50,7 @@ pub struct CommandInfo {
impl CommandInfo { impl CommandInfo {
/// ///
pub fn new( pub const fn new(
text: CommandText, text: CommandText,
enabled: bool, enabled: bool,
available: 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; let mut res = self;
res.order = order; res.order = order;
res res
} }
/// ///
pub fn hidden(self) -> Self { pub const fn hidden(self) -> Self {
let mut res = self; let mut res = self;
res.quick_bar = false; res.quick_bar = false;
res res

View File

@ -58,12 +58,12 @@ impl CommitList {
} }
/// ///
pub fn selection(&self) -> usize { pub const fn selection(&self) -> usize {
self.selection self.selection
} }
/// ///
pub fn current_size(&self) -> (u16, u16) { pub const fn current_size(&self) -> (u16, u16) {
self.current_size self.current_size
} }
@ -73,12 +73,13 @@ impl CommitList {
} }
/// ///
#[allow(clippy::missing_const_for_fn)]
pub fn selection_max(&self) -> usize { pub fn selection_max(&self) -> usize {
self.count_total.saturating_sub(1) self.count_total.saturating_sub(1)
} }
/// ///
pub fn tags(&self) -> &Tags { pub const fn tags(&self) -> &Tags {
&self.tags &self.tags
} }
@ -242,6 +243,7 @@ impl CommitList {
txt txt
} }
#[allow(clippy::missing_const_for_fn)]
fn relative_selection(&self) -> usize { fn relative_selection(&self) -> usize {
self.selection.saturating_sub(self.items.index_offset()) self.selection.saturating_sub(self.items.index_offset())
} }

View File

@ -54,7 +54,7 @@ impl DiffComponent {
} }
} }
/// ///
fn can_scroll(&self) -> bool { const fn can_scroll(&self) -> bool {
self.diff.lines > 1 self.diff.lines > 1
} }
/// ///

View File

@ -96,7 +96,7 @@ impl Component for MsgComponent {
} }
impl MsgComponent { impl MsgComponent {
pub fn new(theme: &Theme) -> Self { pub const fn new(theme: &Theme) -> Self {
Self { Self {
msg: String::new(), msg: String::new(),
visible: false, visible: false,

View File

@ -48,7 +48,7 @@ impl TextInputComponent {
} }
/// ///
pub fn get_text(&self) -> &String { pub const fn get_text(&self) -> &String {
&self.msg &self.msg
} }
} }

View File

@ -23,7 +23,11 @@ pub struct TreeItemInfo {
} }
impl 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 { Self {
indent, indent,
visible: true, visible: true,
@ -147,22 +151,22 @@ impl FileTreeItems {
{ {
let item_path = Path::new(&e.path); let item_path = Path::new(&e.path);
FileTreeItems::push_dirs( Self::push_dirs(
item_path, item_path,
&mut nodes, &mut nodes,
&mut paths_added, &mut paths_added,
&collapsed, collapsed,
)?; )?;
} }
nodes.push(FileTreeItem::new_file(&e)?); nodes.push(FileTreeItem::new_file(e)?);
} }
Ok(Self(nodes)) Ok(Self(nodes))
} }
/// ///
pub(crate) fn items(&self) -> &Vec<FileTreeItem> { pub(crate) const fn items(&self) -> &Vec<FileTreeItem> {
&self.0 &self.0
} }

View File

@ -45,7 +45,7 @@ impl ItemBatch {
} }
/// ///
pub fn index_offset(&self) -> usize { pub const fn index_offset(&self) -> usize {
self.index_offset self.index_offset
} }

View File

@ -29,7 +29,7 @@ struct SelectionChange {
changes: bool, changes: bool,
} }
impl SelectionChange { impl SelectionChange {
fn new(new_index: usize, changes: bool) -> Self { const fn new(new_index: usize, changes: bool) -> Self {
Self { new_index, changes } Self { new_index, changes }
} }
} }

View File

@ -4,6 +4,7 @@
//https://github.com/crossterm-rs/crossterm/issues/432 //https://github.com/crossterm-rs/crossterm/issues/432
#![allow(clippy::cargo::multiple_crate_versions)] #![allow(clippy::cargo::multiple_crate_versions)]
#![deny(clippy::pedantic)] #![deny(clippy::pedantic)]
#![deny(clippy::nursery)]
#![deny(clippy::result_unwrap_used)] #![deny(clippy::result_unwrap_used)]
#![deny(clippy::panic)] #![deny(clippy::panic)]
#![allow(clippy::module_name_repetitions)] #![allow(clippy::module_name_repetitions)]

View File

@ -194,19 +194,19 @@ impl Theme {
Ok(app_home.join("theme.ron")) Ok(app_home.join("theme.ron"))
} }
fn read_file(theme_file: PathBuf) -> Result<Theme> { fn read_file(theme_file: PathBuf) -> Result<Self> {
let mut f = File::open(theme_file)?; let mut f = File::open(theme_file)?;
let mut buffer = Vec::new(); let mut buffer = Vec::new();
f.read_to_end(&mut buffer)?; f.read_to_end(&mut buffer)?;
Ok(from_bytes(&buffer)?) Ok(from_bytes(&buffer)?)
} }
fn init_internal() -> Result<Theme> { fn init_internal() -> Result<Self> {
let file = Theme::get_theme_file()?; let file = Self::get_theme_file()?;
if file.exists() { if file.exists() {
Ok(Theme::read_file(file)?) Ok(Self::read_file(file)?)
} else { } else {
let def = Theme::default(); let def = Self::default();
if def.save().is_err() { if def.save().is_err() {
log::warn!("failed to store default theme to disk.") log::warn!("failed to store default theme to disk.")
} }
@ -214,8 +214,8 @@ impl Theme {
} }
} }
pub fn init() -> Theme { pub fn init() -> Self {
Theme::init_internal().unwrap_or_default() Self::init_internal().unwrap_or_default()
} }
} }