fmt, clippy

This commit is contained in:
Connor Skees 2022-02-08 20:22:38 -05:00
parent 3c5463ac4c
commit 15a58313e5
12 changed files with 83 additions and 66 deletions

View File

@ -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,

View File

@ -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<String> {
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

View File

@ -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;

View File

@ -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() {

View File

@ -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 {

View File

@ -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(':')?;

View File

@ -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,
})
}

View File

@ -200,35 +200,36 @@ impl<'a, 'b> Parser<'a, 'b> {
&mut self,
mut module: Spanned<Identifier>,
) -> SassResult<Spanned<IntermediateValue>> {
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,

View File

@ -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();

View File

@ -30,7 +30,10 @@ pub(crate) struct Extension {
/// The span in which `extender` was defined.
pub span: Span,
#[allow(dead_code)]
pub left: Option<Box<Extension>>,
#[allow(dead_code)]
pub right: Option<Box<Extension>>,
}

View File

@ -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,
}

View File

@ -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<Vec<Unit>>),
/// Units divided by each other
@ -222,6 +222,7 @@ impl Mul<Unit> for Unit {
impl Div<Unit> for Unit {
type Output = Unit;
#[allow(clippy::if_same_then_else)]
fn div(self, rhs: Unit) -> Self::Output {
if let Unit::Div(..) = self {
todo!()