Skip to content

Commit

Permalink
Add clippy allow exceptions across qsv
Browse files Browse the repository at this point in the history
for things that we allow beyond the clippy allows in main.rs

this results in clippy having no warnings even for perf, pedantic and nursery
  • Loading branch information
jqnatividad committed Jul 2, 2022
1 parent 3652f4a commit 8d285f2
Show file tree
Hide file tree
Showing 15 changed files with 62 additions and 34 deletions.
71 changes: 38 additions & 33 deletions src/cmd/apply.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(dead_code)]
use crate::config::{Config, Delimiter};
use crate::select::SelectColumns;
use crate::CliError;
Expand Down Expand Up @@ -758,39 +759,43 @@ fn search_cached(cell: &str, formatstr: &str) -> Option<String> {
let long = loccaps[2].to_string().parse::<f64>().unwrap_or_default();
if (-90.0..=90.00).contains(&lat) && (-180.0..=180.0).contains(&long) {
let search_result = geocoder.search((lat, long));
search_result.map(|locdetails| match formatstr {
"%+" | "city-state" => format!(
"{name}, {admin1}",
name = locdetails.record.name,
admin1 = locdetails.record.admin1,
),
"city-country" => format!(
"{name}, {cc}",
name = locdetails.record.name,
cc = locdetails.record.cc
),
"city-state-country" | "city-admin1-country" => format!(
"{name}, {admin1} {cc}",
name = locdetails.record.name,
admin1 = locdetails.record.admin1,
cc = locdetails.record.cc
),
"city" => locdetails.record.name.to_string(),
"county" | "admin2" => locdetails.record.admin2.to_string(),
"state" | "admin1" => locdetails.record.admin1.to_string(),
"county-country" | "admin2-country" => format!(
"{admin2}, {cc}",
admin2 = locdetails.record.admin2,
cc = locdetails.record.cc
),
"county-state-country" | "admin2-admin1-country" => format!(
"{admin2}, {admin1} {cc}",
admin2 = locdetails.record.admin2,
admin1 = locdetails.record.admin1,
cc = locdetails.record.cc
),
"country" => locdetails.record.cc.to_string(),
_ => locdetails.record.name.to_string(),
search_result.map(|locdetails| {
#[allow(clippy::match_same_arms)]
match formatstr {
"%+" | "city-state" => format!(
"{name}, {admin1}",
name = locdetails.record.name,
admin1 = locdetails.record.admin1,
),
"city-country" => format!(
"{name}, {cc}",
name = locdetails.record.name,
cc = locdetails.record.cc
),
"city-state-country" | "city-admin1-country" => format!(
"{name}, {admin1} {cc}",
name = locdetails.record.name,
admin1 = locdetails.record.admin1,
cc = locdetails.record.cc
),
"city" => locdetails.record.name.to_string(),
"county" | "admin2" => locdetails.record.admin2.to_string(),
"state" | "admin1" => locdetails.record.admin1.to_string(),
"county-country" | "admin2-country" => format!(
"{admin2}, {cc}",
admin2 = locdetails.record.admin2,
cc = locdetails.record.cc
),
"county-state-country" | "admin2-admin1-country" => format!(
"{admin2}, {admin1} {cc}",
admin2 = locdetails.record.admin2,
admin1 = locdetails.record.admin1,
cc = locdetails.record.cc
),
"country" => locdetails.record.cc.to_string(),
#[allow(clippy::match_same_arms)]
_ => locdetails.record.name.to_string(),
}
})
} else {
None
Expand Down
1 change: 1 addition & 0 deletions src/cmd/enumerate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
record.push_field(constant_value.as_bytes());
}
} else if copy_operation {
#[allow(clippy::unnecessary_to_owned)]
record.push_field(&record[copy_index].to_vec());
} else if args.flag_uuid {
let id = Uuid::new_v4();
Expand Down
1 change: 1 addition & 0 deletions src/cmd/exclude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ impl Args {
})
}

#[allow(clippy::unused_self)]
fn get_selections<R: io::Read>(
&self,
rconf1: &Config,
Expand Down
1 change: 1 addition & 0 deletions src/cmd/fetch.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(dead_code)]
use crate::config::{Config, Delimiter};
use crate::select::SelectColumns;
use crate::CliError;
Expand Down
1 change: 1 addition & 0 deletions src/cmd/fill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ struct ByteRecord(Vec<ByteString>);

impl<'a> From<&'a csv::ByteRecord> for ByteRecord {
fn from(record: &'a csv::ByteRecord) -> Self {
#[allow(clippy::redundant_closure_for_method_calls)]
ByteRecord(record.iter().map(|f| f.to_vec()).collect())
}
}
Expand Down
1 change: 1 addition & 0 deletions src/cmd/frequency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ impl Args {
) -> CliResult<(csv::ByteRecord, Selection)> {
let headers = rdr.byte_headers()?;
let sel = self.rconfig().selection(headers)?;
#[allow(clippy::redundant_closure_for_method_calls)]
Ok((sel.select(headers).map(|h| h.to_vec()).collect(), sel))
}
}
Expand Down
1 change: 1 addition & 0 deletions src/cmd/join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ impl Args {
})
}

#[allow(clippy::unused_self)]
fn get_selections<R: io::Read>(
&self,
rconf1: &Config,
Expand Down
1 change: 1 addition & 0 deletions src/cmd/partition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ impl Args {
}

/// Get the column to use as a key.
#[allow(clippy::unused_self)]
fn key_column(&self, rconfig: &Config, headers: &csv::ByteRecord) -> CliResult<usize> {
let select_cols = rconfig.selection(headers)?;
if select_cols.len() == 1 {
Expand Down
1 change: 1 addition & 0 deletions src/cmd/sample.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ pub fn run(argv: &[&str]) -> CliResult<()> {

let mut wtr = Config::new(&args.flag_output).writer()?;
let sampled = if let Some(mut idx) = rconfig.indexed()? {
#[allow(clippy::cast_precision_loss)]
if sample_size < 1.0 {
sample_size *= idx.count() as f64;
}
Expand Down
1 change: 1 addition & 0 deletions src/cmd/sniff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
let mut sample_size = args.flag_sample;
let mut sample_all = false;
// its a percentage, get the actual sample size
#[allow(clippy::cast_precision_loss)]
if sample_size < 1.0 {
sample_size *= n_rows as f64;
} else if (sample_size - 0.0).abs() < f64::EPSILON {
Expand Down
2 changes: 2 additions & 0 deletions src/cmd/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,9 @@ enum Number {
fn compare_num(n1: Number, n2: Number) -> cmp::Ordering {
match (n1, n2) {
(Int(i1), Int(i2)) => i1.cmp(&i2),
#[allow(clippy::cast_precision_loss)]
(Int(i1), Float(f2)) => compare_float(i1 as f64, f2),
#[allow(clippy::cast_precision_loss)]
(Float(f1), Int(i2)) => compare_float(f1, i2 as f64),
(Float(f1), Float(f2)) => compare_float(f1, f2),
}
Expand Down
8 changes: 8 additions & 0 deletions src/cmd/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ Common options:
Must be a single character. (default: ,)
"#;

#[allow(clippy::unsafe_derive_deserialize)]
#[derive(Clone, Deserialize)]
pub struct Args {
pub arg_input: Option<String>,
Expand Down Expand Up @@ -466,6 +467,7 @@ impl Stats {
if sample_type == TNull {
self.nullcount += 1;
}
#[allow(clippy::match_same_arms)]
match self.typ {
TNull => {
if self.which.include_nulls {
Expand Down Expand Up @@ -692,6 +694,7 @@ impl FieldType {

impl Commute for FieldType {
#[inline]
#[allow(clippy::match_same_arms)]
fn merge(&mut self, other: FieldType) {
*self = match (*self, other) {
(TString, TString) => TString,
Expand Down Expand Up @@ -759,6 +762,7 @@ impl TypedSum {
if sample.is_empty() {
return;
}
#[allow(clippy::cast_precision_loss)]
match typ {
TFloat => {
let float: f64 = from_bytes::<f64>(sample);
Expand Down Expand Up @@ -806,7 +810,9 @@ impl Commute for TypedSum {
fn merge(&mut self, other: TypedSum) {
match (self.float, other.float) {
(Some(f1), Some(f2)) => self.float = Some(f1 + f2),
#[allow(clippy::cast_precision_loss)]
(Some(f1), None) => self.float = Some(f1 + (other.integer as f64)),
#[allow(clippy::cast_precision_loss)]
(None, Some(f2)) => self.float = Some((self.integer as f64) + f2),
(None, None) => self.integer = self.integer.saturating_add(other.integer),
}
Expand Down Expand Up @@ -841,6 +847,7 @@ impl TypedMinMax {
.unwrap();

self.floats.add(n);
#[allow(clippy::cast_precision_loss)]
self.integers.add(n as i64);
},
TInteger => unsafe {
Expand All @@ -849,6 +856,7 @@ impl TypedMinMax {
.ok()
.unwrap();
self.integers.add(n);
#[allow(clippy::cast_precision_loss)]
self.floats.add(n as f64);
},
TDate | TDateTime => unsafe {
Expand Down
1 change: 1 addition & 0 deletions src/cmd/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Common options:
-q, --quiet Don't show progress bars.
";

#[allow(clippy::struct_excessive_bools)]
#[derive(Deserialize)]
struct Args {
flag_fail_fast: bool,
Expand Down
2 changes: 2 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ impl<'de> Deserialize<'de> for Delimiter {
}
}

#[allow(clippy::struct_excessive_bools)]
#[derive(Debug)]
pub struct Config {
path: Option<PathBuf>, // None implies <stdin>
Expand Down Expand Up @@ -241,6 +242,7 @@ impl Config {
self
}

#[allow(clippy::missing_const_for_fn)]
pub fn select(mut self, sel_cols: SelectColumns) -> Config {
self.select_columns = Some(sel_cols);
self
Expand Down
3 changes: 2 additions & 1 deletion src/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ impl Selection {
) -> iter::Scan<slice::Iter<'a, usize>, &'b csv::ByteRecord, _GetField> {
// This is horrifying.
#[allow(clippy::unnecessary_wraps)]
#[allow(clippy::trivially_copy_pass_by_ref)]
fn get_field<'c>(row: &mut &'c csv::ByteRecord, idx: &usize) -> Option<&'c [u8]> {
Some(&row[*idx])
}
Expand Down Expand Up @@ -452,7 +453,7 @@ impl NormalSelection {
where
I: Iterator<Item = T>,
{
fn filmap<T>(v: Option<T>) -> Option<T> {
const fn filmap<T>(v: Option<T>) -> Option<T> {
v
}
#[allow(clippy::option_option)]
Expand Down

0 comments on commit 8d285f2

Please sign in to comment.