remove usage of .expect

This commit is contained in:
ConnorSkees 2020-05-24 16:57:07 -04:00
parent 2a4d4f960b
commit 21d830d6ff
3 changed files with 10 additions and 25 deletions

View File

@ -1,4 +1,4 @@
use std::ffi::OsStr; use std::ffi::{OsStr, OsString};
use std::path::Path; use std::path::Path;
use codemap::{CodeMap, Spanned}; use codemap::{CodeMap, Spanned};
@ -18,32 +18,26 @@ pub(crate) fn import(
todo!("absolute import") todo!("absolute import")
} }
let path_buf = ctx.parent().unwrap_or(Path::new("")).join(path); 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")) { if path_buf.extension() == Some(OsStr::new(".css")) {
// || name.starts_with("http://") || name.starts_with("https://") { // || name.starts_with("http://") || name.starts_with("https://") {
todo!("handle css imports") todo!("handle css imports")
} }
let mut p1 = path_buf.clone(); let mut p1 = path_buf.clone();
p1.push("index.scss"); p1.push(OsString::from("index.scss"));
let mut p2 = path_buf.clone(); let mut p2 = path_buf.clone();
p2.push("_index.scss"); p2.push(OsString::from("_index.scss"));
let paths = [ let paths = [
path_buf.with_file_name(format!( path_buf.with_file_name(name).with_extension("scss"),
"{}.scss", path_buf.with_file_name(format!("_{}.scss", name.to_str().unwrap())),
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, path_buf,
p1, p1,
p2, p2,
]; ];
for name in &paths { for name in &paths {
if name.is_file() { if name.is_file() {
let (rules2, scope2) = let (rules2, scope2) = StyleSheet::export_from_path(&name.to_str().unwrap(), map)?;
StyleSheet::export_from_path(&name.to_str().expect("path should be UTF-8"), map)?;
rules.extend(rules2); rules.extend(rules2);
scope.extend(scope2); scope.extend(scope2);
} }

View File

@ -46,8 +46,6 @@ grass input.scss
clippy::unreachable, clippy::unreachable,
// _ => {} has many valid use cases // _ => {} has many valid use cases
clippy::wildcard_enum_match_arm, 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! // this is too pedantic -- we are allowed to add numbers!
clippy::integer_arithmetic, clippy::integer_arithmetic,
// 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
@ -71,7 +69,6 @@ grass input.scss
clippy::panic, clippy::panic,
clippy::option_unwrap_used, clippy::option_unwrap_used,
clippy::result_unwrap_used, clippy::result_unwrap_used,
clippy::result_expect_used,
clippy::cast_possible_truncation, clippy::cast_possible_truncation,
clippy::single_match_else, clippy::single_match_else,
clippy::indexing_slicing, clippy::indexing_slicing,

View File

@ -83,14 +83,8 @@ impl Css {
for rule in rules { for rule in rules {
match rule.node { match rule.node {
Stmt::RuleSet(_) => vals.extend(self.parse_stmt(rule.node)?), Stmt::RuleSet(_) => vals.extend(self.parse_stmt(rule.node)?),
Stmt::Style(s) => vals Stmt::Style(s) => vals.get_mut(0).unwrap().push_style(*s)?,
.get_mut(0) Stmt::MultilineComment(s) => vals.get_mut(0).unwrap().push_comment(s),
.expect("expected block to exist")
.push_style(*s)?,
Stmt::MultilineComment(s) => vals
.get_mut(0)
.expect("expected block to exist")
.push_comment(s),
Stmt::AtRule(AtRule::AtRoot(stmts)) => stmts Stmt::AtRule(AtRule::AtRoot(stmts)) => stmts
.into_iter() .into_iter()
.map(|r| Ok(vals.extend(self.parse_stmt(r.node)?))) .map(|r| Ok(vals.extend(self.parse_stmt(r.node)?)))