Merge branch 'master' into selector-fns
This commit is contained in:
commit
ab61f9fb32
58
.github/workflows/tests.yml
vendored
58
.github/workflows/tests.yml
vendored
@ -19,7 +19,7 @@ jobs:
|
|||||||
override: true
|
override: true
|
||||||
|
|
||||||
- name: version info
|
- name: version info
|
||||||
run: rustc --version; cargo --version;
|
run: rustc --version; cargo --version;
|
||||||
|
|
||||||
- name: Run all tests
|
- name: Run all tests
|
||||||
run: cargo test
|
run: cargo test
|
||||||
@ -57,35 +57,27 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
command: clippy
|
command: clippy
|
||||||
args: -- -D warnings
|
args: -- -D warnings
|
||||||
|
# sass-spec:
|
||||||
|
# continue-on-error: true
|
||||||
sass-spec:
|
# runs-on: ubuntu-latest
|
||||||
continue-on-error: true
|
# steps:
|
||||||
runs-on: ubuntu-latest
|
# - name: Checkout
|
||||||
steps:
|
# uses: actions/checkout@master
|
||||||
- name: Checkout
|
# - uses: actions-rs/toolchain@v1
|
||||||
uses: actions/checkout@master
|
# with:
|
||||||
|
# profile: minimal
|
||||||
- uses: actions-rs/toolchain@v1
|
# toolchain: stable
|
||||||
with:
|
# override: true
|
||||||
profile: minimal
|
# - name: version info
|
||||||
toolchain: stable
|
# run: rustc --version; cargo --version;
|
||||||
override: true
|
# - name: Build binary
|
||||||
|
# run: cargo b --release
|
||||||
- name: version info
|
# - name: Get sass-spec
|
||||||
run: rustc --version; cargo --version;
|
# run: git submodule init && git submodule update
|
||||||
|
# - name: Install whatever Ruby needs
|
||||||
- name: Build binary
|
# run: |
|
||||||
run: cargo b --release
|
# sudo apt-get install libncurses5-dev libncursesw5-dev
|
||||||
|
# sudo gem install bundler
|
||||||
- name: Get sass-spec
|
# cd sass-spec && bundler install
|
||||||
run: git submodule init && git submodule update
|
# - name: Run Sass spec
|
||||||
|
# run: ./sass-spec/sass-spec.rb -c './target/release/grass'
|
||||||
- name: Install whatever Ruby needs
|
|
||||||
run: |
|
|
||||||
sudo apt-get install libncurses5-dev libncursesw5-dev
|
|
||||||
sudo gem install bundler
|
|
||||||
cd sass-spec && bundler install
|
|
||||||
|
|
||||||
- name: Run Sass spec
|
|
||||||
run: ./sass-spec/sass-spec.rb -c './target/release/grass'
|
|
||||||
|
@ -73,6 +73,7 @@ impl For {
|
|||||||
Ok(stmts)
|
Ok(stmts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::range_plus_one)]
|
||||||
pub fn iter(&self) -> ForIterator {
|
pub fn iter(&self) -> ForIterator {
|
||||||
if self.from < self.to {
|
if self.from < self.to {
|
||||||
ForIterator::Forward(self.from..(self.to + self.through))
|
ForIterator::Forward(self.from..(self.to + self.through))
|
||||||
|
@ -173,6 +173,7 @@ impl AtRule {
|
|||||||
body.push(toks.next().unwrap());
|
body.push(toks.next().unwrap());
|
||||||
devour_whitespace(toks);
|
devour_whitespace(toks);
|
||||||
let mut styles = Vec::new();
|
let mut styles = Vec::new();
|
||||||
|
#[allow(clippy::unnecessary_filter_map)]
|
||||||
let raw_stmts = eat_stmts_at_root(
|
let raw_stmts = eat_stmts_at_root(
|
||||||
&mut body.into_iter().peekmore(),
|
&mut body.into_iter().peekmore(),
|
||||||
scope,
|
scope,
|
||||||
|
@ -86,6 +86,7 @@ fn type_of(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> Sass
|
|||||||
|
|
||||||
fn unitless(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassResult<Value> {
|
fn unitless(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassResult<Value> {
|
||||||
args.max_args(1)?;
|
args.max_args(1)?;
|
||||||
|
#[allow(clippy::match_same_arms)]
|
||||||
Ok(match arg!(args, scope, super_selector, 0, "number") {
|
Ok(match arg!(args, scope, super_selector, 0, "number") {
|
||||||
Value::Dimension(_, Unit::None) => Value::True,
|
Value::Dimension(_, Unit::None) => Value::True,
|
||||||
Value::Dimension(_, _) => Value::False,
|
Value::Dimension(_, _) => Value::False,
|
||||||
|
@ -346,6 +346,7 @@ fn str_insert(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> S
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "random")]
|
#[cfg(feature = "random")]
|
||||||
|
#[allow(clippy::needless_pass_by_value)]
|
||||||
fn unique_id(args: CallArgs, _: &Scope, _: &Selector) -> SassResult<Value> {
|
fn unique_id(args: CallArgs, _: &Scope, _: &Selector) -> SassResult<Value> {
|
||||||
args.max_args(0)?;
|
args.max_args(0)?;
|
||||||
let mut rng = thread_rng();
|
let mut rng = thread_rng();
|
||||||
|
@ -139,6 +139,7 @@ impl Default for Identifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Identifier {
|
impl Identifier {
|
||||||
|
#[allow(clippy::missing_const_for_fn)]
|
||||||
pub fn into_inner(self) -> String {
|
pub fn into_inner(self) -> String {
|
||||||
self.0
|
self.0
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ pub(crate) fn import(
|
|||||||
if path.is_absolute() {
|
if path.is_absolute() {
|
||||||
todo!("absolute import")
|
todo!("absolute import")
|
||||||
}
|
}
|
||||||
let path_buf = ctx.parent().unwrap_or(Path::new("")).join(path);
|
let path_buf = ctx.parent().unwrap_or_else(|| Path::new("")).join(path);
|
||||||
// "todo: will panic if path ended in `..`"
|
// "todo: will panic if path ended in `..`"
|
||||||
let name = path_buf.file_name().unwrap();
|
let name = path_buf.file_name().unwrap();
|
||||||
if path_buf.extension() == Some(OsStr::new(".css")) {
|
if path_buf.extension() == Some(OsStr::new(".css")) {
|
||||||
|
14
src/lib.rs
14
src/lib.rs
@ -50,9 +50,6 @@ grass input.scss
|
|||||||
// this is too pedantic for now -- the library is changing too quickly for
|
// this is too pedantic for now -- the library is changing too quickly for
|
||||||
// good docs to be written
|
// good docs to be written
|
||||||
clippy::missing_errors_doc,
|
clippy::missing_errors_doc,
|
||||||
// this incorrectly results in errors for types that derive `Debug`
|
|
||||||
// https://github.com/rust-lang/rust-clippy/issues/4980
|
|
||||||
// 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,
|
||||||
@ -61,6 +58,7 @@ grass input.scss
|
|||||||
// filter isn't fallible
|
// filter isn't fallible
|
||||||
clippy::filter_map,
|
clippy::filter_map,
|
||||||
clippy::else_if_without_else,
|
clippy::else_if_without_else,
|
||||||
|
clippy::new_ret_no_self,
|
||||||
|
|
||||||
// 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
|
||||||
@ -74,9 +72,15 @@ grass input.scss
|
|||||||
clippy::cast_possible_truncation,
|
clippy::cast_possible_truncation,
|
||||||
clippy::single_match_else,
|
clippy::single_match_else,
|
||||||
clippy::indexing_slicing,
|
clippy::indexing_slicing,
|
||||||
// clippy::match_same_arms,
|
|
||||||
// clippy::or_fun_call,
|
|
||||||
clippy::redundant_pub_crate,
|
clippy::redundant_pub_crate,
|
||||||
|
|
||||||
|
clippy::string_add,
|
||||||
|
clippy::get_unwrap,
|
||||||
|
clippy::unit_arg,
|
||||||
|
clippy::wrong_self_convention,
|
||||||
|
clippy::items_after_statements,
|
||||||
|
clippy::shadow_reuse,
|
||||||
|
clippy::shadow_unrelated,
|
||||||
)]
|
)]
|
||||||
#![cfg_attr(feature = "nightly", feature(track_caller))]
|
#![cfg_attr(feature = "nightly", feature(track_caller))]
|
||||||
#![cfg_attr(feature = "profiling", inline(never))]
|
#![cfg_attr(feature = "profiling", inline(never))]
|
||||||
|
@ -378,6 +378,7 @@ impl<'a> StyleSheetParser<'a> {
|
|||||||
node: Stmt::Style(s),
|
node: Stmt::Style(s),
|
||||||
span,
|
span,
|
||||||
}),
|
}),
|
||||||
|
#[allow(clippy::match_same_arms)]
|
||||||
Expr::AtRule(a) => match a {
|
Expr::AtRule(a) => match a {
|
||||||
AtRule::For(f) => stmts.extend(f.ruleset_eval(scope, super_selector, None)?),
|
AtRule::For(f) => stmts.extend(f.ruleset_eval(scope, super_selector, None)?),
|
||||||
AtRule::While(w) => {
|
AtRule::While(w) => {
|
||||||
|
@ -214,7 +214,7 @@ impl From<i64> for Number {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo: implement std::convertTryFrom instead
|
#[allow(clippy::fallible_impl_from)]
|
||||||
impl From<f64> for Number {
|
impl From<f64> for Number {
|
||||||
fn from(b: f64) -> Self {
|
fn from(b: f64) -> Self {
|
||||||
Number::Big(BigRational::from_float(b).unwrap())
|
Number::Big(BigRational::from_float(b).unwrap())
|
||||||
@ -241,10 +241,10 @@ impl Display for Number {
|
|||||||
let mut whole = self.to_integer().abs();
|
let mut whole = self.to_integer().abs();
|
||||||
let has_decimal = self.is_decimal();
|
let has_decimal = self.is_decimal();
|
||||||
let mut frac = self.abs().fract();
|
let mut frac = self.abs().fract();
|
||||||
let mut dec = String::with_capacity(if has_decimal { PRECISION + 1 } else { 0 });
|
let mut dec = String::with_capacity(if has_decimal { PRECISION } else { 0 });
|
||||||
if has_decimal {
|
if has_decimal {
|
||||||
for _ in 0..(PRECISION - 1) {
|
for _ in 0..(PRECISION - 1) {
|
||||||
frac *= Self::from(10);
|
frac *= 10_i64;
|
||||||
write!(dec, "{}", frac.to_integer())?;
|
write!(dec, "{}", frac.to_integer())?;
|
||||||
frac = frac.fract();
|
frac = frac.fract();
|
||||||
if frac.is_zero() {
|
if frac.is_zero() {
|
||||||
@ -252,7 +252,7 @@ impl Display for Number {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !frac.is_zero() {
|
if !frac.is_zero() {
|
||||||
let end = (frac * Self::from(10)).round().to_integer();
|
let end = (frac * 10_i64).round().to_integer();
|
||||||
if end.is_ten() {
|
if end.is_ten() {
|
||||||
loop {
|
loop {
|
||||||
match dec.pop() {
|
match dec.pop() {
|
||||||
@ -495,6 +495,24 @@ impl Mul for Number {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Mul<i64> for Number {
|
||||||
|
type Output = Self;
|
||||||
|
|
||||||
|
fn mul(self, other: i64) -> Self {
|
||||||
|
match self {
|
||||||
|
Self::Machine(val1) => Self::Machine(val1 * other),
|
||||||
|
Self::Big(val1) => Self::Big(val1 * BigInt::from(other)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MulAssign<i64> for Number {
|
||||||
|
fn mul_assign(&mut self, other: i64) {
|
||||||
|
let tmp = mem::take(self);
|
||||||
|
*self = tmp * other;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl MulAssign for Number {
|
impl MulAssign for Number {
|
||||||
fn mul_assign(&mut self, other: Self) {
|
fn mul_assign(&mut self, other: Self) {
|
||||||
let tmp = mem::take(self);
|
let tmp = mem::take(self);
|
||||||
|
@ -77,7 +77,7 @@ impl Value {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
},
|
||||||
s => s == other.eval(span)?.node,
|
s => s == other.eval(span)?.node,
|
||||||
})
|
})
|
||||||
.span(span))
|
.span(span))
|
||||||
@ -151,7 +151,7 @@ impl Value {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => true,
|
_ => true,
|
||||||
}
|
},
|
||||||
s => s != other.eval(span)?.node,
|
s => s != other.eval(span)?.node,
|
||||||
})
|
})
|
||||||
.span(span))
|
.span(span))
|
||||||
@ -487,11 +487,7 @@ impl Value {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Self::List(..) => Value::String(
|
Self::List(..) | Self::String(..) => Value::String(
|
||||||
format!("{}{}-{}", num, unit, other.to_css_string(span)?),
|
|
||||||
QuoteKind::None,
|
|
||||||
),
|
|
||||||
Self::String(..) => Value::String(
|
|
||||||
format!("{}{}-{}", num, unit, other.to_css_string(span)?),
|
format!("{}{}-{}", num, unit, other.to_css_string(span)?),
|
||||||
QuoteKind::None,
|
QuoteKind::None,
|
||||||
),
|
),
|
||||||
|
@ -431,7 +431,7 @@ fn single_value<I: Iterator<Item = Token>>(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_i64(s: String) -> i64 {
|
fn parse_i64(s: &str) -> i64 {
|
||||||
s.as_bytes()
|
s.as_bytes()
|
||||||
.iter()
|
.iter()
|
||||||
.fold(0, |total, this| total * 10 + i64::from(this - b'0'))
|
.fold(0, |total, this| total * 10 + i64::from(this - b'0'))
|
||||||
@ -741,7 +741,7 @@ impl Value {
|
|||||||
|
|
||||||
let n = if val.dec_len == 0 {
|
let n = if val.dec_len == 0 {
|
||||||
if val.num.len() <= 18 && val.times_ten.is_empty() {
|
if val.num.len() <= 18 && val.times_ten.is_empty() {
|
||||||
let n = Rational64::new_raw(parse_i64(val.num), 1);
|
let n = Rational64::new_raw(parse_i64(&val.num), 1);
|
||||||
return Some(Ok(IntermediateValue::Value(Value::Dimension(
|
return Some(Ok(IntermediateValue::Value(Value::Dimension(
|
||||||
Number::new_machine(n),
|
Number::new_machine(n),
|
||||||
unit,
|
unit,
|
||||||
@ -751,7 +751,7 @@ impl Value {
|
|||||||
BigRational::new_raw(val.num.parse::<BigInt>().unwrap(), BigInt::one())
|
BigRational::new_raw(val.num.parse::<BigInt>().unwrap(), BigInt::one())
|
||||||
} else {
|
} else {
|
||||||
if val.num.len() <= 18 && val.times_ten.is_empty() {
|
if val.num.len() <= 18 && val.times_ten.is_empty() {
|
||||||
let n = Rational64::new(parse_i64(val.num), pow(10, val.dec_len));
|
let n = Rational64::new(parse_i64(&val.num), pow(10, val.dec_len));
|
||||||
return Some(Ok(IntermediateValue::Value(Value::Dimension(
|
return Some(Ok(IntermediateValue::Value(Value::Dimension(
|
||||||
Number::new_machine(n),
|
Number::new_machine(n),
|
||||||
unit,
|
unit,
|
||||||
@ -884,9 +884,10 @@ impl Value {
|
|||||||
IntermediateValue::Comma.span(span)
|
IntermediateValue::Comma.span(span)
|
||||||
}
|
}
|
||||||
q @ '>' | q @ '<' => {
|
q @ '>' | q @ '<' => {
|
||||||
let mut span = toks.next().unwrap().pos();
|
let mut span = toks.next().unwrap().pos;
|
||||||
|
#[allow(clippy::eval_order_dependence)]
|
||||||
IntermediateValue::Op(if let Some(Token { kind: '=', .. }) = toks.peek() {
|
IntermediateValue::Op(if let Some(Token { kind: '=', .. }) = toks.peek() {
|
||||||
span = span.merge(toks.next().unwrap().pos());
|
span = span.merge(toks.next().unwrap().pos);
|
||||||
match q {
|
match q {
|
||||||
'>' => Op::GreaterThanEqual,
|
'>' => Op::GreaterThanEqual,
|
||||||
'<' => Op::LessThanEqual,
|
'<' => Op::LessThanEqual,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user