Skip to content

Commit 81740ae

Browse files
committed
Fix warnings
1 parent 70edb78 commit 81740ae

23 files changed

+91
-90
lines changed

src/lib.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ fn transform(ctx: CallContext) -> napi::Result<JsBuffer> {
6565
let opts = ctx.get::<JsObject>(0)?;
6666
let config: Config = ctx.env.from_js_value(opts)?;
6767
let code = unsafe { std::str::from_utf8_unchecked(&config.code) };
68-
let res = compile(code, config.minify.unwrap_or(false), config.targets);
68+
let res = compile(code, config.minify.unwrap_or(false), config.targets).unwrap();
6969

7070
Ok(ctx.env.create_buffer_with_data(res.into_bytes())?.into_raw())
7171
}
@@ -89,7 +89,7 @@ struct Config {
8989
pub minify: Option<bool>
9090
}
9191

92-
fn compile(code: &str, minify: bool, targets: Option<Browsers>) -> String {
92+
fn compile(code: &str, minify: bool, targets: Option<Browsers>) -> Result<String, std::fmt::Error> {
9393
let mut input = ParserInput::new(&code);
9494
let mut parser = Parser::new(&mut input);
9595
let rule_list = RuleListParser::new_for_stylesheet(&mut parser, TopLevelRuleParser {});
@@ -202,14 +202,14 @@ fn compile(code: &str, minify: bool, targets: Option<Browsers>) -> String {
202202
if first {
203203
first = false;
204204
} else {
205-
printer.newline();
205+
printer.newline()?;
206206
}
207207

208-
rule.to_css(&mut printer);
209-
printer.newline();
208+
rule.to_css(&mut printer)?;
209+
printer.newline()?;
210210
}
211211

212-
dest
212+
Ok(dest)
213213
}
214214

215215
#[cfg(test)]
@@ -219,17 +219,17 @@ mod tests {
219219
use self::indoc::indoc;
220220

221221
fn test(source: &str, expected: &str) {
222-
let res = compile(source, false, None);
222+
let res = compile(source, false, None).unwrap();
223223
assert_eq!(res, expected);
224224
}
225225

226226
fn minify_test(source: &str, expected: &str) {
227-
let res = compile(source, true, None);
227+
let res = compile(source, true, None).unwrap();
228228
assert_eq!(res, expected);
229229
}
230230

231231
fn prefix_test(source: &str, expected: &str, targets: Browsers) {
232-
let res = compile(source, false, Some(targets));
232+
let res = compile(source, false, Some(targets)).unwrap();
233233
assert_eq!(res, expected);
234234
}
235235

@@ -1927,7 +1927,7 @@ mod tests {
19271927
font-variant-caps: small-caps;
19281928
line-height: 1.2em;
19291929
}
1930-
"#, indoc! {".foo{font:italic small-caps 700 50% 12px/1.2em Helvetica,Times New Roman,sans-serif}"
1930+
"#, indoc! {".foo{font:italic small-caps 700 125% 12px/1.2em Helvetica,Times New Roman,sans-serif}"
19311931
});
19321932

19331933
test(r#"
@@ -1948,7 +1948,7 @@ mod tests {
19481948
font-size: 12px;
19491949
font-stretch: expanded;
19501950
}
1951-
"#, indoc! {".foo{font-family:Helvetica,Times New Roman,sans-serif;font-size:12px;font-stretch:50%}"
1951+
"#, indoc! {".foo{font-family:Helvetica,Times New Roman,sans-serif;font-size:12px;font-stretch:125%}"
19521952
});
19531953

19541954
test(r#"

src/macros.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ macro_rules! enum_property {
3131
}
3232

3333
impl $name {
34+
#[allow(dead_code)]
3435
pub fn from_str(s: &str) -> Option<Self> {
3536
match s {
3637
$(
@@ -73,6 +74,7 @@ macro_rules! enum_property {
7374
}
7475

7576
impl $name {
77+
#[allow(dead_code)]
7678
pub fn from_str(s: &str) -> Option<Self> {
7779
match s {
7880
$(

src/media_query.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl MediaList {
2626

2727
let mut media_queries = vec![];
2828
loop {
29-
let start_position = input.position();
29+
// let start_position = input.position();
3030
match input.parse_until_before(Delimiter::Comma, |i| MediaQuery::parse(i)) {
3131
Ok(mq) => {
3232
media_queries.push(mq);
@@ -179,7 +179,7 @@ impl ToCss for MediaQuery {
179179
}
180180
}
181181

182-
/// A binary `and` or `or` operator.
182+
// A binary `and` or `or` operator.
183183
enum_property!(Operator,
184184
And,
185185
Or
@@ -334,7 +334,7 @@ impl MediaFeatureExpression {
334334
input: &mut Parser<'i, 't>,
335335
) -> Result<Self, ParseError<'i, ()>> {
336336
// let mut requirements = ParsingRequirements::empty();
337-
let location = input.current_source_location();
337+
// let location = input.current_source_location();
338338
let ident = input.expect_ident()?;
339339

340340
// if context.in_ua_or_chrome_sheet() {

src/parser.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ impl<'b> TopLevelRuleParser {
7474

7575
/// A rule prelude for at-rule with block.
7676
#[derive(Debug)]
77+
#[allow(dead_code)]
7778
pub enum AtRulePrelude {
7879
/// A @font-face rule prelude.
7980
FontFace,
@@ -403,10 +404,8 @@ impl<'a, 'b> NestedRuleParser {
403404
while let Some(result) = iter.next() {
404405
match result {
405406
Ok(rule) => rules.push(rule),
406-
Err((error, slice)) => {
407-
let location = error.location;
408-
// let error = ContextualParseError::InvalidRule(slice, error);
409-
// self.context.log_css_error(location, error);
407+
Err(_) => {
408+
// TODO
410409
},
411410
}
412411
}
@@ -510,7 +509,7 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser {
510509
fn parse_block<'t>(
511510
&mut self,
512511
prelude: AtRulePrelude,
513-
start: &ParserState,
512+
_: &ParserState,
514513
input: &mut Parser<'i, 't>,
515514
) -> Result<CssRule, ParseError<'i, Self::Error>> {
516515
match prelude {
@@ -663,7 +662,7 @@ impl<'a, 'b, 'i> QualifiedRuleParser<'i> for NestedRuleParser {
663662
fn parse_block<'t>(
664663
&mut self,
665664
selectors: Self::Prelude,
666-
start: &ParserState,
665+
_: &ParserState,
667666
input: &mut Parser<'i, 't>,
668667
) -> Result<CssRule, ParseError<'i, Self::Error>> {
669668
// let declarations = parse_property_declaration_list(&context, input, Some(&selectors));

src/properties/background.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::values::{
55
color::CssColor,
66
image::Image
77
};
8-
use super::prefixes::{Feature, Browsers, is_webkit_gradient};
8+
use super::prefixes::{Browsers, is_webkit_gradient};
99
use crate::traits::{Parse, ToCss, PropertyHandler};
1010
use crate::macros::*;
1111
use crate::properties::{Property, VendorPrefix};
@@ -528,7 +528,7 @@ impl BackgroundHandler {
528528
if prefixes.contains(VendorPrefix::None) {
529529
dest.push(Property::Background(backgrounds));
530530
}
531-
531+
532532
self.reset();
533533
return
534534
}

src/properties/flex.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use cssparser::*;
22
use crate::macros::*;
33
use crate::values::{
4-
length::{LengthPercentageOrAuto, LengthPercentage, Length},
4+
length::{LengthPercentageOrAuto, LengthPercentage},
55
percentage::Percentage
66
};
77
use crate::traits::{Parse, ToCss, PropertyHandler, FromStandard};

src/properties/font.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ impl Default for FontStretchKeyword {
166166

167167
impl FontStretchKeyword {
168168
fn to_percentage(&self) -> Percentage {
169+
use FontStretchKeyword::*;
169170
let val = match self {
170171
UltraCondensed => 0.5,
171172
ExtraCondensed => 0.625,
@@ -482,7 +483,7 @@ impl Parse for Font {
482483
let mut style = None;
483484
let mut weight = None;
484485
let mut stretch = None;
485-
let mut size = None;
486+
let size;
486487
let mut variant_caps = None;
487488

488489
loop {

src/properties/mod.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(non_upper_case_globals)]
2+
13
pub mod custom;
24
pub mod margin_padding;
35
pub mod background;
@@ -89,7 +91,7 @@ impl ToCss for VendorPrefix {
8991

9092
macro_rules! define_properties {
9193
(
92-
$( $name: tt: $property: ident($type: ty $(, $vp: ident)?) $( / $prefix: tt )*, )+
94+
$( $name: tt: $property: ident($type: ty $(, $vp: ty)?) $( / $prefix: tt )*, )+
9395
) => {
9496
#[derive(Debug, Clone, PartialEq)]
9597
pub enum Property {
@@ -129,13 +131,20 @@ macro_rules! define_properties {
129131
pub fn to_css<W>(&self, dest: &mut Printer<W>, important: bool) -> std::fmt::Result where W: std::fmt::Write {
130132
use Property::*;
131133

134+
macro_rules! vp_name {
135+
($x: ty, $n: ident) => {
136+
$n
137+
};
138+
}
139+
132140
match self {
133141
$(
134-
$property(val, $($vp)?) => {
142+
$property(val, $(vp_name!($vp, prefix))?) => {
135143
// If there are multiple vendor prefixes set, this expands them.
136144
let mut first = true;
137145
macro_rules! start {
138146
() => {
147+
#[allow(unused_assignments)]
139148
if first {
140149
first = false;
141150
} else {
@@ -161,8 +170,8 @@ macro_rules! define_properties {
161170
start!();
162171
write!();
163172
};
164-
($v: ident, $p: expr) => {
165-
if $v.contains($p) {
173+
($v: ty, $p: expr) => {
174+
if prefix.contains($p) {
166175
start!();
167176
$p.to_css(dest)?;
168177
write!();

src/properties/overflow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub struct OverflowHandler {
5353
}
5454

5555
impl PropertyHandler for OverflowHandler {
56-
fn handle_property(&mut self, property: &Property, dest: &mut DeclarationList) -> bool {
56+
fn handle_property(&mut self, property: &Property, _: &mut DeclarationList) -> bool {
5757
use Property::*;
5858

5959
match property {

src/properties/prefixes.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub struct Browsers {
1616
pub samsung: Option<u32>
1717
}
1818

19+
#[allow(dead_code)]
1920
pub enum Feature {
2021
AlignContent,
2122
AlignItems,

0 commit comments

Comments
 (0)