From b64ad5b1f3307635c5f5d91522e8879885b5f2ed Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Sun, 31 May 2020 05:32:19 -0400 Subject: [PATCH] resolve all clippy lints --- src/atrule/for_rule.rs | 1 + src/atrule/mod.rs | 1 + src/builtin/meta.rs | 1 + src/builtin/string.rs | 1 + src/common.rs | 1 + src/imports.rs | 2 +- src/lib.rs | 14 +++++++++----- src/stylesheet.rs | 1 + src/value/number/mod.rs | 2 +- src/value/ops.rs | 10 +++------- src/value/parse.rs | 11 ++++++----- 11 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/atrule/for_rule.rs b/src/atrule/for_rule.rs index 4c20dd9..2d024b3 100644 --- a/src/atrule/for_rule.rs +++ b/src/atrule/for_rule.rs @@ -73,6 +73,7 @@ impl For { Ok(stmts) } + #[allow(clippy::range_plus_one)] pub fn iter(&self) -> ForIterator { if self.from < self.to { ForIterator::Forward(self.from..(self.to + self.through)) diff --git a/src/atrule/mod.rs b/src/atrule/mod.rs index f364173..1a3b251 100644 --- a/src/atrule/mod.rs +++ b/src/atrule/mod.rs @@ -172,6 +172,7 @@ impl AtRule { body.push(toks.next().unwrap()); devour_whitespace(toks); let mut styles = Vec::new(); + #[allow(clippy::unnecessary_filter_map)] let raw_stmts = eat_stmts_at_root( &mut body.into_iter().peekmore(), scope, diff --git a/src/builtin/meta.rs b/src/builtin/meta.rs index 5033238..68a54db 100644 --- a/src/builtin/meta.rs +++ b/src/builtin/meta.rs @@ -86,6 +86,7 @@ fn type_of(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> Sass fn unitless(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassResult { args.max_args(1)?; + #[allow(clippy::match_same_arms)] Ok(match arg!(args, scope, super_selector, 0, "number") { Value::Dimension(_, Unit::None) => Value::True, Value::Dimension(_, _) => Value::False, diff --git a/src/builtin/string.rs b/src/builtin/string.rs index 74443df..b8d62c2 100644 --- a/src/builtin/string.rs +++ b/src/builtin/string.rs @@ -346,6 +346,7 @@ fn str_insert(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> S } #[cfg(feature = "random")] +#[allow(clippy::needless_pass_by_value)] fn unique_id(args: CallArgs, _: &Scope, _: &Selector) -> SassResult { args.max_args(0)?; let mut rng = thread_rng(); diff --git a/src/common.rs b/src/common.rs index 458f11b..add4e2a 100644 --- a/src/common.rs +++ b/src/common.rs @@ -154,6 +154,7 @@ impl Default for Identifier { } impl Identifier { + #[allow(clippy::missing_const_for_fn)] pub fn into_inner(self) -> String { self.0 } diff --git a/src/imports.rs b/src/imports.rs index 5220b3e..eea987d 100644 --- a/src/imports.rs +++ b/src/imports.rs @@ -17,7 +17,7 @@ pub(crate) fn import( if path.is_absolute() { todo!("absolute import") } - let path_buf = ctx.parent().unwrap_or(Path::new("")).join(path); + let path_buf = ctx.parent().unwrap_or_else(|| Path::new("")).join(path); // "todo: will panic if path ended in `..`" let name = path_buf.file_name().unwrap(); if path_buf.extension() == Some(OsStr::new(".css")) { diff --git a/src/lib.rs b/src/lib.rs index e94fb13..f2fa4ad 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -50,9 +50,6 @@ grass input.scss // this is too pedantic for now -- the library is changing too quickly for // good docs to be written clippy::missing_errors_doc, - // this incorrectly results in errors for types that derive `Debug` - // https://github.com/rust-lang/rust-clippy/issues/4980 - // clippy::let_underscore_must_use, // this is too pedantic -- it results in some names being less explicit // than they should clippy::module_name_repetitions, @@ -61,6 +58,7 @@ grass input.scss // filter isn't fallible clippy::filter_map, clippy::else_if_without_else, + clippy::new_ret_no_self, // temporarily allowed while under heavy development. // eventually these allows should be refactored away @@ -74,9 +72,15 @@ grass input.scss clippy::cast_possible_truncation, clippy::single_match_else, clippy::indexing_slicing, - // clippy::match_same_arms, - // clippy::or_fun_call, clippy::redundant_pub_crate, + + clippy::string_add, + clippy::get_unwrap, + clippy::unit_arg, + clippy::wrong_self_convention, + clippy::items_after_statements, + clippy::shadow_reuse, + clippy::shadow_unrelated, )] #![cfg_attr(feature = "nightly", feature(track_caller))] #![cfg_attr(feature = "profiling", inline(never))] diff --git a/src/stylesheet.rs b/src/stylesheet.rs index f852910..6ea1ad9 100644 --- a/src/stylesheet.rs +++ b/src/stylesheet.rs @@ -378,6 +378,7 @@ impl<'a> StyleSheetParser<'a> { node: Stmt::Style(s), span, }), + #[allow(clippy::match_same_arms)] Expr::AtRule(a) => match a { AtRule::For(f) => stmts.extend(f.ruleset_eval(scope, super_selector, None)?), AtRule::While(w) => { diff --git a/src/value/number/mod.rs b/src/value/number/mod.rs index ab8322a..85f6dc2 100644 --- a/src/value/number/mod.rs +++ b/src/value/number/mod.rs @@ -214,7 +214,7 @@ impl From for Number { } } -// todo: implement std::convertTryFrom instead +#[allow(clippy::fallible_impl_from)] impl From for Number { fn from(b: f64) -> Self { Number::Big(BigRational::from_float(b).unwrap()) diff --git a/src/value/ops.rs b/src/value/ops.rs index 0c0e0c8..e8c684b 100644 --- a/src/value/ops.rs +++ b/src/value/ops.rs @@ -77,7 +77,7 @@ impl Value { } } _ => false, - } + }, s => s == other.eval(span)?.node, }) .span(span)) @@ -151,7 +151,7 @@ impl Value { } } _ => true, - } + }, s => s != other.eval(span)?.node, }) .span(span)) @@ -487,11 +487,7 @@ impl Value { ) } } - Self::List(..) => Value::String( - format!("{}{}-{}", num, unit, other.to_css_string(span)?), - QuoteKind::None, - ), - Self::String(..) => Value::String( + Self::List(..) | Self::String(..) => Value::String( format!("{}{}-{}", num, unit, other.to_css_string(span)?), QuoteKind::None, ), diff --git a/src/value/parse.rs b/src/value/parse.rs index 5e818fe..6577ab2 100644 --- a/src/value/parse.rs +++ b/src/value/parse.rs @@ -431,7 +431,7 @@ fn single_value>( }) } -fn parse_i64(s: String) -> i64 { +fn parse_i64(s: &str) -> i64 { s.as_bytes() .iter() .fold(0, |total, this| total * 10 + i64::from(this - b'0')) @@ -741,7 +741,7 @@ impl Value { let n = if val.dec_len == 0 { if val.num.len() <= 18 && val.times_ten.is_empty() { - let n = Rational64::new_raw(parse_i64(val.num), 1); + let n = Rational64::new_raw(parse_i64(&val.num), 1); return Some(Ok(IntermediateValue::Value(Value::Dimension( Number::new_machine(n), unit, @@ -751,7 +751,7 @@ impl Value { BigRational::new_raw(val.num.parse::().unwrap(), BigInt::one()) } else { if val.num.len() <= 18 && val.times_ten.is_empty() { - let n = Rational64::new(parse_i64(val.num), pow(10, val.dec_len)); + let n = Rational64::new(parse_i64(&val.num), pow(10, val.dec_len)); return Some(Ok(IntermediateValue::Value(Value::Dimension( Number::new_machine(n), unit, @@ -884,9 +884,10 @@ impl Value { IntermediateValue::Comma.span(span) } q @ '>' | q @ '<' => { - let mut span = toks.next().unwrap().pos(); + let mut span = toks.next().unwrap().pos; + #[allow(clippy::eval_order_dependence)] IntermediateValue::Op(if let Some(Token { kind: '=', .. }) = toks.peek() { - span = span.merge(toks.next().unwrap().pos()); + span = span.merge(toks.next().unwrap().pos); match q { '>' => Op::GreaterThanEqual, '<' => Op::LessThanEqual,