From 21d830d6ff9fbeb77f16f2c9c6a98ef8484d052d Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Sun, 24 May 2020 16:57:07 -0400 Subject: [PATCH] remove usage of `.expect` --- src/imports.rs | 22 ++++++++-------------- src/lib.rs | 3 --- src/output.rs | 10 ++-------- 3 files changed, 10 insertions(+), 25 deletions(-) diff --git a/src/imports.rs b/src/imports.rs index 2b87429..5220b3e 100644 --- a/src/imports.rs +++ b/src/imports.rs @@ -1,4 +1,4 @@ -use std::ffi::OsStr; +use std::ffi::{OsStr, OsString}; use std::path::Path; use codemap::{CodeMap, Spanned}; @@ -18,32 +18,26 @@ pub(crate) fn import( todo!("absolute import") } let path_buf = ctx.parent().unwrap_or(Path::new("")).join(path); - let name = path_buf.file_name().expect("todo! path ended in `..`"); + // "todo: will panic if path ended in `..`" + let name = path_buf.file_name().unwrap(); if path_buf.extension() == Some(OsStr::new(".css")) { // || name.starts_with("http://") || name.starts_with("https://") { todo!("handle css imports") } let mut p1 = path_buf.clone(); - p1.push("index.scss"); + p1.push(OsString::from("index.scss")); let mut p2 = path_buf.clone(); - p2.push("_index.scss"); + p2.push(OsString::from("_index.scss")); let paths = [ - path_buf.with_file_name(format!( - "{}.scss", - name.to_str().expect("path should be UTF-8") - )), - path_buf.with_file_name(format!( - "_{}.scss", - name.to_str().expect("path should be UTF-8") - )), + path_buf.with_file_name(name).with_extension("scss"), + path_buf.with_file_name(format!("_{}.scss", name.to_str().unwrap())), path_buf, p1, p2, ]; for name in &paths { if name.is_file() { - let (rules2, scope2) = - StyleSheet::export_from_path(&name.to_str().expect("path should be UTF-8"), map)?; + let (rules2, scope2) = StyleSheet::export_from_path(&name.to_str().unwrap(), map)?; rules.extend(rules2); scope.extend(scope2); } diff --git a/src/lib.rs b/src/lib.rs index 50382e7..ea2baef 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -46,8 +46,6 @@ grass input.scss 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, // 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 @@ -71,7 +69,6 @@ grass input.scss clippy::panic, clippy::option_unwrap_used, clippy::result_unwrap_used, - clippy::result_expect_used, clippy::cast_possible_truncation, clippy::single_match_else, clippy::indexing_slicing, diff --git a/src/output.rs b/src/output.rs index da1d3ae..95bdc7c 100644 --- a/src/output.rs +++ b/src/output.rs @@ -83,14 +83,8 @@ impl Css { for rule in rules { match rule.node { Stmt::RuleSet(_) => vals.extend(self.parse_stmt(rule.node)?), - Stmt::Style(s) => vals - .get_mut(0) - .expect("expected block to exist") - .push_style(*s)?, - Stmt::MultilineComment(s) => vals - .get_mut(0) - .expect("expected block to exist") - .push_comment(s), + Stmt::Style(s) => vals.get_mut(0).unwrap().push_style(*s)?, + Stmt::MultilineComment(s) => vals.get_mut(0).unwrap().push_comment(s), Stmt::AtRule(AtRule::AtRoot(stmts)) => stmts .into_iter() .map(|r| Ok(vals.extend(self.parse_stmt(r.node)?)))