This commit is contained in:
ConnorSkees 2020-02-14 18:28:09 -05:00
parent ae9b97a6b2
commit c16d6fed4e
6 changed files with 28 additions and 20 deletions

View File

@ -38,7 +38,7 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
_ => todo!("expected either unitless or % number for $blue")
};
if !red.is_none() || !green.is_none() || !blue.is_none() {
if red.is_some() || green.is_some() || blue.is_some() {
return Some(Value::Color(Color::from_rgba(red.unwrap_or(color.red()), green.unwrap_or(color.green()), blue.unwrap_or(color.blue()), alpha.unwrap_or(color.alpha()))))
}
@ -62,14 +62,14 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
_ => todo!("expected either unitless or % number for luminance"),
};
if !hue.is_none() || !saturation.is_none() || !luminance.is_none() {
if hue.is_some() || saturation.is_some() || luminance.is_some() {
// Color::as_hsla() returns more exact values than Color::hue(), etc.
let (this_hue, this_saturation, this_luminance, this_alpha) = color.as_hsla();
return Some(Value::Color(Color::from_hsla(hue.unwrap_or(this_hue), saturation.unwrap_or(this_saturation), luminance.unwrap_or(this_luminance), alpha.unwrap_or(this_alpha))))
}
Some(Value::Color(if !alpha.is_none() {
color.with_alpha(alpha.unwrap())
Some(Value::Color(if let Some(a) = alpha {
color.with_alpha(a)
} else {
color
}))

View File

@ -42,7 +42,7 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
_ => todo!("missing element $green")
};
assert_eq!(channels.len(), 3usize);
assert_eq!(channels.len(), 3_usize);
let blue = match channels.pop() {
Some(Value::Dimension(n, Unit::None)) => n,
@ -103,19 +103,19 @@ pub(crate) fn register(f: &mut BTreeMap<String, Builtin>) {
});
decl!(f "red", |args, _| {
match arg!(args, 0, "color") {
Value::Color(c) => Some(Value::Dimension(Number::from(c.red()), Unit::None)),
Value::Color(c) => Some(Value::Dimension(c.red(), Unit::None)),
_ => todo!("non-color given to builtin function `red()`")
}
});
decl!(f "green", |args, _| {
match arg!(args, 0, "color") {
Value::Color(c) => Some(Value::Dimension(Number::from(c.green()), Unit::None)),
Value::Color(c) => Some(Value::Dimension(c.green(), Unit::None)),
_ => todo!("non-color given to builtin function `green()`")
}
});
decl!(f "blue", |args, _| {
match arg!(args, 0, "color") {
Value::Color(c) => Some(Value::Dimension(Number::from(c.blue()), Unit::None)),
Value::Color(c) => Some(Value::Dimension(c.blue(), Unit::None)),
_ => todo!("non-color given to builtin function `blue()`")
}
});

View File

@ -111,7 +111,7 @@ impl Color {
Color::from_rgba(
self.red * weight1.clone() + other.red * weight2.clone(),
self.green * weight1.clone() + other.green * weight2.clone(),
self.blue * weight1.clone() + other.blue * weight2,
self.blue * weight1 + other.blue * weight2,
self.alpha * weight.clone() + other.alpha * (Number::from(1) - weight),
)
}
@ -188,7 +188,7 @@ impl Color {
let lightness = (min.clone() + max.clone()) / Number::from(2);
let saturation = if &min == &max {
let saturation = if min == max {
Number::from(0)
} else {
let d = max.clone() - min.clone();

View File

@ -14,7 +14,7 @@ enum Toplevel {
#[derive(Debug, Clone)]
enum BlockEntry {
Style(Style),
Style(Box<Style>),
MultilineComment(String),
#[allow(dead_code)]
AtRule(AtRule),
@ -37,7 +37,7 @@ impl Toplevel {
fn push_style(&mut self, s: Style) {
if let Toplevel::RuleSet(_, entries) = self {
entries.push(BlockEntry::Style(s));
entries.push(BlockEntry::Style(Box::new(s)));
}
}

View File

@ -13,20 +13,12 @@
clippy::use_self,
// this is way too pedantic -- some things don't need docs!
clippy::missing_docs_in_private_items,
// this crate is too new to deny todo!()
clippy::todo,
// unreachable!() has many valid use cases
clippy::unreachable,
// _ => {} has many valid use cases
clippy::wildcard_enum_match_arm,
// .expect() has many valid use cases, like when we know a value is `Some(..)`
clippy::option_expect_used,
// for now, panic() is an acceptable solution
clippy::panic,
// for now, some functions require a lot of lines
// future refactoring should make functions small and make
// this lint less annoying
clippy::too_many_lines,
// this is too pedantic -- we are allowed to add numbers!
clippy::integer_arithmetic,
// this is too pedantic for now -- the library is changing too quickly for
@ -41,6 +33,20 @@
clippy::option_unwrap_used,
// this is too pedantic -- it is sometimes useful to break up `impl`s
clippy::multiple_inherent_impl,
// temporarily allowed while under heavy development.
// eventually these allows should be refactored away
// to no longer be necessary
clippy::as_conversions,
clippy::todo,
clippy::too_many_lines,
clippy::panic,
clippy::result_unwrap_used,
clippy::result_expect_used,
clippy::cast_possible_truncation,
clippy::single_match_else,
clippy::indexing_slicing,
clippy::match_same_arms
)]
#![cfg_attr(feature = "nightly", feature(track_caller))]
// todo! handle erroring on styles at the toplevel
@ -231,6 +237,7 @@ enum Expr {
impl Display for StyleSheet {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// todo!(implement into fmt::Result for SassResult)
Ok(PrettyPrinter::new(f).pretty_print(self).unwrap())
}
}

View File

@ -66,6 +66,7 @@ impl From<BigInt> for Number {
}
impl From<Number> for BigInt {
#[inline]
fn from(b: Number) -> Self {
b.to_integer()
}