From 3d0ae02b0ac2256856b3542f5d164e55b1e1570e Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Sun, 5 Jan 2020 12:52:50 -0500 Subject: [PATCH] clippy & rustfmt --- src/css.rs | 11 +++++------ src/format.rs | 5 ++++- src/lexer.rs | 6 ++---- src/main.rs | 13 +++++++++---- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/css.rs b/src/css.rs index b9dd41f..fce4cef 100644 --- a/src/css.rs +++ b/src/css.rs @@ -1,7 +1,6 @@ -//! # Convert from SCSS AST to CSS +//! # Convert from SCSS AST to CSS +use crate::{RuleSet, Selector, Stmt, Style, StyleSheet}; use std::io; -use crate::{Selector, Style, StyleSheet, Stmt, RuleSet}; - #[derive(Debug, Clone)] pub struct Block { @@ -10,7 +9,7 @@ pub struct Block { } impl Block { - fn new(selector: Selector) -> Self { + const fn new(selector: Selector) -> Self { Block { selector, styles: Vec::new(), @@ -29,7 +28,7 @@ pub struct Css { } impl Css { - pub fn new() -> Self { + pub const fn new() -> Self { Css { blocks: Vec::new(), idx: 0, @@ -91,4 +90,4 @@ impl Css { } Ok(()) } -} \ No newline at end of file +} diff --git a/src/format.rs b/src/format.rs index 6708d6c..e061709 100644 --- a/src/format.rs +++ b/src/format.rs @@ -99,7 +99,10 @@ impl PrettyPrinter { /// Pretty print a special form of SCSS that shows what the full selectors are for children /// Meant for debugging /// Empty rules are included - pub(crate) fn pretty_print_preserve_super_selectors(&mut self, s: &StyleSheet) -> io::Result<()> { + pub(crate) fn pretty_print_preserve_super_selectors( + &mut self, + s: &StyleSheet, + ) -> io::Result<()> { for rule in &s.rules { self.pretty_print_stmt(rule)?; } diff --git a/src/lexer.rs b/src/lexer.rs index 8125336..61ddb11 100644 --- a/src/lexer.rs +++ b/src/lexer.rs @@ -127,10 +127,8 @@ impl<'a> Lexer<'a> { } '*' => { while let Some(tok) = self.buf.next() { - if tok == '*' { - if self.buf.next() == Some('/') { - break; - } + if tok == '*' && self.buf.next() == Some('/') { + break; } } } diff --git a/src/main.rs b/src/main.rs index c98bd30..b095908 100644 --- a/src/main.rs +++ b/src/main.rs @@ -240,7 +240,9 @@ impl<'a> StyleSheetParser<'a> { | TokenKind::Symbol(Symbol::Hash) | TokenKind::Symbol(Symbol::Colon) | TokenKind::Symbol(Symbol::Mul) - | TokenKind::Symbol(Symbol::Period) => rules.extend(self.eat_rules(Selector::None)), + | TokenKind::Symbol(Symbol::Period) => { + rules.extend(self.eat_rules(&Selector::None)) + } TokenKind::Whitespace(_) | TokenKind::Symbol(_) => { self.lexer.next(); continue; @@ -251,13 +253,13 @@ impl<'a> StyleSheetParser<'a> { StyleSheet { rules } } - fn eat_rules(&mut self, super_selector: Selector) -> Vec { + fn eat_rules(&mut self, super_selector: &Selector) -> Vec { let mut stmts = Vec::new(); while let Ok(tok) = self.eat_expr() { match tok { Expr::Style(s) => stmts.push(Stmt::Style(s)), Expr::Selector(s) => { - let rules = self.eat_rules(super_selector.clone().zip(s.clone())); + let rules = self.eat_rules(&super_selector.clone().zip(s.clone())); stmts.push(Stmt::RuleSet(RuleSet { super_selector: super_selector.clone(), selector: s, @@ -306,7 +308,10 @@ fn main() -> io::Result<()> { let mut stdout = std::io::stdout(); let s = StyleSheet::new(&input); // dbg!(s); - s.pretty_print(&mut stdout)?; + // s.pretty_print(&mut stdout)?; + // s.pretty_print_selectors(&mut stdout)?; + s.print_as_css(&mut stdout)?; + // dbg!(Css::from_stylesheet(s)); // println!("{}", s); // drop(input); Ok(())