diff --git a/src/atrule/unknown.rs b/src/atrule/unknown.rs index 93e639d..51a8e5e 100644 --- a/src/atrule/unknown.rs +++ b/src/atrule/unknown.rs @@ -1,6 +1,7 @@ use crate::{parse::Stmt, selector::Selector}; #[derive(Debug, Clone)] +#[allow(dead_code)] pub(crate) struct UnknownAtRule { pub name: String, pub super_selector: Selector, diff --git a/src/lib.rs b/src/lib.rs index c545b06..199394b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -48,7 +48,6 @@ grass input.scss clippy::new_ret_no_self, renamed_and_removed_lints, clippy::unknown_clippy_lints, - clippy::replace_consts, clippy::single_match, clippy::float_arithmetic, clippy::unimplemented, @@ -60,6 +59,12 @@ grass input.scss clippy::map_err_ignore, clippy::default_numeric_fallback, clippy::if_then_some_else_none, + clippy::string_slice, + clippy::separated_literal_suffix, + clippy::non_ascii_literal, + clippy::same_name_method, + clippy::undocumented_unsafe_blocks, + clippy::exhaustive_structs, // temporarily allowed while under heavy development. // eventually these allows should be refactored away @@ -69,8 +74,7 @@ grass input.scss clippy::too_many_lines, clippy::panic, clippy::unwrap_used, - clippy::option_unwrap_used, - clippy::result_unwrap_used, + clippy::unwrap_used, clippy::cast_possible_truncation, clippy::single_match_else, clippy::indexing_slicing, @@ -334,7 +338,11 @@ fn from_string_with_file_name(input: String, file_name: &str, options: &Options) #[cfg_attr(feature = "profiling", inline(never))] #[cfg_attr(not(feature = "profiling"), inline)] pub fn from_path(p: &str, options: &Options) -> Result { - from_string_with_file_name(String::from_utf8(options.fs.read(Path::new(p))?)?, p, options) + from_string_with_file_name( + String::from_utf8(options.fs.read(Path::new(p))?)?, + p, + options, + ) } /// Compile CSS from a string diff --git a/src/parse/args.rs b/src/parse/args.rs index f36cfdf..13dde73 100644 --- a/src/parse/args.rs +++ b/src/parse/args.rs @@ -75,8 +75,7 @@ impl<'a, 'b> Parser<'a, 'b> { }; continue; } - q @ '"' | q @ '\'' => { - let q = *q; + &q @ '"' | &q @ '\'' => { default.push(self.toks.next().unwrap()); default.extend(read_until_closing_quote(self.toks, q)?); continue; diff --git a/src/parse/control_flow.rs b/src/parse/control_flow.rs index 4b374d7..31bd62a 100644 --- a/src/parse/control_flow.rs +++ b/src/parse/control_flow.rs @@ -151,7 +151,7 @@ impl<'a, 'b> Parser<'a, 'b> { let var = self .parse_identifier_no_interpolation(false)? - .map_node(|n| n.into()); + .map_node(Into::into); self.whitespace_or_comment(); self.span_before = match self.toks.peek() { @@ -257,7 +257,8 @@ impl<'a, 'b> Parser<'a, 'b> { var.node, Value::Dimension(Some(Number::from(i)), Unit::None, true), ); - let mut these_stmts = self.subparser_with_in_control_flow_flag() + let mut these_stmts = self + .subparser_with_in_control_flow_flag() .with_toks(&mut Lexer::new_ref(&body)) .parse_stmt()?; if self.flags.in_function() { @@ -298,7 +299,8 @@ impl<'a, 'b> Parser<'a, 'b> { let mut val = self.parse_value_from_vec(&cond, true)?; self.scopes.enter_new_scope(); while val.node.is_true() { - let mut these_stmts = self.subparser_with_in_control_flow_flag() + let mut these_stmts = self + .subparser_with_in_control_flow_flag() .with_toks(&mut Lexer::new_ref(&body)) .parse_stmt()?; if self.flags.in_function() { @@ -322,7 +324,7 @@ impl<'a, 'b> Parser<'a, 'b> { loop { self.expect_char('$')?; - vars.push(self.parse_identifier()?.map_node(|i| i.into())); + vars.push(self.parse_identifier()?.map_node(Into::into)); self.whitespace_or_comment(); if self @@ -374,7 +376,8 @@ impl<'a, 'b> Parser<'a, 'b> { } } - let mut these_stmts = self.subparser_with_in_control_flow_flag() + let mut these_stmts = self + .subparser_with_in_control_flow_flag() .with_toks(&mut Lexer::new_ref(&body)) .parse_stmt()?; if self.flags.in_function() { diff --git a/src/parse/import.rs b/src/parse/import.rs index ebc0b5b..68a7858 100644 --- a/src/parse/import.rs +++ b/src/parse/import.rs @@ -64,12 +64,14 @@ impl<'a, 'b> Parser<'a, 'b> { for path in &self.options.load_paths { if self.options.fs.is_dir(path) { - try_path!(path.join(&path_buf) - .with_file_name(name) - .with_extension("scss")); - try_path!(path.join(&path_buf) - .with_file_name(format!("_{}", name.to_str().unwrap())) - .with_extension("scss")); + try_path!(path + .join(&path_buf) + .with_file_name(name) + .with_extension("scss")); + try_path!(path + .join(&path_buf) + .with_file_name(format!("_{}", name.to_str().unwrap())) + .with_extension("scss")); try_path!(path.join(&path_buf).join("index.scss")); try_path!(path.join(&path_buf).join("_index.scss")); } else { diff --git a/src/parse/module.rs b/src/parse/module.rs index 90f9d45..00674ee 100644 --- a/src/parse/module.rs +++ b/src/parse/module.rs @@ -85,7 +85,7 @@ impl<'a, 'b> Parser<'a, 'b> { ) })?; - config.insert(name.map_node(|n| n.into()), value)?; + config.insert(name.map_node(Into::into), value)?; match self.toks.next() { Some(Token { kind: ',', .. }) => { @@ -271,7 +271,7 @@ impl<'a, 'b> Parser<'a, 'b> { ) -> SassResult<()> { let variable = self .parse_identifier_no_interpolation(false)? - .map_node(|n| n.into()); + .map_node(Into::into); self.whitespace_or_comment(); self.expect_char(':')?; diff --git a/src/parse/value/eval.rs b/src/parse/value/eval.rs index 758d166..10ea34c 100644 --- a/src/parse/value/eval.rs +++ b/src/parse/value/eval.rs @@ -224,7 +224,7 @@ impl<'a, 'b: 'a, 'c> ValueVisitor<'a, 'b, 'c> { HigherIntermediateValue::Function(function, args, module) => { HigherIntermediateValue::Literal(self.parser.call_function(function, args, module)?) } - val => val, + _ => val, }) } diff --git a/src/parse/value/parse.rs b/src/parse/value/parse.rs index bec9b22..ca0caca 100644 --- a/src/parse/value/parse.rs +++ b/src/parse/value/parse.rs @@ -200,35 +200,36 @@ impl<'a, 'b> Parser<'a, 'b> { &mut self, mut module: Spanned, ) -> SassResult> { - Ok( - IntermediateValue::Value(if self.consume_char_if_exists('$') { - let var = self - .parse_identifier_no_interpolation(false)? - .map_node(|i| i.into()); + let is_var_start = self.consume_char_if_exists('$'); - module.span = module.span.merge(var.span); + let var_or_fn_name = self + .parse_identifier_no_interpolation(false)? + .map_node(Into::into); - let value = self.modules.get(module.node, module.span)?.get_var(var)?; - HigherIntermediateValue::Literal(value.clone()) - } else { - let fn_name = self - .parse_identifier_no_interpolation(false)? - .map_node(|i| i.into()); + let value = if is_var_start { + module.span = module.span.merge(var_or_fn_name.span); - let function = self - .modules - .get(module.node, module.span)? - .get_fn(fn_name)? - .ok_or(("Undefined function.", fn_name.span))?; + let value = self + .modules + .get(module.node, module.span)? + .get_var(var_or_fn_name)?; - self.expect_char('(')?; + HigherIntermediateValue::Literal(value.clone()) + } else { + let function = self + .modules + .get(module.node, module.span)? + .get_fn(var_or_fn_name)? + .ok_or(("Undefined function.", var_or_fn_name.span))?; - let call_args = self.parse_call_args()?; + self.expect_char('(')?; - HigherIntermediateValue::Function(function, call_args, Some(module)) - }) - .span(module.span), - ) + let call_args = self.parse_call_args()?; + + HigherIntermediateValue::Function(function, call_args, Some(module)) + }; + + Ok(IntermediateValue::Value(value).span(module.span)) } fn parse_fn_call( @@ -532,8 +533,10 @@ impl<'a, 'b> Parser<'a, 'b> { Unit::from(u.node) } '-' => { - if let Some(Token { kind, .. }) = self.toks.peek_next() { - self.toks.reset_cursor(); + let next_token = self.toks.peek_next(); + self.toks.reset_cursor(); + + if let Some(Token { kind, .. }) = next_token { if matches!(kind, 'a'..='z' | 'A'..='Z' | '_' | '\\' | '\u{7f}'..=std::char::MAX) { let u = self.parse_identifier_no_interpolation(true)?; @@ -543,7 +546,6 @@ impl<'a, 'b> Parser<'a, 'b> { Unit::None } } else { - self.toks.reset_cursor(); Unit::None } } @@ -889,7 +891,7 @@ impl<'a, 'b> Parser<'a, 'b> { '$' => { self.toks.next(); let val = match self.parse_identifier_no_interpolation(false) { - Ok(v) => v.map_node(|i| i.into()), + Ok(v) => v.map_node(Into::into), Err(e) => return Some(Err(e)), }; IntermediateValue::Value(HigherIntermediateValue::Literal( @@ -1168,9 +1170,10 @@ impl<'a, 'b: 'a, 'c> IntermediateValueIterator<'a, 'b, 'c> { } } Op::Plus => { + self.whitespace(); + let right = self.single_value(in_paren)?; + if let Some(left) = space_separated.pop() { - self.whitespace(); - let right = self.single_value(in_paren)?; space_separated.push(Spanned { node: HigherIntermediateValue::BinaryOp( Box::new(left.node), @@ -1180,8 +1183,6 @@ impl<'a, 'b: 'a, 'c> IntermediateValueIterator<'a, 'b, 'c> { span: left.span.merge(right.span), }); } else { - self.whitespace(); - let right = self.single_value(in_paren)?; space_separated.push(Spanned { node: HigherIntermediateValue::UnaryOp(op.node, Box::new(right.node)), span: right.span, diff --git a/src/selector/compound.rs b/src/selector/compound.rs index 8b4ae07..3264fb1 100644 --- a/src/selector/compound.rs +++ b/src/selector/compound.rs @@ -134,13 +134,13 @@ impl CompoundSelector { if !sel.contains_parent_selector() { return Ok(SimpleSelector::Pseudo(pseudo)); } + pseudo.selector = Some(Box::new( sel.resolve_parent_selectors(Some(parent.clone()), false)?, )); - Ok(SimpleSelector::Pseudo(pseudo)) - } else { - Ok(SimpleSelector::Pseudo(pseudo)) } + + Ok(SimpleSelector::Pseudo(pseudo)) } else { Ok(simple) } @@ -181,20 +181,17 @@ impl CompoundSelector { .into()); }; - let last = if let Some(SimpleSelector::Parent(Some(suffix))) = - self.components.first() - { - let mut components = last.components; + let mut components = last.components; + + if let Some(SimpleSelector::Parent(Some(suffix))) = self.components.first() { let mut end = components.pop().unwrap(); end.add_suffix(suffix, span)?; components.push(end); - components.extend(resolved_members.clone().into_iter().skip(1)); - CompoundSelector { components } - } else { - let mut components = last.components; - components.extend(resolved_members.clone().into_iter().skip(1)); - CompoundSelector { components } - }; + } + + components.extend(resolved_members.clone().into_iter().skip(1)); + + let last = CompoundSelector { components }; complex.components.pop(); diff --git a/src/selector/extend/extension.rs b/src/selector/extend/extension.rs index e6e416a..f766027 100644 --- a/src/selector/extend/extension.rs +++ b/src/selector/extend/extension.rs @@ -30,7 +30,10 @@ pub(crate) struct Extension { /// The span in which `extender` was defined. pub span: Span, + #[allow(dead_code)] pub left: Option>, + + #[allow(dead_code)] pub right: Option>, } diff --git a/src/selector/extend/rule.rs b/src/selector/extend/rule.rs index f0d7a69..25da0eb 100644 --- a/src/selector/extend/rule.rs +++ b/src/selector/extend/rule.rs @@ -4,8 +4,10 @@ use crate::selector::Selector; #[derive(Clone, Debug)] pub(crate) struct ExtendRule { + #[allow(dead_code)] pub selector: Selector, pub is_optional: bool, + #[allow(dead_code)] pub span: Span, } diff --git a/src/unit/mod.rs b/src/unit/mod.rs index 26d0b6e..d413dae 100644 --- a/src/unit/mod.rs +++ b/src/unit/mod.rs @@ -107,7 +107,7 @@ pub(crate) enum Unit { /// Units multiplied together /// Boxed under the assumption that mul units are exceedingly rare - #[allow(clippy::box_vec)] + #[allow(clippy::box_collection)] Mul(Box>), /// Units divided by each other @@ -222,6 +222,7 @@ impl Mul for Unit { impl Div for Unit { type Output = Unit; + #[allow(clippy::if_same_then_else)] fn div(self, rhs: Unit) -> Self::Output { if let Unit::Div(..) = self { todo!()