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),
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
}

View File

@ -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

View File

@ -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())
}

View File

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

View File

@ -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,

View File

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

View File

@ -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<FileTreeItem> {
pub(crate) const fn items(&self) -> &Vec<FileTreeItem> {
&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
}

View File

@ -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 }
}
}

View File

@ -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)]

View File

@ -194,19 +194,19 @@ impl Theme {
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 buffer = Vec::new();
f.read_to_end(&mut buffer)?;
Ok(from_bytes(&buffer)?)
}
fn init_internal() -> Result<Theme> {
let file = Theme::get_theme_file()?;
fn init_internal() -> Result<Self> {
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()
}
}