Merge branch 'master' into selector-fns

This commit is contained in:
ConnorSkees 2020-05-31 05:38:24 -04:00
commit ab61f9fb32
12 changed files with 72 additions and 55 deletions

View File

@ -19,7 +19,7 @@ jobs:
override: true
- name: version info
run: rustc --version; cargo --version;
run: rustc --version; cargo --version;
- name: Run all tests
run: cargo test
@ -57,35 +57,27 @@ jobs:
with:
command: clippy
args: -- -D warnings
sass-spec:
continue-on-error: true
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@master
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: version info
run: rustc --version; cargo --version;
- name: Build binary
run: cargo b --release
- name: Get sass-spec
run: git submodule init && git submodule update
- 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'
# sass-spec:
# continue-on-error: true
# runs-on: ubuntu-latest
# steps:
# - name: Checkout
# uses: actions/checkout@master
# - uses: actions-rs/toolchain@v1
# with:
# profile: minimal
# toolchain: stable
# override: true
# - name: version info
# run: rustc --version; cargo --version;
# - name: Build binary
# run: cargo b --release
# - name: Get sass-spec
# run: git submodule init && git submodule update
# - 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'

View File

@ -73,6 +73,7 @@ impl For {
Ok(stmts)
}
#[allow(clippy::range_plus_one)]
pub fn iter(&self) -> ForIterator {
if self.from < self.to {
ForIterator::Forward(self.from..(self.to + self.through))

View File

@ -173,6 +173,7 @@ impl AtRule {
body.push(toks.next().unwrap());
devour_whitespace(toks);
let mut styles = Vec::new();
#[allow(clippy::unnecessary_filter_map)]
let raw_stmts = eat_stmts_at_root(
&mut body.into_iter().peekmore(),
scope,

View File

@ -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> {
args.max_args(1)?;
#[allow(clippy::match_same_arms)]
Ok(match arg!(args, scope, super_selector, 0, "number") {
Value::Dimension(_, Unit::None) => Value::True,
Value::Dimension(_, _) => Value::False,

View File

@ -346,6 +346,7 @@ fn str_insert(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> S
}
#[cfg(feature = "random")]
#[allow(clippy::needless_pass_by_value)]
fn unique_id(args: CallArgs, _: &Scope, _: &Selector) -> SassResult<Value> {
args.max_args(0)?;
let mut rng = thread_rng();

View File

@ -139,6 +139,7 @@ impl Default for Identifier {
}
impl Identifier {
#[allow(clippy::missing_const_for_fn)]
pub fn into_inner(self) -> String {
self.0
}

View File

@ -17,7 +17,7 @@ pub(crate) fn import(
if path.is_absolute() {
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 `..`"
let name = path_buf.file_name().unwrap();
if path_buf.extension() == Some(OsStr::new(".css")) {

View File

@ -50,9 +50,6 @@ grass input.scss
// this is too pedantic for now -- the library is changing too quickly for
// good docs to be written
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
// than they should
clippy::module_name_repetitions,
@ -61,6 +58,7 @@ grass input.scss
// filter isn't fallible
clippy::filter_map,
clippy::else_if_without_else,
clippy::new_ret_no_self,
// temporarily allowed while under heavy development.
// eventually these allows should be refactored away
@ -74,9 +72,15 @@ grass input.scss
clippy::cast_possible_truncation,
clippy::single_match_else,
clippy::indexing_slicing,
// clippy::match_same_arms,
// clippy::or_fun_call,
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 = "profiling", inline(never))]

View File

@ -378,6 +378,7 @@ impl<'a> StyleSheetParser<'a> {
node: Stmt::Style(s),
span,
}),
#[allow(clippy::match_same_arms)]
Expr::AtRule(a) => match a {
AtRule::For(f) => stmts.extend(f.ruleset_eval(scope, super_selector, None)?),
AtRule::While(w) => {

View File

@ -214,7 +214,7 @@ impl From<i64> for Number {
}
}
// todo: implement std::convertTryFrom instead
#[allow(clippy::fallible_impl_from)]
impl From<f64> for Number {
fn from(b: f64) -> Self {
Number::Big(BigRational::from_float(b).unwrap())
@ -241,10 +241,10 @@ impl Display for Number {
let mut whole = self.to_integer().abs();
let has_decimal = self.is_decimal();
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 {
for _ in 0..(PRECISION - 1) {
frac *= Self::from(10);
frac *= 10_i64;
write!(dec, "{}", frac.to_integer())?;
frac = frac.fract();
if frac.is_zero() {
@ -252,7 +252,7 @@ impl Display for Number {
}
}
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() {
loop {
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 {
fn mul_assign(&mut self, other: Self) {
let tmp = mem::take(self);

View File

@ -77,7 +77,7 @@ impl Value {
}
}
_ => false,
}
},
s => s == other.eval(span)?.node,
})
.span(span))
@ -151,7 +151,7 @@ impl Value {
}
}
_ => true,
}
},
s => s != other.eval(span)?.node,
})
.span(span))
@ -487,11 +487,7 @@ impl Value {
)
}
}
Self::List(..) => Value::String(
format!("{}{}-{}", num, unit, other.to_css_string(span)?),
QuoteKind::None,
),
Self::String(..) => Value::String(
Self::List(..) | Self::String(..) => Value::String(
format!("{}{}-{}", num, unit, other.to_css_string(span)?),
QuoteKind::None,
),

View File

@ -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()
.iter()
.fold(0, |total, this| total * 10 + i64::from(this - b'0'))
@ -741,7 +741,7 @@ impl Value {
let n = if val.dec_len == 0 {
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(
Number::new_machine(n),
unit,
@ -751,7 +751,7 @@ impl Value {
BigRational::new_raw(val.num.parse::<BigInt>().unwrap(), BigInt::one())
} else {
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(
Number::new_machine(n),
unit,
@ -884,9 +884,10 @@ impl Value {
IntermediateValue::Comma.span(span)
}
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() {
span = span.merge(toks.next().unwrap().pos());
span = span.merge(toks.next().unwrap().pos);
match q {
'>' => Op::GreaterThanEqual,
'<' => Op::LessThanEqual,