refactor(clippy): apply all super pedantic lints

Realised that I hadn't turned on super pedantic mode for clippy in the
komorebi-core and komorebic crates. This commit ensures the same clippy
config across all crates and applies the lint suggestions that arose as
a result of turning on the same config everywhere.
This commit is contained in:
LGUG2Z
2021-08-20 13:26:14 -07:00
parent 1625ca6e5d
commit 292bdb282f
9 changed files with 115 additions and 126 deletions
+2 -1
View File
@@ -12,7 +12,8 @@ pub enum CycleDirection {
}
impl CycleDirection {
pub fn next_idx(&self, idx: usize, len: usize) -> usize {
#[must_use]
pub const fn next_idx(&self, idx: usize, len: usize) -> usize {
match self {
CycleDirection::Previous => {
if idx == 0 {
+27 -36
View File
@@ -20,13 +20,15 @@ pub enum Layout {
#[derive(Clone, Copy, Debug, Serialize, Deserialize, Display, EnumString, ArgEnum)]
#[strum(serialize_all = "snake_case")]
pub enum LayoutFlip {
pub enum Flip {
Horizontal,
Vertical,
HorizontalAndVertical,
}
impl Layout {
#[must_use]
#[allow(clippy::cast_precision_loss)]
pub fn resize(
&self,
unaltered: &Rect,
@@ -35,10 +37,14 @@ impl Layout {
sizing: Sizing,
step: Option<i32>,
) -> Option<Rect> {
if !matches!(self, Self::BSP) {
return None;
};
let max_divisor = 1.005;
let mut r = resize.unwrap_or_default();
let resize_step = if let Some(step) = step { step } else { 50 };
let resize_step = step.unwrap_or(50);
match edge {
OperationDirection::Left => match sizing {
@@ -117,19 +123,21 @@ impl Layout {
},
};
if !r.eq(&Rect::default()) {
Option::from(r)
} else {
if r.eq(&Rect::default()) {
None
} else {
Option::from(r)
}
}
#[must_use]
#[allow(clippy::cast_possible_truncation, clippy::cast_possible_wrap)]
pub fn calculate(
&self,
area: &Rect,
len: NonZeroUsize,
container_padding: Option<i32>,
layout_flip: Option<LayoutFlip>,
layout_flip: Option<Flip>,
resize_dimensions: &[Option<Rect>],
) -> Vec<Rect> {
let len = usize::from(len);
@@ -187,24 +195,6 @@ impl Layout {
}
}
impl Layout {
pub fn next(&mut self) {
match self {
Layout::BSP => *self = Layout::Columns,
Layout::Columns => *self = Layout::Rows,
Layout::Rows => *self = Layout::BSP,
}
}
pub fn previous(&mut self) {
match self {
Layout::BSP => *self = Layout::Rows,
Layout::Columns => *self = Layout::BSP,
Layout::Rows => *self = Layout::Columns,
}
}
}
fn calculate_resize_adjustments(resize_dimensions: &[Option<Rect>]) -> Vec<Option<Rect>> {
let mut resize_adjustments = resize_dimensions.to_vec();
@@ -213,6 +203,7 @@ fn calculate_resize_adjustments(resize_dimensions: &[Option<Rect>]) -> Vec<Optio
if let Some(resize_ref) = opt {
if i > 0 {
if resize_ref.left != 0 {
#[allow(clippy::if_not_else)]
let range = if i == 1 {
0..1
} else if i & 1 != 0 {
@@ -291,7 +282,7 @@ fn recursive_fibonacci(
idx: usize,
count: usize,
area: &Rect,
layout_flip: Option<LayoutFlip>,
layout_flip: Option<Flip>,
resize_adjustments: Vec<Option<Rect>>,
) -> Vec<Rect> {
let mut a = *area;
@@ -313,37 +304,37 @@ fn recursive_fibonacci(
let (main_x, alt_x, alt_y, main_y);
match layout_flip {
Some(flip) => match flip {
LayoutFlip::Horizontal => {
if let Some(flip) = layout_flip {
match flip {
Flip::Horizontal => {
main_x = resized.left + half_width + (half_width - half_resized_width);
alt_x = resized.left;
alt_y = resized.top + half_resized_height;
main_y = resized.top;
}
LayoutFlip::Vertical => {
Flip::Vertical => {
main_y = resized.top + half_height + (half_height - half_resized_height);
alt_y = resized.top;
main_x = resized.left;
alt_x = resized.left + half_resized_width;
}
LayoutFlip::HorizontalAndVertical => {
Flip::HorizontalAndVertical => {
main_x = resized.left + half_width + (half_width - half_resized_width);
alt_x = resized.left;
main_y = resized.top + half_height + (half_height - half_resized_height);
alt_y = resized.top;
}
},
None => {
main_x = resized.left;
alt_x = resized.left + half_resized_width;
main_y = resized.top;
alt_y = resized.top + half_resized_height;
}
} else {
main_x = resized.left;
alt_x = resized.left + half_resized_width;
main_y = resized.top;
alt_y = resized.top + half_resized_height;
}
#[allow(clippy::if_not_else)]
if count == 0 {
vec![]
} else if count == 1 {
+7 -3
View File
@@ -1,3 +1,6 @@
#![warn(clippy::all, clippy::nursery, clippy::pedantic)]
#![allow(clippy::missing_errors_doc)]
use std::str::FromStr;
use clap::ArgEnum;
@@ -8,8 +11,8 @@ use strum::Display;
use strum::EnumString;
pub use cycle_direction::CycleDirection;
pub use layout::Flip;
pub use layout::Layout;
pub use layout::LayoutFlip;
pub use operation_direction::OperationDirection;
pub use rect::Rect;
@@ -39,7 +42,7 @@ pub enum SocketMessage {
AdjustContainerPadding(Sizing, i32),
AdjustWorkspacePadding(Sizing, i32),
ChangeLayout(Layout),
FlipLayout(LayoutFlip),
FlipLayout(Flip),
// Monitor and Workspace Commands
EnsureWorkspaces(usize, usize),
NewWorkspace,
@@ -99,7 +102,8 @@ pub enum Sizing {
}
impl Sizing {
pub fn adjust_by(&self, value: i32, adjustment: i32) -> i32 {
#[must_use]
pub const fn adjust_by(&self, value: i32, adjustment: i32) -> i32 {
match self {
Sizing::Increase => value + adjustment,
Sizing::Decrease => {
+37 -49
View File
@@ -4,8 +4,8 @@ use serde::Serialize;
use strum::Display;
use strum::EnumString;
use crate::Flip;
use crate::Layout;
use crate::LayoutFlip;
#[derive(Clone, Copy, Debug, Serialize, Deserialize, Display, EnumString, ArgEnum)]
#[strum(serialize_all = "snake_case")]
@@ -17,59 +17,46 @@ pub enum OperationDirection {
}
impl OperationDirection {
pub fn opposite(self) -> Self {
#[must_use]
pub const fn opposite(self) -> Self {
match self {
OperationDirection::Left => OperationDirection::Right,
OperationDirection::Right => OperationDirection::Left,
OperationDirection::Up => OperationDirection::Down,
OperationDirection::Down => OperationDirection::Up,
Self::Left => Self::Right,
Self::Right => Self::Left,
Self::Up => Self::Down,
Self::Down => Self::Up,
}
}
fn flip_direction(
direction: &OperationDirection,
layout_flip: Option<LayoutFlip>,
) -> OperationDirection {
if let Some(flip) = layout_flip {
match direction {
OperationDirection::Left => match flip {
LayoutFlip::Horizontal | LayoutFlip::HorizontalAndVertical => {
OperationDirection::Right
}
_ => *direction,
},
OperationDirection::Right => match flip {
LayoutFlip::Horizontal | LayoutFlip::HorizontalAndVertical => {
OperationDirection::Left
}
_ => *direction,
},
OperationDirection::Up => match flip {
LayoutFlip::Vertical | LayoutFlip::HorizontalAndVertical => {
OperationDirection::Down
}
_ => *direction,
},
OperationDirection::Down => match flip {
LayoutFlip::Vertical | LayoutFlip::HorizontalAndVertical => {
OperationDirection::Up
}
_ => *direction,
},
}
} else {
*direction
}
fn flip_direction(direction: Self, layout_flip: Option<Flip>) -> Self {
layout_flip.map_or(direction, |flip| match direction {
Self::Left => match flip {
Flip::Horizontal | Flip::HorizontalAndVertical => Self::Right,
Flip::Vertical => direction,
},
Self::Right => match flip {
Flip::Horizontal | Flip::HorizontalAndVertical => Self::Left,
Flip::Vertical => direction,
},
Self::Up => match flip {
Flip::Vertical | Flip::HorizontalAndVertical => Self::Down,
Flip::Horizontal => direction,
},
Self::Down => match flip {
Flip::Vertical | Flip::HorizontalAndVertical => Self::Up,
Flip::Horizontal => direction,
},
})
}
#[must_use]
pub fn is_valid(
&self,
self,
layout: Layout,
layout_flip: Option<LayoutFlip>,
layout_flip: Option<Flip>,
idx: usize,
len: usize,
) -> bool {
match OperationDirection::flip_direction(self, layout_flip) {
match Self::flip_direction(self, layout_flip) {
OperationDirection::Up => match layout {
Layout::BSP => len > 2 && idx != 0 && idx != 1,
Layout::Columns => false,
@@ -93,9 +80,10 @@ impl OperationDirection {
}
}
pub fn new_idx(&self, layout: Layout, layout_flip: Option<LayoutFlip>, idx: usize) -> usize {
match OperationDirection::flip_direction(self, layout_flip) {
OperationDirection::Up => match layout {
#[must_use]
pub fn new_idx(self, layout: Layout, layout_flip: Option<Flip>, idx: usize) -> usize {
match Self::flip_direction(self, layout_flip) {
Self::Up => match layout {
Layout::BSP => {
if idx % 2 == 0 {
idx - 1
@@ -106,11 +94,11 @@ impl OperationDirection {
Layout::Columns => unreachable!(),
Layout::Rows => idx - 1,
},
OperationDirection::Down => match layout {
Self::Down => match layout {
Layout::BSP | Layout::Rows => idx + 1,
Layout::Columns => unreachable!(),
},
OperationDirection::Left => match layout {
Self::Left => match layout {
Layout::BSP => {
if idx % 2 == 0 {
idx - 2
@@ -121,7 +109,7 @@ impl OperationDirection {
Layout::Columns => idx - 1,
Layout::Rows => unreachable!(),
},
OperationDirection::Right => match layout {
Self::Right => match layout {
Layout::BSP | Layout::Columns => idx + 1,
Layout::Rows => unreachable!(),
},
+4 -3
View File
@@ -12,7 +12,7 @@ pub struct Rect {
impl Default for Rect {
fn default() -> Self {
Rect {
Self {
left: 0,
top: 0,
right: 0,
@@ -23,7 +23,7 @@ impl Default for Rect {
impl From<RECT> for Rect {
fn from(rect: RECT) -> Self {
Rect {
Self {
left: rect.left,
top: rect.top,
right: rect.right - rect.left,
@@ -42,7 +42,8 @@ impl Rect {
}
}
pub fn contains_point(&self, point: (i32, i32)) -> bool {
#[must_use]
pub const fn contains_point(&self, point: (i32, i32)) -> bool {
point.0 >= self.left
&& point.0 <= self.left + self.right
&& point.1 >= self.top