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

View File

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