clippy
This commit is contained in:
parent
e4843180c7
commit
beff60ad31
@ -69,19 +69,18 @@ impl Function {
|
|||||||
match stmt {
|
match stmt {
|
||||||
Stmt::AtRule(AtRule::Return(toks)) => {
|
Stmt::AtRule(AtRule::Return(toks)) => {
|
||||||
return Value::from_tokens(
|
return Value::from_tokens(
|
||||||
&mut toks.clone().into_iter().peekable(),
|
&mut toks.into_iter().peekable(),
|
||||||
&self.scope,
|
&self.scope,
|
||||||
super_selector,
|
super_selector,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Stmt::AtRule(AtRule::For(..)) => todo!("@for in function"),
|
Stmt::AtRule(AtRule::For(..)) => todo!("@for in function"),
|
||||||
Stmt::AtRule(AtRule::If(i)) => {
|
Stmt::AtRule(AtRule::If(i)) => {
|
||||||
match self.call(
|
if let Ok(v) = self.call(
|
||||||
super_selector,
|
super_selector,
|
||||||
i.eval(&mut self.scope.clone(), super_selector)?,
|
i.eval(&mut self.scope.clone(), super_selector)?,
|
||||||
) {
|
) {
|
||||||
Ok(v) => return Ok(v),
|
return Ok(v);
|
||||||
Err(..) => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => return Err("This at-rule is not allowed here.".into()),
|
_ => return Err("This at-rule is not allowed here.".into()),
|
||||||
|
@ -132,7 +132,7 @@ impl AtRule {
|
|||||||
'h' => {
|
'h' => {
|
||||||
let r = toks.next().unwrap();
|
let r = toks.next().unwrap();
|
||||||
these_toks.push(r);
|
these_toks.push(r);
|
||||||
if &r.kind != &'r' {
|
if r.kind != 'r' {
|
||||||
from_toks.extend(these_toks);
|
from_toks.extend(these_toks);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
Value::List(v, ..) if v.is_empty() => SassMap::new(),
|
Value::List(v, ..) if v.is_empty() => SassMap::new(),
|
||||||
v => return Err(format!("$map: {} is not a map.", v).into()),
|
v => return Err(format!("$map: {} is not a map.", v).into()),
|
||||||
};
|
};
|
||||||
Ok(map.get(key)?.unwrap_or(Value::Null).clone())
|
Ok(map.get(&key)?.unwrap_or(Value::Null))
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
@ -28,7 +28,7 @@ pub(crate) fn register(f: &mut HashMap<String, Builtin>) {
|
|||||||
Value::List(v, ..) if v.is_empty() => SassMap::new(),
|
Value::List(v, ..) if v.is_empty() => SassMap::new(),
|
||||||
v => return Err(format!("$map: {} is not a map.", v).into()),
|
v => return Err(format!("$map: {} is not a map.", v).into()),
|
||||||
};
|
};
|
||||||
Ok(Value::bool(map.get(key)?.is_some()))
|
Ok(Value::bool(map.get(&key)?.is_some()))
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
f.insert(
|
f.insert(
|
||||||
|
@ -201,7 +201,7 @@ impl<'a> SelectorParser<'a> {
|
|||||||
let s = format!(
|
let s = format!(
|
||||||
"{}{}",
|
"{}{}",
|
||||||
v,
|
v,
|
||||||
eat_ident(tokens, &self.scope, &self.super_selector)?
|
eat_ident(tokens, self.scope, self.super_selector)?
|
||||||
);
|
);
|
||||||
if let Some(Token { kind: '(', .. }) = tokens.peek() {
|
if let Some(Token { kind: '(', .. }) = tokens.peek() {
|
||||||
tokens.next();
|
tokens.next();
|
||||||
@ -225,7 +225,7 @@ impl<'a> SelectorParser<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
':' => {
|
':' => {
|
||||||
let s = eat_ident(tokens, &self.scope, &self.super_selector)?;
|
let s = eat_ident(tokens, self.scope, self.super_selector)?;
|
||||||
self.selectors.push(SelectorKind::PseudoElement(s))
|
self.selectors.push(SelectorKind::PseudoElement(s))
|
||||||
}
|
}
|
||||||
_ => return Err("Expected identifier.".into()),
|
_ => return Err("Expected identifier.".into()),
|
||||||
|
@ -192,7 +192,7 @@ impl<'a> StyleParser<'a> {
|
|||||||
mut super_property: String,
|
mut super_property: String,
|
||||||
) -> SassResult<String> {
|
) -> SassResult<String> {
|
||||||
devour_whitespace(toks);
|
devour_whitespace(toks);
|
||||||
let property = eat_ident(toks, &self.scope, &self.super_selector)?;
|
let property = eat_ident(toks, self.scope, self.super_selector)?;
|
||||||
devour_whitespace_or_comment(toks)?;
|
devour_whitespace_or_comment(toks)?;
|
||||||
if toks.peek().is_some() && toks.peek().unwrap().kind == ':' {
|
if toks.peek().is_some() && toks.peek().unwrap().kind == ':' {
|
||||||
toks.next();
|
toks.next();
|
||||||
|
@ -515,7 +515,7 @@ pub(crate) fn eat_number<I: Iterator<Item = Token>>(toks: &mut Peekable<I>) -> S
|
|||||||
///
|
///
|
||||||
/// The newline is consumed
|
/// The newline is consumed
|
||||||
pub(crate) fn read_until_newline<I: Iterator<Item = Token>>(toks: &mut Peekable<I>) {
|
pub(crate) fn read_until_newline<I: Iterator<Item = Token>>(toks: &mut Peekable<I>) {
|
||||||
while let Some(tok) = toks.next() {
|
for tok in toks {
|
||||||
if tok.kind == '\n' {
|
if tok.kind == '\n' {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -534,12 +534,10 @@ pub(crate) fn eat_comment<I: Iterator<Item = Token>>(
|
|||||||
) -> SassResult<String> {
|
) -> SassResult<String> {
|
||||||
let mut comment = String::new();
|
let mut comment = String::new();
|
||||||
while let Some(tok) = toks.next() {
|
while let Some(tok) = toks.next() {
|
||||||
if tok.kind == '*' {
|
if tok.kind == '*' && toks.peek().unwrap().kind == '/' {
|
||||||
if toks.peek().unwrap().kind == '/' {
|
|
||||||
toks.next();
|
toks.next();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
comment.push(tok.kind);
|
comment.push(tok.kind);
|
||||||
}
|
}
|
||||||
devour_whitespace(toks);
|
devour_whitespace(toks);
|
||||||
|
@ -8,11 +8,11 @@ use crate::error::SassResult;
|
|||||||
pub(crate) struct SassMap(Vec<(Value, Value)>);
|
pub(crate) struct SassMap(Vec<(Value, Value)>);
|
||||||
|
|
||||||
impl SassMap {
|
impl SassMap {
|
||||||
pub fn new() -> SassMap {
|
pub const fn new() -> SassMap {
|
||||||
SassMap(Vec::new())
|
SassMap(Vec::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get(self, key: Value) -> SassResult<Option<Value>> {
|
pub fn get(self, key: &Value) -> SassResult<Option<Value>> {
|
||||||
for (k, v) in self.0 {
|
for (k, v) in self.0 {
|
||||||
if k.equals(key.clone())? {
|
if k.equals(key.clone())? {
|
||||||
return Ok(Some(v));
|
return Ok(Some(v));
|
||||||
@ -31,7 +31,7 @@ impl SassMap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn merge(&mut self, other: SassMap) {
|
pub fn merge(&mut self, other: SassMap) {
|
||||||
for (key, value) in other.into_iter() {
|
for (key, value) in other {
|
||||||
self.insert(key, value);
|
self.insert(key, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -228,7 +228,7 @@ impl Value {
|
|||||||
Ok(match self {
|
Ok(match self {
|
||||||
Self::Dimension(num, ref unit) => match other {
|
Self::Dimension(num, ref unit) => match other {
|
||||||
Self::Dimension(num2, unit2) => {
|
Self::Dimension(num2, unit2) => {
|
||||||
if !unit.comparable(&unit2) {
|
if !unit.comparable(unit2) {
|
||||||
return Err(format!("Incompatible units {} and {}.", unit2, unit).into());
|
return Err(format!("Incompatible units {} and {}.", unit2, unit).into());
|
||||||
}
|
}
|
||||||
if unit == unit2 {
|
if unit == unit2 {
|
||||||
|
@ -170,7 +170,7 @@ impl Sub for Value {
|
|||||||
format!("{}-{}{}{}", self, q.normalize(), s, q.normalize()),
|
format!("{}-{}{}{}", self, q.normalize(), s, q.normalize()),
|
||||||
QuoteKind::None,
|
QuoteKind::None,
|
||||||
),
|
),
|
||||||
Self::Paren(..) => (self + other.eval()?)?,
|
Self::Paren(..) => (self - other.eval()?)?,
|
||||||
_ => Value::Ident(format!("{}-{}", self, other), QuoteKind::None),
|
_ => Value::Ident(format!("{}-{}", self, other), QuoteKind::None),
|
||||||
},
|
},
|
||||||
_ => match other {
|
_ => match other {
|
||||||
|
@ -186,7 +186,7 @@ impl Value {
|
|||||||
let right = Self::from_tokens(toks, scope, super_selector)?;
|
let right = Self::from_tokens(toks, scope, super_selector)?;
|
||||||
Ok(Value::BinaryOp(Box::new(left), Op::Equal, Box::new(right)))
|
Ok(Value::BinaryOp(Box::new(left), Op::Equal, Box::new(right)))
|
||||||
} else {
|
} else {
|
||||||
return Err("expected \"=\".".into());
|
Err("expected \"=\".".into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
q @ '>' | q @ '<' => {
|
q @ '>' | q @ '<' => {
|
||||||
@ -231,7 +231,7 @@ impl Value {
|
|||||||
Brackets::None,
|
Brackets::None,
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
return Err("Expected \"important\".".into());
|
Err("Expected \"important\".".into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
'-' => {
|
'-' => {
|
||||||
|
@ -113,11 +113,9 @@ test!(
|
|||||||
);
|
);
|
||||||
error!(
|
error!(
|
||||||
map_get_one_arg,
|
map_get_one_arg,
|
||||||
"a {\n color: map-get(1);\n}\n",
|
"a {\n color: map-get(1);\n}\n", "Error: Missing argument $key."
|
||||||
"Error: Missing argument $key."
|
|
||||||
);
|
);
|
||||||
error!(
|
error!(
|
||||||
map_has_key_one_arg,
|
map_has_key_one_arg,
|
||||||
"a {\n color: map-has-key(1);\n}\n",
|
"a {\n color: map-has-key(1);\n}\n", "Error: Missing argument $key."
|
||||||
"Error: Missing argument $key."
|
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user