Skip to content

Commit

Permalink
[CHORE] add/fix many clippy lints (#2978)
Browse files Browse the repository at this point in the history
mostly auto-fix; a few manual fixes
  • Loading branch information
andrewgazelka authored Oct 7, 2024
1 parent 98dbadb commit 0c39007
Show file tree
Hide file tree
Showing 265 changed files with 1,918 additions and 1,656 deletions.
69 changes: 69 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,76 @@ features = ["derive", "rc"]
version = "1.0.200"

[workspace.lints.clippy]
as_conversions = "allow"
cast-sign-loss = "allow"
cast_lossless = "allow"
cast_possible_truncation = "allow"
cast_possible_wrap = "allow"
cast_precision_loss = "allow"
cognitive_complexity = "allow"
default_trait_access = "allow"
doc-markdown = "allow"
doc_link_with_quotes = "allow"
enum_glob_use = "allow"
float_cmp = "allow"
fn_params_excessive_bools = "allow"
from_iter_instead_of_collect = "allow"
future_not_send = "allow"
if_not_else = "allow"
implicit_hasher = "allow"
inline_always = "allow"
into_iter_without_iter = "allow"
items_after_statements = "allow"
iter_with_drain = "allow" # REMOVE
iter_without_into_iter = "allow"
manual_let_else = "allow"
many_single_char_names = "allow"
map_unwrap_or = "allow"
match_bool = "allow"
match_same_arms = "allow"
match_wildcard_for_single_variants = "allow"
missing-panics-doc = "allow"
missing_const_for_fn = "allow"
missing_errors_doc = "allow"
module_name_repetitions = "allow"
must_use_candidate = "allow"
needless_pass_by_value = "allow"
needless_return = "allow"
nonminimal_bool = "allow"
nursery = {level = "deny", priority = -1}
only_used_in_recursion = "allow"
option_if_let_else = "allow"
pedantic = {level = "deny", priority = -1}
perf = {level = "deny", priority = -1}
redundant_closure = "allow"
redundant_closure_for_method_calls = "allow"
redundant_else = "allow"
redundant_pub_crate = "allow"
return_self_not_must_use = "allow"
significant_drop_in_scrutinee = "allow" # REMOVE
significant_drop_tightening = "allow" # REMOVE
similar_names = "allow"
single_match = "allow"
single_match_else = "allow"
struct_excessive_bools = "allow"
style = {level = "deny", priority = 1}
suspicious_operation_groupings = "allow"
too_many_lines = "allow"
trivially_copy_pass_by_ref = "allow"
type_repetition_in_bounds = "allow"
uninlined_format_args = "allow"
unnecessary_wraps = "allow"
unnested_or_patterns = "allow"
unreadable_literal = "allow"
# todo: remove?
unsafe_derive_deserialize = "allow"
unused_async = "allow"
# used_underscore_items = "allow" # REMOVE
unused_self = "allow"
use-self = "deny"
used_underscore_binding = "allow" # REMOVE REMOVE
wildcard_imports = "allow"
zero_sized_map_values = "allow"

[workspace.package]
edition = "2021"
Expand Down
5 changes: 2 additions & 3 deletions src/arrow2/src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -802,10 +802,9 @@ mod tests {
use super::*;
use crate::{
array::{
BooleanArray, Float32Array, Int32Array, Int64Array, ListArray, MapArray, StructArray,
UnionArray, Utf8Array,
BooleanArray, Int32Array, Int64Array, ListArray, StructArray,
},
datatypes::{DataType, Field, IntervalUnit, TimeUnit},
datatypes::{DataType, Field, TimeUnit},
};

#[test]
Expand Down
2 changes: 2 additions & 0 deletions src/common/daft-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub struct DaftPlanningConfig {
}

impl DaftPlanningConfig {
#[must_use]
pub fn from_env() -> Self {
let mut cfg = Self::default();

Expand Down Expand Up @@ -84,6 +85,7 @@ impl Default for DaftExecutionConfig {
}

impl DaftExecutionConfig {
#[must_use]
pub fn from_env() -> Self {
let mut cfg = Self::default();
let aqe_env_var_name = "DAFT_ENABLE_AQE";
Expand Down
4 changes: 4 additions & 0 deletions src/common/daft-config/src/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ pub struct PyDaftPlanningConfig {
#[pymethods]
impl PyDaftPlanningConfig {
#[new]
#[must_use]
pub fn new() -> Self {
Self::default()
}

#[staticmethod]
#[must_use]
pub fn from_env() -> Self {
Self {
config: Arc::new(DaftPlanningConfig::from_env()),
Expand Down Expand Up @@ -71,11 +73,13 @@ pub struct PyDaftExecutionConfig {
#[pymethods]
impl PyDaftExecutionConfig {
#[new]
#[must_use]
pub fn new() -> Self {
Self::default()
}

#[staticmethod]
#[must_use]
pub fn from_env() -> Self {
Self {
config: Arc::new(DaftExecutionConfig::from_env()),
Expand Down
3 changes: 2 additions & 1 deletion src/common/display/src/ascii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,15 @@ fn fmt_tree_gitstyle<'a, W: fmt::Write + 'a>(
s: &'a mut W,
level: crate::DisplayLevel,
) -> fmt::Result {
use terminal_size::{terminal_size, Width};

// Print the current node.
// e.g. | | * <node contents line 1>
// | | | <node contents line 2>

let desc = node.display_as(level);
let lines = desc.lines();

use terminal_size::{terminal_size, Width};
let size = terminal_size();
let term_width = if let Some((Width(w), _)) = size {
w as usize
Expand Down
27 changes: 12 additions & 15 deletions src/common/display/src/mermaid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ where
if display.is_empty() {
return Err(fmt::Error);
}
writeln!(self.output, r#"{}["{}"]"#, id, display)?;
writeln!(self.output, r#"{id}["{display}"]"#)?;

self.nodes.insert(node.id(), id);
Ok(())
Expand Down Expand Up @@ -146,21 +146,18 @@ where
}

pub fn fmt(&mut self, node: &dyn TreeDisplay) -> fmt::Result {
match &self.subgraph_options {
Some(SubgraphOptions { name, subgraph_id }) => {
writeln!(self.output, r#"subgraph {subgraph_id}["{name}"]"#)?;
self.fmt_node(node)?;
writeln!(self.output, "end")?;
}
None => {
if self.bottom_up {
writeln!(self.output, "flowchart BT")?;
} else {
writeln!(self.output, "flowchart TD")?;
}

self.fmt_node(node)?;
if let Some(SubgraphOptions { name, subgraph_id }) = &self.subgraph_options {
writeln!(self.output, r#"subgraph {subgraph_id}["{name}"]"#)?;
self.fmt_node(node)?;
writeln!(self.output, "end")?;
} else {
if self.bottom_up {
writeln!(self.output, "flowchart BT")?;
} else {
writeln!(self.output, "flowchart TD")?;
}

self.fmt_node(node)?;
}
Ok(())
}
Expand Down
46 changes: 17 additions & 29 deletions src/common/display/src/table_display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ pub fn make_comfy_table<S: AsRef<str>>(
num_rows: Option<usize>,
max_col_width: Option<usize>,
) -> comfy_table::Table {
const DOTS: &str = "…";
const TOTAL_ROWS: usize = 10;

let mut table = comfy_table::Table::new();

let default_width_if_no_tty = 120usize;
Expand All @@ -74,22 +77,17 @@ pub fn make_comfy_table<S: AsRef<str>>(

let expected_col_width = 18usize;

let max_cols = (((terminal_width + expected_col_width - 1) / expected_col_width) - 1).max(1);
const DOTS: &str = "…";
let max_cols = (terminal_width.div_ceil(expected_col_width) - 1).max(1);
let num_columns = fields.len();

let head_cols;
let tail_cols;
let total_cols;
if num_columns > max_cols {
head_cols = (max_cols + 1) / 2;
tail_cols = max_cols / 2;
total_cols = head_cols + tail_cols + 1;
let (head_cols, tail_cols, total_cols) = if num_columns > max_cols {
let head_cols = (max_cols + 1) / 2;
let tail_cols = max_cols / 2;
(head_cols, tail_cols, head_cols + tail_cols + 1)
} else {
head_cols = num_columns;
tail_cols = 0;
total_cols = head_cols;
}
(num_columns, 0, num_columns)
};

let mut header = fields
.iter()
.take(head_cols)
Expand All @@ -98,12 +96,8 @@ pub fn make_comfy_table<S: AsRef<str>>(
if tail_cols > 0 {
let unseen_cols = num_columns - (head_cols + tail_cols);
header.push(
create_table_cell(&format!(
"{DOTS}\n\n({unseen_cols} hidden)",
DOTS = DOTS,
unseen_cols = unseen_cols
))
.set_alignment(comfy_table::CellAlignment::Center),
create_table_cell(&format!("{DOTS}\n\n({unseen_cols} hidden)"))
.set_alignment(comfy_table::CellAlignment::Center),
);
header.extend(
fields
Expand All @@ -118,17 +112,11 @@ pub fn make_comfy_table<S: AsRef<str>>(
{
table.set_header(header);
let len = num_rows.expect("if columns are set, so should `num_rows`");
const TOTAL_ROWS: usize = 10;
let head_rows;
let tail_rows;

if len > TOTAL_ROWS {
head_rows = TOTAL_ROWS / 2;
tail_rows = TOTAL_ROWS / 2;
let (head_rows, tail_rows) = if len > TOTAL_ROWS {
(TOTAL_ROWS / 2, TOTAL_ROWS / 2)
} else {
head_rows = len;
tail_rows = 0;
}
(len, 0)
};

for i in 0..head_rows {
let all_cols = columns
Expand Down
5 changes: 4 additions & 1 deletion src/common/display/src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ pub trait TreeDisplay {
fn id(&self) -> String {
let mut s = String::new();
s.push_str(&self.get_name());
s.push_str(&format!("{:p}", self as *const Self as *const ()));
s.push_str(&format!(
"{:p}",
std::ptr::from_ref::<Self>(self).cast::<()>()
));
s
}

Expand Down
4 changes: 3 additions & 1 deletion src/common/display/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#[must_use]
pub fn bytes_to_human_readable(byte_count: usize) -> String {
const UNITS: &[&str] = &["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"];

if byte_count == 0 {
return "0 B".to_string();
}

const UNITS: &[&str] = &["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"];
let base = byte_count.ilog2() / 10; // log2(1024) = 10

let index = std::cmp::min(base, (UNITS.len() - 1) as u32);
Expand Down
5 changes: 2 additions & 3 deletions src/common/file-formats/src/file_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl FromStr for FileFormat {
type Err = DaftError;

fn from_str(file_format: &str) -> DaftResult<Self> {
use FileFormat::*;
use FileFormat::{Csv, Database, Json, Parquet};

if file_format.trim().eq_ignore_ascii_case("parquet") {
Ok(Parquet)
Expand All @@ -51,8 +51,7 @@ impl FromStr for FileFormat {
Ok(Database)
} else {
Err(DaftError::TypeError(format!(
"FileFormat {} not supported!",
file_format
"FileFormat {file_format} not supported!"
)))
}
}
Expand Down
Loading

0 comments on commit 0c39007

Please sign in to comment.