clippy and rustfmt

This commit is contained in:
ConnorSkees 2020-02-02 10:27:08 -05:00
parent bad318aae8
commit 6bc96aeff4
4 changed files with 34 additions and 29 deletions

View File

@ -37,7 +37,8 @@
clippy::let_underscore_must_use,
// this is too pedantic -- it results in some names being less explicit
// than they should
clippy::module_name_repetitions
clippy::module_name_repetitions,
clippy::option_unwrap_used,
)]
#![cfg_attr(feature = "nightly", feature(track_caller))]
// todo! handle erroring on styles at the toplevel
@ -207,8 +208,8 @@ enum Expr {
/// A variable declaration `$var: 1px`
VariableDecl(String, Value),
/// A mixin declaration `@mixin foo {}`
MixinDecl(String, Mixin),
FunctionDecl(String, Function),
MixinDecl(String, Box<Mixin>),
FunctionDecl(String, Box<Function>),
/// An include statement `@include foo;`
Include(Vec<Stmt>),
/// A multiline comment: `/* foobar */`
@ -434,7 +435,7 @@ impl<'a> StyleSheetParser<'a> {
}
}
TokenKind::Symbol(Symbol::BitAnd) => {
return Err(SassError::new("Base-level rules cannot contain the parent-selector-referencing character '&'.", pos.clone()))
return Err(SassError::new("Base-level rules cannot contain the parent-selector-referencing character '&'.", *pos))
}
_ => match dbg!(self.lexer.next()) {
Some(Token { pos, .. }) => self.error(pos, "unexpected toplevel token"),
@ -452,12 +453,13 @@ impl<'a> StyleSheetParser<'a> {
{
match expr {
Expr::Style(s) => stmts.push(Stmt::Style(s)),
#[allow(clippy::redundant_closure)]
Expr::Styles(s) => stmts.extend(s.into_iter().map(|s| Stmt::Style(s))),
Expr::MixinDecl(name, mixin) => {
scope.mixins.insert(name, mixin);
scope.mixins.insert(name, *mixin);
}
Expr::FunctionDecl(name, func) => {
scope.functions.insert(name, func);
scope.functions.insert(name, *func);
}
Expr::Selector(s) => {
self.scope += 1;
@ -517,7 +519,7 @@ pub(crate) fn eat_expr<I: Iterator<Item = Token>>(
devour_whitespace(toks);
// special edge case where there was no space between the colon
// in a style `color:red`. todo: refactor
let mut v = values.clone().into_iter().peekable();
let mut v = values.into_iter().peekable();
let property = Style::parse_property(&mut v, scope, super_selector, String::new());
let value = Style::parse_value(&mut v, scope, super_selector);
return Ok(Some(Expr::Style(Style { property, value })));
@ -531,8 +533,9 @@ pub(crate) fn eat_expr<I: Iterator<Item = Token>>(
// special edge case where there was no space between the colon
// and no semicolon following the style
// in a style `color:red`. todo: refactor
let mut v = values.clone().into_iter().peekable();
let property = Style::parse_property(&mut v, scope, super_selector, String::new());
let mut v = values.into_iter().peekable();
let property =
Style::parse_property(&mut v, scope, super_selector, String::new());
let value = Style::parse_value(&mut v, scope, super_selector);
return Ok(Some(Expr::Style(Style { property, value })));
}
@ -598,8 +601,8 @@ pub(crate) fn eat_expr<I: Iterator<Item = Token>>(
}) = toks.next()
{
return match AtRule::from_tokens(rule, pos, toks, scope) {
AtRule::Mixin(name, mixin) => Ok(Some(Expr::MixinDecl(name, *mixin))),
AtRule::Function(name, func) => Ok(Some(Expr::FunctionDecl(name, *func))),
AtRule::Mixin(name, mixin) => Ok(Some(Expr::MixinDecl(name, mixin))),
AtRule::Function(name, func) => Ok(Some(Expr::FunctionDecl(name, func))),
AtRule::Charset(_) => todo!("@charset as expr"),
AtRule::Debug(a, b) => Ok(Some(Expr::Debug(a, b))),
AtRule::Warn(a, b) => Ok(Some(Expr::Warn(a, b))),

View File

@ -188,13 +188,13 @@ impl<'a> StyleParser<'a> {
};
}
devour_whitespace(toks);
if !super_property.is_empty() {
if super_property.is_empty() {
property
} else {
super_property.reserve(1 + property.len());
super_property.push('-');
super_property.push_str(&property);
super_property
} else {
property
}
}
}

View File

@ -83,19 +83,20 @@ impl Add for Value {
fn add(self, other: Self) -> Self {
match self {
Self::Important => todo!(),
Self::True => todo!(),
Self::False => todo!(),
Self::Null => todo!(),
// Self::Important => todo!(),
// Self::True => todo!(),
// Self::False => todo!(),
// Self::Null => todo!(),
Self::Dimension(num, unit) => match other {
Self::Dimension(num2, unit2) => Value::Dimension(num + num2, unit),
_ => todo!(),
},
Self::List(..) => todo!(),
Self::Color(..) => todo!(),
Self::BinaryOp(..) => todo!(),
Self::Paren(..) => todo!(),
Self::Ident(..) => todo!(),
// Self::List(..) => todo!(),
// Self::Color(..) => todo!(),
// Self::BinaryOp(..) => todo!(),
// Self::Paren(..) => todo!(),
// Self::Ident(..) => todo!(),
_ => todo!(),
}
}
}
@ -148,7 +149,9 @@ impl Value {
None => return Some(left),
};
match next.kind {
TokenKind::Symbol(Symbol::SemiColon) => Some(left),
TokenKind::Symbol(Symbol::SemiColon) | TokenKind::Symbol(Symbol::CloseParen) => {
Some(left)
}
TokenKind::Symbol(Symbol::Comma) => {
toks.next();
devour_whitespace_or_comment(toks);
@ -158,7 +161,6 @@ impl Value {
};
Some(Value::List(vec![left, right], ListSeparator::Comma))
}
TokenKind::Symbol(Symbol::CloseParen) => Some(left),
TokenKind::Symbol(Symbol::Plus)
| TokenKind::Symbol(Symbol::Minus)
| TokenKind::Op(_)

View File

@ -7,9 +7,9 @@ macro_rules! test {
fn $func() {
let mut buf = Vec::new();
grass::StyleSheet::new($input)
.expect(concat!("failed to parse on ", $input))
.print_as_css(&mut buf)
.expect(concat!("failed to pretty print on ", $input));
.expect(concat!("failed to parse on ", $input))
.print_as_css(&mut buf)
.expect(concat!("failed to pretty print on ", $input));
assert_eq!(
String::from($input),
String::from_utf8(buf).expect("produced invalid utf8")