fmt, clippy
This commit is contained in:
parent
3c5463ac4c
commit
15a58313e5
@ -1,6 +1,7 @@
|
|||||||
use crate::{parse::Stmt, selector::Selector};
|
use crate::{parse::Stmt, selector::Selector};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
#[allow(dead_code)]
|
||||||
pub(crate) struct UnknownAtRule {
|
pub(crate) struct UnknownAtRule {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub super_selector: Selector,
|
pub super_selector: Selector,
|
||||||
|
16
src/lib.rs
16
src/lib.rs
@ -48,7 +48,6 @@ grass input.scss
|
|||||||
clippy::new_ret_no_self,
|
clippy::new_ret_no_self,
|
||||||
renamed_and_removed_lints,
|
renamed_and_removed_lints,
|
||||||
clippy::unknown_clippy_lints,
|
clippy::unknown_clippy_lints,
|
||||||
clippy::replace_consts,
|
|
||||||
clippy::single_match,
|
clippy::single_match,
|
||||||
clippy::float_arithmetic,
|
clippy::float_arithmetic,
|
||||||
clippy::unimplemented,
|
clippy::unimplemented,
|
||||||
@ -60,6 +59,12 @@ grass input.scss
|
|||||||
clippy::map_err_ignore,
|
clippy::map_err_ignore,
|
||||||
clippy::default_numeric_fallback,
|
clippy::default_numeric_fallback,
|
||||||
clippy::if_then_some_else_none,
|
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.
|
// temporarily allowed while under heavy development.
|
||||||
// eventually these allows should be refactored away
|
// eventually these allows should be refactored away
|
||||||
@ -69,8 +74,7 @@ grass input.scss
|
|||||||
clippy::too_many_lines,
|
clippy::too_many_lines,
|
||||||
clippy::panic,
|
clippy::panic,
|
||||||
clippy::unwrap_used,
|
clippy::unwrap_used,
|
||||||
clippy::option_unwrap_used,
|
clippy::unwrap_used,
|
||||||
clippy::result_unwrap_used,
|
|
||||||
clippy::cast_possible_truncation,
|
clippy::cast_possible_truncation,
|
||||||
clippy::single_match_else,
|
clippy::single_match_else,
|
||||||
clippy::indexing_slicing,
|
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(feature = "profiling", inline(never))]
|
||||||
#[cfg_attr(not(feature = "profiling"), inline)]
|
#[cfg_attr(not(feature = "profiling"), inline)]
|
||||||
pub fn from_path(p: &str, options: &Options) -> Result<String> {
|
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
|
/// Compile CSS from a string
|
||||||
|
@ -75,8 +75,7 @@ impl<'a, 'b> Parser<'a, 'b> {
|
|||||||
};
|
};
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
q @ '"' | q @ '\'' => {
|
&q @ '"' | &q @ '\'' => {
|
||||||
let q = *q;
|
|
||||||
default.push(self.toks.next().unwrap());
|
default.push(self.toks.next().unwrap());
|
||||||
default.extend(read_until_closing_quote(self.toks, q)?);
|
default.extend(read_until_closing_quote(self.toks, q)?);
|
||||||
continue;
|
continue;
|
||||||
|
@ -151,7 +151,7 @@ impl<'a, 'b> Parser<'a, 'b> {
|
|||||||
|
|
||||||
let var = self
|
let var = self
|
||||||
.parse_identifier_no_interpolation(false)?
|
.parse_identifier_no_interpolation(false)?
|
||||||
.map_node(|n| n.into());
|
.map_node(Into::into);
|
||||||
|
|
||||||
self.whitespace_or_comment();
|
self.whitespace_or_comment();
|
||||||
self.span_before = match self.toks.peek() {
|
self.span_before = match self.toks.peek() {
|
||||||
@ -257,7 +257,8 @@ impl<'a, 'b> Parser<'a, 'b> {
|
|||||||
var.node,
|
var.node,
|
||||||
Value::Dimension(Some(Number::from(i)), Unit::None, true),
|
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))
|
.with_toks(&mut Lexer::new_ref(&body))
|
||||||
.parse_stmt()?;
|
.parse_stmt()?;
|
||||||
if self.flags.in_function() {
|
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)?;
|
let mut val = self.parse_value_from_vec(&cond, true)?;
|
||||||
self.scopes.enter_new_scope();
|
self.scopes.enter_new_scope();
|
||||||
while val.node.is_true() {
|
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))
|
.with_toks(&mut Lexer::new_ref(&body))
|
||||||
.parse_stmt()?;
|
.parse_stmt()?;
|
||||||
if self.flags.in_function() {
|
if self.flags.in_function() {
|
||||||
@ -322,7 +324,7 @@ impl<'a, 'b> Parser<'a, 'b> {
|
|||||||
loop {
|
loop {
|
||||||
self.expect_char('$')?;
|
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();
|
self.whitespace_or_comment();
|
||||||
if self
|
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))
|
.with_toks(&mut Lexer::new_ref(&body))
|
||||||
.parse_stmt()?;
|
.parse_stmt()?;
|
||||||
if self.flags.in_function() {
|
if self.flags.in_function() {
|
||||||
|
@ -64,10 +64,12 @@ impl<'a, 'b> Parser<'a, 'b> {
|
|||||||
|
|
||||||
for path in &self.options.load_paths {
|
for path in &self.options.load_paths {
|
||||||
if self.options.fs.is_dir(path) {
|
if self.options.fs.is_dir(path) {
|
||||||
try_path!(path.join(&path_buf)
|
try_path!(path
|
||||||
|
.join(&path_buf)
|
||||||
.with_file_name(name)
|
.with_file_name(name)
|
||||||
.with_extension("scss"));
|
.with_extension("scss"));
|
||||||
try_path!(path.join(&path_buf)
|
try_path!(path
|
||||||
|
.join(&path_buf)
|
||||||
.with_file_name(format!("_{}", name.to_str().unwrap()))
|
.with_file_name(format!("_{}", name.to_str().unwrap()))
|
||||||
.with_extension("scss"));
|
.with_extension("scss"));
|
||||||
try_path!(path.join(&path_buf).join("index.scss"));
|
try_path!(path.join(&path_buf).join("index.scss"));
|
||||||
|
@ -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() {
|
match self.toks.next() {
|
||||||
Some(Token { kind: ',', .. }) => {
|
Some(Token { kind: ',', .. }) => {
|
||||||
@ -271,7 +271,7 @@ impl<'a, 'b> Parser<'a, 'b> {
|
|||||||
) -> SassResult<()> {
|
) -> SassResult<()> {
|
||||||
let variable = self
|
let variable = self
|
||||||
.parse_identifier_no_interpolation(false)?
|
.parse_identifier_no_interpolation(false)?
|
||||||
.map_node(|n| n.into());
|
.map_node(Into::into);
|
||||||
|
|
||||||
self.whitespace_or_comment();
|
self.whitespace_or_comment();
|
||||||
self.expect_char(':')?;
|
self.expect_char(':')?;
|
||||||
|
@ -224,7 +224,7 @@ impl<'a, 'b: 'a, 'c> ValueVisitor<'a, 'b, 'c> {
|
|||||||
HigherIntermediateValue::Function(function, args, module) => {
|
HigherIntermediateValue::Function(function, args, module) => {
|
||||||
HigherIntermediateValue::Literal(self.parser.call_function(function, args, module)?)
|
HigherIntermediateValue::Literal(self.parser.call_function(function, args, module)?)
|
||||||
}
|
}
|
||||||
val => val,
|
_ => val,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,35 +200,36 @@ impl<'a, 'b> Parser<'a, 'b> {
|
|||||||
&mut self,
|
&mut self,
|
||||||
mut module: Spanned<Identifier>,
|
mut module: Spanned<Identifier>,
|
||||||
) -> SassResult<Spanned<IntermediateValue>> {
|
) -> SassResult<Spanned<IntermediateValue>> {
|
||||||
Ok(
|
let is_var_start = self.consume_char_if_exists('$');
|
||||||
IntermediateValue::Value(if self.consume_char_if_exists('$') {
|
|
||||||
let var = self
|
let var_or_fn_name = self
|
||||||
.parse_identifier_no_interpolation(false)?
|
.parse_identifier_no_interpolation(false)?
|
||||||
.map_node(|i| i.into());
|
.map_node(Into::into);
|
||||||
|
|
||||||
module.span = module.span.merge(var.span);
|
let value = if is_var_start {
|
||||||
|
module.span = module.span.merge(var_or_fn_name.span);
|
||||||
|
|
||||||
|
let value = self
|
||||||
|
.modules
|
||||||
|
.get(module.node, module.span)?
|
||||||
|
.get_var(var_or_fn_name)?;
|
||||||
|
|
||||||
let value = self.modules.get(module.node, module.span)?.get_var(var)?;
|
|
||||||
HigherIntermediateValue::Literal(value.clone())
|
HigherIntermediateValue::Literal(value.clone())
|
||||||
} else {
|
} else {
|
||||||
let fn_name = self
|
|
||||||
.parse_identifier_no_interpolation(false)?
|
|
||||||
.map_node(|i| i.into());
|
|
||||||
|
|
||||||
let function = self
|
let function = self
|
||||||
.modules
|
.modules
|
||||||
.get(module.node, module.span)?
|
.get(module.node, module.span)?
|
||||||
.get_fn(fn_name)?
|
.get_fn(var_or_fn_name)?
|
||||||
.ok_or(("Undefined function.", fn_name.span))?;
|
.ok_or(("Undefined function.", var_or_fn_name.span))?;
|
||||||
|
|
||||||
self.expect_char('(')?;
|
self.expect_char('(')?;
|
||||||
|
|
||||||
let call_args = self.parse_call_args()?;
|
let call_args = self.parse_call_args()?;
|
||||||
|
|
||||||
HigherIntermediateValue::Function(function, call_args, Some(module))
|
HigherIntermediateValue::Function(function, call_args, Some(module))
|
||||||
})
|
};
|
||||||
.span(module.span),
|
|
||||||
)
|
Ok(IntermediateValue::Value(value).span(module.span))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_fn_call(
|
fn parse_fn_call(
|
||||||
@ -532,8 +533,10 @@ impl<'a, 'b> Parser<'a, 'b> {
|
|||||||
Unit::from(u.node)
|
Unit::from(u.node)
|
||||||
}
|
}
|
||||||
'-' => {
|
'-' => {
|
||||||
if let Some(Token { kind, .. }) = self.toks.peek_next() {
|
let next_token = self.toks.peek_next();
|
||||||
self.toks.reset_cursor();
|
self.toks.reset_cursor();
|
||||||
|
|
||||||
|
if let Some(Token { kind, .. }) = next_token {
|
||||||
if matches!(kind, 'a'..='z' | 'A'..='Z' | '_' | '\\' | '\u{7f}'..=std::char::MAX)
|
if matches!(kind, 'a'..='z' | 'A'..='Z' | '_' | '\\' | '\u{7f}'..=std::char::MAX)
|
||||||
{
|
{
|
||||||
let u = self.parse_identifier_no_interpolation(true)?;
|
let u = self.parse_identifier_no_interpolation(true)?;
|
||||||
@ -543,7 +546,6 @@ impl<'a, 'b> Parser<'a, 'b> {
|
|||||||
Unit::None
|
Unit::None
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
self.toks.reset_cursor();
|
|
||||||
Unit::None
|
Unit::None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -889,7 +891,7 @@ impl<'a, 'b> Parser<'a, 'b> {
|
|||||||
'$' => {
|
'$' => {
|
||||||
self.toks.next();
|
self.toks.next();
|
||||||
let val = match self.parse_identifier_no_interpolation(false) {
|
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)),
|
Err(e) => return Some(Err(e)),
|
||||||
};
|
};
|
||||||
IntermediateValue::Value(HigherIntermediateValue::Literal(
|
IntermediateValue::Value(HigherIntermediateValue::Literal(
|
||||||
@ -1168,9 +1170,10 @@ impl<'a, 'b: 'a, 'c> IntermediateValueIterator<'a, 'b, 'c> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Op::Plus => {
|
Op::Plus => {
|
||||||
if let Some(left) = space_separated.pop() {
|
|
||||||
self.whitespace();
|
self.whitespace();
|
||||||
let right = self.single_value(in_paren)?;
|
let right = self.single_value(in_paren)?;
|
||||||
|
|
||||||
|
if let Some(left) = space_separated.pop() {
|
||||||
space_separated.push(Spanned {
|
space_separated.push(Spanned {
|
||||||
node: HigherIntermediateValue::BinaryOp(
|
node: HigherIntermediateValue::BinaryOp(
|
||||||
Box::new(left.node),
|
Box::new(left.node),
|
||||||
@ -1180,8 +1183,6 @@ impl<'a, 'b: 'a, 'c> IntermediateValueIterator<'a, 'b, 'c> {
|
|||||||
span: left.span.merge(right.span),
|
span: left.span.merge(right.span),
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
self.whitespace();
|
|
||||||
let right = self.single_value(in_paren)?;
|
|
||||||
space_separated.push(Spanned {
|
space_separated.push(Spanned {
|
||||||
node: HigherIntermediateValue::UnaryOp(op.node, Box::new(right.node)),
|
node: HigherIntermediateValue::UnaryOp(op.node, Box::new(right.node)),
|
||||||
span: right.span,
|
span: right.span,
|
||||||
|
@ -134,13 +134,13 @@ impl CompoundSelector {
|
|||||||
if !sel.contains_parent_selector() {
|
if !sel.contains_parent_selector() {
|
||||||
return Ok(SimpleSelector::Pseudo(pseudo));
|
return Ok(SimpleSelector::Pseudo(pseudo));
|
||||||
}
|
}
|
||||||
|
|
||||||
pseudo.selector = Some(Box::new(
|
pseudo.selector = Some(Box::new(
|
||||||
sel.resolve_parent_selectors(Some(parent.clone()), false)?,
|
sel.resolve_parent_selectors(Some(parent.clone()), false)?,
|
||||||
));
|
));
|
||||||
Ok(SimpleSelector::Pseudo(pseudo))
|
|
||||||
} else {
|
|
||||||
Ok(SimpleSelector::Pseudo(pseudo))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok(SimpleSelector::Pseudo(pseudo))
|
||||||
} else {
|
} else {
|
||||||
Ok(simple)
|
Ok(simple)
|
||||||
}
|
}
|
||||||
@ -181,20 +181,17 @@ impl CompoundSelector {
|
|||||||
.into());
|
.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();
|
let mut end = components.pop().unwrap();
|
||||||
end.add_suffix(suffix, span)?;
|
end.add_suffix(suffix, span)?;
|
||||||
components.push(end);
|
components.push(end);
|
||||||
|
}
|
||||||
|
|
||||||
components.extend(resolved_members.clone().into_iter().skip(1));
|
components.extend(resolved_members.clone().into_iter().skip(1));
|
||||||
CompoundSelector { components }
|
|
||||||
} else {
|
let last = CompoundSelector { components };
|
||||||
let mut components = last.components;
|
|
||||||
components.extend(resolved_members.clone().into_iter().skip(1));
|
|
||||||
CompoundSelector { components }
|
|
||||||
};
|
|
||||||
|
|
||||||
complex.components.pop();
|
complex.components.pop();
|
||||||
|
|
||||||
|
@ -30,7 +30,10 @@ pub(crate) struct Extension {
|
|||||||
/// The span in which `extender` was defined.
|
/// The span in which `extender` was defined.
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub left: Option<Box<Extension>>,
|
pub left: Option<Box<Extension>>,
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub right: Option<Box<Extension>>,
|
pub right: Option<Box<Extension>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,8 +4,10 @@ use crate::selector::Selector;
|
|||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub(crate) struct ExtendRule {
|
pub(crate) struct ExtendRule {
|
||||||
|
#[allow(dead_code)]
|
||||||
pub selector: Selector,
|
pub selector: Selector,
|
||||||
pub is_optional: bool,
|
pub is_optional: bool,
|
||||||
|
#[allow(dead_code)]
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ pub(crate) enum Unit {
|
|||||||
|
|
||||||
/// Units multiplied together
|
/// Units multiplied together
|
||||||
/// Boxed under the assumption that mul units are exceedingly rare
|
/// Boxed under the assumption that mul units are exceedingly rare
|
||||||
#[allow(clippy::box_vec)]
|
#[allow(clippy::box_collection)]
|
||||||
Mul(Box<Vec<Unit>>),
|
Mul(Box<Vec<Unit>>),
|
||||||
|
|
||||||
/// Units divided by each other
|
/// Units divided by each other
|
||||||
@ -222,6 +222,7 @@ impl Mul<Unit> for Unit {
|
|||||||
|
|
||||||
impl Div<Unit> for Unit {
|
impl Div<Unit> for Unit {
|
||||||
type Output = Unit;
|
type Output = Unit;
|
||||||
|
#[allow(clippy::if_same_then_else)]
|
||||||
fn div(self, rhs: Unit) -> Self::Output {
|
fn div(self, rhs: Unit) -> Self::Output {
|
||||||
if let Unit::Div(..) = self {
|
if let Unit::Div(..) = self {
|
||||||
todo!()
|
todo!()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user