fix(clippy): get ci passing again

This commit is contained in:
Brooks J Rady 2021-04-13 18:14:13 +01:00
parent 23e0b8adf1
commit 6f4dcfbf65
13 changed files with 141 additions and 125 deletions

View file

@ -19,7 +19,7 @@ To build Zellij, we're using cargo-make you can install it by running `cargo
Here are some of the commands currently supported by the build system: Here are some of the commands currently supported by the build system:
```sh ```sh
# Format code, build, then run tests # Format code, build, then run tests and clippy
cargo make cargo make
# You can also perform these actions individually # You can also perform these actions individually
cargo make format cargo make format

View file

@ -3,6 +3,18 @@
CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = true CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = true
SKIP_TEST = false SKIP_TEST = false
# Add clippy to the default flow
[tasks.dev-test-flow]
dependencies = [
"format-flow",
"format-toml-conditioned-flow",
"pre-build",
"build",
"post-build",
"test-flow",
"clippy",
]
# Patching the default flows to skip testing of wasm32-wasi targets # Patching the default flows to skip testing of wasm32-wasi targets
[tasks.pre-test] [tasks.pre-test]
condition = { env = { "CARGO_MAKE_CRATE_TARGET_TRIPLE" = "wasm32-wasi" } } condition = { env = { "CARGO_MAKE_CRATE_TARGET_TRIPLE" = "wasm32-wasi" } }

View file

@ -1,7 +1,10 @@
use crate::os_input_output::OsApi; use crate::os_input_output::OsApi;
use crate::panes::{PaneId, PositionAndSize}; use crate::panes::{PaneId, PositionAndSize};
use crate::tab::Pane; use crate::tab::Pane;
use std::collections::{BTreeMap, HashSet}; use std::{
cmp::Ordering,
collections::{BTreeMap, HashSet},
};
pub struct PaneResizer<'a> { pub struct PaneResizer<'a> {
panes: &'a mut BTreeMap<PaneId, Box<dyn Pane>>, panes: &'a mut BTreeMap<PaneId, Box<dyn Pane>>,
@ -29,63 +32,72 @@ impl<'a> PaneResizer<'a> {
let mut successfully_resized = false; let mut successfully_resized = false;
let mut column_difference: isize = 0; let mut column_difference: isize = 0;
let mut row_difference: isize = 0; let mut row_difference: isize = 0;
if new_size.columns < current_size.columns { match new_size.columns.cmp(&current_size.columns) {
let reduce_by = current_size.columns - new_size.columns; Ordering::Greater => {
find_reducible_vertical_chain( let increase_by = new_size.columns - current_size.columns;
&self.panes, if let Some(panes_to_resize) = find_increasable_vertical_chain(
reduce_by, &self.panes,
current_size.columns, increase_by,
current_size.rows, current_size.columns,
) current_size.rows,
.map(|panes_to_resize| { ) {
self.reduce_panes_left_and_pull_adjacents_left(panes_to_resize, reduce_by); self.increase_panes_right_and_push_adjacents_right(
column_difference = new_size.columns as isize - current_size.columns as isize; panes_to_resize,
current_size.columns = (current_size.columns as isize + column_difference) as usize; increase_by,
successfully_resized = true; );
}); column_difference = new_size.columns as isize - current_size.columns as isize;
} else if new_size.columns > current_size.columns { current_size.columns =
let increase_by = new_size.columns - current_size.columns; (current_size.columns as isize + column_difference) as usize;
find_increasable_vertical_chain( successfully_resized = true;
&self.panes, };
increase_by, }
current_size.columns, Ordering::Less => {
current_size.rows, let reduce_by = current_size.columns - new_size.columns;
) if let Some(panes_to_resize) = find_reducible_vertical_chain(
.map(|panes_to_resize| { &self.panes,
self.increase_panes_right_and_push_adjacents_right(panes_to_resize, increase_by); reduce_by,
column_difference = new_size.columns as isize - current_size.columns as isize; current_size.columns,
current_size.columns = (current_size.columns as isize + column_difference) as usize; current_size.rows,
successfully_resized = true; ) {
}); self.reduce_panes_left_and_pull_adjacents_left(panes_to_resize, reduce_by);
column_difference = new_size.columns as isize - current_size.columns as isize;
current_size.columns =
(current_size.columns as isize + column_difference) as usize;
successfully_resized = true;
};
}
Ordering::Equal => (),
} }
if new_size.rows < current_size.rows { match new_size.rows.cmp(&current_size.rows) {
let reduce_by = current_size.rows - new_size.rows; Ordering::Greater => {
find_reducible_horizontal_chain( let increase_by = new_size.rows - current_size.rows;
&self.panes, if let Some(panes_to_resize) = find_increasable_horizontal_chain(
reduce_by, &self.panes,
current_size.columns, increase_by,
current_size.rows, current_size.columns,
) current_size.rows,
.map(|panes_to_resize| { ) {
self.reduce_panes_up_and_pull_adjacents_up(panes_to_resize, reduce_by); self.increase_panes_down_and_push_down_adjacents(panes_to_resize, increase_by);
row_difference = new_size.rows as isize - current_size.rows as isize; row_difference = new_size.rows as isize - current_size.rows as isize;
current_size.rows = (current_size.rows as isize + row_difference) as usize; current_size.rows = (current_size.rows as isize + row_difference) as usize;
successfully_resized = true; successfully_resized = true;
}); };
} else if new_size.rows > current_size.rows { }
let increase_by = new_size.rows - current_size.rows; Ordering::Less => {
find_increasable_horizontal_chain( let reduce_by = current_size.rows - new_size.rows;
&self.panes, if let Some(panes_to_resize) = find_reducible_horizontal_chain(
increase_by, &self.panes,
current_size.columns, reduce_by,
current_size.rows, current_size.columns,
) current_size.rows,
.map(|panes_to_resize| { ) {
self.increase_panes_down_and_push_down_adjacents(panes_to_resize, increase_by); self.reduce_panes_up_and_pull_adjacents_up(panes_to_resize, reduce_by);
row_difference = new_size.rows as isize - current_size.rows as isize; row_difference = new_size.rows as isize - current_size.rows as isize;
current_size.rows = (current_size.rows as isize + row_difference) as usize; current_size.rows = (current_size.rows as isize + row_difference) as usize;
successfully_resized = true; successfully_resized = true;
}); };
}
Ordering::Equal => (),
} }
if successfully_resized { if successfully_resized {
Some((column_difference, row_difference)) Some((column_difference, row_difference))
@ -229,13 +241,12 @@ impl<'a> PaneResizer<'a> {
fn find_next_increasable_horizontal_pane( fn find_next_increasable_horizontal_pane(
panes: &BTreeMap<PaneId, Box<dyn Pane>>, panes: &BTreeMap<PaneId, Box<dyn Pane>>,
right_of: &Box<dyn Pane>, right_of: &dyn Pane,
increase_by: usize, increase_by: usize,
) -> Option<PaneId> { ) -> Option<PaneId> {
let next_pane_candidates = panes.values().filter( let next_pane_candidates = panes.values().filter(
|p| { |p| {
p.x() == right_of.x() + right_of.columns() + 1 p.x() == right_of.x() + right_of.columns() + 1 && p.horizontally_overlaps_with(right_of)
&& p.horizontally_overlaps_with(right_of.as_ref())
}, // TODO: the name here is wrong, it should be vertically_overlaps_with }, // TODO: the name here is wrong, it should be vertically_overlaps_with
); );
let resizable_candidates = let resizable_candidates =
@ -255,11 +266,11 @@ fn find_next_increasable_horizontal_pane(
fn find_next_increasable_vertical_pane( fn find_next_increasable_vertical_pane(
panes: &BTreeMap<PaneId, Box<dyn Pane>>, panes: &BTreeMap<PaneId, Box<dyn Pane>>,
below: &Box<dyn Pane>, below: &dyn Pane,
increase_by: usize, increase_by: usize,
) -> Option<PaneId> { ) -> Option<PaneId> {
let next_pane_candidates = panes.values().filter( let next_pane_candidates = panes.values().filter(
|p| p.y() == below.y() + below.rows() + 1 && p.vertically_overlaps_with(below.as_ref()), // TODO: the name here is wrong, it should be horizontally_overlaps_with |p| p.y() == below.y() + below.rows() + 1 && p.vertically_overlaps_with(below), // TODO: the name here is wrong, it should be horizontally_overlaps_with
); );
let resizable_candidates = let resizable_candidates =
next_pane_candidates.filter(|p| p.can_increase_width_by(increase_by)); next_pane_candidates.filter(|p| p.can_increase_width_by(increase_by));
@ -278,11 +289,11 @@ fn find_next_increasable_vertical_pane(
fn find_next_reducible_vertical_pane( fn find_next_reducible_vertical_pane(
panes: &BTreeMap<PaneId, Box<dyn Pane>>, panes: &BTreeMap<PaneId, Box<dyn Pane>>,
below: &Box<dyn Pane>, below: &dyn Pane,
reduce_by: usize, reduce_by: usize,
) -> Option<PaneId> { ) -> Option<PaneId> {
let next_pane_candidates = panes.values().filter( let next_pane_candidates = panes.values().filter(
|p| p.y() == below.y() + below.rows() + 1 && p.vertically_overlaps_with(below.as_ref()), // TODO: the name here is wrong, it should be horizontally_overlaps_with |p| p.y() == below.y() + below.rows() + 1 && p.vertically_overlaps_with(below), // TODO: the name here is wrong, it should be horizontally_overlaps_with
); );
let resizable_candidates = next_pane_candidates.filter(|p| p.can_reduce_width_by(reduce_by)); let resizable_candidates = next_pane_candidates.filter(|p| p.can_reduce_width_by(reduce_by));
resizable_candidates.fold(None, |next_pane_id, p| match next_pane_id { resizable_candidates.fold(None, |next_pane_id, p| match next_pane_id {
@ -300,13 +311,12 @@ fn find_next_reducible_vertical_pane(
fn find_next_reducible_horizontal_pane( fn find_next_reducible_horizontal_pane(
panes: &BTreeMap<PaneId, Box<dyn Pane>>, panes: &BTreeMap<PaneId, Box<dyn Pane>>,
right_of: &Box<dyn Pane>, right_of: &dyn Pane,
reduce_by: usize, reduce_by: usize,
) -> Option<PaneId> { ) -> Option<PaneId> {
let next_pane_candidates = panes.values().filter( let next_pane_candidates = panes.values().filter(
|p| { |p| {
p.x() == right_of.x() + right_of.columns() + 1 p.x() == right_of.x() + right_of.columns() + 1 && p.horizontally_overlaps_with(right_of)
&& p.horizontally_overlaps_with(right_of.as_ref())
}, // TODO: the name here is wrong, it should be vertically_overlaps_with }, // TODO: the name here is wrong, it should be vertically_overlaps_with
); );
let resizable_candidates = next_pane_candidates.filter(|p| p.can_reduce_height_by(reduce_by)); let resizable_candidates = next_pane_candidates.filter(|p| p.can_reduce_height_by(reduce_by));
@ -351,7 +361,11 @@ fn find_increasable_horizontal_chain(
if current_pane.x() + current_pane.columns() == screen_width { if current_pane.x() + current_pane.columns() == screen_width {
return Some(panes_to_resize); return Some(panes_to_resize);
} }
match find_next_increasable_horizontal_pane(panes, &current_pane, increase_by) { match find_next_increasable_horizontal_pane(
panes,
current_pane.as_ref(),
increase_by,
) {
Some(next_pane_id) => { Some(next_pane_id) => {
current_pane = panes.get(&next_pane_id).unwrap(); current_pane = panes.get(&next_pane_id).unwrap();
} }
@ -397,7 +411,11 @@ fn find_increasable_vertical_chain(
if current_pane.y() + current_pane.rows() == screen_height { if current_pane.y() + current_pane.rows() == screen_height {
return Some(panes_to_resize); return Some(panes_to_resize);
} }
match find_next_increasable_vertical_pane(panes, &current_pane, increase_by) { match find_next_increasable_vertical_pane(
panes,
current_pane.as_ref(),
increase_by,
) {
Some(next_pane_id) => { Some(next_pane_id) => {
current_pane = panes.get(&next_pane_id).unwrap(); current_pane = panes.get(&next_pane_id).unwrap();
} }
@ -443,7 +461,11 @@ fn find_reducible_horizontal_chain(
if current_pane.x() + current_pane.columns() == screen_width { if current_pane.x() + current_pane.columns() == screen_width {
return Some(panes_to_resize); return Some(panes_to_resize);
} }
match find_next_reducible_horizontal_pane(panes, &current_pane, reduce_by) { match find_next_reducible_horizontal_pane(
panes,
current_pane.as_ref(),
reduce_by,
) {
Some(next_pane_id) => { Some(next_pane_id) => {
current_pane = panes.get(&next_pane_id).unwrap(); current_pane = panes.get(&next_pane_id).unwrap();
} }
@ -489,7 +511,11 @@ fn find_reducible_vertical_chain(
if current_pane.y() + current_pane.rows() == screen_height { if current_pane.y() + current_pane.rows() == screen_height {
return Some(panes_to_resize); return Some(panes_to_resize);
} }
match find_next_reducible_vertical_pane(panes, &current_pane, increase_by) { match find_next_reducible_vertical_pane(
panes,
current_pane.as_ref(),
increase_by,
) {
Some(next_pane_id) => { Some(next_pane_id) => {
current_pane = panes.get(&next_pane_id).unwrap(); current_pane = panes.get(&next_pane_id).unwrap();
} }

View file

@ -29,11 +29,9 @@ fn get_top_non_canonical_rows(rows: &mut Vec<Row>) -> Vec<Row> {
fn get_bottom_canonical_row_and_wraps(rows: &mut Vec<Row>) -> Vec<Row> { fn get_bottom_canonical_row_and_wraps(rows: &mut Vec<Row>) -> Vec<Row> {
let mut index_of_last_non_canonical_row = None; let mut index_of_last_non_canonical_row = None;
for (i, row) in rows.iter().enumerate().rev() { for (i, row) in rows.iter().enumerate().rev() {
index_of_last_non_canonical_row = Some(i);
if row.is_canonical { if row.is_canonical {
index_of_last_non_canonical_row = Some(i);
break; break;
} else {
index_of_last_non_canonical_row = Some(i);
} }
} }
match index_of_last_non_canonical_row { match index_of_last_non_canonical_row {
@ -496,9 +494,7 @@ impl Grid {
} }
pub fn add_character(&mut self, terminal_character: TerminalCharacter) { pub fn add_character(&mut self, terminal_character: TerminalCharacter) {
// TODO: try to separate adding characters from moving the cursors in this function // TODO: try to separate adding characters from moving the cursors in this function
if self.cursor.x < self.width { if self.cursor.x >= self.width {
self.insert_character_at_cursor_position(terminal_character);
} else {
// line wrap // line wrap
self.cursor.x = 0; self.cursor.x = 0;
if self.cursor.y == self.height - 1 { if self.cursor.y == self.height - 1 {
@ -519,8 +515,8 @@ impl Grid {
self.viewport.push(line_wrapped_row); self.viewport.push(line_wrapped_row);
} }
} }
self.insert_character_at_cursor_position(terminal_character);
} }
self.insert_character_at_cursor_position(terminal_character);
self.move_cursor_forward_until_edge(1); self.move_cursor_forward_until_edge(1);
} }
pub fn move_cursor_forward_until_edge(&mut self, count: usize) { pub fn move_cursor_forward_until_edge(&mut self, count: usize) {

View file

@ -1,5 +1,3 @@
#![allow(clippy::clippy::if_same_then_else)]
use crate::{common::SenderWithContext, pty_bus::VteBytes, tab::Pane, wasm_vm::PluginInstruction}; use crate::{common::SenderWithContext, pty_bus::VteBytes, tab::Pane, wasm_vm::PluginInstruction};
use std::{sync::mpsc::channel, unimplemented}; use std::{sync::mpsc::channel, unimplemented};

View file

@ -48,7 +48,7 @@ pub enum NamedColor {
} }
impl NamedColor { impl NamedColor {
fn to_foreground_ansi_code(&self) -> String { fn to_foreground_ansi_code(self) -> String {
match self { match self {
NamedColor::Black => format!("{}", 30), NamedColor::Black => format!("{}", 30),
NamedColor::Red => format!("{}", 31), NamedColor::Red => format!("{}", 31),
@ -68,7 +68,7 @@ impl NamedColor {
NamedColor::BrightWhite => format!("{}", 97), NamedColor::BrightWhite => format!("{}", 97),
} }
} }
fn to_background_ansi_code(&self) -> String { fn to_background_ansi_code(self) -> String {
match self { match self {
NamedColor::Black => format!("{}", 40), NamedColor::Black => format!("{}", 40),
NamedColor::Red => format!("{}", 41), NamedColor::Red => format!("{}", 41),

View file

@ -1,5 +1,3 @@
#![allow(clippy::clippy::if_same_then_else)]
use crate::tab::Pane; use crate::tab::Pane;
use ::nix::pty::Winsize; use ::nix::pty::Winsize;
use ::std::os::unix::io::RawFd; use ::std::os::unix::io::RawFd;
@ -566,12 +564,6 @@ impl vte::Perform for TerminalPane {
} else { } else {
self.grid.clear_scroll_region(); self.grid.clear_scroll_region();
} }
} else if c == 't' {
// TBD - title?
} else if c == 'n' {
// TBD - device status report
} else if c == 'c' {
// TBD - identify terminal
} else if c == 'M' { } else if c == 'M' {
// delete lines if currently inside scroll region // delete lines if currently inside scroll region
let line_count_to_delete = if params[0] == 0 { let line_count_to_delete = if params[0] == 0 {

View file

@ -205,6 +205,7 @@ pub trait Pane {
impl Tab { impl Tab {
// FIXME: Too many arguments here! Maybe bundle all of the senders for the whole program in a struct? // FIXME: Too many arguments here! Maybe bundle all of the senders for the whole program in a struct?
#[allow(clippy::too_many_arguments)]
pub fn new( pub fn new(
index: usize, index: usize,
position: usize, position: usize,
@ -1720,24 +1721,22 @@ impl Tab {
// this is not ideal but until we get rid of expansion_boundary, it's a necessity // this is not ideal but until we get rid of expansion_boundary, it's a necessity
self.toggle_active_pane_fullscreen(); self.toggle_active_pane_fullscreen();
} }
match PaneResizer::new(&mut self.panes, &mut self.os_api) if let Some((column_difference, row_difference)) =
.resize(self.full_screen_ws, new_screen_size) PaneResizer::new(&mut self.panes, &mut self.os_api)
.resize(self.full_screen_ws, new_screen_size)
{ {
Some((column_difference, row_difference)) => { self.should_clear_display_before_rendering = true;
self.should_clear_display_before_rendering = true; if let Some(expansion_boundary) = self.expansion_boundary.as_mut() {
self.expansion_boundary.as_mut().map(|expansion_boundary| { // TODO: this is not always accurate
// TODO: this is not always accurate expansion_boundary.columns =
expansion_boundary.columns = (expansion_boundary.columns as isize + column_difference) as usize;
(expansion_boundary.columns as isize + column_difference) as usize; expansion_boundary.rows =
expansion_boundary.rows = (expansion_boundary.rows as isize + row_difference) as usize;
(expansion_boundary.rows as isize + row_difference) as usize; };
}); self.full_screen_ws.columns =
self.full_screen_ws.columns = (self.full_screen_ws.columns as isize + column_difference) as usize;
(self.full_screen_ws.columns as isize + column_difference) as usize; self.full_screen_ws.rows =
self.full_screen_ws.rows = (self.full_screen_ws.rows as isize + row_difference) as usize;
(self.full_screen_ws.rows as isize + row_difference) as usize;
}
None => {}
}; };
} }
pub fn resize_left(&mut self) { pub fn resize_left(&mut self) {

View file

@ -51,7 +51,6 @@ impl Config {
} }
/// Deserializes from given path. /// Deserializes from given path.
#[allow(unused_must_use)]
pub fn new(path: &Path) -> ConfigResult { pub fn new(path: &Path) -> ConfigResult {
match File::open(path) { match File::open(path) {
Ok(mut file) => { Ok(mut file) => {
@ -90,7 +89,6 @@ impl Config {
} }
} }
//#[allow(unused_must_use)]
/// In order not to mess up tests from changing configurations /// In order not to mess up tests from changing configurations
#[cfg(test)] #[cfg(test)]
pub fn from_cli_config(_: Option<ConfigCli>) -> ConfigResult { pub fn from_cli_config(_: Option<ConfigCli>) -> ConfigResult {

View file

@ -84,15 +84,10 @@ fn handle_command_exit(mut child: Child) {
} }
for signal in signals.pending() { for signal in signals.pending() {
// FIXME: We need to handle more signals here! if let SIGINT = signal {
#[allow(clippy::single_match)] child.kill().unwrap();
match signal { child.wait().unwrap();
SIGINT => { break 'handle_exit;
child.kill().unwrap();
child.wait().unwrap();
break 'handle_exit;
}
_ => {}
} }
} }
} }

View file

@ -81,7 +81,9 @@ pub struct Screen {
} }
impl Screen { impl Screen {
// FIXME: This lint needs actual fixing! Maybe by bundling the Senders
/// Creates and returns a new [`Screen`]. /// Creates and returns a new [`Screen`].
#[allow(clippy::too_many_arguments)]
pub fn new( pub fn new(
receive_screen_instructions: Receiver<(ScreenInstruction, ErrorContext)>, receive_screen_instructions: Receiver<(ScreenInstruction, ErrorContext)>,
send_pty_instructions: SenderWithContext<PtyInstruction>, send_pty_instructions: SenderWithContext<PtyInstruction>,

View file

@ -47,8 +47,7 @@ pub fn _debug_log_to_file_pid_3(message: String, pid: RawFd) -> io::Result<()> {
} }
} }
#[allow(dead_code)] pub fn _delete_log_file() -> io::Result<()> {
pub fn delete_log_file() -> io::Result<()> {
if fs::metadata(ZELLIJ_TMP_LOG_FILE).is_ok() { if fs::metadata(ZELLIJ_TMP_LOG_FILE).is_ok() {
fs::remove_file(ZELLIJ_TMP_LOG_FILE) fs::remove_file(ZELLIJ_TMP_LOG_FILE)
} else { } else {
@ -56,8 +55,7 @@ pub fn delete_log_file() -> io::Result<()> {
} }
} }
#[allow(dead_code)] pub fn _delete_log_dir() -> io::Result<()> {
pub fn delete_log_dir() -> io::Result<()> {
if fs::metadata(ZELLIJ_TMP_LOG_DIR).is_ok() { if fs::metadata(ZELLIJ_TMP_LOG_DIR).is_ok() {
fs::remove_dir_all(ZELLIJ_TMP_LOG_DIR) fs::remove_dir_all(ZELLIJ_TMP_LOG_DIR)
} else { } else {

View file

@ -18,9 +18,9 @@ pub fn adjust_to_size(s: &str, rows: usize, columns: usize) -> String {
if actual_len > columns { if actual_len > columns {
let mut line = String::from(l); let mut line = String::from(l);
line.truncate(columns); line.truncate(columns);
return line; line
} else { } else {
return [l, &str::repeat(" ", columns - ansi_len(l))].concat(); [l, &str::repeat(" ", columns - ansi_len(l))].concat()
} }
}) })
.chain(iter::repeat(str::repeat(" ", columns))) .chain(iter::repeat(str::repeat(" ", columns)))