More practical clippy settings, simplify some checks

This commit is contained in:
Timothy Warren 2021-03-11 15:52:30 -05:00
parent fa70f3fd61
commit ec01b65bce
2 changed files with 8 additions and 23 deletions

View File

@ -65,7 +65,6 @@ impl Editor {
let args: Vec<String> = env::args().collect();
let mut initial_status = String::from("HELP: Ctrl-S = save | Ctrl-Q = quit");
let document = if let Some(file_name) = args.get(1) {
let file_name = &args[1];
let doc = Document::open(&file_name);
if let Ok(doc) = doc {
doc
@ -285,11 +284,8 @@ impl Editor {
let terminal_height = self.terminal.size().height as usize;
let Position { mut y, mut x } = self.cursor_position;
let height = self.document.len();
let mut width = if let Some(row) = self.document.row(y) {
row.len()
} else {
0
};
let mut width = self.document.row(y).map_or(0, Row::len);
match key {
Key::Up => y = y.saturating_sub(1),
@ -303,11 +299,7 @@ impl Editor {
x -= 1;
} else if y > 0 {
y -= 1;
if let Some(row) = self.document.row(y) {
x = row.len()
} else {
x = 0
}
x = self.document.row(y).map_or(0, Row::len);
}
},
Key::Right => {
@ -337,11 +329,7 @@ impl Editor {
_ => (),
}
width = if let Some(row) = self.document.row(y) {
row.len()
} else {
0
};
width = self.document.row(y).map_or(0, Row::len);
if x > width {
x = width;

View File

@ -1,11 +1,8 @@
#![warn(clippy::all, clippy::pedantic, clippy::restriction)]
#![warn(clippy::all, clippy::pedantic)]
#![allow(
clippy::missing_docs_in_private_items,
clippy::implicit_return,
clippy::shadow_reuse,
clippy::print_stdout,
clippy::wildcard_enum_match_arm,
clippy::else_if_without_else
clippy::missing_errors_doc,
clippy::must_use_candidate,
clippy::panic,
)]
mod document;
mod editor;