Move to using clippy (#1142)

* Clippy fixes

* Finish converting to use clippy

* fix warnings in new master

* fix windows

* fix windows

Co-authored-by: Artem Vorotnikov <artem@vorotnikov.me>
This commit is contained in:
Jonathan Turner
2019-12-31 20:36:08 +13:00
committed by GitHub
parent 8093612cac
commit 72838cc083
93 changed files with 754 additions and 852 deletions

View File

@@ -30,14 +30,14 @@ impl EvaluatedArgs {
pub fn nth(&self, pos: usize) -> Option<&Value> {
match &self.positional {
None => None,
Some(array) => array.iter().nth(pos),
Some(array) => array.get(pos),
}
}
pub fn expect_nth(&self, pos: usize) -> Result<&Value, ShellError> {
match &self.positional {
None => Err(ShellError::unimplemented("Better error: expect_nth")),
Some(array) => match array.iter().nth(pos) {
Some(array) => match array.get(pos) {
None => Err(ShellError::unimplemented("Better error: expect_nth")),
Some(item) => Ok(item),
},
@@ -51,6 +51,10 @@ impl EvaluatedArgs {
}
}
pub fn is_empty(&self) -> bool {
self.len() == 0
}
pub fn has(&self, name: &str) -> bool {
match &self.named {
None => false,

View File

@@ -1,3 +1,5 @@
#![allow(clippy::should_implement_trait)]
#[derive(Debug)]
pub enum MaybeOwned<'a, T> {
Owned(T),

View File

@@ -278,7 +278,7 @@ impl<'a> PrettyDebug for DebugEntry<'a> {
fn pretty(&self) -> DebugDocBuilder {
(b::key(match self.key {
Column::String(string) => string.clone(),
Column::Value => format!("<value>"),
Column::Value => "<value>".to_string(),
}) + b::delimit("(", self.value.pretty(), ")").into_kind())
}
}
@@ -346,12 +346,12 @@ where
None => {
self.values.insert(key, {
let mut group = G::new();
group.merge(value.into());
group.merge(value);
group
});
}
Some(group) => {
group.merge(value.into());
group.merge(value);
}
}
}

View File

@@ -46,12 +46,7 @@ impl UntaggedValue {
pub fn data_descriptors(&self) -> Vec<String> {
match self {
UntaggedValue::Primitive(_) => vec![],
UntaggedValue::Row(columns) => columns
.entries
.keys()
.into_iter()
.map(|x| x.to_string())
.collect(),
UntaggedValue::Row(columns) => columns.entries.keys().map(|x| x.to_string()).collect(),
UntaggedValue::Block(_) => vec![],
UntaggedValue::Table(_) => vec![],
UntaggedValue::Error(_) => vec![],
@@ -116,7 +111,7 @@ impl UntaggedValue {
UntaggedValue::Row(entries.into())
}
pub fn table(list: &Vec<Value>) -> UntaggedValue {
pub fn table(list: &[Value]) -> UntaggedValue {
UntaggedValue::Table(list.to_vec())
}
@@ -227,9 +222,7 @@ impl Value {
pub fn as_path(&self) -> Result<PathBuf, ShellError> {
match &self.value {
UntaggedValue::Primitive(Primitive::Path(path)) => Ok(path.clone()),
UntaggedValue::Primitive(Primitive::String(path_str)) => {
Ok(PathBuf::from(&path_str).clone())
}
UntaggedValue::Primitive(Primitive::String(path_str)) => Ok(PathBuf::from(&path_str)),
_ => Err(ShellError::type_error("Path", self.spanned_type_name())),
}
}

View File

@@ -69,7 +69,7 @@ impl PrettyDebug for ColumnPath {
impl HasFallibleSpan for ColumnPath {
fn maybe_span(&self) -> Option<Span> {
if self.members.len() == 0 {
if self.members.is_empty() {
None
} else {
Some(span_for_spanned_list(self.members.iter().map(|m| m.span)))
@@ -98,7 +98,7 @@ pub fn did_you_mean(obj_source: &Value, field_tried: &PathMember) -> Option<Vec<
let mut possible_matches: Vec<_> = possibilities
.into_iter()
.map(|x| {
let word = x.clone();
let word = x;
let distance = natural::distance::levenshtein_distance(&word, &field_tried);
(distance, word)

View File

@@ -15,6 +15,7 @@ pub struct Dictionary {
pub entries: IndexMap<String, Value>,
}
#[allow(clippy::derive_hash_xor_eq)]
impl Hash for Dictionary {
fn hash<H: Hasher>(&self, state: &mut H) {
let mut entries = self.entries.clone();
@@ -105,7 +106,7 @@ impl From<IndexMap<String, Value>> for Dictionary {
}
impl Dictionary {
pub fn get_data(&self, desc: &String) -> MaybeOwned<'_, Value> {
pub fn get_data(&self, desc: &str) -> MaybeOwned<'_, Value> {
match self.entries.get(desc) {
Some(v) => MaybeOwned::Borrowed(v),
None => MaybeOwned::Owned(

View File

@@ -108,7 +108,7 @@ pub fn format_primitive(primitive: &Primitive, field_name: Option<&String>) -> S
match byte.get_unit() {
byte_unit::ByteUnit::B => format!("{} B ", byte.get_value()),
_ => byte.format(1).to_string(),
_ => byte.format(1),
}
}
Primitive::Duration(sec) => format_duration(*sec),
@@ -150,7 +150,7 @@ pub fn format_primitive(primitive: &Primitive, field_name: Option<&String>) -> S
}
.to_owned(),
Primitive::Binary(_) => "<binary>".to_owned(),
Primitive::Date(d) => d.humanize().to_string(),
Primitive::Date(d) => d.humanize(),
}
}

View File

@@ -10,14 +10,14 @@ pub enum RangeInclusion {
}
impl RangeInclusion {
pub fn debug_left_bracket(&self) -> DebugDocBuilder {
pub fn debug_left_bracket(self) -> DebugDocBuilder {
b::delimiter(match self {
RangeInclusion::Exclusive => "(",
RangeInclusion::Inclusive => "[",
})
}
pub fn debug_right_bracket(&self) -> DebugDocBuilder {
pub fn debug_right_bracket(self) -> DebugDocBuilder {
b::delimiter(match self {
RangeInclusion::Exclusive => ")",
RangeInclusion::Inclusive => "]",

View File

@@ -9,7 +9,7 @@ where
serde::Serialize::serialize(
&big_decimal
.to_f64()
.ok_or(serde::ser::Error::custom("expected a f64-sized bignum"))?,
.ok_or_else(|| serde::ser::Error::custom("expected a f64-sized bignum"))?,
serializer,
)
}
@@ -20,5 +20,5 @@ where
{
let x: f64 = serde::Deserialize::deserialize(deserializer)?;
Ok(BigDecimal::from_f64(x)
.ok_or(serde::de::Error::custom("expected a f64-sized bigdecimal"))?)
.ok_or_else(|| serde::de::Error::custom("expected a f64-sized bigdecimal"))?)
}

View File

@@ -9,7 +9,7 @@ where
serde::Serialize::serialize(
&big_int
.to_i64()
.ok_or(serde::ser::Error::custom("expected a i64-sized bignum"))?,
.ok_or_else(|| serde::ser::Error::custom("expected a i64-sized bignum"))?,
serializer,
)
}
@@ -19,5 +19,6 @@ where
D: serde::Deserializer<'de>,
{
let x: i64 = serde::Deserialize::deserialize(deserializer)?;
Ok(BigInt::from_i64(x).ok_or(serde::de::Error::custom("expected a i64-sized bignum"))?)
Ok(BigInt::from_i64(x)
.ok_or_else(|| serde::de::Error::custom("expected a i64-sized bignum"))?)
}